Use a different menu shell for the zoom view and the frame
This commit is contained in:
parent
e8a457a266
commit
9ff192d0b3
@ -2,8 +2,8 @@ from sugar.canvas.MenuIcon import MenuIcon
|
|||||||
from view.BuddyMenu import BuddyMenu
|
from view.BuddyMenu import BuddyMenu
|
||||||
|
|
||||||
class BuddyIcon(MenuIcon):
|
class BuddyIcon(MenuIcon):
|
||||||
def __init__(self, shell, friend):
|
def __init__(self, shell, menu_shell, friend):
|
||||||
MenuIcon.__init__(self, shell.get_grid(), icon_name='stock-buddy',
|
MenuIcon.__init__(self, menu_shell, icon_name='stock-buddy',
|
||||||
color=friend.get_color(), size=96)
|
color=friend.get_color(), size=96)
|
||||||
|
|
||||||
self._shell = shell
|
self._shell = shell
|
||||||
|
@ -8,6 +8,7 @@ from view.frame.RightPanel import RightPanel
|
|||||||
from view.frame.TopPanel import TopPanel
|
from view.frame.TopPanel import TopPanel
|
||||||
from view.frame.PanelWindow import PanelWindow
|
from view.frame.PanelWindow import PanelWindow
|
||||||
from sugar.canvas.Grid import Grid
|
from sugar.canvas.Grid import Grid
|
||||||
|
from sugar.canvas.MenuShell import MenuShell
|
||||||
|
|
||||||
class EventFrame(gobject.GObject):
|
class EventFrame(gobject.GObject):
|
||||||
__gsignals__ = {
|
__gsignals__ = {
|
||||||
@ -74,6 +75,7 @@ class Frame:
|
|||||||
root = model.get_root_item()
|
root = model.get_root_item()
|
||||||
|
|
||||||
grid = shell.get_grid()
|
grid = shell.get_grid()
|
||||||
|
menu_shell = MenuShell(grid)
|
||||||
|
|
||||||
bg = goocanvas.Rect(fill_color="#4f4f4f", line_width=0)
|
bg = goocanvas.Rect(fill_color="#4f4f4f", line_width=0)
|
||||||
grid.set_constraints(bg, 0, 0, 80, 60)
|
grid.set_constraints(bg, 0, 0, 80, 60)
|
||||||
@ -85,12 +87,12 @@ class Frame:
|
|||||||
|
|
||||||
self._add_panel(model, 0, 55, 80, 5)
|
self._add_panel(model, 0, 55, 80, 5)
|
||||||
|
|
||||||
panel = TopPanel(shell)
|
panel = TopPanel(shell, menu_shell)
|
||||||
root.add_child(panel)
|
root.add_child(panel)
|
||||||
|
|
||||||
self._add_panel(model, 0, 0, 80, 5)
|
self._add_panel(model, 0, 0, 80, 5)
|
||||||
|
|
||||||
panel = RightPanel(shell)
|
panel = RightPanel(shell, menu_shell)
|
||||||
grid.set_constraints(panel, 75, 5)
|
grid.set_constraints(panel, 75, 5)
|
||||||
root.add_child(panel)
|
root.add_child(panel)
|
||||||
|
|
||||||
|
@ -9,9 +9,10 @@ from model.BuddyInfo import BuddyInfo
|
|||||||
from view.frame.MenuStrategy import MenuStrategy
|
from view.frame.MenuStrategy import MenuStrategy
|
||||||
|
|
||||||
class RightPanel(CanvasBox):
|
class RightPanel(CanvasBox):
|
||||||
def __init__(self, shell):
|
def __init__(self, shell, menu_shell):
|
||||||
CanvasBox.__init__(self, shell.get_grid(), CanvasBox.VERTICAL, 1)
|
CanvasBox.__init__(self, shell.get_grid(), CanvasBox.VERTICAL, 1)
|
||||||
self._shell = shell
|
self._shell = shell
|
||||||
|
self._menu_shell = menu_shell
|
||||||
self._activity_ps = None
|
self._activity_ps = None
|
||||||
self._joined_hid = -1
|
self._joined_hid = -1
|
||||||
self._left_hid = -1
|
self._left_hid = -1
|
||||||
@ -24,7 +25,7 @@ class RightPanel(CanvasBox):
|
|||||||
shell.connect('activity-changed', self.__activity_changed_cb)
|
shell.connect('activity-changed', self.__activity_changed_cb)
|
||||||
|
|
||||||
def add(self, buddy):
|
def add(self, buddy):
|
||||||
icon = BuddyIcon(self._shell, BuddyInfo(buddy))
|
icon = BuddyIcon(self._shell, self._menu_shell, BuddyInfo(buddy))
|
||||||
icon.set_menu_strategy(MenuStrategy())
|
icon.set_menu_strategy(MenuStrategy())
|
||||||
self.set_constraints(icon, 3, 3)
|
self.set_constraints(icon, 3, 3)
|
||||||
self.add_child(icon)
|
self.add_child(icon)
|
||||||
|
@ -22,14 +22,14 @@ class ActivityMenu(Menu):
|
|||||||
self.add_action(icon, ActivityMenu.ACTION_CLOSE)
|
self.add_action(icon, ActivityMenu.ACTION_CLOSE)
|
||||||
|
|
||||||
class ActivityIcon(MenuIcon):
|
class ActivityIcon(MenuIcon):
|
||||||
def __init__(self, shell, activity_host):
|
def __init__(self, shell, menu_shell, activity_host):
|
||||||
self._shell = shell
|
self._shell = shell
|
||||||
self._activity_host = activity_host
|
self._activity_host = activity_host
|
||||||
|
|
||||||
icon_name = activity_host.get_icon_name()
|
icon_name = activity_host.get_icon_name()
|
||||||
icon_color = activity_host.get_icon_color()
|
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)
|
color=icon_color)
|
||||||
|
|
||||||
self.set_menu_strategy(MenuStrategy())
|
self.set_menu_strategy(MenuStrategy())
|
||||||
@ -52,10 +52,11 @@ class ActivityIcon(MenuIcon):
|
|||||||
activity.close()
|
activity.close()
|
||||||
|
|
||||||
class TopPanel(goocanvas.Group):
|
class TopPanel(goocanvas.Group):
|
||||||
def __init__(self, shell):
|
def __init__(self, shell, menu_shell):
|
||||||
goocanvas.Group.__init__(self)
|
goocanvas.Group.__init__(self)
|
||||||
|
|
||||||
self._shell = shell
|
self._shell = shell
|
||||||
|
self._menu_shell = menu_shell
|
||||||
self._activity_icon = None
|
self._activity_icon = None
|
||||||
|
|
||||||
grid = shell.get_grid()
|
grid = shell.get_grid()
|
||||||
@ -94,7 +95,7 @@ class TopPanel(goocanvas.Group):
|
|||||||
self._box.remove_child(self._activity_icon)
|
self._box.remove_child(self._activity_icon)
|
||||||
|
|
||||||
if activity:
|
if activity:
|
||||||
icon = ActivityIcon(self._shell, activity)
|
icon = ActivityIcon(self._shell, self._menu_shell, activity)
|
||||||
self._box.set_constraints(icon, 3, 3)
|
self._box.set_constraints(icon, 3, 3)
|
||||||
self._box.add_child(icon)
|
self._box.add_child(icon)
|
||||||
self._activity_icon = icon
|
self._activity_icon = icon
|
||||||
|
@ -7,10 +7,11 @@ from view.home.MyIcon import MyIcon
|
|||||||
from view.BuddyIcon import BuddyIcon
|
from view.BuddyIcon import BuddyIcon
|
||||||
|
|
||||||
class FriendsGroup(goocanvas.Group):
|
class FriendsGroup(goocanvas.Group):
|
||||||
def __init__(self, shell):
|
def __init__(self, shell, menu_shell):
|
||||||
goocanvas.Group.__init__(self)
|
goocanvas.Group.__init__(self)
|
||||||
|
|
||||||
self._shell = shell
|
self._shell = shell
|
||||||
|
self._menu_shell = menu_shell
|
||||||
self._icon_layout = IconLayout(1200, 900)
|
self._icon_layout = IconLayout(1200, 900)
|
||||||
self._friends = {}
|
self._friends = {}
|
||||||
|
|
||||||
@ -28,7 +29,7 @@ class FriendsGroup(goocanvas.Group):
|
|||||||
friends.connect('friend-removed', self._friend_removed_cb)
|
friends.connect('friend-removed', self._friend_removed_cb)
|
||||||
|
|
||||||
def add_friend(self, buddy_info):
|
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.add_child(icon)
|
||||||
self._icon_layout.add_icon(icon)
|
self._icon_layout.add_icon(icon)
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ import goocanvas
|
|||||||
import cairo
|
import cairo
|
||||||
|
|
||||||
from sugar.canvas.CanvasView import CanvasView
|
from sugar.canvas.CanvasView import CanvasView
|
||||||
|
from sugar.canvas.MenuShell import MenuShell
|
||||||
from view.home.MeshGroup import MeshGroup
|
from view.home.MeshGroup import MeshGroup
|
||||||
from view.home.HomeGroup import HomeGroup
|
from view.home.HomeGroup import HomeGroup
|
||||||
from view.home.FriendsGroup import FriendsGroup
|
from view.home.FriendsGroup import FriendsGroup
|
||||||
@ -23,8 +24,10 @@ class HomeWindow(gtk.Window):
|
|||||||
self.add(self._nb)
|
self.add(self._nb)
|
||||||
self._nb.show()
|
self._nb.show()
|
||||||
|
|
||||||
|
menu_shell = MenuShell(shell.get_grid())
|
||||||
|
|
||||||
self._add_page(HomeGroup(shell))
|
self._add_page(HomeGroup(shell))
|
||||||
self._add_page(FriendsGroup(shell))
|
self._add_page(FriendsGroup(shell, menu_shell))
|
||||||
self._add_page(MeshGroup(shell))
|
self._add_page(MeshGroup(shell))
|
||||||
|
|
||||||
def _add_page(self, group):
|
def _add_page(self, group):
|
||||||
|
@ -4,15 +4,6 @@ import gobject
|
|||||||
from sugar.canvas.IconItem import IconItem
|
from sugar.canvas.IconItem import IconItem
|
||||||
from sugar.canvas.Grid import Grid
|
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:
|
class _MenuStrategy:
|
||||||
def get_menu_position(self, menu, grid_x1, grid_y1, grid_x2, grid_y2):
|
def get_menu_position(self, menu, grid_x1, grid_y1, grid_x2, grid_y2):
|
||||||
grid_x = grid_x2
|
grid_x = grid_x2
|
||||||
@ -29,12 +20,11 @@ class _MenuStrategy:
|
|||||||
return [grid_x, grid_y]
|
return [grid_x, grid_y]
|
||||||
|
|
||||||
class MenuIcon(IconItem, goocanvas.Item):
|
class MenuIcon(IconItem, goocanvas.Item):
|
||||||
_menu_shell = _MenuShell()
|
def __init__(self, menu_shell, **kwargs):
|
||||||
|
|
||||||
def __init__(self, grid, **kwargs):
|
|
||||||
IconItem.__init__(self, **kwargs)
|
IconItem.__init__(self, **kwargs)
|
||||||
|
|
||||||
self._grid = grid
|
self._menu_shell = menu_shell
|
||||||
|
self._grid = menu_shell.get_grid()
|
||||||
self._menu = None
|
self._menu = None
|
||||||
self._hover_menu = False
|
self._hover_menu = False
|
||||||
self._popdown_on_leave = False
|
self._popdown_on_leave = False
|
||||||
@ -45,6 +35,7 @@ class MenuIcon(IconItem, goocanvas.Item):
|
|||||||
if self._menu:
|
if self._menu:
|
||||||
self._menu.destroy()
|
self._menu.destroy()
|
||||||
self._menu = None
|
self._menu = None
|
||||||
|
self._menu_shell.set_active(None)
|
||||||
|
|
||||||
def set_menu_strategy(self, strategy):
|
def set_menu_strategy(self, strategy):
|
||||||
self._menu_strategy = strategy
|
self._menu_strategy = strategy
|
||||||
@ -52,7 +43,7 @@ class MenuIcon(IconItem, goocanvas.Item):
|
|||||||
def _popup(self, x1, y1, x2, y2):
|
def _popup(self, x1, y1, x2, y2):
|
||||||
self.popdown()
|
self.popdown()
|
||||||
|
|
||||||
MenuIcon._menu_shell.set_active(None)
|
self._menu_shell.set_active(None)
|
||||||
|
|
||||||
grid = self._shell.get_grid()
|
grid = self._shell.get_grid()
|
||||||
self._menu = self.create_menu()
|
self._menu = self.create_menu()
|
||||||
@ -74,7 +65,7 @@ class MenuIcon(IconItem, goocanvas.Item):
|
|||||||
|
|
||||||
self._menu.show()
|
self._menu.show()
|
||||||
|
|
||||||
MenuIcon._menu_shell.set_active(self)
|
self._menu_shell.set_active(self)
|
||||||
|
|
||||||
def _menu_enter_notify_event_cb(self, widget, event):
|
def _menu_enter_notify_event_cb(self, widget, event):
|
||||||
self._hover_menu = True
|
self._hover_menu = True
|
||||||
|
12
sugar/canvas/MenuShell.py
Normal file
12
sugar/canvas/MenuShell.py
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user