Allow to attach the invoker to the widget after construction,
so that gproperties to constructor can be implemented correctly.
This commit is contained in:
parent
6dcc35bc17
commit
f4bda5eb22
@ -402,12 +402,14 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem):
|
|||||||
__gtype_name__ = 'CanvasIcon'
|
__gtype_name__ = 'CanvasIcon'
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
|
from sugar.graphics.palette import CanvasInvoker
|
||||||
|
|
||||||
self._buffer = _IconBuffer()
|
self._buffer = _IconBuffer()
|
||||||
|
self._palette_invoker = CanvasInvoker()
|
||||||
|
|
||||||
hippo.CanvasBox.__init__(self, **kwargs)
|
hippo.CanvasBox.__init__(self, **kwargs)
|
||||||
|
|
||||||
from sugar.graphics.palette import CanvasInvoker
|
self._palette_invoker.attach(self)
|
||||||
self._palette_invoker = CanvasInvoker(self)
|
|
||||||
|
|
||||||
self.connect('destroy', self.__destroy_cb)
|
self.connect('destroy', self.__destroy_cb)
|
||||||
|
|
||||||
|
@ -721,10 +721,10 @@ 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, parent):
|
def __init__(self):
|
||||||
gobject.GObject.__init__(self)
|
gobject.GObject.__init__(self)
|
||||||
|
|
||||||
self.parent = parent
|
self.parent = None
|
||||||
|
|
||||||
self._screen_area = gtk.gdk.Rectangle(0, 0, gtk.gdk.screen_width(),
|
self._screen_area = gtk.gdk.Rectangle(0, 0, gtk.gdk.screen_width(),
|
||||||
gtk.gdk.screen_height())
|
gtk.gdk.screen_height())
|
||||||
@ -733,6 +733,12 @@ class Invoker(gobject.GObject):
|
|||||||
self._cursor_y = -1
|
self._cursor_y = -1
|
||||||
self._palette = None
|
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):
|
def _get_position_for_alignment(self, alignment, palette_dim):
|
||||||
palette_halign = alignment[0]
|
palette_halign = alignment[0]
|
||||||
palette_valign = alignment[1]
|
palette_valign = alignment[1]
|
||||||
@ -898,9 +904,15 @@ class Invoker(gobject.GObject):
|
|||||||
type=object, setter=set_palette, getter=get_palette)
|
type=object, setter=set_palette, getter=get_palette)
|
||||||
|
|
||||||
class WidgetInvoker(Invoker):
|
class WidgetInvoker(Invoker):
|
||||||
def __init__(self, parent, widget=None):
|
def __init__(self, parent=None, widget=None):
|
||||||
Invoker.__init__(self, parent)
|
Invoker.__init__(self)
|
||||||
|
|
||||||
|
self._widget = None
|
||||||
|
|
||||||
|
if parent or widget:
|
||||||
|
self.attach_widget(parent, widget)
|
||||||
|
|
||||||
|
def attach_widget(self, parent, widget=None):
|
||||||
if widget:
|
if widget:
|
||||||
self._widget = widget
|
self._widget = widget
|
||||||
else:
|
else:
|
||||||
@ -911,6 +923,13 @@ class WidgetInvoker(Invoker):
|
|||||||
self._leave_hid = widget.connect('leave-notify-event',
|
self._leave_hid = widget.connect('leave-notify-event',
|
||||||
self._leave_notify_event_cb)
|
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):
|
def get_rect(self):
|
||||||
allocation = self._widget.get_allocation()
|
allocation = self._widget.get_allocation()
|
||||||
if self._widget.window is not None:
|
if self._widget.window is not None:
|
||||||
@ -971,24 +990,30 @@ 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, parent=None):
|
||||||
Invoker.__init__(self, item)
|
Invoker.__init__(self)
|
||||||
|
|
||||||
self._item = item
|
|
||||||
self._position_hint = self.AT_CURSOR
|
self._position_hint = self.AT_CURSOR
|
||||||
|
|
||||||
self._motion_hid = item.connect('motion-notify-event',
|
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)
|
self._motion_notify_event_cb)
|
||||||
|
|
||||||
|
def detach(self):
|
||||||
|
Invoker.detach(self)
|
||||||
|
self._item.disconnect(self._motion_hid)
|
||||||
|
|
||||||
def get_default_position(self):
|
def get_default_position(self):
|
||||||
return self.AT_CURSOR
|
return self.AT_CURSOR
|
||||||
|
|
||||||
@ -1012,12 +1037,15 @@ class CanvasInvoker(Invoker):
|
|||||||
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, parent=None):
|
||||||
WidgetInvoker.__init__(self, widget, widget.child)
|
WidgetInvoker.__init__(self)
|
||||||
|
|
||||||
|
if parent:
|
||||||
|
self.attach_tool(parent)
|
||||||
|
|
||||||
|
def attach_tool(self, widget):
|
||||||
|
self.attach_widget(widget, widget.child)
|
||||||
|
|
||||||
def _get_alignments(self):
|
def _get_alignments(self):
|
||||||
parent = self._widget.get_parent()
|
parent = self._widget.get_parent()
|
||||||
|
@ -30,10 +30,11 @@ class RadioToolButton(gtk.RadioToolButton):
|
|||||||
self._accelerator = None
|
self._accelerator = None
|
||||||
self._tooltip = None
|
self._tooltip = None
|
||||||
self._xo_color = xo_color
|
self._xo_color = xo_color
|
||||||
|
self._palette_invoker = ToolInvoker()
|
||||||
|
|
||||||
gobject.GObject.__init__(self, **kwargs)
|
gobject.GObject.__init__(self, **kwargs)
|
||||||
|
|
||||||
self._palette_invoker = ToolInvoker(self)
|
self._palette_invoker.attach_tool(self)
|
||||||
|
|
||||||
if named_icon:
|
if named_icon:
|
||||||
self.set_named_icon(named_icon)
|
self.set_named_icon(named_icon)
|
||||||
|
@ -55,10 +55,11 @@ class ToolButton(gtk.ToolButton):
|
|||||||
def __init__(self, icon_name=None, **kwargs):
|
def __init__(self, icon_name=None, **kwargs):
|
||||||
self._accelerator = None
|
self._accelerator = None
|
||||||
self._tooltip = None
|
self._tooltip = None
|
||||||
|
self._palette_invoker = ToolInvoker()
|
||||||
|
|
||||||
gobject.GObject.__init__(self, **kwargs)
|
gobject.GObject.__init__(self, **kwargs)
|
||||||
|
|
||||||
self._palette_invoker = ToolInvoker(self)
|
self._palette_invoker.attach_tool(self)
|
||||||
|
|
||||||
if icon_name:
|
if icon_name:
|
||||||
self.set_icon(icon_name)
|
self.set_icon(icon_name)
|
||||||
|
Loading…
Reference in New Issue
Block a user