From f3fbea70a34ea7e762d0c8057fdb2cbc813bdf6f Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Wed, 18 Oct 2006 17:57:41 +0200 Subject: [PATCH 1/9] Rework menu positioning logic --- shell/view/frame/Frame.py | 4 +++ sugar/graphics/menushell.py | 57 ++++++++++++++++++++++++++++--------- 2 files changed, 47 insertions(+), 14 deletions(-) diff --git a/shell/view/frame/Frame.py b/shell/view/frame/Frame.py index de3091b9..64c75855 100644 --- a/shell/view/frame/Frame.py +++ b/shell/view/frame/Frame.py @@ -26,6 +26,7 @@ from view.frame.PanelWindow import PanelWindow from view.frame.notificationtray import NotificationTray from sugar.graphics.timeline import Timeline from sugar.graphics.grid import Grid +from sugar.graphics.menushell import MenuShell class EventFrame(gobject.GObject): __gsignals__ = { @@ -151,6 +152,7 @@ class Frame: # Top panel [menu_shell, root] = self._create_panel(grid, 0, 0, 16, 1) + menu_shell.set_position(MenuShell.BOTTOM) box = ZoomBox(self._shell, menu_shell) @@ -173,6 +175,7 @@ class Frame: # Bottom panel [menu_shell, root] = self._create_panel(grid, 0, 11, 16, 1) + menu_shell.set_position(MenuShell.TOP) box = ActivitiesBox(self._shell) root.append(box, hippo.PACK_FIXED) @@ -182,6 +185,7 @@ class Frame: # Right panel [menu_shell, root] = self._create_panel(grid, 15, 1, 1, 10) + menu_shell.set_position(MenuShell.LEFT) box = FriendsBox(self._shell, menu_shell) root.append(box) diff --git a/sugar/graphics/menushell.py b/sugar/graphics/menushell.py index bb25f9cd..c99db003 100644 --- a/sugar/graphics/menushell.py +++ b/sugar/graphics/menushell.py @@ -16,6 +16,7 @@ # Boston, MA 02111-1307, USA. import gobject +import gtk class MenuShell(gobject.GObject): __gsignals__ = { @@ -25,11 +26,21 @@ class MenuShell(gobject.GObject): gobject.TYPE_NONE, ([])), } + AUTO = 0 + LEFT = 1 + RIGHT = 2 + TOP = 3 + BOTTOM = 4 + def __init__(self, parent_canvas): gobject.GObject.__init__(self) self._parent_canvas = parent_canvas self._menu_controller = None + self._position = MenuShell.AUTO + + def set_position(self, position): + self._position = position def is_active(self): return (self._menu_controller != None) @@ -44,29 +55,47 @@ class MenuShell(gobject.GObject): self._menu_controller.popdown() self._menu_controller = controller - def _get_item_origin(self, item): + def _get_item_rect(self, item): [x, y] = item.get_context().translate_to_widget(item) [origin_x, origin_y] = self._parent_canvas.window.get_origin() x += origin_x y += origin_y - return [x, y] + [w, h] = item.get_allocation() + + return [x, y, w, h] def get_position(self, menu, item): - [x, y] = self._get_item_origin(item) - [width, height] = item.get_allocation() - - [canvas_x, canvas_y] = self._parent_canvas.window.get_origin() - canvas_rect = self._parent_canvas.get_allocation() + [item_x, item_y, item_w, item_h] = self._get_item_rect(item) [menu_w, menu_h] = menu.size_request() - menu_x = x - menu_y = y + height + left_x = item_x - menu_w + left_y = item_y + right_x = item_x + item_w + right_y = item_y + top_x = item_x + top_y = item_y - menu_h + bottom_x = item_x + bottom_y = item_y + item_h - if (menu_x + menu_w > canvas_x) and \ - (menu_y < canvas_y + canvas_rect.height): - menu_x = x - menu_w - menu_y = y + if self._position == MenuShell.LEFT: + [x, y] = [left_x, left_y] + elif self._position == MenuShell.RIGHT: + [x, y] = [right_x, right_y] + elif self._position == MenuShell.TOP: + [x, y] = [top_x, top_y] + elif self._position == MenuShell.BOTTOM: + [x, y] = [bottom_x, bottom_y] + elif self._position == MenuShell.AUTO: + [x, y] = [right_x, right_y] + if x + menu_w > gtk.gdk.screen_width(): + [x, y] = [left_x, left_y] - return [menu_x, menu_y] + x = min(x, gtk.gdk.screen_width()) + x = max(0, x) + + y = min(y, gtk.gdk.screen_height()) + y = max(0, y) + + return [x, y] From 6c375a20f3e08f28d3a9fa6d020f71aca9b9bcd3 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Wed, 18 Oct 2006 19:41:34 +0200 Subject: [PATCH 2/9] Center the icon in the allocation space --- shell/view/home/FriendView.py | 2 +- sugar/graphics/canvasicon.py | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/shell/view/home/FriendView.py b/shell/view/home/FriendView.py index 5b54cced..52bc26e8 100644 --- a/shell/view/home/FriendView.py +++ b/shell/view/home/FriendView.py @@ -75,7 +75,7 @@ class FriendView(hippo.CanvasBox): self._activity_icon.props.icon_name = name self._activity_icon.props.color = buddy.get_color() if not self._activity_icon_visible: - self.append(self._activity_icon) + self.append(self._activity_icon, hippo.PACK_EXPAND) self._activity_icon_visible = True else: self._remove_activity_icon() diff --git a/sugar/graphics/canvasicon.py b/sugar/graphics/canvasicon.py index 01e4c0b4..2d983ae2 100644 --- a/sugar/graphics/canvasicon.py +++ b/sugar/graphics/canvasicon.py @@ -143,7 +143,11 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem): icon_name, self._color, self._size) buf = self._get_buffer(cr, handle, self._size) - cr.set_source_surface(buf, 0.0, 0.0) + [width, height] = self.get_allocation() + x = (width - self._size) / 2 + y = (height - self._size) / 2 + + cr.set_source_surface(buf, x, y) cr.paint() def do_get_width_request(self): From e098bdf8ebfdf4a403f48479699ba767df020957 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Wed, 18 Oct 2006 21:50:14 +0200 Subject: [PATCH 3/9] Fix out of screen computation. Release 0.37 --- configure.ac | 2 +- sugar/graphics/menushell.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index f17f720e..9f2dd088 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -AC_INIT([Sugar],[0.36],[],[sugar]) +AC_INIT([Sugar],[0.37],[],[sugar]) AC_PREREQ([2.59]) diff --git a/sugar/graphics/menushell.py b/sugar/graphics/menushell.py index c99db003..48183e1e 100644 --- a/sugar/graphics/menushell.py +++ b/sugar/graphics/menushell.py @@ -92,10 +92,10 @@ class MenuShell(gobject.GObject): if x + menu_w > gtk.gdk.screen_width(): [x, y] = [left_x, left_y] - x = min(x, gtk.gdk.screen_width()) + x = min(x, gtk.gdk.screen_width() - menu_w) x = max(0, x) - y = min(y, gtk.gdk.screen_height()) + y = min(y, gtk.gdk.screen_height() - menu_h) y = max(0, y) return [x, y] From fafa1ae35ed73141131e445f4a883d71f9ef278d Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Thu, 19 Oct 2006 11:54:51 +0200 Subject: [PATCH 4/9] Refactor stylsheets code a bit to load the global stylsheet for all modules. Implement the links sidebar per discussion with Eben. --- activities/web/linksview.py | 47 +++++++++++++++++++------------- activities/web/stylesheet.py | 15 +++-------- shell/view/stylesheet.py | 52 +++++++----------------------------- sugar/graphics/__init__.py | 4 +++ sugar/graphics/style.py | 17 ++++++++++++ sugar/graphics/stylesheet.py | 21 +++++++++++++++ 6 files changed, 83 insertions(+), 73 deletions(-) create mode 100644 sugar/graphics/stylesheet.py diff --git a/activities/web/linksview.py b/activities/web/linksview.py index 92d7026d..70af786a 100644 --- a/activities/web/linksview.py +++ b/activities/web/linksview.py @@ -17,16 +17,31 @@ import gtk import hippo -from sugar.graphics.bubble import Bubble +from sugar.graphics.menu import Menu +from sugar.graphics.menushell import MenuShell +from sugar.graphics.menuicon import MenuIcon from sugar.graphics.iconcolor import IconColor from sugar.graphics import style +class LinkIcon(MenuIcon): + def __init__(self, menu_shell, link): + color = IconColor(link.buddy.get_color()) + MenuIcon.__init__(self, menu_shell, color=color, + icon_name='activity-web') + + self._link = link + + def create_menu(self): + menu = Menu(self._link.title) + return menu + class LinksView(hippo.Canvas): def __init__(self, model, browser): hippo.Canvas.__init__(self) - self._bubbles = {} + self._icons = {} self._browser = browser + self._menu_shell = MenuShell(self) self._box = hippo.CanvasBox() style.apply_stylesheet(self._box, 'links.Box') @@ -39,36 +54,30 @@ class LinksView(hippo.Canvas): model.connect('link_removed', self._link_removed_cb) def _add_link(self, link): - if len(self._bubbles) == 0: + if len(self._icons) == 0: self.show() - color = IconColor(link.buddy.get_color()) + icon = LinkIcon(self._menu_shell, link) + icon.connect('activated', self._link_activated_cb, link) + style.apply_stylesheet(icon, 'links.Icon') + self._box.append(icon) - bubble = Bubble(color=color) - style.apply_stylesheet(bubble, 'links.Bubble') - self._box.append(bubble) - - text = hippo.CanvasLink(text=link.title) - text.connect('activated', self._link_activated_cb, link) - style.apply_stylesheet(text, 'links.Text') - bubble.append(text, hippo.PACK_EXPAND) - - self._bubbles[link] = bubble + self._icons[link] = icon def _remove_link(self, link): - bubble = self._bubbles[link] - self._box.remove(bubble) + icon = self._icons[link] + self._box.remove(icon) - del self._bubbles[link] + del self._icons[link] - if len(self._bubbles) == 0: + if len(self._icons) == 0: self.hide() def _link_added_cb(self, model, link): self._add_link(link) def _link_removed_cb(self, model, link): - self._removed_link(link) + self._remove_link(link) def _link_activated_cb(self, link_item, link): self._browser.load_url(link.url) diff --git a/activities/web/stylesheet.py b/activities/web/stylesheet.py index b513c143..3628818f 100644 --- a/activities/web/stylesheet.py +++ b/activities/web/stylesheet.py @@ -16,19 +16,12 @@ import gtk -_screen_factor = gtk.gdk.screen_width() / 1200.0 +from sugar.graphics import style -links_Bubble = { - 'box-width' : int(250.0 * _screen_factor) -} - -links_Text = { - 'color' : 0x000000FF, - 'font' : '14px', - 'padding' : 6 +links_Icon = { + 'size' : style.standard_icon_size } links_Box = { - 'background_color' : 0x646464ff, - 'padding' : 4 + 'background_color' : 0x414141ff, } diff --git a/shell/view/stylesheet.py b/shell/view/stylesheet.py index 26c4f636..22ce2100 100644 --- a/shell/view/stylesheet.py +++ b/shell/view/stylesheet.py @@ -18,71 +18,37 @@ import gtk import hippo from sugar.graphics.iconcolor import IconColor - -_screen_factor = gtk.gdk.screen_width() / 1200.0 - -_standard_icon_size = int(75.0 * _screen_factor) -_small_icon_size = _standard_icon_size * 0.5 -_medium_icon_size = _standard_icon_size * 1.5 -_large_icon_size = _standard_icon_size * 2.0 -_xlarge_icon_size = _standard_icon_size * 3.0 - -_space_unit = 9 * _screen_factor -_separator_thickness = 3 * _screen_factor - -def _font_description(style, relative_size): - base_size = 18 * _screen_factor - return '%s %dpx' % (style, int(base_size * relative_size)) +from sugar.graphics import style frame_ActivityIcon = { 'color' : IconColor('white'), - 'size' : _standard_icon_size + 'size' : style.standard_icon_size } frame_ZoomIcon = { - 'size' : _standard_icon_size + 'size' : style.standard_icon_size } frame_BuddyIcon = { - 'size' : _standard_icon_size -} - -menu = { - 'background_color' : 0x000000FF, - 'spacing' : _space_unit, - 'padding' : _space_unit -} - -menu_Title = { - 'color' : 0xFFFFFFFF, - 'font' : _font_description('Bold', 1.2) -} - -menu_Separator = { - 'background_color' : 0xFFFFFFFF, - 'box_height' : _separator_thickness -} - -menu_ActionIcon = { - 'size' : _standard_icon_size + 'size' : style.standard_icon_size } home_MyIcon = { - 'size' : _xlarge_icon_size + 'size' : style.xlarge_icon_size } ring_ActivityIcon = { - 'size' : _medium_icon_size + 'size' : style.medium_icon_size } friends_MyIcon = { - 'size' : _large_icon_size + 'size' : style.large_icon_size } friends_FriendIcon = { - 'size' : _large_icon_size + 'size' : style.large_icon_size } friends_ActivityIcon = { - 'size' : _standard_icon_size + 'size' : style.standard_icon_size } diff --git a/sugar/graphics/__init__.py b/sugar/graphics/__init__.py index e69de29b..420e0e5e 100644 --- a/sugar/graphics/__init__.py +++ b/sugar/graphics/__init__.py @@ -0,0 +1,4 @@ +from sugar.graphics import style +from sugar.graphics import stylesheet + +style.load_stylesheet(stylesheet) diff --git a/sugar/graphics/style.py b/sugar/graphics/style.py index c211e07d..f0ab3e80 100644 --- a/sugar/graphics/style.py +++ b/sugar/graphics/style.py @@ -15,8 +15,21 @@ # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. +import gtk + _styles = {} +_screen_factor = gtk.gdk.screen_width() / 1200.0 + +space_unit = 9 * _screen_factor +separator_thickness = 3 * _screen_factor + +standard_icon_size = int(75.0 * _screen_factor) +small_icon_size = standard_icon_size * 0.5 +medium_icon_size = standard_icon_size * 1.5 +large_icon_size = standard_icon_size * 2.0 +xlarge_icon_size = standard_icon_size * 3.0 + def load_stylesheet(module): for objname in dir(module): if not objname.startswith('_'): @@ -32,3 +45,7 @@ def apply_stylesheet(item, stylesheet_name): style_sheet = _styles[stylesheet_name] for name in style_sheet.keys(): item.set_property(name, style_sheet[name]) + +def get_font_description(style, relative_size): + base_size = 18 * _screen_factor + return '%s %dpx' % (style, int(base_size * relative_size)) diff --git a/sugar/graphics/stylesheet.py b/sugar/graphics/stylesheet.py new file mode 100644 index 00000000..c387a259 --- /dev/null +++ b/sugar/graphics/stylesheet.py @@ -0,0 +1,21 @@ +from sugar.graphics import style + +menu = { + 'background_color' : 0x000000FF, + 'spacing' : style.space_unit, + 'padding' : style.space_unit +} + +menu_Title = { + 'color' : 0xFFFFFFFF, + 'font' : style.get_font_description('Bold', 1.2) +} + +menu_Separator = { + 'background_color' : 0xFFFFFFFF, + 'box_height' : style.separator_thickness +} + +menu_ActionIcon = { + 'size' : style.standard_icon_size +} From 3d3ef947e10e5d5fc2b6656bd299a42cc17f9615 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Thu, 19 Oct 2006 12:55:25 +0200 Subject: [PATCH 5/9] Fix method naming conflict --- shell/view/frame/FriendsBox.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/shell/view/frame/FriendsBox.py b/shell/view/frame/FriendsBox.py index 92e66b6d..57e9528f 100644 --- a/shell/view/frame/FriendsBox.py +++ b/shell/view/frame/FriendsBox.py @@ -39,7 +39,7 @@ class FriendsBox(hippo.CanvasBox): shell.connect('activity-changed', self.__activity_changed_cb) - def add(self, buddy): + def add_buddy(self, buddy): model = BuddyModel(buddy=buddy) icon = BuddyIcon(self._shell, self._menu_shell, model) style.apply_stylesheet(icon, 'frame.BuddyIcon') @@ -47,7 +47,7 @@ class FriendsBox(hippo.CanvasBox): self._buddies[buddy.get_name()] = icon - def remove(self, buddy): + def remove_buddy(self, buddy): self.remove(self._buddies[buddy.get_name()]) def clear(self): @@ -77,7 +77,7 @@ class FriendsBox(hippo.CanvasBox): if activity_ps != None: for buddy in activity_ps.get_joined_buddies(): - self.add(buddy) + self.add_buddy(buddy) self._joined_hid = activity_ps.connect( 'buddy-joined', self.__buddy_joined_cb) @@ -92,7 +92,7 @@ class FriendsBox(hippo.CanvasBox): self._set_activity_ps(None) def __buddy_joined_cb(self, activity, buddy): - self.add(buddy) + self.add_buddy(buddy) def __buddy_left_cb(self, activity, buddy): - self.remove(buddy) + self.remove_buddy(buddy) From 21aa37cc24edf3b4f4e69e263f049c7298bf7bf0 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Thu, 19 Oct 2006 13:28:59 +0200 Subject: [PATCH 6/9] Do not assume when curactivity change we already know about that activity. --- shell/model/MeshModel.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/shell/model/MeshModel.py b/shell/model/MeshModel.py index 374e5fa1..f65b9807 100644 --- a/shell/model/MeshModel.py +++ b/shell/model/MeshModel.py @@ -86,7 +86,7 @@ class MeshModel(gobject.GObject): if cur_activity == None: self.emit('buddy-moved', buddy_model, None) - else: + elif self._activities.has_key(cur_activity.get_id()): activity_model = self._activities[cur_activity.get_id()] self.emit('buddy-moved', buddy_model, activity_model) @@ -121,6 +121,12 @@ class MeshModel(gobject.GObject): self._activities[model.get_id()] = model self.emit('activity-added', model) + for buddy in self._pservice.get_buddies(): + cur_activity = buddy.get_current_activity() + if cur_activity == activity: + buddy_model = self._buddies[buddy.get_name()] + self.emit('buddy-moved', buddy, model) + def _activity_disappeared_cb(self, pservice, activity): if self._activities.has_key(activity.get_id()): activity_model = self._activities[activity.get_id()] From cf13a7ff5bcf4987d23d56669e6c984142033338 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Thu, 19 Oct 2006 14:51:13 +0200 Subject: [PATCH 7/9] Unregister the chat service on destroy. --- shell/model/BuddyModel.py | 5 +---- shell/view/ActivityHost.py | 2 +- sugar/chat/ActivityChat.py | 5 +++++ 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/shell/model/BuddyModel.py b/shell/model/BuddyModel.py index 32054256..651e911e 100644 --- a/shell/model/BuddyModel.py +++ b/shell/model/BuddyModel.py @@ -139,7 +139,4 @@ class BuddyModel(gobject.GObject): def __buddy_current_activity_changed_cb(self, buddy, activity=None): if not self._buddy: return - if activity: - self.emit('current-activity-changed', activity) - else: - self.emit('current-activity-changed') + self.emit('current-activity-changed', activity) diff --git a/shell/view/ActivityHost.py b/shell/view/ActivityHost.py index 4074de22..eacb30ff 100644 --- a/shell/view/ActivityHost.py +++ b/shell/view/ActivityHost.py @@ -150,6 +150,6 @@ class ActivityHost: def _activity_closed_cb(self, shell, activity): if activity == self: - self.chat_hide() + self._chat_window.destroy() self._frame_was_visible = False diff --git a/sugar/chat/ActivityChat.py b/sugar/chat/ActivityChat.py index 971b87df..a426abc2 100644 --- a/sugar/chat/ActivityChat.py +++ b/sugar/chat/ActivityChat.py @@ -26,6 +26,8 @@ class ActivityChat(GroupChat): GroupChat.__init__(self) self._chat_service = None + self.connect('destroy', self._destroy_cb) + self._activity = activity self._pservice.register_service_type(ActivityChat.SERVICE_TYPE) self._pservice.connect('service-appeared', self._service_appeared_cb) @@ -59,3 +61,6 @@ class ActivityChat(GroupChat): self._chat_service = self._pservice.share_activity(self._activity, stype=ActivityChat.SERVICE_TYPE) self._setup_stream(self._chat_service) + + def _destroy_cb(self, widget): + self._pservice.unregister_service(self._chat_service) From cd29967c2ece4e5569bbc5e11752e415ab971fda Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Thu, 19 Oct 2006 15:22:42 +0200 Subject: [PATCH 8/9] Refactor a bit to keep host independent from the shell --- shell/view/ActivityHost.py | 18 ++++++------------ shell/view/Shell.py | 26 +++++++++++++++++++++----- sugar/chat/ActivityChat.py | 3 ++- 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/shell/view/ActivityHost.py b/shell/view/ActivityHost.py index eacb30ff..61b7078d 100644 --- a/shell/view/ActivityHost.py +++ b/shell/view/ActivityHost.py @@ -42,9 +42,7 @@ class ActivityChatWindow(gtk.Window): self.add(chat_widget) class ActivityHost: - def __init__(self, shell, window): - self._shell = shell - + def __init__(self, window): self._window = window self._xid = window.get_xid() self._pservice = PresenceService.get_instance() @@ -73,8 +71,6 @@ class ActivityHost: self._chat_window = ActivityChatWindow(win, self._chat_widget) self._frame_was_visible = False - self._shell.connect('activity-changed', self._activity_changed_cb) - self._shell.connect('activity-closed', self._activity_closed_cb) def get_id(self): return self._id @@ -143,13 +139,11 @@ class ActivityHost: def is_chat_visible(self): return self._chat_window.get_property('visible') - def _activity_changed_cb(self, shell, activity): - if activity != self: + def set_active(self, active): + if not active: self.chat_hide() self._frame_was_visible = False - def _activity_closed_cb(self, shell, activity): - if activity == self: - self._chat_window.destroy() - self._frame_was_visible = False - + def destroy(self): + self._chat_window.destroy() + self._frame_was_visible = False diff --git a/shell/view/Shell.py b/shell/view/Shell.py index b2d9d738..29305cd5 100644 --- a/shell/view/Shell.py +++ b/shell/view/Shell.py @@ -45,6 +45,7 @@ class Shell(gobject.GObject): self._model = model self._hosts = {} self._screen = wnck.screen_get_default() + self._current_host = None style.load_stylesheet(view.stylesheet) @@ -95,7 +96,7 @@ class Shell(gobject.GObject): def __window_opened_cb(self, screen, window): if window.get_window_type() == wnck.WINDOW_NORMAL: - activity_host = ActivityHost(self, window) + activity_host = ActivityHost(window) self._hosts[activity_host.get_xid()] = activity_host self.emit('activity-opened', activity_host) @@ -104,24 +105,39 @@ class Shell(gobject.GObject): if window and window.get_window_type() == wnck.WINDOW_NORMAL: activity_host = self._hosts[window.get_xid()] - current = self._model.get_current_activity() if activity_host.get_id() == current: return - self._model.set_current_activity(activity_host.get_id()) - self.emit('activity-changed', activity_host) + self._set_current_activity(activity_host) def __window_closed_cb(self, screen, window): if window.get_window_type() == wnck.WINDOW_NORMAL: if self._hosts.has_key(window.get_xid()): host = self._hosts[window.get_xid()] + host.destroy() + self.emit('activity-closed', host) del self._hosts[window.get_xid()] if len(self._hosts) == 0: + self._set_current_activity(None) + + def _set_current_activity(self, host): + if host: + self._model.set_current_activity(host.get_id()) + else: self._model.set_current_activity(None) - self.emit('activity-changed', None) + + if self._current_host: + self._current_host.set_active(False) + + self._current_host = host + + if self._current_host: + self._current_host.set_active(True) + + self.emit('activity-changed', host) def get_model(self): return self._model diff --git a/sugar/chat/ActivityChat.py b/sugar/chat/ActivityChat.py index a426abc2..18926721 100644 --- a/sugar/chat/ActivityChat.py +++ b/sugar/chat/ActivityChat.py @@ -63,4 +63,5 @@ class ActivityChat(GroupChat): self._setup_stream(self._chat_service) def _destroy_cb(self, widget): - self._pservice.unregister_service(self._chat_service) + if self._chat_service: + self._pservice.unregister_service(self._chat_service) From 62659e280638e8b4a7509dbb1a6c6cd8c601bd7f Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Thu, 19 Oct 2006 15:44:00 +0200 Subject: [PATCH 9/9] Show the share button only when the activity is not shared --- shell/view/frame/ZoomBox.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/shell/view/frame/ZoomBox.py b/shell/view/frame/ZoomBox.py index 3c21f20d..45c76cda 100644 --- a/shell/view/frame/ZoomBox.py +++ b/shell/view/frame/ZoomBox.py @@ -29,9 +29,16 @@ class ActivityMenu(Menu): def __init__(self, activity_host): Menu.__init__(self, activity_host.get_title()) + if not activity_host.get_shared(): + self._add_mesh_action() + + self._add_close_action() + + def _add_mesh_action(self): icon = CanvasIcon(icon_name='stock-share-mesh') self.add_action(icon, ActivityMenu.ACTION_SHARE) + def _add_close_action(self): icon = CanvasIcon(icon_name='stock-close') self.add_action(icon, ActivityMenu.ACTION_CLOSE)