diff options
author | Walter Bender <walter.bender@gmail.com> | 2011-07-08 18:48:33 (GMT) |
---|---|---|
committer | Walter Bender <walter.bender@gmail.com> | 2011-07-08 18:48:33 (GMT) |
commit | fc1949e0a3e41be2f443803eabf134d8b301bb36 (patch) | |
tree | 423cfb81153274cc5cdd3c119fd5d497e07abbfa | |
parent | e9a6c1d6789224d5041503176ee4455472a49391 (diff) |
incorporation of Tomeu no-hippo patches with hippo-less CanvasIcon
-rw-r--r-- | src/jarabe/desktop/favoritesview.py | 248 |
1 files changed, 166 insertions, 82 deletions
diff --git a/src/jarabe/desktop/favoritesview.py b/src/jarabe/desktop/favoritesview.py index b609b1b..4c48faf 100644 --- a/src/jarabe/desktop/favoritesview.py +++ b/src/jarabe/desktop/favoritesview.py @@ -22,7 +22,6 @@ import math import gobject import gconf import gtk -import hippo from sugar.graphics import style from sugar.graphics.icon import Icon, CanvasIcon @@ -63,13 +62,149 @@ about the layout can be accessed with fields of the class.""" _favorites_settings = None -class FavoritesView(hippo.Canvas): +class FavoritesContainer(gtk.Container): + __gtype_name__ = 'SugarFavoritesContainer' + + def __init__(self, **kwargs): + gobject.GObject.__init__(self, **kwargs) + + self._my_icon = None + self._current_activity = None + self._activity_icons = [] + self._layout = None + + def do_realize(self): + self.set_flags(self.flags() | gtk.REALIZED) + + self.window = gtk.gdk.Window( + self.get_parent_window(), + width=self.allocation.width, + height=self.allocation.height, + window_type=gtk.gdk.WINDOW_CHILD, + wclass=gtk.gdk.INPUT_OUTPUT, + event_mask=self.get_events() | gtk.gdk.EXPOSURE_MASK + | gtk.gdk.BUTTON1_MOTION_MASK + | gtk.gdk.BUTTON_PRESS_MASK + | gtk.gdk.POINTER_MOTION_MASK + | gtk.gdk.POINTER_MOTION_HINT_MASK) + self.window.set_user_data(self) + + self.style.attach(self.window) + self.style.set_background(self.window, gtk.STATE_NORMAL) + self.window.move_resize(*self.allocation) + self.gc = self.style.fg_gc[gtk.STATE_NORMAL] + + self.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse('white')) + + def do_forall(self, include_internals, forall_cb, user_data): + children = self._activity_icons[:] + + if self._my_icon is not None: + children.append(self._my_icon) + + if self._current_activity is not None: + children.append(self._current_activity) + + for child in children: + forall_cb(child, user_data) + + def do_remove(self, child): + if child == self._my_icon: + self._my_icon = None + elif child == self._current_activity: + self._current_activity = None + else: + self._activity_icons.remove(child) + + def do_size_request(self, requisition): + # TODO: calculate our minimum size + requisition.height = 200 + requisition.width = 200 + + def do_size_allocate(self, allocation): + if self.flags() & gtk.REALIZED: + self.window.move_resize(*allocation) + + width, height = allocation.width, allocation.height + + # Position the XO icon in the center of the screen + my_icon_width, my_icon_height = self._my_icon.size_request() + x = (width - my_icon_width) / 2 + y = (height - my_icon_height - style.GRID_CELL_SIZE) / 2 + + child_allocation = gtk.gdk.Rectangle(x, y, my_icon_width, my_icon_height) + self._my_icon.size_allocate(child_allocation) + + # Position the current activity just below the XO icon + icon_width, icon_height = self._current_activity.size_request() + logging.debug('CURRENT ACTIVITY SIZE REQUEST: %d %d', + icon_width, icon_height) + x = (width - icon_width) / 2 + y = (height - my_icon_height - style.GRID_CELL_SIZE) / 2 + \ + my_icon_height + style.DEFAULT_PADDING + + child_allocation = gtk.gdk.Rectangle(x, y, icon_width, icon_height) + self._current_activity.size_allocate(child_allocation) + + # Position the favorite activities + allocations = self._layout.allocate_icons(self._activity_icons, width, + height) + assert len(allocations) == len(self._activity_icons) + for icon, allocation in zip(self._activity_icons, allocations): + icon.size_allocate(allocation) + + def set_my_icon(self, icon): + self._my_icon = icon + self._my_icon.set_parent(self) + + def set_current_activity(self, icon): + self._current_activity = icon + self._current_activity.set_parent(self) + + def add_activity_icon(self, icon): + self._activity_icons.append(icon) + icon.set_parent(self) + + def _set_layout(self, layout): + if layout not in LAYOUT_MAP: + logging.warn('Unknown favorites layout: %r' % layout) + layout = favoriteslayout.RingLayout.key + assert layout in LAYOUT_MAP + + if type(self._layout) == LAYOUT_MAP[layout]: + return + + ''' + # TODO: add sort() + self.sort(self._layout.compare_activities) + + for icon in self.get_children(): + if icon not in [self._my_icon, self._current_activity]: + self._layout.append(icon) + + self._layout.append(self._my_icon, locked=True) + self._layout.append(self._current_activity, locked=True) + + if self._layout.allow_dnd(): + self.drag_source_set(0, [], 0) + self.drag_dest_set(0, [], 0) + else: + self.drag_source_unset() + self.drag_dest_unset() + ''' + + self._layout = LAYOUT_MAP[layout]() + + layout = property(None, _set_layout) + + +class FavoritesView(FavoritesContainer): __gtype_name__ = 'SugarFavoritesView' def __init__(self, **kwargs): logging.debug('STARTUP: Loading the favorites view') - gobject.GObject.__init__(self, **kwargs) + FavoritesContainer.__init__(self, **kwargs) # DND stuff self._pressed_button = None @@ -79,16 +214,14 @@ class FavoritesView(hippo.Canvas): self._hot_y = None self._last_clicked_icon = None - self._box = hippo.CanvasBox() - self._box.props.background_color = style.COLOR_WHITE.get_int() - self.set_root(self._box) - self._my_icon = OwnerIcon(style.XLARGE_ICON_SIZE) self._my_icon.connect('register-activate', self.__register_activate_cb) - self._box.append(self._my_icon) + self.set_my_icon(self._my_icon) + self._my_icon.show() self._current_activity = CurrentActivityIcon() - self._box.append(self._current_activity) + self.set_current_activity(self._current_activity) + self._current_activity.show() self._layout = None self._alert = None @@ -132,8 +265,8 @@ class FavoritesView(hippo.Canvas): icon = ActivityIcon(activity_info) icon.props.size = style.STANDARD_ICON_SIZE icon.set_resume_mode(self._resume_mode) - self._box.insert_sorted(icon, 0, self._layout.compare_activities) - self._layout.append(icon) + self.add_activity_icon(icon) + icon.show() def __activity_added_cb(self, activity_registry, activity_info): registry = bundleregistry.get_registry() @@ -161,34 +294,14 @@ class FavoritesView(hippo.Canvas): icon = self._find_activity_icon(activity_info.get_bundle_id(), activity_info.get_activity_version()) if icon is not None: - self._box.remove(icon) + self._layout.remove(icon) + self.remove(icon) registry = bundleregistry.get_registry() if registry.is_bundle_favorite(activity_info.get_bundle_id(), activity_info.get_activity_version()): self._add_activity(activity_info) - def do_size_allocate(self, allocation): - width = allocation.width - height = allocation.height - - min_w_, my_icon_width = self._my_icon.get_width_request() - min_h_, my_icon_height = self._my_icon.get_height_request( - my_icon_width) - x = (width - my_icon_width) / 2 - y = (height - my_icon_height - style.GRID_CELL_SIZE) / 2 - self._layout.move_icon(self._my_icon, x, y, locked=True) - - min_w_, icon_width = self._current_activity.get_width_request() - min_h_, icon_height = \ - self._current_activity.get_height_request(icon_width) - x = (width - icon_width) / 2 - y = (height - my_icon_height - style.GRID_CELL_SIZE) / 2 + \ - my_icon_height + style.DEFAULT_PADDING - self._layout.move_icon(self._current_activity, x, y, locked=True) - - hippo.Canvas.do_size_allocate(self, allocation) - # TODO: Dnd methods. This should be merged somehow inside hippo-canvas. def __button_press_event_cb(self, widget, event): if event.button == 1 and event.type == gtk.gdk.BUTTON_PRESS: @@ -202,12 +315,10 @@ class FavoritesView(hippo.Canvas): return False def _get_icon_at_coords(self, x, y): - for icon in self._box.get_children(): - icon_x, icon_y = icon.get_context().translate_to_widget(icon) - icon_width, icon_height = icon.get_allocation() - - if (x >= icon_x) and (x <= icon_x + icon_width) and \ - (y >= icon_y) and (y <= icon_y + icon_height) and \ + for icon in self.get_children(): + rect = icon.get_allocation() + if (x >= rect.x) and (x <= rect.x + rect.width) and \ + (y >= rect.y) and (y <= rect.y + rect.height) and \ isinstance(icon, ActivityIcon): return icon return None @@ -275,48 +386,16 @@ class FavoritesView(hippo.Canvas): info, time): context.drop_finish(success=True, time=time) - def _set_layout(self, layout): - if layout not in LAYOUT_MAP: - logging.warn('Unknown favorites layout: %r', layout) - layout = favoriteslayout.RingLayout.key - assert layout in LAYOUT_MAP - - if type(self._layout) == LAYOUT_MAP[layout]: - return - - self._layout = LAYOUT_MAP[layout]() - self._box.set_layout(self._layout) - - #TODO: compatibility hack while sort() gets added to the hippo python - # bindings - if hasattr(self._box, 'sort'): - self._box.sort(self._layout.compare_activities) - - for icon in self._box.get_children(): - if icon not in [self._my_icon, self._current_activity]: - self._layout.append(icon) - - self._layout.append(self._my_icon, locked=True) - self._layout.append(self._current_activity, locked=True) - - if self._layout.allow_dnd(): - self.drag_source_set(0, [], 0) - self.drag_dest_set(0, [], 0) - else: - self.drag_source_unset() - self.drag_dest_unset() - - layout = property(None, _set_layout) - def add_alert(self, alert): + # TODO: debug alert if self._alert is not None: self.remove_alert() alert.set_size_request(gtk.gdk.screen_width(), -1) - self._alert = hippo.CanvasWidget(widget=alert) - self._box.append(self._alert, hippo.PACK_FIXED) + self._alert = gtk.VBox() # widget=alert) + # self.append(self._alert) # , hippo.PACK_FIXED) def remove_alert(self): - self._box.remove(self._alert) + self.remove(self._alert) self._alert = None def __register_activate_cb(self, icon): @@ -343,7 +422,7 @@ class FavoritesView(hippo.Canvas): def set_resume_mode(self, resume_mode): self._resume_mode = resume_mode - for icon in self._box.get_children(): + for icon in self.get_children(): if hasattr(icon, 'set_resume_mode'): icon.set_resume_mode(self._resume_mode) @@ -363,7 +442,8 @@ class ActivityIcon(CanvasIcon): self._hovering = False self._resume_mode = True - self.connect('hovering-changed', self.__hovering_changed_event_cb) + self.connect('enter-notify-event', self.__hovering_changed_event_cb) + self.connect('leave-notify-event', self.__hovering_changed_event_cb) self.connect('button-release-event', self.__button_release_event_cb) datastore.updated.connect(self.__datastore_listener_updated_cb) @@ -456,8 +536,7 @@ class ActivityIcon(CanvasIcon): cr.arc(x + radius, y + height - radius, radius, math.pi * 0.5, math.pi) cr.arc(x + radius, y + radius, radius, math.pi, math.pi * 1.5) - color = style.COLOR_SELECTION_GREY.get_int() - hippo.cairo_set_source_rgba32(cr, color) + cr.set_source_color(style.COLOR_SELECTION_GREY.get_gtk_color()) cr.set_line_width(ActivityIcon._BORDER_WIDTH) cr.stroke() @@ -560,7 +639,7 @@ class FavoritePalette(ActivityPalette): self.emit('entry-activate', entry) -class CurrentActivityIcon(CanvasIcon, hippo.CanvasItem): +class CurrentActivityIcon(CanvasIcon): def __init__(self): CanvasIcon.__init__(self, cache=True) self._home_model = shell.get_model() @@ -580,8 +659,10 @@ class CurrentActivityIcon(CanvasIcon, hippo.CanvasItem): def _update(self): self.props.file_name = self._home_activity.get_icon_path() + logging.debug('CURRENT_ACTIVITY PATH %s', + self._home_activity.get_icon_path()) self.props.xo_color = self._home_activity.get_icon_color() - self.props.size = style.STANDARD_ICON_SIZE + # self.props.size = style.STANDARD_ICON_SIZE if self.palette is not None: self.palette.destroy() @@ -638,7 +719,10 @@ class OwnerIcon(BuddyIcon): return palette def get_toplevel(self): - return hippo.get_canvas_for_item(self).get_toplevel() + # called by palettewindow.py + # FIXME?: this was a call to + # hippo.get_canvas_for_item(self).get_toplevel() + return None def __register_activate_cb(self, menuitem): self.emit('register-activate') |