From 067f703bfe7787bd4706172f0c56e57874899966 Mon Sep 17 00:00:00 2001 From: Tomeu Vizoso Date: Sat, 24 Feb 2007 18:18:50 +0100 Subject: [PATCH] Make OptionMenu grab the pointer on popup. --- sugar/graphics/canvasicon.py | 2 +- sugar/graphics/optionmenu.py | 8 +++++++- sugar/graphics/popup.py | 8 ++++++++ tests/test-option-menu.py | 2 +- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/sugar/graphics/canvasicon.py b/sugar/graphics/canvasicon.py index 76d29b0b..fe04074f 100644 --- a/sugar/graphics/canvasicon.py +++ b/sugar/graphics/canvasicon.py @@ -355,7 +355,7 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem): [x, y] = context.translate_to_screen(self) # TODO: Any better place to do this? - popup.props.box_width = max(popup.props.box_width, + popup.props.box_width = max(popup.get_width_request(), self.get_width_request()) [width, height] = self.get_allocation() diff --git a/sugar/graphics/optionmenu.py b/sugar/graphics/optionmenu.py index edd1d39e..f5a44175 100644 --- a/sugar/graphics/optionmenu.py +++ b/sugar/graphics/optionmenu.py @@ -64,6 +64,8 @@ class OptionMenu(hippo.CanvasBox, hippo.CanvasItem): self._round_box = RoundBox() self._round_box.props.border_color = color.FRAME_BORDER.get_int() + self._round_box.props.spacing = units.points_to_pixels(3) + self._round_box.props.padding = units.points_to_pixels(1) self.append(self._round_box, hippo.PACK_EXPAND) self._canvas_text = hippo.CanvasText() @@ -111,10 +113,14 @@ class OptionMenu(hippo.CanvasBox, hippo.CanvasItem): [x, y] = context.translate_to_screen(self._round_box) # TODO: Any better place to do this? - self._menu.props.box_width = self.get_width_request() + self._menu.props.box_width = max(self.get_width_request(), + self._menu.get_width_request()) [width, height] = self._round_box.get_allocation() self._menu.popup(x, y + height) + + # Grab the pointer so the menu will popdown on mouse click. + self._menu.grab_pointer() def _menu_action_cb(self, menu, menu_item): action_id = menu_item.props.action_id diff --git a/sugar/graphics/popup.py b/sugar/graphics/popup.py index 5c63b6e3..d0bee06e 100644 --- a/sugar/graphics/popup.py +++ b/sugar/graphics/popup.py @@ -46,5 +46,13 @@ class Popup(hippo.CanvasBox, hippo.CanvasItem): self._window.hide() self._visible = False + def grab_pointer(self): + gtk.gdk.pointer_grab(self._window.window, owner_events=False, + event_mask=gtk.gdk.BUTTON_PRESS_MASK | + gtk.gdk.BUTTON_RELEASE_MASK | + gtk.gdk.ENTER_NOTIFY_MASK | + gtk.gdk.LEAVE_NOTIFY_MASK | + gtk.gdk.POINTER_MOTION_MASK) + def _button_press_event_cb(self, menu, event): self.emit('action-completed') diff --git a/tests/test-option-menu.py b/tests/test-option-menu.py index bbcc03a0..f320afcc 100755 --- a/tests/test-option-menu.py +++ b/tests/test-option-menu.py @@ -48,7 +48,7 @@ canvas.set_root(vbox) toolbar = Toolbar() vbox.append(toolbar) -button = IconButton('theme:stock-close') +button = IconButton(icon_name='theme:stock-close') toolbar.append(button) OPTION_ANYTHING = 1