Move the update method to View.
[matthijs/upstream/mobilegtd.git] / src / gui / gui.py
index 815edc5be6fc2cda7afcbc6334a8a7565d63f5e2..f03880854f2310bdccda1216bc322c4a60e1277a 100644 (file)
@@ -137,14 +137,30 @@ class View(object):
     def exit(self):
         self.exit_flag = True
         self.lock.signal()
-        super(View, self).exit()
+
+    def update(self,subject=None):
+        """
+        Update the current view (e.g., make sure refresh is called). We
+        can't call it directly, since we're in another thread.
+        """
+        if self.lock:
+            self.lock.signal()
 
     def refresh(self):
         """
-        Update the gui after a change in model or some user interaction.
-        Should be filled by subclasses.
+        Called when the current view must be updated. Never call
+        directly. Subclasses should extend this method, not update.
+        """
+        appuifw.app.menu=self.get_menu_entries()
+
+    def get_menu_entries(self):
+        """ Returns a list of menu entries to display. Will be
+        automatically updated on each refresh.
+
+        Each menu entry is a tuple of a title for the entry and a
+        function to call when the entry is selected.
         """
-        super(View, self).refresh()
+        return []
 
 class ListView(View):
     def __init__(self):
@@ -156,14 +172,8 @@ class ListView(View):
         This function is called when the user selects an an entry (e.g.,
         navigates to it and push the ok button).
         """
-        super(ListView).entry_selected()
+        pass
     
-    def update(self,subject=None):
-        #logger.log(u'Updated %s'%repr(self))
-        if self.lock:
-            self.lock.signal()
-        #pass
-
     def index_changed(self,adjustment=None):
         if adjustment:
             index = self.selected_index() + adjustment
@@ -175,9 +185,6 @@ class ListView(View):
             index = 0
         self.set_bindings_for_selection(index)
 
-    def refresh(self):
-        appuifw.app.menu=self.get_menu_entries()
-
     def set_index(self,index):
         if index > len(self.widgets):
             index = len(self.widgets)
@@ -188,7 +195,6 @@ class ListView(View):
     def selected_index(self):
         return self.view.current()
 
-
 class WidgetBasedListView(ListView):
     def __init__(self):
         self.widgets = self.generate_widgets()
@@ -218,7 +224,7 @@ class WidgetBasedListView(ListView):
         return self.widgets[self.selected_index()]
         
 
-class KeyBindingView(object):
+class KeyBindingView(View):
     
     def __init__(self):
         self.binding_map = {}
@@ -248,7 +254,8 @@ class KeyBindingView(object):
                     description='    '+description
                 menu_entries.append((description,function)) 
         menu_entries.append((u'Exit', self.exit))
-        return menu_entries       
+        return menu_entries + super(KeyBindingView, self).get_menu_entries()
+
     def set_bindings_for_selection(self,selected_index):
         self.remove_all_key_bindings()