Move most of the drawing logic inside Palette/Invoker.

This commit is contained in:
Marco Pesenti Gritti 2007-08-15 21:53:31 +02:00
parent d7d1e172a3
commit 8d9383c48e
4 changed files with 17 additions and 21 deletions

View File

@ -87,9 +87,7 @@ class Palette(gtk.Window):
'invoker' : (object, None, None,
gobject.PARAM_READWRITE),
'position' : (gobject.TYPE_INT, None, None, 0, 6,
0, gobject.PARAM_READWRITE),
'draw-gap' : (bool, None, None, False,
gobject.PARAM_READWRITE)
0, gobject.PARAM_READWRITE)
}
__gsignals__ = {
@ -114,7 +112,6 @@ class Palette(gtk.Window):
self._group_id = None
self._up = False
self._position = self.DEFAULT
self._draw_gap = False
self._palette_popup_sid = None
self._popup_anim = animator.Animator(0.3, 10)
@ -206,9 +203,6 @@ class Palette(gtk.Window):
self._invoker.connect('mouse-leave', self._invoker_mouse_leave_cb)
elif pspec.name == 'position':
self._position = value
elif pspec.name == 'draw-gap':
self._draw_gap = value
self.queue_draw()
else:
raise AssertionError
@ -217,8 +211,6 @@ class Palette(gtk.Window):
return self._invoker
elif pspec.name == 'position':
return self._position
elif pspec.name == 'draw-gap':
return self._draw_gap
else:
raise AssertionError
@ -228,7 +220,7 @@ class Palette(gtk.Window):
def do_expose_event(self, event):
# We want to draw a border with a beautiful gap
if self._draw_gap:
if self._invoker.has_rectangle_gap():
invoker = self._invoker.get_rect()
palette = self.get_rect()
@ -542,6 +534,12 @@ class Invoker(gobject.GObject):
def __init__(self):
gobject.GObject.__init__(self)
def has_rectangle_gap(self):
return False
def draw_rectangle(self, event, palette):
pass
def get_default_position(self):
return Palette.AROUND
@ -575,7 +573,10 @@ class WidgetInvoker(Invoker):
return gtk.gdk.Rectangle(x, y, width, height)
def draw_invoker_rect(self, event, palette):
def has_rectangle_gap(self):
return True
def draw_rectangle(self, event, palette):
style = self._widget.style
gap = _calculate_gap(self.get_rect(), palette.get_rect())
if gap:

View File

@ -40,16 +40,14 @@ class RadioToolButton(gtk.RadioToolButton):
def set_palette(self, palette):
self._palette = palette
self._palette.props.invoker = WidgetInvoker(self.child)
self._palette.props.draw_gap = True
def set_tooltip(self, text):
self._palette = Palette(text)
self._palette.props.invoker = WidgetInvoker(self.child)
self._set_palette(Palette(text))
def do_expose_event(self, event):
if self._palette and self._palette.is_up():
invoker = self._palette.props.invoker
invoker.draw_invoker_rect(event, self._palette)
invoker.draw_rectangle(event, self._palette)
gtk.RadioToolButton.do_expose_event(self, event)

View File

@ -39,16 +39,14 @@ class ToggleToolButton(gtk.ToggleToolButton):
def set_palette(self, palette):
self._palette = palette
self._palette.props.invoker = WidgetInvoker(self.child)
self._palette.props.draw_gap = True
def set_tooltip(self, text):
self._palette = Palette(text)
self._palette.props.invoker = WidgetInvoker(self.child)
self._set_palette(Palette(text))
def do_expose_event(self, event):
if self._palette and self._palette.is_up():
invoker = self._palette.props.invoker
invoker.draw_invoker_rect(event, self._palette)
invoker.draw_rectangle(event, self._palette)
gtk.ToggleToolButton.do_expose_event(self, event)

View File

@ -42,7 +42,6 @@ class ToolButton(gtk.ToolButton):
def set_palette(self, palette):
self._palette = palette
self._palette.props.invoker = WidgetInvoker(self.child)
self._palette.props.draw_gap = True
def set_tooltip(self, text):
self.set_palette(Palette(text))
@ -50,7 +49,7 @@ class ToolButton(gtk.ToolButton):
def do_expose_event(self, event):
if self._palette and self._palette.is_up():
invoker = self._palette.props.invoker
invoker.draw_invoker_rect(event, self._palette)
invoker.draw_rectangle(event, self._palette)
gtk.ToolButton.do_expose_event(self, event)