added fields configurator for entry window
authorMax Usachev <maxusachev@gmail.com>
Tue, 15 Jun 2010 13:11:13 +0000 (16:11 +0300)
committerMax Usachev <maxusachev@gmail.com>
Tue, 15 Jun 2010 13:11:13 +0000 (16:11 +0300)
controller.py
ui/hildon_ui.py
ui/ui.py

index a6c347c..e160e8f 100644 (file)
@@ -11,7 +11,7 @@ class MeabookController:
     def __init__(self, model, view_class, config):
         self.config = config
         self.model = model
-        self.view = view_class(self)
+        self.view = view_class(self, self.config)
         self.view.start()
 
     def stop(self):
index 588c191..25e7a1c 100644 (file)
@@ -22,8 +22,8 @@ def create_button(title, value):
 
 
 class HildonMeabook(MeabookUI):
-    def __init__(self, controller):
-        MeabookUI.__init__(self, controller)
+    def __init__(self, controller, config):
+        MeabookUI.__init__(self, controller, config)
         self.handler = None
         self.window = hildon.StackableWindow()
         self.window.set_title(_('Meabook'))
@@ -106,20 +106,46 @@ class HildonMeabook(MeabookUI):
         self._set_selector_content(selector, handler, items)
         window.show_all()
 
-    def _show_item_dialog(self, title, entry):
+    def _show_item_dialog(self, title, entry_id):
         """Shows detailed item information."""
 
+        def show_settings_dialog(widget, parent, func1, func2, entry_id):
+            dialog = ConfigurationDialog(self.controller, self.config)
+            getattr(dialog, func1)(None, parent)
+            func2(parent, entry_id)
+
+        def update_entry(window, entry_id):
+            pannable_area = hildon.PannableArea()
+            vbox = gtk.VBox()
+            for fname, fvalue in self.controller.get_item(entry_id):
+                button = create_button(_(fname) , fvalue)
+                vbox.pack_start(button, expand=False)
+            pannable_area.add_with_viewport(vbox)
+            child = window.get_child()
+            if child:
+                child.destroy()
+            window.add(pannable_area)
+            pannable_area.show_all()
+
+
+        # create widgets
         window = hildon.StackableWindow()
         window.set_title(title)
-        pannable_area = hildon.PannableArea()
-        vbox = gtk.VBox()
-
-        for fname, fvalue in entry:
-            button = create_button(_(fname) , fvalue)
-            vbox.pack_start(button, expand=False)
-
-        pannable_area.add_with_viewport(vbox)
-        window.add(pannable_area)
+        menu = hildon.AppMenu()
+        fields_button = hildon.Button(gtk.HILDON_SIZE_AUTO, \
+            hildon.BUTTON_ARRANGEMENT_HORIZONTAL, _('Fields to show'))
+        order_button = hildon.Button(gtk.HILDON_SIZE_AUTO, \
+            hildon.BUTTON_ARRANGEMENT_HORIZONTAL, _('Fields order'))
+        fields_button.connect('clicked', show_settings_dialog, window, \
+            'show_fields_settings_cb', update_entry, entry_id)
+        order_button.connect('clicked', show_settings_dialog, window, \
+            'show_order_settings_cb', update_entry, entry_id)
+        menu.append(fields_button)
+        menu.append(order_button)
+
+        update_entry(window, entry_id)
+        window.set_app_menu(menu)
+        menu.show_all()
         window.show_all()
 
 
@@ -168,7 +194,8 @@ class HildonMeabook(MeabookUI):
         self._unfreeze_ui()
 
     def create_configuration_dialog(self, controller, config):
-        ConfigurationDialog(controller, config)
+        dialog = ConfigurationDialog(controller, config)
+        dialog.run()
 
 
     # Hildon UI callbacks
@@ -220,7 +247,8 @@ class HildonMeabook(MeabookUI):
             self._show_items_dialog(_iter[0], self.controller.get_items(\
                 _iter[1]))
         else:
-            self._show_item_dialog(_iter[0], self.controller.get_item(_iter[1]))
+            #self._show_item_dialog(_iter[0], self.controller.get_item(_iter[1]))
+            self._show_item_dialog(_iter[0], _iter[1])
 
 
 
@@ -232,6 +260,7 @@ class ConfigurationDialog:
         self.config = config
         self.controller = controller
 
+    def run(self):
         dialog = hildon.Dialog()
         dialog.set_title(_('Settings'))
 
index 173a3b7..8b3cd4c 100644 (file)
--- a/ui/ui.py
+++ b/ui/ui.py
@@ -3,7 +3,8 @@ General Meabook UI
 """
 
 class MeabookUI:
-    def __init__(self, controller):
+    def __init__(self, controller, config):
+        self.config = config
         self.controller = controller
 
     def start(self):