parent
4958c43b33
commit
a951b36347
@ -1,28 +1,15 @@
|
||||
class MenuStrategy:
|
||||
def get_menu_position(self, menu, grid_x1, grid_y1, grid_x2, grid_y2):
|
||||
grid = menu.get_grid()
|
||||
from sugar.graphics.grid import Grid
|
||||
|
||||
[x1, y1] = grid.micro_to_macro(grid_x1, grid_y1)
|
||||
[x2, y2] = grid.micro_to_macro(grid_x2, grid_y2)
|
||||
class MenuStrategy:
|
||||
def get_menu_position(self, menu, x, y, width, height):
|
||||
grid = Grid()
|
||||
|
||||
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_x1, grid_y1] = grid.fit_point(x, y)
|
||||
[grid_x2, grid_y2] = grid.fit_point(x + width, y + height)
|
||||
|
||||
[grid_x, grid_y] = grid.macro_to_micro(x, y)
|
||||
menu_grid_x = grid_x1
|
||||
menu_grid_y = grid_y2
|
||||
|
||||
if x2 == grid.get_macro_cols():
|
||||
grid_x -= menu.get_width()
|
||||
elif y2 == grid.get_macro_rows():
|
||||
grid_y -= menu.get_height()
|
||||
[menu_x, menu_y] = grid.point(menu_grid_x, menu_grid_y)
|
||||
|
||||
return [grid_x, grid_y]
|
||||
return [menu_x, menu_y]
|
||||
|
@ -0,0 +1,50 @@
|
||||
import gtk
|
||||
import hippo
|
||||
import gobject
|
||||
|
||||
from sugar.graphics.canvasicon import CanvasIcon
|
||||
|
||||
class Menu(gtk.Window):
|
||||
__gsignals__ = {
|
||||
'action': (gobject.SIGNAL_RUN_FIRST,
|
||||
gobject.TYPE_NONE, ([int])),
|
||||
}
|
||||
|
||||
def __init__(self, title, content_box=None):
|
||||
gtk.Window.__init__(self, gtk.WINDOW_POPUP)
|
||||
|
||||
canvas = hippo.Canvas()
|
||||
self.add(canvas)
|
||||
canvas.show()
|
||||
|
||||
self._root = hippo.CanvasBox(background_color=0x000000FF,
|
||||
spacing=6)
|
||||
canvas.set_root(self._root)
|
||||
|
||||
text = hippo.CanvasText(text=title, color=0xFFFFFFFF)
|
||||
self._root.append(text)
|
||||
|
||||
if content_box:
|
||||
separator = self._create_separator()
|
||||
self._root.append(separator)
|
||||
self._root.append(content_box)
|
||||
|
||||
separator = self._create_separator()
|
||||
self._root.append(separator)
|
||||
|
||||
self._action_box = hippo.CanvasBox(
|
||||
orientation=hippo.ORIENTATION_HORIZONTAL)
|
||||
self._root.append(self._action_box)
|
||||
|
||||
def _create_separator(self):
|
||||
separator = hippo.CanvasBox(background_color=0xFFFFFFFF,
|
||||
border_left=6, border_right=6,
|
||||
box_height=2)
|
||||
return separator
|
||||
|
||||
def add_action(self, icon, action_id):
|
||||
icon.connect('activated', self._action_clicked_cb, action_id)
|
||||
self._action_box.append(icon)
|
||||
|
||||
def _action_clicked_cb(self, icon, action):
|
||||
self.emit('action', action)
|
Loading…
Reference in New Issue