Finish to hook up the new palette stuff.

This commit is contained in:
Marco Pesenti Gritti 2008-05-23 18:00:47 +02:00
parent bbd3404310
commit ce235e7405
4 changed files with 55 additions and 32 deletions

View File

@ -406,7 +406,9 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem):
hippo.CanvasBox.__init__(self, **kwargs)
self._palette = None
from sugar.graphics.palette import CanvasInvoker
self._palette_invoker = CanvasInvoker(self)
self.connect('destroy', self.__destroy_cb)
def __destroy_cb(self, icon):
@ -547,17 +549,27 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem):
self.emit_activated()
return True
def get_palette(self):
return self._palette
def set_palette(self, palette):
from sugar.graphics.palette import CanvasInvoker
def create_palette(self):
return None
if self._palette is not None:
self._palette.props.invoker = None
self._palette = palette
if not self._palette.props.invoker:
self._palette.props.invoker = CanvasInvoker(self)
def get_palette(self):
return self._palette_invoker.palette
def set_palette(self, palette):
self._palette_invoker.palette = palette
palette = gobject.property(
type=object, setter=set_palette, getter=get_palette)
def get_palette_invoker(self):
return self._palette_invoker
def set_palette_invoker(self, palette_invoker):
self._palette_invoker.detach()
self._palette_invoker = palette_invoker
palette_invoker = gobject.property(
type=object, setter=set_palette_invoker, getter=get_palette_invoker)
def set_tooltip(self, text):
from sugar.graphics.palette import Palette

View File

@ -101,9 +101,9 @@ class RadioToolButton(gtk.RadioToolButton):
child = self.get_child()
allocation = self.get_allocation()
if self._palette and self._palette.is_up():
invoker = self._palette.props.invoker
invoker.draw_rectangle(event, self._palette)
if self.palette and self.palette.is_up():
invoker = self.palette.props.invoker
invoker.draw_rectangle(event, self.palette)
elif child.state == gtk.STATE_PRELIGHT:
child.style.paint_box(event.window, gtk.STATE_PRELIGHT,
gtk.SHADOW_NONE, event.area,

View File

@ -63,9 +63,9 @@ class ToggleToolButton(gtk.ToggleToolButton):
allocation = self.get_allocation()
child = self.get_child()
if self._palette and self._palette.is_up():
invoker = self._palette.props.invoker
invoker.draw_rectangle(event, self._palette)
if self.palette and self.palette.is_up():
invoker = self.palette.props.invoker
invoker.draw_rectangle(event, self.palette)
elif child.state == gtk.STATE_PRELIGHT:
child.style.paint_box(event.window, gtk.STATE_PRELIGHT,
gtk.SHADOW_NONE, event.area,

View File

@ -259,8 +259,6 @@ class _IconWidget(gtk.EventBox):
def __init__(self, icon_name=None, xo_color=None):
gtk.EventBox.__init__(self)
self._palette = None
self.set_app_paintable(True)
self._icon = Icon(icon_name=icon_name, xo_color=xo_color,
@ -269,18 +267,13 @@ class _IconWidget(gtk.EventBox):
self._icon.show()
def do_expose_event(self, event):
if self._palette and self._palette.is_up():
invoker = self._palette.props.invoker
invoker.draw_rectangle(event, self._palette)
palette = self.parent.palette
if palette and palette.is_up():
invoker = palette.props.invoker
invoker.draw_rectangle(event, palette)
gtk.EventBox.do_expose_event(self, event)
def set_palette(self, palette):
if self._palette is not None:
self._palette.props.invoker = None
self._palette = palette
self._palette.props.invoker = ToolInvoker(self)
def get_icon(self):
return self._icon
@ -294,13 +287,31 @@ class TrayIcon(gtk.ToolItem):
self.add(self._icon_widget)
self._icon_widget.show()
self._palette_invoker = ToolInvoker(self)
self.set_size_request(style.GRID_CELL_SIZE, style.GRID_CELL_SIZE)
def set_palette(self, palette):
self._icon_widget.set_palette(palette)
def create_palette(self):
return None
def set_tooltip(self, text):
self.set_palette(Palette(text))
def get_palette(self):
return self._palette_invoker.palette
def set_palette(self, palette):
self._palette_invoker.palette = palette
palette = gobject.property(
type=object, setter=set_palette, getter=get_palette)
def get_palette_invoker(self):
return self._palette_invoker
def set_palette_invoker(self, palette_invoker):
self._palette_invoker.detach()
self._palette_invoker = palette_invoker
palette_invoker = gobject.property(
type=object, setter=set_palette_invoker, getter=get_palette_invoker)
def get_icon(self):
return self._icon_widget.get_icon()