Ticket #3989: 0002-CanvasIcon-use-set_state_flags-and-unset_state_flags.patch

File 0002-CanvasIcon-use-set_state_flags-and-unset_state_flags.patch, 2.9 KB (added by manuq, 10 years ago)

Fixup for toolkit - use state flags

  • src/sugar3/graphics/icon.py

    From 5ccd99f62ebb1bfd3380a51dd70f2065ce588dee Mon Sep 17 00:00:00 2001
    From: =?UTF-8?q?Manuel=20Qui=C3=B1ones?= <manuq@laptop.org>
    Date: Mon, 15 Oct 2012 11:28:44 -0300
    Subject: [PATCH toolkit 2/2] CanvasIcon: use set_state_flags and
     unset_state_flags instead of deprecated
     set_state - 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>
    
    set_state is deprecated [1] and using flags improves the code and
    makes it less error prone, because there is no need to handle the
    prelight state in a variable _in_prelight_state .
    
    [1] http://developer.gnome.org/gtk3/stable/GtkWidget.html#gtk-widget-set-state
    
    Signed-off-by: Manuel Quiñones <manuq@laptop.org>
    ---
     src/sugar3/graphics/icon.py | 23 ++++++++---------------
     1 file changed, 8 insertions(+), 15 deletions(-)
    
    diff --git a/src/sugar3/graphics/icon.py b/src/sugar3/graphics/icon.py
    index 95a72b8..5863118 100644
    a b class CanvasIcon(EventIcon): 
    694694    def __init__(self, **kwargs):
    695695        EventIcon.__init__(self, **kwargs)
    696696
    697         self._in_prelight_state = False
    698 
    699697        self.connect('enter-notify-event', self.__enter_notify_event_cb)
    700698        self.connect('leave-notify-event', self.__leave_notify_event_cb)
    701699        self.connect('button-press-event', self.__button_press_event_cb)
    class CanvasIcon(EventIcon): 
    716714        EventIcon.do_draw(self, cr)
    717715
    718716    def __enter_notify_event_cb(self, icon, event):
    719         self._in_prelight_state = True
    720         if self.get_state() != Gtk.StateFlags.ACTIVE:
    721             self.set_state(Gtk.StateFlags.PRELIGHT)
     717        self.set_state_flags(self.get_state_flags() | Gtk.StateFlags.PRELIGHT,
     718                             clear=True)
    722719
    723720    def __leave_notify_event_cb(self, icon, event):
    724721        if self.palette and self.palette.is_up():
    725722            return
    726723
    727         self._in_prelight_state = False
    728         if self.get_state() != Gtk.StateFlags.ACTIVE:
    729             self.set_state(False)
     724        self.unset_state_flags(Gtk.StateFlags.PRELIGHT)
    730725
    731726    def __button_press_event_cb(self, icon, event):
    732         self.set_state(Gtk.StateFlags.ACTIVE)
     727        self.set_state_flags(self.get_state_flags() | Gtk.StateFlags.ACTIVE,
     728                             clear=True)
    733729
    734730    def __button_release_event_cb(self, icon, event):
    735         if self._in_prelight_state:
    736             self.set_state(Gtk.StateFlags.PRELIGHT)
    737         else:
    738             self.set_state(False)
     731        self.unset_state_flags(Gtk.StateFlags.ACTIVE)
    739732
    740733    def __palette_popup_cb(self, palette):
    741         self.set_state(Gtk.StateFlags.PRELIGHT)
     734        self.set_state_flags(Gtk.StateFlags.PRELIGHT, clear=True)
    742735
    743736    def __palette_popdown_cb(self, palette):
    744         self.set_state(False)
     737        self.unset_state_flags(Gtk.StateFlags.PRELIGHT)
    745738
    746739
    747740class CellRendererIcon(Gtk.CellRenderer):