diff options
author | Manuel Quiñones <manuq@laptop.org> | 2012-10-10 19:20:05 (GMT) |
---|---|---|
committer | Manuel Quiñones <manuq@laptop.org> | 2012-10-12 18:00:58 (GMT) |
commit | 845371f2bc9140ba0c7e04cb994ebb8c3a86df64 (patch) | |
tree | 768215c89d3729877bf0ab0a54fcef98cc74ac24 | |
parent | 23399f51dd67dc96032f07309f993fd251b36c07 (diff) |
Icon: add new class CanvasIcon - SL #3989
Move code from shell ActivityIcon to new class CanvasIcon, that will
allow to reuse it in other icons. This class inherits EventIcon and
adds state and drawing handling. The right-click callback for the
palette invoker is not needed.
Signed-off-by: Manuel Quiñones <manuq@laptop.org>
Acked-by: Simon Schampijer <simon@laptop.org>
-rw-r--r-- | src/sugar3/graphics/icon.py | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/sugar3/graphics/icon.py b/src/sugar3/graphics/icon.py index 9008f3f..2d9c531 100644 --- a/src/sugar3/graphics/icon.py +++ b/src/sugar3/graphics/icon.py @@ -679,6 +679,71 @@ class EventIcon(Gtk.EventBox): self.set_palette(Palette(text)) +class CanvasIcon(EventIcon): + """ + An EventIcon with active and prelight states, and a styleable + background. + + If the icon pops up a palette, the prelight state is set until the + palette pops down. + + """ + + __gtype_name__ = 'SugarCanvasIcon' + + def __init__(self, **kwargs): + EventIcon.__init__(self, **kwargs) + + self._in_prelight_state = False + + self.connect('enter-notify-event', self.__enter_notify_event_cb) + self.connect('leave-notify-event', self.__leave_notify_event_cb) + self.connect('button-press-event', self.__button_press_event_cb) + self.connect('button-release-event', self.__button_release_event_cb) + + def connect_to_palette_pop_events(self, palette): + palette.connect('popup', self.__palette_popup_cb) + palette.connect('popdown', self.__palette_popdown_cb) + + def do_draw(self, cr): + """Render a background that fits the allocated space.""" + allocation = self.get_allocation() + context = self.get_style_context() + Gtk.render_background(context, cr, 0, 0, + allocation.width, + allocation.height) + + EventIcon.do_draw(self, cr) + + def __enter_notify_event_cb(self, icon, event): + self._in_prelight_state = True + if self.get_state() != Gtk.StateFlags.ACTIVE: + self.set_state(Gtk.StateFlags.PRELIGHT) + + def __leave_notify_event_cb(self, icon, event): + if self.palette.is_up(): + return + + self._in_prelight_state = False + if self.get_state() != Gtk.StateFlags.ACTIVE: + self.set_state(False) + + def __button_press_event_cb(self, icon, event): + self.set_state(Gtk.StateFlags.ACTIVE) + + def __button_release_event_cb(self, icon, event): + if self._in_prelight_state: + self.set_state(Gtk.StateFlags.PRELIGHT) + else: + self.set_state(False) + + def __palette_popup_cb(self, palette): + self.set_state(Gtk.StateFlags.PRELIGHT) + + def __palette_popdown_cb(self, palette): + self.set_state(False) + + class CellRendererIcon(Gtk.CellRenderer): __gtype_name__ = 'SugarCellRendererIcon' |