[wiican: 7/15] [m][ui] wiican indicator merged to a single menu app



commit 5d44b073b80431755b33a35fb4d2dddc6ed5be46
Author: J. FÃlix OntaÃÃn <fontanon emergya es>
Date:   Fri Aug 5 20:53:46 2011 +0200

    [m][ui] wiican indicator merged to a single menu app

 bin/wiican             |   59 +++++++++++++++++++++--------------------------
 data/wiimotemanager.ui |   18 ++++++++++++++
 2 files changed, 44 insertions(+), 33 deletions(-)
---
diff --git a/bin/wiican b/bin/wiican
index fdc865e..498928b 100755
--- a/bin/wiican
+++ b/bin/wiican
@@ -44,6 +44,10 @@ from wiican.service import WIICAN_PATH, WIICAN_URI
 from wiican.service import WC_DISABLED, WC_BLUEZ_PRESENT, WC_UINPUT_PRESENT, \
     WC_WIIMOTE_DISCOVERING
 
+# Disconnect menuitem position is needed for adding mappings below on menu
+DISCONNECT_MENUITEM_POSITION = 4
+
+# The mapping manager single instance
 mapping_manager = MappingManager()
 
 class WiicanIndicator(appindicator.Indicator, GConfStore):
@@ -57,6 +61,7 @@ class WiicanIndicator(appindicator.Indicator, GConfStore):
         GConfStore.__init__(self, GCONF_KEY)
 
         self.set_status (appindicator.STATUS_ACTIVE)
+        self.menu_mappings = []
 
         # Load UI
         builder = gtk.Builder()
@@ -68,9 +73,11 @@ class WiicanIndicator(appindicator.Indicator, GConfStore):
         self.main_menu = builder.get_object('main_menu')
         self.mngrstartup_menuitem = builder.get_object('mngrstartup_menuitem')
         self.error_menuitem = builder.get_object('error_menuitem')
+        self.disconnect_menuitem = builder.get_object('disconnect_menuitem')
 
         self.set_menu(self.main_menu)
         self.aboutdlg.connect('response', lambda d, r: d.hide())
+        self.disconnect_menuitem.connect('activate', self.__discover_cb, -1)
 
         self.__animation = PngAnimation(['wiican-on', 'wiican-discover1', 
             'wiican-discover2', 'wiican-discover3'])
@@ -109,16 +116,16 @@ class WiicanIndicator(appindicator.Indicator, GConfStore):
         self.set_icon('wiican-off')
         self.error_menuitem.get_child().set_text(_('Plug a bluetooth adapter'))
         self.error_menuitem.set_visible(True)
-        self.__disconnect_item.set_sensitive(False)
+        self.disconnect_menuitem.set_sensitive(False)
 
     def __set_no_uinput_st(self):
         self.set_icon('wiican-off')
         self.error_menuitem.get_child().set_text(_('Please load uinput module first'))
         self.error_menuitem.set_visible(True)
-        self.__disconnect_item.set_sensitive(False)
+        self.disconnect_menuitem.set_sensitive(False)
 
     def __idle_st(self):
-        self.__disconnect_item.set_sensitive(False)
+        self.disconnect_menuitem.set_sensitive(False)
         self.error_menuitem.set_visible(False)
         self.set_icon('wiican-on')
 
@@ -130,27 +137,20 @@ class WiicanIndicator(appindicator.Indicator, GConfStore):
                 self.set_icon(self.__animation.next())
                 return True
 
-        self.__disconnect_item.set_sensitive(True)
+        self.disconnect_menuitem.set_sensitive(True)
         gobject.timeout_add(500, animate)
 
     def __load_mappings_menu(self):
-        self.__mappings_menu = gtk.Menu()
-
-        disconnect_item = gtk.ImageMenuItem(gtk.STOCK_DISCONNECT)
-        disconnect_item.connect('activate', self.__discover_cb, -1)
-        disconnect_item.show()
-        self.__mappings_menu.append(disconnect_item)
-        self.__disconnect_item = disconnect_item
-        if not self.__cur_status & WC_WIIMOTE_DISCOVERING:
-            self.__disconnect_item.set_sensitive(False)
-
-        sep_item = gtk.SeparatorMenuItem()
-        sep_item.show()
-        self.__mappings_menu.append(sep_item)
+        # Remove all mapping menuitems before addin<g the updated list
+        for mapping_menuitem in self.menu_mappings:
+            self.main_menu.remove(mapping_menuitem)
 
+        # Check for mappings via manager
         mapping_manager.scan_mappings()
 
+        # Add mappings to menu
         no_visible_mappings = True
+        cur_position = DISCONNECT_MENUITEM_POSITION + 1
         for mapping_id, mapping in mapping_manager.items():
             if not mapping_manager.is_visible(mapping_id):
                 continue
@@ -161,25 +161,18 @@ class WiicanIndicator(appindicator.Indicator, GConfStore):
             menuitem.set_image(gtk.image_new_from_pixbuf(icon))
             menuitem.connect('activate', self.__discover_cb, mapping)
             menuitem.show()
-            self.__mappings_menu.append(menuitem)
             no_visible_mappings = False
+            self.main_menu.insert(menuitem, cur_position)
+            self.menu_mappings.append(menuitem)
+            cur_position += 1
 
         if no_visible_mappings:
-            add_mappings_item = gtk.MenuItem(_('Add visible mappings'))
-            add_mappings_item.connect('activate', self.preferences_cb)
-            add_mappings_item.show()
-            self.__mappings_menu.append(add_mappings_item)
-
-    def __icon_popupmenu_cb(self, status_icon, button, activate_time, data):
-        self.main_menu.popup(None, None, gtk.status_icon_position_menu, button, 
-                activate_time, status_icon)
-
-    def __activate_cb(self, status_icon):
-        if self.__cur_status & WC_UINPUT_PRESENT and \
-                self.__cur_status & WC_BLUEZ_PRESENT:
-            self.__mappings_menu.popup(None, None, 
-                    gtk.status_icon_position_menu, 1, 
-                    gtk.get_current_event_time(), status_icon)
+            menuitem = gtk.MenuItem(_('Set some visible mappings'))
+            menuitem.connect('activate', self.preferences_cb)
+            menuitem.show()
+            self.main_menu.insert(menuitem, cur_position)
+            self.menu_mappings.append(menuitem)
+            cur_position += 1
 
     def mngrstartup_menuitem_toggled_cb(self, widget):
         self.options['show_manager_on_startup'] = widget.get_active()
diff --git a/data/wiimotemanager.ui b/data/wiimotemanager.ui
index 30632ab..fc85b2d 100644
--- a/data/wiimotemanager.ui
+++ b/data/wiimotemanager.ui
@@ -893,6 +893,24 @@ Ulisse &lt;ulisail yahoo it&gt;</property>
       <object class="GtkSeparatorMenuItem" id="menuitem3">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
+        <property name="resize_mode">queue</property>
+      </object>
+    </child>
+    <child>
+      <object class="GtkImageMenuItem" id="disconnect_menuitem">
+        <property name="label">gtk-disconnect</property>
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="use_action_appearance">False</property>
+        <property name="use_underline">True</property>
+        <property name="use_stock">True</property>
+      </object>
+    </child>
+    <child>
+      <object class="GtkSeparatorMenuItem" id="menuitem1">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="use_action_appearance">False</property>
       </object>
     </child>
     <child>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]