Remove the entry_filters argument from *View constructors.
authorMatthijs Kooijman <matthijs@stdin.nl>
Mon, 17 Aug 2009 21:41:08 +0000 (23:41 +0200)
committerMatthijs Kooijman <matthijs@stdin.nl>
Mon, 17 Aug 2009 21:41:08 +0000 (23:41 +0200)
src/gui/gui.py
src/gui/project_details/project_view.py
src/gui/projects_list/project_list_view.py

index 1dc34b291ea2d2875aa3405657900e978701188a..0247175fc22ee76eb165184427b36aa257f67cd0 100644 (file)
@@ -236,13 +236,26 @@ class KeyBindingView(object):
             self.view.bind(key,no_action)
 
 class SearchableListView(WidgetBasedListView):
-    def __init__(self,entry_filters):
-        self.current_entry_filter_index = 0
-        self.entry_filters = entry_filters
-        self.filtered_list = self.entry_filters[0]
+    def __init__(self):
+        self.current_entry_filter_index = -1
+        self.entry_filters = []
+        self.filtered_list = lambda:[]
         self.lock = None
         super(SearchableListView,self).__init__()
 
+    def set_filters(self, entry_filters):
+        """
+        Set the filters that could be applied to this list. Each filter
+        can be applied in turn by calling switch_entry_filter (for
+        example from a key binding).
+
+        The entry_filters argument should be a list of filters. The
+        active filter is stored into self.filtered_list and should be
+        processed by generate_widgets in the subclass.
+        """
+        self.current_entry_filter_index = 0
+        self.entry_filters = entry_filters
+        self.filtered_list = self.entry_filters[0]
 
     def search_item(self):
         selected_item = appuifw.selection_list(self.all_widget_texts(),search_field=1)
@@ -250,6 +263,7 @@ class SearchableListView(WidgetBasedListView):
             selected_item = self.selected_index()
         self.view.set_list(self.items(),selected_item)
         self.set_bindings_for_selection(selected_item)
+
     def switch_entry_filter(self):
         self.current_entry_filter_index += 1
         self.filtered_list = self.entry_filters[self.current_entry_filter_index % len(self.entry_filters)]
@@ -257,9 +271,9 @@ class SearchableListView(WidgetBasedListView):
 
 
 class EditableListView(SearchableListView,KeyBindingView):
-    def __init__(self,entry_filters):
+    def __init__(self):
         KeyBindingView.__init__(self)
-        super(EditableListView, self).__init__(entry_filters)
+        super(EditableListView, self).__init__()
 
     def key_and_menu_bindings(self,selected_index):
         key_and_menu_bindings=[]
index f1bc81af93351426d10f2af7b1be522bd61eeb58..7827009e621d6a9f2dcce89a01553caf5c9f2249 100644 (file)
@@ -63,9 +63,10 @@ class ProjectView(EditableListView):
     def __init__(self,project):
         self.project = project
         self.project.observers.append(self)
-        super(ProjectView, self).__init__([lambda:self.project.actions.with_property(lambda a:a.status==action.active)])
+        super(ProjectView, self).__init__()
         self.set_keybindings(ACTION_LIST_KEYS_AND_MENU)
         self.set_title(self.project.name)
+        self.set_filters([lambda:self.project.actions.with_property(lambda a:a.status==action.active)])
 
     def exit(self):
         self.project.observers.remove(self)
index 80bffec06f1016c1d09c5ccc1608d90bf131c282..bbb81f6085627f37c0d40e2cda12f5f611f444e5 100644 (file)
@@ -24,9 +24,10 @@ class ProjectListView(EditableListView):
     def __init__(self,projects):
         self.projects = projects
         self.projects.observers.append(self)
-        super(ProjectListView, self).__init__([lambda:projects])
+        super(ProjectListView, self).__init__()
         self.set_keybindings(PROJECT_LIST_KEYS_AND_MENU)
         self.set_title(u'Projects')
+        self.set_filters([lambda:projects])
         #appuifw.note(u'Before starting thread')
 #        thread.start_new_thread(projects.process,())
         #appuifw.note(u'After starting thread %s'%repr(projects.observers))