From 9ff192d0b3ab7ed3259e1f934eb4421e3ff9032d Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Tue, 19 Sep 2006 14:04:11 +0200 Subject: [PATCH] Use a different menu shell for the zoom view and the frame --- shell/view/BuddyIcon.py | 4 ++-- shell/view/frame/Frame.py | 6 ++++-- shell/view/frame/RightPanel.py | 5 +++-- shell/view/frame/TopPanel.py | 9 +++++---- shell/view/home/FriendsGroup.py | 5 +++-- shell/view/home/HomeWindow.py | 5 ++++- sugar/canvas/MenuIcon.py | 21 ++++++--------------- sugar/canvas/MenuShell.py | 12 ++++++++++++ 8 files changed, 39 insertions(+), 28 deletions(-) create mode 100644 sugar/canvas/MenuShell.py diff --git a/shell/view/BuddyIcon.py b/shell/view/BuddyIcon.py index ad5fd033..0cf90feb 100644 --- a/shell/view/BuddyIcon.py +++ b/shell/view/BuddyIcon.py @@ -2,8 +2,8 @@ from sugar.canvas.MenuIcon import MenuIcon from view.BuddyMenu import BuddyMenu class BuddyIcon(MenuIcon): - def __init__(self, shell, friend): - MenuIcon.__init__(self, shell.get_grid(), icon_name='stock-buddy', + def __init__(self, shell, menu_shell, friend): + MenuIcon.__init__(self, menu_shell, icon_name='stock-buddy', color=friend.get_color(), size=96) self._shell = shell diff --git a/shell/view/frame/Frame.py b/shell/view/frame/Frame.py index d76d1ced..bd99b98d 100644 --- a/shell/view/frame/Frame.py +++ b/shell/view/frame/Frame.py @@ -8,6 +8,7 @@ from view.frame.RightPanel import RightPanel from view.frame.TopPanel import TopPanel from view.frame.PanelWindow import PanelWindow from sugar.canvas.Grid import Grid +from sugar.canvas.MenuShell import MenuShell class EventFrame(gobject.GObject): __gsignals__ = { @@ -74,6 +75,7 @@ class Frame: root = model.get_root_item() grid = shell.get_grid() + menu_shell = MenuShell(grid) bg = goocanvas.Rect(fill_color="#4f4f4f", line_width=0) grid.set_constraints(bg, 0, 0, 80, 60) @@ -85,12 +87,12 @@ class Frame: self._add_panel(model, 0, 55, 80, 5) - panel = TopPanel(shell) + panel = TopPanel(shell, menu_shell) root.add_child(panel) self._add_panel(model, 0, 0, 80, 5) - panel = RightPanel(shell) + panel = RightPanel(shell, menu_shell) grid.set_constraints(panel, 75, 5) root.add_child(panel) diff --git a/shell/view/frame/RightPanel.py b/shell/view/frame/RightPanel.py index 3cc2935c..144c50e3 100644 --- a/shell/view/frame/RightPanel.py +++ b/shell/view/frame/RightPanel.py @@ -9,9 +9,10 @@ from model.BuddyInfo import BuddyInfo from view.frame.MenuStrategy import MenuStrategy class RightPanel(CanvasBox): - def __init__(self, shell): + def __init__(self, shell, menu_shell): CanvasBox.__init__(self, shell.get_grid(), CanvasBox.VERTICAL, 1) self._shell = shell + self._menu_shell = menu_shell self._activity_ps = None self._joined_hid = -1 self._left_hid = -1 @@ -24,7 +25,7 @@ class RightPanel(CanvasBox): shell.connect('activity-changed', self.__activity_changed_cb) def add(self, buddy): - icon = BuddyIcon(self._shell, BuddyInfo(buddy)) + icon = BuddyIcon(self._shell, self._menu_shell, BuddyInfo(buddy)) icon.set_menu_strategy(MenuStrategy()) self.set_constraints(icon, 3, 3) self.add_child(icon) diff --git a/shell/view/frame/TopPanel.py b/shell/view/frame/TopPanel.py index 35df67fa..17dd13a5 100644 --- a/shell/view/frame/TopPanel.py +++ b/shell/view/frame/TopPanel.py @@ -22,14 +22,14 @@ class ActivityMenu(Menu): self.add_action(icon, ActivityMenu.ACTION_CLOSE) class ActivityIcon(MenuIcon): - def __init__(self, shell, activity_host): + def __init__(self, shell, menu_shell, activity_host): self._shell = shell self._activity_host = activity_host icon_name = activity_host.get_icon_name() icon_color = activity_host.get_icon_color() - MenuIcon.__init__(self, shell.get_grid(), icon_name=icon_name, + MenuIcon.__init__(self, menu_shell, icon_name=icon_name, color=icon_color) self.set_menu_strategy(MenuStrategy()) @@ -52,10 +52,11 @@ class ActivityIcon(MenuIcon): activity.close() class TopPanel(goocanvas.Group): - def __init__(self, shell): + def __init__(self, shell, menu_shell): goocanvas.Group.__init__(self) self._shell = shell + self._menu_shell = menu_shell self._activity_icon = None grid = shell.get_grid() @@ -94,7 +95,7 @@ class TopPanel(goocanvas.Group): self._box.remove_child(self._activity_icon) if activity: - icon = ActivityIcon(self._shell, activity) + icon = ActivityIcon(self._shell, self._menu_shell, activity) self._box.set_constraints(icon, 3, 3) self._box.add_child(icon) self._activity_icon = icon diff --git a/shell/view/home/FriendsGroup.py b/shell/view/home/FriendsGroup.py index 17497388..bac8cff6 100644 --- a/shell/view/home/FriendsGroup.py +++ b/shell/view/home/FriendsGroup.py @@ -7,10 +7,11 @@ from view.home.MyIcon import MyIcon from view.BuddyIcon import BuddyIcon class FriendsGroup(goocanvas.Group): - def __init__(self, shell): + def __init__(self, shell, menu_shell): goocanvas.Group.__init__(self) self._shell = shell + self._menu_shell = menu_shell self._icon_layout = IconLayout(1200, 900) self._friends = {} @@ -28,7 +29,7 @@ class FriendsGroup(goocanvas.Group): friends.connect('friend-removed', self._friend_removed_cb) def add_friend(self, buddy_info): - icon = BuddyIcon(self._shell, buddy_info) + icon = BuddyIcon(self._shell, self._menu_shell, buddy_info) self.add_child(icon) self._icon_layout.add_icon(icon) diff --git a/shell/view/home/HomeWindow.py b/shell/view/home/HomeWindow.py index ba1129e4..9e2fb2a3 100644 --- a/shell/view/home/HomeWindow.py +++ b/shell/view/home/HomeWindow.py @@ -3,6 +3,7 @@ import goocanvas import cairo from sugar.canvas.CanvasView import CanvasView +from sugar.canvas.MenuShell import MenuShell from view.home.MeshGroup import MeshGroup from view.home.HomeGroup import HomeGroup from view.home.FriendsGroup import FriendsGroup @@ -23,8 +24,10 @@ class HomeWindow(gtk.Window): self.add(self._nb) self._nb.show() + menu_shell = MenuShell(shell.get_grid()) + self._add_page(HomeGroup(shell)) - self._add_page(FriendsGroup(shell)) + self._add_page(FriendsGroup(shell, menu_shell)) self._add_page(MeshGroup(shell)) def _add_page(self, group): diff --git a/sugar/canvas/MenuIcon.py b/sugar/canvas/MenuIcon.py index b4297e52..bd4122e0 100644 --- a/sugar/canvas/MenuIcon.py +++ b/sugar/canvas/MenuIcon.py @@ -4,15 +4,6 @@ import gobject from sugar.canvas.IconItem import IconItem from sugar.canvas.Grid import Grid -class _MenuShell: - def __init__(self): - self._menu_controller = None - - def set_active(self, controller): - if self._menu_controller: - self._menu_controller.popdown() - self._menu_controller = controller - class _MenuStrategy: def get_menu_position(self, menu, grid_x1, grid_y1, grid_x2, grid_y2): grid_x = grid_x2 @@ -29,12 +20,11 @@ class _MenuStrategy: return [grid_x, grid_y] class MenuIcon(IconItem, goocanvas.Item): - _menu_shell = _MenuShell() - - def __init__(self, grid, **kwargs): + def __init__(self, menu_shell, **kwargs): IconItem.__init__(self, **kwargs) - self._grid = grid + self._menu_shell = menu_shell + self._grid = menu_shell.get_grid() self._menu = None self._hover_menu = False self._popdown_on_leave = False @@ -45,6 +35,7 @@ class MenuIcon(IconItem, goocanvas.Item): if self._menu: self._menu.destroy() self._menu = None + self._menu_shell.set_active(None) def set_menu_strategy(self, strategy): self._menu_strategy = strategy @@ -52,7 +43,7 @@ class MenuIcon(IconItem, goocanvas.Item): def _popup(self, x1, y1, x2, y2): self.popdown() - MenuIcon._menu_shell.set_active(None) + self._menu_shell.set_active(None) grid = self._shell.get_grid() self._menu = self.create_menu() @@ -74,7 +65,7 @@ class MenuIcon(IconItem, goocanvas.Item): self._menu.show() - MenuIcon._menu_shell.set_active(self) + self._menu_shell.set_active(self) def _menu_enter_notify_event_cb(self, widget, event): self._hover_menu = True diff --git a/sugar/canvas/MenuShell.py b/sugar/canvas/MenuShell.py new file mode 100644 index 00000000..fad35f40 --- /dev/null +++ b/sugar/canvas/MenuShell.py @@ -0,0 +1,12 @@ +class MenuShell: + def __init__(self, grid): + self._menu_controller = None + self._grid = grid + + def set_active(self, controller): + if self._menu_controller: + self._menu_controller.popdown() + self._menu_controller = controller + + def get_grid(self): + return self._grid