diff options
author | Marco Pesenti Gritti <marco@localhost.localdomain> | 2006-10-18 14:23:06 (GMT) |
---|---|---|
committer | Marco Pesenti Gritti <marco@localhost.localdomain> | 2006-10-18 14:23:06 (GMT) |
commit | 54dcb672e563063b590775eb157b3b6c9f9af752 (patch) | |
tree | 0a746ee03d0909134c3985e3d1bc954d2656a32a /shell | |
parent | 7a06102b2eff1d7e19cd1a9b153f328dba989704 (diff) |
Move the menu positioning code inside menu shell and
unify it.
Diffstat (limited to 'shell')
-rw-r--r-- | shell/view/frame/Frame.py | 50 | ||||
-rw-r--r-- | shell/view/frame/FriendsBox.py | 2 | ||||
-rw-r--r-- | shell/view/frame/Makefile.am | 1 | ||||
-rw-r--r-- | shell/view/frame/MenuStrategy.py | 55 | ||||
-rw-r--r-- | shell/view/frame/PanelWindow.py | 7 | ||||
-rw-r--r-- | shell/view/frame/ZoomBox.py | 3 | ||||
-rw-r--r-- | shell/view/home/HomeWindow.py | 8 |
7 files changed, 38 insertions, 88 deletions
diff --git a/shell/view/frame/Frame.py b/shell/view/frame/Frame.py index bdac9fa..de3091b 100644 --- a/shell/view/frame/Frame.py +++ b/shell/view/frame/Frame.py @@ -25,7 +25,6 @@ from view.frame.FriendsBox import FriendsBox from view.frame.PanelWindow import PanelWindow from view.frame.notificationtray import NotificationTray from sugar.graphics.timeline import Timeline -from sugar.graphics.menushell import MenuShell from sugar.graphics.grid import Grid class EventFrame(gobject.GObject): @@ -133,6 +132,7 @@ class Frame: def __init__(self, shell): self._windows = [] + self._active_menus = 0 self._shell = shell self._mode = Frame.INACTIVE @@ -149,17 +149,14 @@ class Frame: grid = Grid() - self._menu_shell = MenuShell() - self._menu_shell.connect('activated', self._menu_shell_activated_cb) - self._menu_shell.connect('deactivated', self._menu_shell_deactivated_cb) + # Top panel + [menu_shell, root] = self._create_panel(grid, 0, 0, 16, 1) - top_panel = self._create_panel(grid, 0, 0, 16, 1) - - box = ZoomBox(self._shell, self._menu_shell) + box = ZoomBox(self._shell, menu_shell) [x, y] = grid.point(1, 0) - top_panel.append(box, hippo.PACK_FIXED) - top_panel.move(box, x, y) + root.append(box, hippo.PACK_FIXED) + root.move(box, x, y) tray = NotificationTray() tray_box = hippo.CanvasBox(box_width=grid.dimension(1), @@ -171,23 +168,26 @@ class Frame: tray_box.append(tray_widget, gtk.EXPAND) [x, y] = grid.point(14, 0) - top_panel.append(tray_box, hippo.PACK_FIXED) - top_panel.move(tray_box, x, y) + root.append(tray_box, hippo.PACK_FIXED) + root.move(tray_box, x, y) - bottom_panel = self._create_panel(grid, 0, 11, 16, 1) + # Bottom panel + [menu_shell, root] = self._create_panel(grid, 0, 11, 16, 1) box = ActivitiesBox(self._shell) - bottom_panel.append(box, hippo.PACK_FIXED) + root.append(box, hippo.PACK_FIXED) [x, y] = grid.point(1, 0) - bottom_panel.move(box, x, y) + root.move(box, x, y) - right_panel = self._create_panel(grid, 15, 1, 1, 10) + # Right panel + [menu_shell, root] = self._create_panel(grid, 15, 1, 1, 10) - box = FriendsBox(self._shell, self._menu_shell) - right_panel.append(box) + box = FriendsBox(self._shell, menu_shell) + root.append(box) - left_panel = self._create_panel(grid, 0, 1, 1, 10) + # Left panel + self._create_panel(grid, 0, 1, 1, 10) def _create_panel(self, grid, x, y, width, height): panel = PanelWindow() @@ -195,6 +195,10 @@ class Frame: panel.connect('enter-notify-event', self._enter_notify_cb) panel.connect('leave-notify-event', self._leave_notify_cb) + menu_shell = panel.get_menu_shell() + menu_shell.connect('activated', self._menu_shell_activated_cb) + menu_shell.connect('deactivated', self._menu_shell_deactivated_cb) + [x, y, width, height] = grid.rectangle(x, y, width, height) panel.move(x, y) @@ -202,12 +206,14 @@ class Frame: self._windows.append(panel) - return panel.get_root() + return [panel.get_menu_shell(), panel.get_root()] def _menu_shell_activated_cb(self, menu_shell): + self._active_menus += 1 self._timeline.goto('slide_in', True) def _menu_shell_deactivated_cb(self, menu_shell): + self._active_menus -= 1 if self._mode != Frame.STICKY: self._timeline.play('before_slide_out', 'slide_out') @@ -219,9 +225,9 @@ class Frame: if event.state == gtk.gdk.BUTTON1_MASK: return - if not self._menu_shell.is_active() and \ - self._mode == Frame.HIDE_ON_LEAVE or \ - self._mode == Frame.AUTOMATIC: + if self._active_menus == 0 and \ + (self._mode == Frame.HIDE_ON_LEAVE or \ + self._mode == Frame.AUTOMATIC): self._timeline.play('before_slide_out', 'slide_out') def _enter_edge_cb(self, event_frame): diff --git a/shell/view/frame/FriendsBox.py b/shell/view/frame/FriendsBox.py index 345a804..92e66b6 100644 --- a/shell/view/frame/FriendsBox.py +++ b/shell/view/frame/FriendsBox.py @@ -22,7 +22,6 @@ from sugar.graphics import style from sugar.presence import PresenceService from view.BuddyIcon import BuddyIcon from model.BuddyModel import BuddyModel -from view.frame.MenuStrategy import MenuStrategy class FriendsBox(hippo.CanvasBox): def __init__(self, shell, menu_shell): @@ -44,7 +43,6 @@ class FriendsBox(hippo.CanvasBox): model = BuddyModel(buddy=buddy) icon = BuddyIcon(self._shell, self._menu_shell, model) style.apply_stylesheet(icon, 'frame.BuddyIcon') - icon.set_menu_strategy(MenuStrategy()) self.append(icon) self._buddies[buddy.get_name()] = icon diff --git a/shell/view/frame/Makefile.am b/shell/view/frame/Makefile.am index d31773a..09573aa 100644 --- a/shell/view/frame/Makefile.am +++ b/shell/view/frame/Makefile.am @@ -6,5 +6,4 @@ sugar_PYTHON = \ PanelWindow.py \ Frame.py \ ZoomBox.py \ - MenuStrategy.py \ notificationtray.py diff --git a/shell/view/frame/MenuStrategy.py b/shell/view/frame/MenuStrategy.py deleted file mode 100644 index 00dcdaa..0000000 --- a/shell/view/frame/MenuStrategy.py +++ /dev/null @@ -1,55 +0,0 @@ -# Copyright (C) 2006, Red Hat, Inc. -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -import hippo - -from sugar.graphics.grid import Grid - -class MenuStrategy: - def _get_canvas(self, item): - canvas = item - while (not isinstance(canvas, hippo.Canvas)): - canvas = canvas.get_context() - return canvas - - def _get_item_origin(self, canvas, item): - [x, y] = item.get_context().translate_to_widget(item) - - [origin_x, origin_y] = canvas.window.get_origin() - x += origin_x - y += origin_y - - return [x, y] - - def get_menu_position(self, menu, item): - canvas = self._get_canvas(item) - - [x, y] = self._get_item_origin(canvas, item) - [width, height] = item.get_allocation() - - [canvas_x, canvas_y] = canvas.window.get_origin() - canvas_rect = canvas.get_allocation() - [menu_w, menu_h] = menu.size_request() - - menu_x = x - menu_y = y + height - - if (menu_x + menu_w > canvas_x) and \ - (menu_y < canvas_y + canvas_rect.height): - menu_x = x - menu_w - menu_y = y - - return [menu_x, menu_y] diff --git a/shell/view/frame/PanelWindow.py b/shell/view/frame/PanelWindow.py index fee538c..14e72b1 100644 --- a/shell/view/frame/PanelWindow.py +++ b/shell/view/frame/PanelWindow.py @@ -17,6 +17,8 @@ import gtk import hippo +from sugar.graphics.menushell import MenuShell + class PanelWindow(gtk.Window): def __init__(self): gtk.Window.__init__(self) @@ -32,6 +34,11 @@ class PanelWindow(gtk.Window): self.add(canvas) canvas.show() + self._menu_shell = MenuShell(canvas) + + def get_menu_shell(self): + return self._menu_shell + def get_root(self): return self._bg diff --git a/shell/view/frame/ZoomBox.py b/shell/view/frame/ZoomBox.py index 6392235..3c21f20 100644 --- a/shell/view/frame/ZoomBox.py +++ b/shell/view/frame/ZoomBox.py @@ -20,7 +20,6 @@ from sugar.graphics.canvasicon import CanvasIcon from sugar.graphics.menuicon import MenuIcon from sugar.graphics.menu import Menu from sugar.graphics import style -from view.frame.MenuStrategy import MenuStrategy import sugar class ActivityMenu(Menu): @@ -47,8 +46,6 @@ class ActivityIcon(MenuIcon): MenuIcon.__init__(self, menu_shell, icon_name=icon_name, color=icon_color) - self.set_menu_strategy(MenuStrategy()) - def create_menu(self): menu = ActivityMenu(self._activity_host) menu.connect('action', self._action_cb) diff --git a/shell/view/home/HomeWindow.py b/shell/view/home/HomeWindow.py index 2e9be82..e07c7d0 100644 --- a/shell/view/home/HomeWindow.py +++ b/shell/view/home/HomeWindow.py @@ -19,10 +19,10 @@ import hippo import cairo from sugar.graphics.menushell import MenuShell +import sugar from view.home.MeshBox import MeshBox from view.home.HomeBox import HomeBox from view.home.FriendsBox import FriendsBox -import sugar class HomeWindow(gtk.Window): def __init__(self, shell): @@ -42,8 +42,6 @@ class HomeWindow(gtk.Window): self.add(self._nb) self._nb.show() - menu_shell = MenuShell() - canvas = hippo.Canvas() box = HomeBox(shell) canvas.set_root(box) @@ -51,13 +49,13 @@ class HomeWindow(gtk.Window): canvas.show() canvas = hippo.Canvas() - box = FriendsBox(shell, menu_shell) + box = FriendsBox(shell, MenuShell(canvas)) canvas.set_root(box) self._nb.append_page(canvas) canvas.show() canvas = hippo.Canvas() - box = MeshBox(shell, menu_shell) + box = MeshBox(shell, MenuShell(canvas)) canvas.set_root(box) self._nb.append_page(canvas) canvas.show() |