[Sugar-devel] [PATCH shell 2/2] Home view: add active state to activity icons for click and tap feedback

Manuel Quiñones manuq at laptop.org
Wed Oct 3 16:44:46 EDT 2012


This makes the active state styleable in the theme.  When the icon is
pressed, the state is changed to active.

Also add a background render to the draw method, to make the backgroud
styleable too.

Signed-off-by: Manuel Quiñones <manuq at laptop.org>
---
 src/jarabe/desktop/favoritesview.py | 30 ++++++++++++++++++++++++++----
 1 file changed, 26 insertions(+), 4 deletions(-)

diff --git a/src/jarabe/desktop/favoritesview.py b/src/jarabe/desktop/favoritesview.py
index 6d0da17..c5ffdd3 100644
--- a/src/jarabe/desktop/favoritesview.py
+++ b/src/jarabe/desktop/favoritesview.py
@@ -357,8 +357,13 @@ class ActivityIcon(EventIcon):
         self._journal_entries = []
         self._resume_mode = True
 
+        self._prelight = False
+        self._active = 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.__press_cb)
+        self.connect('button-release-event', self.__release_cb)
         self.connect_after('button-release-event',
                            self.__button_release_event_cb)
 
@@ -429,20 +434,37 @@ class ActivityIcon(EventIcon):
         self._resume(metadata)
 
     def __enter_notify_event_cb(self, icon, event):
-        self.set_state(Gtk.StateFlags.PRELIGHT)
+        self._prelight = Gtk.StateFlags.PRELIGHT
+        self._update_states()
 
     def __leave_notify_event_cb(self, icon, event):
-        self.set_state(Gtk.StateFlags.NORMAL)
+        self._prelight = False
+        self._update_states()
 
-    def do_draw(self, cr):
-        EventIcon.do_draw(self, cr)
+    def __press_cb(self, icon, event):
+        self._active = Gtk.StateFlags.ACTIVE
+        self._update_states()
+
+    def __release_cb(self, icon, event):
+        self._active = False
+        self._update_states()
 
+    def _update_states(self):
+        state = self._active if self._active else self._prelight
+        self.set_state(state)
+
+    def do_draw(self, cr):
         allocation = self.get_allocation()
         context = self.get_style_context()
+        Gtk.render_background(context, cr, 0, 0,
+                              allocation.width,
+                              allocation.height)
         Gtk.render_frame(context, cr, 0, 0,
                          allocation.width,
                          allocation.height)
 
+        EventIcon.do_draw(self, cr)
+
     def do_get_preferred_width(self):
         width = EventIcon.do_get_preferred_width(self)[0]
         width += ActivityIcon._BORDER_WIDTH * 2
-- 
1.7.11.4



More information about the Sugar-devel mailing list