CanvasIcon: use set_state_flags and unset_state_flags instead of deprecated set_state - SL #3989
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> Acked-by: Simon Schampijer <simon@laptop.org>
This commit is contained in:
parent
e591d9aa80
commit
e4e1881662
@ -694,8 +694,6 @@ class CanvasIcon(EventIcon):
|
||||
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)
|
||||
@ -716,32 +714,27 @@ class CanvasIcon(EventIcon):
|
||||
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)
|
||||
self.set_state_flags(self.get_state_flags() | Gtk.StateFlags.PRELIGHT,
|
||||
clear=True)
|
||||
|
||||
def __leave_notify_event_cb(self, icon, event):
|
||||
if self.palette and self.palette.is_up():
|
||||
return
|
||||
|
||||
self._in_prelight_state = False
|
||||
if self.get_state() != Gtk.StateFlags.ACTIVE:
|
||||
self.set_state(False)
|
||||
self.unset_state_flags(Gtk.StateFlags.PRELIGHT)
|
||||
|
||||
def __button_press_event_cb(self, icon, event):
|
||||
self.set_state(Gtk.StateFlags.ACTIVE)
|
||||
self.set_state_flags(self.get_state_flags() | Gtk.StateFlags.ACTIVE,
|
||||
clear=True)
|
||||
|
||||
def __button_release_event_cb(self, icon, event):
|
||||
if self._in_prelight_state:
|
||||
self.set_state(Gtk.StateFlags.PRELIGHT)
|
||||
else:
|
||||
self.set_state(False)
|
||||
self.unset_state_flags(Gtk.StateFlags.ACTIVE)
|
||||
|
||||
def __palette_popup_cb(self, palette):
|
||||
self.set_state(Gtk.StateFlags.PRELIGHT)
|
||||
self.set_state_flags(Gtk.StateFlags.PRELIGHT, clear=True)
|
||||
|
||||
def __palette_popdown_cb(self, palette):
|
||||
self.set_state(False)
|
||||
self.unset_state_flags(Gtk.StateFlags.PRELIGHT)
|
||||
|
||||
|
||||
class CellRendererIcon(Gtk.CellRenderer):
|
||||
|
Loading…
Reference in New Issue
Block a user