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, 11 years ago) |
---|
-
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 29 29 from sugar3.graphics import style 30 30 from sugar3.graphics.icon import Icon 31 31 from sugar3.graphics.icon import EventIcon 32 from sugar3.graphics.icon import CanvasIcon 32 33 from sugar3.graphics.menuitem import MenuItem 33 34 from sugar3.graphics.alert import Alert 34 35 from sugar3.graphics.xocolor import XoColor … … class FavoritesView(ViewContainer): 349 350 icon.set_resume_mode(self._resume_mode) 350 351 351 352 352 class ActivityIcon( EventIcon):353 class ActivityIcon(CanvasIcon): 353 354 __gtype_name__ = 'SugarFavoriteActivityIcon' 354 355 355 356 _BORDER_WIDTH = style.zoom(9) 356 357 _MAX_RESUME_ENTRIES = 5 357 358 358 359 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()) 361 362 362 363 self._activity_info = activity_info 363 364 self._journal_entries = [] 364 365 self._resume_mode = True 365 366 366 self._prelight_state = False367 self._active_state = False368 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)374 367 self.connect_after('button-release-event', 375 368 self.__button_release_event_cb) 376 369 … … class ActivityIcon(EventIcon): 432 425 palette = FavoritePalette(self._activity_info, self._journal_entries) 433 426 palette.connect('activate', self.__palette_activate_cb) 434 427 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) 437 429 return palette 438 430 439 431 def __palette_activate_cb(self, palette): … … class ActivityIcon(EventIcon): 442 434 def __palette_entry_activate_cb(self, palette, metadata): 443 435 self._resume(metadata) 444 436 445 def __palette_popup_cb(self, palette):446 self._prelight_state = Gtk.StateFlags.PRELIGHT447 self._active_state = False448 self._update_states()449 450 def __palette_popdown_cb(self, palette):451 self._prelight_state = False452 self._active_state = False453 self._update_states()454 455 def __enter_notify_event_cb(self, icon, event):456 self._prelight_state = Gtk.StateFlags.PRELIGHT457 self._update_states()458 459 def __leave_notify_event_cb(self, icon, event):460 if self.palette.is_up():461 return462 self._prelight_state = False463 self._update_states()464 465 def __button_press_event_cb(self, icon, event):466 self._active_state = Gtk.StateFlags.ACTIVE467 self._update_states()468 469 def _update_states(self):470 state = self._active_state if self._active_state \471 else self._prelight_state472 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 486 437 def do_get_preferred_width(self): 487 width = EventIcon.do_get_preferred_width(self)[0]438 width = CanvasIcon.do_get_preferred_width(self)[0] 488 439 width += ActivityIcon._BORDER_WIDTH * 2 489 440 return (width, width) 490 441 491 442 def do_get_preferred_height(self): 492 height = EventIcon.do_get_preferred_height(self)[0]443 height = CanvasIcon.do_get_preferred_height(self)[0] 493 444 height += ActivityIcon._BORDER_WIDTH * 2 494 445 return (height, height) 495 446 496 def __invoker_right_click_cb(self, invoker):497 self._active_state = False498 self._update_states()499 500 447 def __button_release_event_cb(self, icon, event): 501 self._active_state = False502 self._update_states()503 448 self._activate() 504 449 505 450 def _resume(self, journal_entry):