Ticket #3989: 0001-Icon-add-new-class-CanvasIcon-SL-3989.patch

File 0001-Icon-add-new-class-CanvasIcon-SL-3989.patch, 3.6 KB (added by manuq, 10 years ago)

Toolkit patch.

  • src/sugar3/graphics/icon.py

    From 3e17c3a04d274bca0405b8083d8b714e2b19011f Mon Sep 17 00:00:00 2001
    From: =?UTF-8?q?Manuel=20Qui=C3=B1ones?= <manuq@laptop.org>
    Date: Wed, 10 Oct 2012 16:20:05 -0300
    Subject: [PATCH toolkit-gtk3] Icon: add new class CanvasIcon - SL #3989
    MIME-Version: 1.0
    Content-Type: text/plain; charset=UTF-8
    Content-Transfer-Encoding: 8bit
    Mail-Followup-To: <sugar-devel@lists.sugarlabs.org>
    
    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.
    
    Signed-off-by: Manuel Quiñones <manuq@laptop.org>
    ---
     src/sugar3/graphics/icon.py | 77 +++++++++++++++++++++++++++++++++++++++++++++
     1 file changed, 77 insertions(+)
    
    diff --git a/src/sugar3/graphics/icon.py b/src/sugar3/graphics/icon.py
    index 9008f3f..91a84ae 100644
    a b class EventIcon(Gtk.EventBox): 
    679679        self.set_palette(Palette(text))
    680680
    681681
     682class CanvasIcon(EventIcon):
     683    """
     684    An EventIcon with active and prelight states, and a styleable
     685    background.
     686
     687    If the icon pops up a palette, the prelight state is set until the
     688    palette pops down.
     689
     690    """
     691
     692    __gtype_name__ = 'SugarCanvasIcon'
     693
     694    def __init__(self, **kwargs):
     695        EventIcon.__init__(self, **kwargs)
     696
     697        self._prelight_state = False
     698        self._active_state = False
     699
     700        self.connect('enter-notify-event', self.__enter_notify_event_cb)
     701        self.connect('leave-notify-event', self.__leave_notify_event_cb)
     702        self.connect('button-press-event', self.__button_press_event_cb)
     703        self.connect('button-release-event', self.__button_release_event_cb)
     704        self.palette_invoker.connect('right-click',
     705                                     self.__invoker_right_click_cb)
     706
     707    def connect_palette_pop_events(self, palette):
     708        palette.connect('popup', self.__palette_popup_cb)
     709        palette.connect('popdown', self.__palette_popdown_cb)
     710
     711    def do_draw(self, cr):
     712        """Render a background that fits the allocated space."""
     713        allocation = self.get_allocation()
     714        context = self.get_style_context()
     715        Gtk.render_background(context, cr, 0, 0,
     716                              allocation.width,
     717                              allocation.height)
     718
     719        EventIcon.do_draw(self, cr)
     720
     721    def _update_states(self):
     722        state = self._active_state if self._active_state \
     723            else self._prelight_state
     724        self.set_state(state)
     725
     726    def __enter_notify_event_cb(self, icon, event):
     727        self._prelight_state = Gtk.StateFlags.PRELIGHT
     728        self._update_states()
     729
     730    def __leave_notify_event_cb(self, icon, event):
     731        if self.palette.is_up():
     732            return
     733        self._prelight_state = False
     734        self._update_states()
     735
     736    def __button_press_event_cb(self, icon, event):
     737        self._active_state = Gtk.StateFlags.ACTIVE
     738        self._update_states()
     739
     740    def __button_release_event_cb(self, icon, event):
     741        self._active_state = False
     742        self._update_states()
     743
     744    def __invoker_right_click_cb(self, invoker):
     745        self._active_state = False
     746        self._update_states()
     747
     748    def __palette_popup_cb(self, palette):
     749        self._prelight_state = Gtk.StateFlags.PRELIGHT
     750        self._active_state = False
     751        self._update_states()
     752
     753    def __palette_popdown_cb(self, palette):
     754        self._prelight_state = False
     755        self._active_state = False
     756        self._update_states()
     757
     758
    682759class CellRendererIcon(Gtk.CellRenderer):
    683760
    684761    __gtype_name__ = 'SugarCellRendererIcon'