Make OptionMenu grab the pointer on popup.
This commit is contained in:
parent
951e92395b
commit
067f703bfe
@ -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()
|
||||
|
@ -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
|
||||
|
@ -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')
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user