Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src/sugar/graphics/palette.py
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <marco@localhost.localdomain>2008-05-23 15:26:15 (GMT)
committer Marco Pesenti Gritti <marco@localhost.localdomain>2008-05-23 15:26:15 (GMT)
commit685a9e3462564a9d7000ffddeb5c6b936881615f (patch)
tree3a2880944246c7e795567169262b200e3f5c8f97 /src/sugar/graphics/palette.py
parentc5b8697d375774c8df611b228b47584e20232dbd (diff)
Move palette creation logic inside the invoker.
Diffstat (limited to 'src/sugar/graphics/palette.py')
-rw-r--r--src/sugar/graphics/palette.py69
1 files changed, 55 insertions, 14 deletions
diff --git a/src/sugar/graphics/palette.py b/src/sugar/graphics/palette.py
index 19a7249..1df2a3b 100644
--- a/src/sugar/graphics/palette.py
+++ b/src/sugar/graphics/palette.py
@@ -721,7 +721,7 @@ class Invoker(gobject.GObject):
LEFT = [(-1.0, 0.0, 0.0, 0.0),
(-1.0, -1.0, 0.0, 1.0)]
- def __init__(self):
+ def __init__(self, parent):
gobject.GObject.__init__(self)
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._cursor_x = -1
self._cursor_y = -1
+ self._palette = None
+ self._parent = parent
def _get_position_for_alignment(self, alignment, palette_dim):
palette_halign = alignment[0]
@@ -868,13 +870,45 @@ class Invoker(gobject.GObject):
self._cursor_x = -1
self._cursor_y = -1
+ def notify_mouse_enter(self):
+ if self.parent and self.palette is None:
+ palette = self.parent.create_palette()
+ if palette:
+ self.palette = palette
+
+ self.emit('mouse-enter')
+
+ 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, widget):
- Invoker.__init__(self)
- self._widget = widget
+ def __init__(self, parent, widget=None):
+ Invoker.__init__(self, parent)
+
+ if widget:
+ self._widget = widget
+ else:
+ self._widget = parent
- widget.connect('enter-notify-event', self._enter_notify_event_cb)
- widget.connect('leave-notify-event', self._leave_notify_event_cb)
+ 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):
allocation = self._widget.get_allocation()
@@ -920,10 +954,10 @@ class WidgetInvoker(Invoker):
self._widget.allocation.height)
def _enter_notify_event_cb(self, widget, event):
- self.emit('mouse-enter')
+ self.notify_mouse_enter()
def _leave_notify_event_cb(self, widget, event):
- self.emit('mouse-leave')
+ self.notify_mouse_leave()
def get_toplevel(self):
return self._widget.get_toplevel()
@@ -936,19 +970,23 @@ class WidgetInvoker(Invoker):
Invoker.notify_popdown(self)
self._widget.queue_draw()
+ def detach(self):
+ self._widget.disconnect(self._enter_hid)
+ self._widget.disconnect(self._leave_hid)
+
def _get_widget(self):
return self._widget
widget = gobject.property(type=object, getter=_get_widget, setter=None)
class CanvasInvoker(Invoker):
def __init__(self, item):
- Invoker.__init__(self)
+ Invoker.__init__(self, item)
self._item = item
self._position_hint = self.AT_CURSOR
- item.connect('motion-notify-event',
- self._motion_notify_event_cb)
+ self._motion_hid = item.connect('motion-notify-event',
+ self._motion_notify_event_cb)
def get_default_position(self):
return self.AT_CURSOR
@@ -964,18 +1002,21 @@ class CanvasInvoker(Invoker):
def _motion_notify_event_cb(self, button, event):
if event.detail == hippo.MOTION_DETAIL_ENTER:
- self.emit('mouse-enter')
+ self.notify_mouse_enter()
elif event.detail == hippo.MOTION_DETAIL_LEAVE:
- self.emit('mouse-leave')
+ self.notify_mouse_leave()
return False
def get_toplevel(self):
return hippo.get_canvas_for_item(self._item).get_toplevel()
+ def detach(self):
+ self._item.disconnect(self._motion_hid)
+
class ToolInvoker(WidgetInvoker):
def __init__(self, widget):
- WidgetInvoker.__init__(self, widget.child)
+ WidgetInvoker.__init__(self, widget, widget.child)
def _get_alignments(self):
parent = self._widget.get_parent()