Move palette creation logic inside the invoker.
This commit is contained in:
parent
c5b8697d37
commit
685a9e3462
@ -721,7 +721,7 @@ class Invoker(gobject.GObject):
|
|||||||
LEFT = [(-1.0, 0.0, 0.0, 0.0),
|
LEFT = [(-1.0, 0.0, 0.0, 0.0),
|
||||||
(-1.0, -1.0, 0.0, 1.0)]
|
(-1.0, -1.0, 0.0, 1.0)]
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, parent):
|
||||||
gobject.GObject.__init__(self)
|
gobject.GObject.__init__(self)
|
||||||
|
|
||||||
self._screen_area = gtk.gdk.Rectangle(0, 0, gtk.gdk.screen_width(),
|
self._screen_area = gtk.gdk.Rectangle(0, 0, gtk.gdk.screen_width(),
|
||||||
@ -729,6 +729,8 @@ class Invoker(gobject.GObject):
|
|||||||
self._position_hint = self.ANCHORED
|
self._position_hint = self.ANCHORED
|
||||||
self._cursor_x = -1
|
self._cursor_x = -1
|
||||||
self._cursor_y = -1
|
self._cursor_y = -1
|
||||||
|
self._palette = None
|
||||||
|
self._parent = parent
|
||||||
|
|
||||||
def _get_position_for_alignment(self, alignment, palette_dim):
|
def _get_position_for_alignment(self, alignment, palette_dim):
|
||||||
palette_halign = alignment[0]
|
palette_halign = alignment[0]
|
||||||
@ -868,13 +870,45 @@ class Invoker(gobject.GObject):
|
|||||||
self._cursor_x = -1
|
self._cursor_x = -1
|
||||||
self._cursor_y = -1
|
self._cursor_y = -1
|
||||||
|
|
||||||
class WidgetInvoker(Invoker):
|
def notify_mouse_enter(self):
|
||||||
def __init__(self, widget):
|
if self.parent and self.palette is None:
|
||||||
Invoker.__init__(self)
|
palette = self.parent.create_palette()
|
||||||
self._widget = widget
|
if palette:
|
||||||
|
self.palette = palette
|
||||||
|
|
||||||
widget.connect('enter-notify-event', self._enter_notify_event_cb)
|
self.emit('mouse-enter')
|
||||||
widget.connect('leave-notify-event', self._leave_notify_event_cb)
|
|
||||||
|
def notify_mouse_leave(self):
|
||||||
|
self.emit('mouse-leave')
|
||||||
|
|
||||||
|
def get_palette(self):
|
||||||
|
return self._palette
|
||||||
|
|
||||||
|
def set_palette(self, palette):
|
||||||
|
if self._palette:
|
||||||
|
self._palette.props.invoker = None
|
||||||
|
|
||||||
|
self._palette = palette
|
||||||
|
|
||||||
|
if self._palette:
|
||||||
|
self._palette.props.invoker = self
|
||||||
|
|
||||||
|
palette = gobject.property(
|
||||||
|
type=object, setter=set_palette, getter=get_palette)
|
||||||
|
|
||||||
|
class WidgetInvoker(Invoker):
|
||||||
|
def __init__(self, parent, widget=None):
|
||||||
|
Invoker.__init__(self, parent)
|
||||||
|
|
||||||
|
if widget:
|
||||||
|
self._widget = widget
|
||||||
|
else:
|
||||||
|
self._widget = parent
|
||||||
|
|
||||||
|
self._enter_hid = widget.connect('enter-notify-event',
|
||||||
|
self._enter_notify_event_cb)
|
||||||
|
self._leave_hid = widget.connect('leave-notify-event',
|
||||||
|
self._leave_notify_event_cb)
|
||||||
|
|
||||||
def get_rect(self):
|
def get_rect(self):
|
||||||
allocation = self._widget.get_allocation()
|
allocation = self._widget.get_allocation()
|
||||||
@ -920,10 +954,10 @@ class WidgetInvoker(Invoker):
|
|||||||
self._widget.allocation.height)
|
self._widget.allocation.height)
|
||||||
|
|
||||||
def _enter_notify_event_cb(self, widget, event):
|
def _enter_notify_event_cb(self, widget, event):
|
||||||
self.emit('mouse-enter')
|
self.notify_mouse_enter()
|
||||||
|
|
||||||
def _leave_notify_event_cb(self, widget, event):
|
def _leave_notify_event_cb(self, widget, event):
|
||||||
self.emit('mouse-leave')
|
self.notify_mouse_leave()
|
||||||
|
|
||||||
def get_toplevel(self):
|
def get_toplevel(self):
|
||||||
return self._widget.get_toplevel()
|
return self._widget.get_toplevel()
|
||||||
@ -936,19 +970,23 @@ class WidgetInvoker(Invoker):
|
|||||||
Invoker.notify_popdown(self)
|
Invoker.notify_popdown(self)
|
||||||
self._widget.queue_draw()
|
self._widget.queue_draw()
|
||||||
|
|
||||||
|
def detach(self):
|
||||||
|
self._widget.disconnect(self._enter_hid)
|
||||||
|
self._widget.disconnect(self._leave_hid)
|
||||||
|
|
||||||
def _get_widget(self):
|
def _get_widget(self):
|
||||||
return self._widget
|
return self._widget
|
||||||
widget = gobject.property(type=object, getter=_get_widget, setter=None)
|
widget = gobject.property(type=object, getter=_get_widget, setter=None)
|
||||||
|
|
||||||
class CanvasInvoker(Invoker):
|
class CanvasInvoker(Invoker):
|
||||||
def __init__(self, item):
|
def __init__(self, item):
|
||||||
Invoker.__init__(self)
|
Invoker.__init__(self, item)
|
||||||
|
|
||||||
self._item = item
|
self._item = item
|
||||||
self._position_hint = self.AT_CURSOR
|
self._position_hint = self.AT_CURSOR
|
||||||
|
|
||||||
item.connect('motion-notify-event',
|
self._motion_hid = item.connect('motion-notify-event',
|
||||||
self._motion_notify_event_cb)
|
self._motion_notify_event_cb)
|
||||||
|
|
||||||
def get_default_position(self):
|
def get_default_position(self):
|
||||||
return self.AT_CURSOR
|
return self.AT_CURSOR
|
||||||
@ -964,18 +1002,21 @@ class CanvasInvoker(Invoker):
|
|||||||
|
|
||||||
def _motion_notify_event_cb(self, button, event):
|
def _motion_notify_event_cb(self, button, event):
|
||||||
if event.detail == hippo.MOTION_DETAIL_ENTER:
|
if event.detail == hippo.MOTION_DETAIL_ENTER:
|
||||||
self.emit('mouse-enter')
|
self.notify_mouse_enter()
|
||||||
elif event.detail == hippo.MOTION_DETAIL_LEAVE:
|
elif event.detail == hippo.MOTION_DETAIL_LEAVE:
|
||||||
self.emit('mouse-leave')
|
self.notify_mouse_leave()
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def get_toplevel(self):
|
def get_toplevel(self):
|
||||||
return hippo.get_canvas_for_item(self._item).get_toplevel()
|
return hippo.get_canvas_for_item(self._item).get_toplevel()
|
||||||
|
|
||||||
|
def detach(self):
|
||||||
|
self._item.disconnect(self._motion_hid)
|
||||||
|
|
||||||
class ToolInvoker(WidgetInvoker):
|
class ToolInvoker(WidgetInvoker):
|
||||||
def __init__(self, widget):
|
def __init__(self, widget):
|
||||||
WidgetInvoker.__init__(self, widget.child)
|
WidgetInvoker.__init__(self, widget, widget.child)
|
||||||
|
|
||||||
def _get_alignments(self):
|
def _get_alignments(self):
|
||||||
parent = self._widget.get_parent()
|
parent = self._widget.get_parent()
|
||||||
|
Loading…
Reference in New Issue
Block a user