Rework menu positioning. Cleanups.
This commit is contained in:
@@ -5,4 +5,5 @@ sugar_PYTHON = \
|
||||
PanelWindow.py \
|
||||
Frame.py \
|
||||
TopPanel.py \
|
||||
BottomPanel.py
|
||||
BottomPanel.py \
|
||||
MenuStrategy.py
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
class MenuStrategy:
|
||||
def get_menu_position(self, menu, grid_x1, grid_y1, grid_x2, grid_y2):
|
||||
grid = menu.get_grid()
|
||||
|
||||
[x1, y1] = grid.micro_to_macro(grid_x1, grid_y1)
|
||||
[x2, y2] = grid.micro_to_macro(grid_x2, grid_y2)
|
||||
|
||||
if x1 == 0:
|
||||
x = x2
|
||||
y = y1
|
||||
elif x2 == grid.get_macro_cols():
|
||||
x = x1
|
||||
y = y1
|
||||
elif y2 == grid.get_macro_rows():
|
||||
x = x1
|
||||
y = y1
|
||||
else:
|
||||
x = x1
|
||||
y = y2
|
||||
|
||||
[grid_x, grid_y] = grid.macro_to_micro(x, y)
|
||||
|
||||
if x2 == grid.get_macro_cols():
|
||||
grid_x -= menu.get_width()
|
||||
elif y2 == grid.get_macro_rows():
|
||||
grid_y -= menu.get_height()
|
||||
|
||||
return [grid_x, grid_y]
|
||||
@@ -6,6 +6,7 @@ from sugar.canvas.CanvasBox import CanvasBox
|
||||
from sugar.presence import PresenceService
|
||||
from view.BuddyIcon import BuddyIcon
|
||||
from model.BuddyInfo import BuddyInfo
|
||||
from view.frame.MenuStrategy import MenuStrategy
|
||||
|
||||
class RightPanel(CanvasBox):
|
||||
def __init__(self, shell):
|
||||
@@ -25,7 +26,7 @@ class RightPanel(CanvasBox):
|
||||
|
||||
def add(self, buddy):
|
||||
icon = BuddyIcon(self._shell, BuddyInfo(buddy))
|
||||
icon.set_menu_distance(1)
|
||||
icon.set_menu_strategy(MenuStrategy())
|
||||
self.set_constraints(icon, 3, 3)
|
||||
self.add_child(icon)
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ from sugar.canvas.CanvasBox import CanvasBox
|
||||
from sugar.canvas.IconItem import IconItem
|
||||
from sugar.canvas.MenuIcon import MenuIcon
|
||||
from sugar.canvas.Menu import Menu
|
||||
from view.frame.MenuStrategy import MenuStrategy
|
||||
import sugar
|
||||
|
||||
class ActivityMenu(Menu):
|
||||
@@ -27,6 +28,8 @@ class ActivityIcon(MenuIcon):
|
||||
MenuIcon.__init__(self, shell.get_grid(), icon_name=icon_name,
|
||||
color=icon_color)
|
||||
|
||||
self.set_menu_strategy(MenuStrategy())
|
||||
|
||||
def create_menu(self):
|
||||
menu = ActivityMenu(self._shell.get_grid(), self._activity_host)
|
||||
menu.connect('action', self._action_cb)
|
||||
|
||||
Reference in New Issue
Block a user