Move the menu positioning code inside menu shell and
unify it.
This commit is contained in:
parent
7a06102b2e
commit
54dcb672e5
@ -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):
|
||||
|
@ -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
|
||||
|
@ -6,5 +6,4 @@ sugar_PYTHON = \
|
||||
PanelWindow.py \
|
||||
Frame.py \
|
||||
ZoomBox.py \
|
||||
MenuStrategy.py \
|
||||
notificationtray.py
|
||||
|
@ -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]
|
@ -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
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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()
|
||||
|
@ -17,14 +17,11 @@
|
||||
|
||||
import hippo
|
||||
import gobject
|
||||
import logging
|
||||
|
||||
from sugar.graphics.canvasicon import CanvasIcon
|
||||
from sugar.graphics.timeline import Timeline
|
||||
|
||||
class _MenuStrategy:
|
||||
def get_menu_position(self, menu, item):
|
||||
return item.get_context().translate_to_widget(item)
|
||||
|
||||
class MenuIcon(CanvasIcon):
|
||||
def __init__(self, menu_shell, **kwargs):
|
||||
CanvasIcon.__init__(self, **kwargs)
|
||||
@ -32,7 +29,6 @@ class MenuIcon(CanvasIcon):
|
||||
self._menu_shell = menu_shell
|
||||
self._menu = None
|
||||
self._hover_menu = False
|
||||
self._menu_strategy = _MenuStrategy()
|
||||
|
||||
self._timeline = Timeline(self)
|
||||
self._timeline.add_tag('popup', 6, 6)
|
||||
@ -41,9 +37,6 @@ class MenuIcon(CanvasIcon):
|
||||
|
||||
self.connect('motion-notify-event', self._motion_notify_event_cb)
|
||||
|
||||
def set_menu_strategy(self, strategy):
|
||||
self._menu_strategy = strategy
|
||||
|
||||
def do_popup(self, current, n_frames):
|
||||
if self._menu:
|
||||
return
|
||||
@ -55,8 +48,7 @@ class MenuIcon(CanvasIcon):
|
||||
self._menu.connect('leave-notify-event',
|
||||
self._menu_leave_notify_event_cb)
|
||||
|
||||
strategy = self._menu_strategy
|
||||
[x, y] = strategy.get_menu_position(self._menu, self)
|
||||
[x, y] = self._menu_shell.get_position(self._menu, self)
|
||||
|
||||
self._menu.move(x, y)
|
||||
self._menu.show()
|
||||
|
@ -25,8 +25,10 @@ class MenuShell(gobject.GObject):
|
||||
gobject.TYPE_NONE, ([])),
|
||||
}
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, parent_canvas):
|
||||
gobject.GObject.__init__(self)
|
||||
|
||||
self._parent_canvas = parent_canvas
|
||||
self._menu_controller = None
|
||||
|
||||
def is_active(self):
|
||||
@ -41,3 +43,30 @@ class MenuShell(gobject.GObject):
|
||||
if self._menu_controller:
|
||||
self._menu_controller.popdown()
|
||||
self._menu_controller = controller
|
||||
|
||||
def _get_item_origin(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]
|
||||
|
||||
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()
|
||||
[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]
|
||||
|
Loading…
Reference in New Issue
Block a user