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

Manuel Quiñones manuq at laptop.org
Thu Oct 4 23:54:26 EDT 2012


- Set the activity icon state to 'active' when it is pressed.  This
  state can then be styled in the theme.

- Set the activity icon state to 'prelight' when its palette pops up.

- Add a background render to the draw method to make the background of
  the icon styleable.

We have to connect to the palette invoker 'right-click' event and
reset the state in the palette 'popdown' event because the invoker
captures the mouse events and does not propagate them.  See
documentation in popup method of _PaletteMenuWidget in toolkit
palettewindow.py for reference.

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

diff --git a/src/jarabe/desktop/favoritesview.py b/src/jarabe/desktop/favoritesview.py
index b727e0e..4600341 100644
--- a/src/jarabe/desktop/favoritesview.py
+++ b/src/jarabe/desktop/favoritesview.py
@@ -361,8 +361,14 @@ class ActivityIcon(EventIcon):
         self._journal_entries = []
         self._resume_mode = True
 
+        self._prelight_state = False
+        self._active_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.palette_invoker.connect('right-click',
+                                     self.__invoker_right_click_cb)
         self.connect_after('button-release-event',
                            self.__button_release_event_cb)
 
@@ -424,6 +430,8 @@ class ActivityIcon(EventIcon):
         palette = FavoritePalette(self._activity_info, self._journal_entries)
         palette.connect('activate', self.__palette_activate_cb)
         palette.connect('entry-activate', self.__palette_entry_activate_cb)
+        palette.connect('popup', self.__palette_popup_cb)
+        palette.connect('popdown', self.__palette_popdown_cb)
         return palette
 
     def __palette_activate_cb(self, palette):
@@ -432,21 +440,47 @@ class ActivityIcon(EventIcon):
     def __palette_entry_activate_cb(self, palette, metadata):
         self._resume(metadata)
 
+    def __palette_popup_cb(self, palette):
+        self._prelight_state = Gtk.StateFlags.PRELIGHT
+        self._active_state = False
+        self._update_states()
+
+    def __palette_popdown_cb(self, palette):
+        self._prelight_state = False
+        self._active_state = False
+        self._update_states()
+
     def __enter_notify_event_cb(self, icon, event):
-        self.set_state(Gtk.StateFlags.PRELIGHT)
+        self._prelight_state = Gtk.StateFlags.PRELIGHT
+        self._update_states()
 
     def __leave_notify_event_cb(self, icon, event):
-        self.set_state(Gtk.StateFlags.NORMAL)
+        if self.palette.is_up():
+            return
+        self._prelight_state = False
+        self._update_states()
 
-    def do_draw(self, cr):
-        EventIcon.do_draw(self, cr)
+    def __button_press_event_cb(self, icon, event):
+        self._active_state = Gtk.StateFlags.ACTIVE
+        self._update_states()
 
+    def _update_states(self):
+        state = self._active_state if self._active_state \
+            else self._prelight_state
+        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
@@ -457,7 +491,13 @@ class ActivityIcon(EventIcon):
         height += ActivityIcon._BORDER_WIDTH * 2
         return (height, height)
 
+    def __invoker_right_click_cb(self, invoker):
+        self._active_state = False
+        self._update_states()
+
     def __button_release_event_cb(self, icon, event):
+        self._active_state = False
+        self._update_states()
         self._activate()
 
     def _resume(self, journal_entry):
-- 
1.7.11.4



More information about the Sugar-devel mailing list