Add toggle_palette property for Palette invoker, SL #4065
The property does specify whether the invoker will popup/popdown the Palette on button left click/touch tap. It defaults to False. In the toolbutton we add a property if the tooltip should be popped down on a click, this is set to true to have the same behavior as before. Signed-off-by: Simon Schampijer <simon@laptop.org> Acked-by: Manuel Quiñones <manuq@laptop.org>
This commit is contained in:
parent
5ce0273900
commit
1a8f89226b
@ -179,9 +179,6 @@ class Palette(PaletteWindow):
|
|||||||
PaletteWindow._setup_widget(self)
|
PaletteWindow._setup_widget(self)
|
||||||
self._widget.connect('destroy', self.__destroy_cb)
|
self._widget.connect('destroy', self.__destroy_cb)
|
||||||
|
|
||||||
def _invoker_right_click_cb(self, invoker):
|
|
||||||
self.popup(immediate=True, state=self.SECONDARY)
|
|
||||||
|
|
||||||
def __destroy_cb(self, palette):
|
def __destroy_cb(self, palette):
|
||||||
self._secondary_anim.stop()
|
self._secondary_anim.stop()
|
||||||
self.popdown(immediate=True)
|
self.popdown(immediate=True)
|
||||||
|
@ -510,6 +510,8 @@ class PaletteWindow(GObject.GObject):
|
|||||||
'mouse-leave', self._invoker_mouse_leave_cb))
|
'mouse-leave', self._invoker_mouse_leave_cb))
|
||||||
self._invoker_hids.append(self._invoker.connect(
|
self._invoker_hids.append(self._invoker.connect(
|
||||||
'right-click', self._invoker_right_click_cb))
|
'right-click', self._invoker_right_click_cb))
|
||||||
|
self._invoker_hids.append(self._invoker.connect(
|
||||||
|
'toggle-state', self._invoker_toggle_state_cb))
|
||||||
|
|
||||||
def get_invoker(self):
|
def get_invoker(self):
|
||||||
return self._invoker
|
return self._invoker
|
||||||
@ -626,7 +628,13 @@ class PaletteWindow(GObject.GObject):
|
|||||||
self.on_invoker_leave()
|
self.on_invoker_leave()
|
||||||
|
|
||||||
def _invoker_right_click_cb(self, invoker):
|
def _invoker_right_click_cb(self, invoker):
|
||||||
self.popup(immediate=True)
|
self.popup(immediate=True, state=1)
|
||||||
|
|
||||||
|
def _invoker_toggle_state_cb(self, invoker):
|
||||||
|
if self.is_up():
|
||||||
|
self.popdown(immediate=True)
|
||||||
|
else:
|
||||||
|
self.popup(immediate=True, state=1)
|
||||||
|
|
||||||
def __enter_notify_cb(self, widget):
|
def __enter_notify_cb(self, widget):
|
||||||
self.on_enter()
|
self.on_enter()
|
||||||
@ -706,6 +714,7 @@ class Invoker(GObject.GObject):
|
|||||||
'mouse-enter': (GObject.SignalFlags.RUN_FIRST, None, ([])),
|
'mouse-enter': (GObject.SignalFlags.RUN_FIRST, None, ([])),
|
||||||
'mouse-leave': (GObject.SignalFlags.RUN_FIRST, None, ([])),
|
'mouse-leave': (GObject.SignalFlags.RUN_FIRST, None, ([])),
|
||||||
'right-click': (GObject.SignalFlags.RUN_FIRST, None, ([])),
|
'right-click': (GObject.SignalFlags.RUN_FIRST, None, ([])),
|
||||||
|
'toggle-state': (GObject.SignalFlags.RUN_FIRST, None, ([])),
|
||||||
'focus-out': (GObject.SignalFlags.RUN_FIRST, None, ([])),
|
'focus-out': (GObject.SignalFlags.RUN_FIRST, None, ([])),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -731,6 +740,7 @@ class Invoker(GObject.GObject):
|
|||||||
self._cursor_y = -1
|
self._cursor_y = -1
|
||||||
self._palette = None
|
self._palette = None
|
||||||
self._cache_palette = True
|
self._cache_palette = True
|
||||||
|
self._toggle_palette = False
|
||||||
|
|
||||||
def attach(self, parent):
|
def attach(self, parent):
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
@ -917,6 +927,10 @@ class Invoker(GObject.GObject):
|
|||||||
self._ensure_palette_exists()
|
self._ensure_palette_exists()
|
||||||
self.emit('right-click')
|
self.emit('right-click')
|
||||||
|
|
||||||
|
def notify_toggle_state(self):
|
||||||
|
self._ensure_palette_exists()
|
||||||
|
self.emit('toggle-state')
|
||||||
|
|
||||||
def get_palette(self):
|
def get_palette(self):
|
||||||
return self._palette
|
return self._palette
|
||||||
|
|
||||||
@ -953,6 +967,18 @@ class Invoker(GObject.GObject):
|
|||||||
to True.
|
to True.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
def get_toggle_palette(self):
|
||||||
|
return self._toggle_palette
|
||||||
|
|
||||||
|
def set_toggle_palette(self, toggle_palette):
|
||||||
|
self._toggle_palette = toggle_palette
|
||||||
|
|
||||||
|
toggle_palette = GObject.property(type=object, setter=set_toggle_palette,
|
||||||
|
getter=get_toggle_palette)
|
||||||
|
"""Whether the invoker will popup/popdown the Palette on
|
||||||
|
button left click/touch tap. Defaults to False.
|
||||||
|
"""
|
||||||
|
|
||||||
def __palette_popdown_cb(self, palette):
|
def __palette_popdown_cb(self, palette):
|
||||||
if not self.props.cache_palette:
|
if not self.props.cache_palette:
|
||||||
self.set_palette(None)
|
self.set_palette(None)
|
||||||
@ -1040,7 +1066,10 @@ class WidgetInvoker(Invoker):
|
|||||||
self.notify_mouse_leave()
|
self.notify_mouse_leave()
|
||||||
|
|
||||||
def __button_release_event_cb(self, widget, event):
|
def __button_release_event_cb(self, widget, event):
|
||||||
if event.button == 3:
|
if event.button == 1:
|
||||||
|
if self.props.toggle_palette:
|
||||||
|
self.notify_toggle_state()
|
||||||
|
elif event.button == 3:
|
||||||
self.notify_right_click()
|
self.notify_right_click()
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
@ -1115,6 +1144,9 @@ class CursorInvoker(Invoker):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def __button_release_event_cb(self, button, event):
|
def __button_release_event_cb(self, button, event):
|
||||||
|
if event.button == 1:
|
||||||
|
if self.props.toggle_palette:
|
||||||
|
self.notify_toggle_state()
|
||||||
if event.button == 3:
|
if event.button == 3:
|
||||||
self.notify_right_click()
|
self.notify_right_click()
|
||||||
return True
|
return True
|
||||||
|
@ -67,6 +67,7 @@ class ToolButton(Gtk.ToolButton):
|
|||||||
|
|
||||||
GObject.GObject.__init__(self, **kwargs)
|
GObject.GObject.__init__(self, **kwargs)
|
||||||
|
|
||||||
|
self._hide_tooltip_on_click = True
|
||||||
self._palette_invoker.attach_tool(self)
|
self._palette_invoker.attach_tool(self)
|
||||||
|
|
||||||
if icon_name:
|
if icon_name:
|
||||||
@ -104,6 +105,17 @@ class ToolButton(Gtk.ToolButton):
|
|||||||
tooltip = GObject.property(type=str, setter=set_tooltip,
|
tooltip = GObject.property(type=str, setter=set_tooltip,
|
||||||
getter=get_tooltip)
|
getter=get_tooltip)
|
||||||
|
|
||||||
|
def get_hide_tooltip_on_click(self):
|
||||||
|
return self._hide_tooltip_on_click
|
||||||
|
|
||||||
|
def set_hide_tooltip_on_click(self, hide_tooltip_on_click):
|
||||||
|
if self._hide_tooltip_on_click != hide_tooltip_on_click:
|
||||||
|
self._hide_tooltip_on_click = hide_tooltip_on_click
|
||||||
|
|
||||||
|
hide_tooltip_on_click = GObject.property(
|
||||||
|
type=bool, default=True, getter=get_hide_tooltip_on_click,
|
||||||
|
setter=set_hide_tooltip_on_click)
|
||||||
|
|
||||||
def set_accelerator(self, accelerator):
|
def set_accelerator(self, accelerator):
|
||||||
self._accelerator = accelerator
|
self._accelerator = accelerator
|
||||||
setup_accelerator(self)
|
setup_accelerator(self)
|
||||||
@ -168,5 +180,5 @@ class ToolButton(Gtk.ToolButton):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def do_clicked(self):
|
def do_clicked(self):
|
||||||
if self.palette:
|
if self._hide_tooltip_on_click and self.palette:
|
||||||
self.palette.popdown(True)
|
self.palette.popdown(True)
|
||||||
|
Loading…
Reference in New Issue
Block a user