Ticket #3989: 0001-ActivityIcon-move-the-states-and-drawing-handling-to.patch

File 0001-ActivityIcon-move-the-states-and-drawing-handling-to.patch, 5.2 KB (added by manuq, 12 years ago)

Shell patch.

  • src/jarabe/desktop/favoritesview.py

    From a6dd681407b2f9692f688432ecfb53e9e9957a45 Mon Sep 17 00:00:00 2001
    From: =?UTF-8?q?Manuel=20Qui=C3=B1ones?= <manuq@laptop.org>
    Date: Wed, 10 Oct 2012 16:11:24 -0300
    Subject: [PATCH shell 1/2] ActivityIcon: move the states and drawing handling
     to the toolkit - 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 ActivityIcon to toolkit new class CanvasIcon, and make
    it the parent class.  This will allow reusing it in other icons.
    
    Signed-off-by: Manuel Quiñones <manuq@laptop.org>
    ---
     src/jarabe/desktop/favoritesview.py | 69 ++++---------------------------------
     1 file changed, 7 insertions(+), 62 deletions(-)
    
    diff --git a/src/jarabe/desktop/favoritesview.py b/src/jarabe/desktop/favoritesview.py
    index 7f5b160..d16b95e 100644
    a b from gi.repository import GdkPixbuf 
    2929from sugar3.graphics import style
    3030from sugar3.graphics.icon import Icon
    3131from sugar3.graphics.icon import EventIcon
     32from sugar3.graphics.icon import CanvasIcon
    3233from sugar3.graphics.menuitem import MenuItem
    3334from sugar3.graphics.alert import Alert
    3435from sugar3.graphics.xocolor import XoColor
    class FavoritesView(ViewContainer): 
    349350                icon.set_resume_mode(self._resume_mode)
    350351
    351352
    352 class ActivityIcon(EventIcon):
     353class ActivityIcon(CanvasIcon):
    353354    __gtype_name__ = 'SugarFavoriteActivityIcon'
    354355
    355356    _BORDER_WIDTH = style.zoom(9)
    356357    _MAX_RESUME_ENTRIES = 5
    357358
    358359    def __init__(self, activity_info):
    359         EventIcon.__init__(self, cache=True,
    360                            file_name=activity_info.get_icon())
     360        CanvasIcon.__init__(self, cache=True,
     361                            file_name=activity_info.get_icon())
    361362
    362363        self._activity_info = activity_info
    363364        self._journal_entries = []
    364365        self._resume_mode = True
    365366
    366         self._prelight_state = False
    367         self._active_state = False
    368 
    369         self.connect('enter-notify-event', self.__enter_notify_event_cb)
    370         self.connect('leave-notify-event', self.__leave_notify_event_cb)
    371         self.connect('button-press-event', self.__button_press_event_cb)
    372         self.palette_invoker.connect('right-click',
    373                                      self.__invoker_right_click_cb)
    374367        self.connect_after('button-release-event',
    375368                           self.__button_release_event_cb)
    376369
    class ActivityIcon(EventIcon): 
    432425        palette = FavoritePalette(self._activity_info, self._journal_entries)
    433426        palette.connect('activate', self.__palette_activate_cb)
    434427        palette.connect('entry-activate', self.__palette_entry_activate_cb)
    435         palette.connect('popup', self.__palette_popup_cb)
    436         palette.connect('popdown', self.__palette_popdown_cb)
     428        self.connect_palette_pop_events(palette)
    437429        return palette
    438430
    439431    def __palette_activate_cb(self, palette):
    class ActivityIcon(EventIcon): 
    442434    def __palette_entry_activate_cb(self, palette, metadata):
    443435        self._resume(metadata)
    444436
    445     def __palette_popup_cb(self, palette):
    446         self._prelight_state = Gtk.StateFlags.PRELIGHT
    447         self._active_state = False
    448         self._update_states()
    449 
    450     def __palette_popdown_cb(self, palette):
    451         self._prelight_state = False
    452         self._active_state = False
    453         self._update_states()
    454 
    455     def __enter_notify_event_cb(self, icon, event):
    456         self._prelight_state = Gtk.StateFlags.PRELIGHT
    457         self._update_states()
    458 
    459     def __leave_notify_event_cb(self, icon, event):
    460         if self.palette.is_up():
    461             return
    462         self._prelight_state = False
    463         self._update_states()
    464 
    465     def __button_press_event_cb(self, icon, event):
    466         self._active_state = Gtk.StateFlags.ACTIVE
    467         self._update_states()
    468 
    469     def _update_states(self):
    470         state = self._active_state if self._active_state \
    471             else self._prelight_state
    472         self.set_state(state)
    473 
    474     def do_draw(self, cr):
    475         allocation = self.get_allocation()
    476         context = self.get_style_context()
    477         Gtk.render_background(context, cr, 0, 0,
    478                               allocation.width,
    479                               allocation.height)
    480         Gtk.render_frame(context, cr, 0, 0,
    481                          allocation.width,
    482                          allocation.height)
    483 
    484         EventIcon.do_draw(self, cr)
    485 
    486437    def do_get_preferred_width(self):
    487         width = EventIcon.do_get_preferred_width(self)[0]
     438        width = CanvasIcon.do_get_preferred_width(self)[0]
    488439        width += ActivityIcon._BORDER_WIDTH * 2
    489440        return (width, width)
    490441
    491442    def do_get_preferred_height(self):
    492         height = EventIcon.do_get_preferred_height(self)[0]
     443        height = CanvasIcon.do_get_preferred_height(self)[0]
    493444        height += ActivityIcon._BORDER_WIDTH * 2
    494445        return (height, height)
    495446
    496     def __invoker_right_click_cb(self, invoker):
    497         self._active_state = False
    498         self._update_states()
    499 
    500447    def __button_release_event_cb(self, icon, event):
    501         self._active_state = False
    502         self._update_states()
    503448        self._activate()
    504449
    505450    def _resume(self, journal_entry):