From 10f263c5a2fd03d4517322f2f0b9f5a4bf7e2e91 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Sat, 19 Jul 2003 14:24:21 +0000 Subject: [PATCH] Make default menu positioning function keep the pointer inside the menu. Allow stock icons in menus. git-svn-id: https://rox.svn.sourceforge.net/svnroot/rox/trunk/ROX-Lib2@2878 66de3db3-b00d-0410-b41b-f4738ad19bea --- AppInfo.xml | 2 +- Help/Changes | 5 +++++ python/rox/Menu.py | 21 ++++++++++++++++----- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/AppInfo.xml b/AppInfo.xml index 22a54d9..52783aa 100644 --- a/AppInfo.xml +++ b/AppInfo.xml @@ -5,7 +5,7 @@ Shared library for ROX Thomas Leonard - 1.9.7 (21-May-2003) + 1.9.8 PREVIEW GNU General Public License http://rox.sourceforge.net diff --git a/Help/Changes b/Help/Changes index 110b643..63128e6 100644 --- a/Help/Changes +++ b/Help/Changes @@ -3,6 +3,11 @@ by Thomas Leonard http://rox.sourceforge.net +19-Jul-2003 +~~~~~~~~~~~ +Make default menu positioning function keep the pointer inside the menu. +Allow stock icons in menus. + 18-Jul-2003 ~~~~~~~~~~~ Added position_fn argument to rox.Menu.popup. diff --git a/python/rox/Menu.py b/python/rox/Menu.py index 131b886..5959f1e 100644 --- a/python/rox/Menu.py +++ b/python/rox/Menu.py @@ -24,7 +24,7 @@ menu = Menu('main', [ ('/Edit/', '', ''), ('/Edit/Process...', 'process', ''), ('/Options', 'show_options', ''), - ('/Help', 'help', '', 'F1'), + ('/Help', 'help', '', 'F1', g.STOCK_HELP), ]) """ @@ -61,17 +61,23 @@ class Menu: out = [] self.fns = [] for item in items: + stock = None + key = None if len(item) == 3: (label, fn, type) = item - key = None - else: + elif len(item) == 4: (label, fn, type, key) = item + else: + (label, fn, type, key, stock) = item if fn: self.fns.append(fn) cb = self._activate else: cb = None - out.append((label, key, cb, len(self.fns) - 1, type)) + if stock: + out.append((label, key, cb, len(self.fns) - 1, type, stock)) + else: + out.append((label, key, cb, len(self.fns) - 1, type)) factory.create_items(out) self.factory = factory @@ -101,11 +107,16 @@ class Menu: window.connect('key-press-event', kev) window.add_accel_group(self.accel_group) + def _position(self, menu): + x, y, mods = g.gdk.get_default_root_window().get_pointer() + width, height = menu.size_request() + return (x - width * 3 / 4, y - 16, True) + def popup(self, caller, event, position_fn = None): """Display the menu. Call 'caller.' when an item is chosen. For applets, position_fn should be my_applet.position_menu).""" self.caller = caller - self.menu.popup(None, None, position_fn, event.button, event.time) + self.menu.popup(None, None, position_fn or self._position, event.button, event.time) def _activate(self, action, widget): if self.caller: -- 2.11.4.GIT