Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <marco@localhost.localdomain>2008-05-24 10:34:46 (GMT)
committer Marco Pesenti Gritti <marco@localhost.localdomain>2008-05-24 10:34:46 (GMT)
commitf4bda5eb226073b9aa61161750aca9203a3c2bd8 (patch)
treec84c6876f453b4e9616eed34a59f194695095f97 /src
parent6dcc35bc17717008c7d90d3430f670cd03e1c18d (diff)
Allow to attach the invoker to the widget after construction,
so that gproperties to constructor can be implemented correctly.
Diffstat (limited to 'src')
-rw-r--r--src/sugar/graphics/icon.py6
-rw-r--r--src/sugar/graphics/palette.py64
-rw-r--r--src/sugar/graphics/radiotoolbutton.py3
-rw-r--r--src/sugar/graphics/toolbutton.py3
4 files changed, 54 insertions, 22 deletions
diff --git a/src/sugar/graphics/icon.py b/src/sugar/graphics/icon.py
index 35e8e43..eeb36a1 100644
--- a/src/sugar/graphics/icon.py
+++ b/src/sugar/graphics/icon.py
@@ -402,12 +402,14 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem):
__gtype_name__ = 'CanvasIcon'
def __init__(self, **kwargs):
+ from sugar.graphics.palette import CanvasInvoker
+
self._buffer = _IconBuffer()
+ self._palette_invoker = CanvasInvoker()
hippo.CanvasBox.__init__(self, **kwargs)
- from sugar.graphics.palette import CanvasInvoker
- self._palette_invoker = CanvasInvoker(self)
+ self._palette_invoker.attach(self)
self.connect('destroy', self.__destroy_cb)
diff --git a/src/sugar/graphics/palette.py b/src/sugar/graphics/palette.py
index f8ed0a3..592a6df 100644
--- a/src/sugar/graphics/palette.py
+++ b/src/sugar/graphics/palette.py
@@ -721,10 +721,10 @@ class Invoker(gobject.GObject):
LEFT = [(-1.0, 0.0, 0.0, 0.0),
(-1.0, -1.0, 0.0, 1.0)]
- def __init__(self, parent):
+ def __init__(self):
gobject.GObject.__init__(self)
- self.parent = parent
+ self.parent = None
self._screen_area = gtk.gdk.Rectangle(0, 0, gtk.gdk.screen_width(),
gtk.gdk.screen_height())
@@ -733,6 +733,12 @@ class Invoker(gobject.GObject):
self._cursor_y = -1
self._palette = None
+ def attach(self, parent):
+ self.parent = parent
+
+ def detach(self):
+ self.parent = None
+
def _get_position_for_alignment(self, alignment, palette_dim):
palette_halign = alignment[0]
palette_valign = alignment[1]
@@ -898,9 +904,15 @@ class Invoker(gobject.GObject):
type=object, setter=set_palette, getter=get_palette)
class WidgetInvoker(Invoker):
- def __init__(self, parent, widget=None):
- Invoker.__init__(self, parent)
+ def __init__(self, parent=None, widget=None):
+ Invoker.__init__(self)
+
+ self._widget = None
+ if parent or widget:
+ self.attach_widget(parent, widget)
+
+ def attach_widget(self, parent, widget=None):
if widget:
self._widget = widget
else:
@@ -911,6 +923,13 @@ class WidgetInvoker(Invoker):
self._leave_hid = widget.connect('leave-notify-event',
self._leave_notify_event_cb)
+ self.attach(parent)
+
+ def detach(self):
+ Invoker.detach(self)
+ self._widget.disconnect(self._enter_hid)
+ self._widget.disconnect(self._leave_hid)
+
def get_rect(self):
allocation = self._widget.get_allocation()
if self._widget.window is not None:
@@ -971,23 +990,29 @@ 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, item)
+ def __init__(self, parent=None):
+ Invoker.__init__(self)
- self._item = item
self._position_hint = self.AT_CURSOR
- self._motion_hid = item.connect('motion-notify-event',
- self._motion_notify_event_cb)
+ if parent:
+ self.attach(parent)
+
+ def attach(self, parent):
+ Invoker.attach(self, parent)
+
+ self._item = parent
+ self._motion_hid = self._item.connect('motion-notify-event',
+ self._motion_notify_event_cb)
+
+ def detach(self):
+ Invoker.detach(self)
+ self._item.disconnect(self._motion_hid)
def get_default_position(self):
return self.AT_CURSOR
@@ -1012,12 +1037,15 @@ class CanvasInvoker(Invoker):
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, widget.child)
+ def __init__(self, parent=None):
+ WidgetInvoker.__init__(self)
+
+ if parent:
+ self.attach_tool(parent)
+
+ def attach_tool(self, widget):
+ self.attach_widget(widget, widget.child)
def _get_alignments(self):
parent = self._widget.get_parent()
diff --git a/src/sugar/graphics/radiotoolbutton.py b/src/sugar/graphics/radiotoolbutton.py
index d6e8b69..1563e2a 100644
--- a/src/sugar/graphics/radiotoolbutton.py
+++ b/src/sugar/graphics/radiotoolbutton.py
@@ -30,10 +30,11 @@ class RadioToolButton(gtk.RadioToolButton):
self._accelerator = None
self._tooltip = None
self._xo_color = xo_color
+ self._palette_invoker = ToolInvoker()
gobject.GObject.__init__(self, **kwargs)
- self._palette_invoker = ToolInvoker(self)
+ self._palette_invoker.attach_tool(self)
if named_icon:
self.set_named_icon(named_icon)
diff --git a/src/sugar/graphics/toolbutton.py b/src/sugar/graphics/toolbutton.py
index 4334dcd..bf392c8 100644
--- a/src/sugar/graphics/toolbutton.py
+++ b/src/sugar/graphics/toolbutton.py
@@ -55,10 +55,11 @@ class ToolButton(gtk.ToolButton):
def __init__(self, icon_name=None, **kwargs):
self._accelerator = None
self._tooltip = None
+ self._palette_invoker = ToolInvoker()
gobject.GObject.__init__(self, **kwargs)
- self._palette_invoker = ToolInvoker(self)
+ self._palette_invoker.attach_tool(self)
if icon_name:
self.set_icon(icon_name)