meld r1140 - trunk



Author: kaiw
Date: Sun Feb  1 08:02:37 2009
New Revision: 1140
URL: http://svn.gnome.org/viewvc/meld?rev=1140&view=rev

Log:
Make tooltips for menu and toolbar items appear in the statusbar

This code was adapted from pygtk/examples/gtk/application.py



Modified:
   trunk/meldapp.py

Modified: trunk/meldapp.py
==============================================================================
--- trunk/meldapp.py	(original)
+++ trunk/meldapp.py	Sun Feb  1 08:02:37 2009
@@ -541,6 +541,9 @@
         self.ui = gtk.UIManager()
         self.ui.insert_action_group(self.actiongroup, 0)
         self.ui.add_ui_from_file(ui_file)
+        self.ui.connect("connect-proxy", self._on_uimanager_connect_proxy)
+        self.ui.connect("disconnect-proxy", self._on_uimanager_disconnect_proxy)
+
         for menuitem in ("Save", "Undo"):
             self.actiongroup.get_action(menuitem).props.is_important = True
         self.widget.add_accel_group(self.ui.get_accel_group())
@@ -548,6 +551,8 @@
         self.toolbar = self.ui.get_widget('/Toolbar')
         self.appvbox.pack_start(self.menubar, expand=False)
         self.appvbox.pack_start(self.toolbar, expand=False)
+        # TODO: should possibly use something other than doc_status
+        self._menu_context = self.doc_status.get_context_id("Tooltips")
         self.statusbar = MeldStatusBar(self.task_progress, self.task_status, self.doc_status)
         self.prefs = MeldPreferences()
         if not developer:#hide magic testing button
@@ -564,6 +569,34 @@
         self.ui.ensure_update()
         self.widget.show()
 
+    def _on_uimanager_connect_proxy(self, ui, action, widget):
+        tooltip = action.props.tooltip
+        if not tooltip:
+            return
+        if isinstance(widget, gtk.MenuItem):
+            cid = widget.connect("select", self._on_action_item_select_enter, tooltip)
+            cid2 = widget.connect("deselect", self._on_action_item_deselect_leave)
+            widget.set_data("meldapp::proxy-signal-ids", (cid, cid2))
+        elif isinstance(widget, gtk.ToolButton):
+            cid = widget.child.connect("enter", self._on_action_item_select_enter, tooltip)
+            cid2 = widget.child.connect("leave", self._on_action_item_deselect_leave)
+            widget.set_data("meldapp::proxy-signal-ids", (cid, cid2))
+
+    def _on_uimanager_disconnect_proxy(self, ui, action, widget):
+        cids = widget.get_data("meldapp::proxy-signal-ids")
+        if not cids:
+            return
+        if isinstance(widget, gtk.ToolButton):
+            widget = widget.child
+        for cid in cids:
+            widget.disconnect(cid)
+
+    def _on_action_item_select_enter(self, item, tooltip):
+        self.statusbar.doc_status.push(self._menu_context, tooltip)
+
+    def _on_action_item_deselect_leave(self, item):
+        self.statusbar.doc_status.pop(self._menu_context)
+
     def on_idle(self):
         ret = self.scheduler.iteration()
         if ret:



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