Reimplement menu using hippo and hook it up for the
activity menu.
This commit is contained in:
@@ -18,3 +18,8 @@ _stylesheet = {
|
||||
'size' : _medium_icon_size
|
||||
}
|
||||
style.register_stylesheet('frame-zoom-icon', _stylesheet)
|
||||
|
||||
_stylesheet = {
|
||||
'size' : _medium_icon_size
|
||||
}
|
||||
style.register_stylesheet('menu-action-icon', _stylesheet)
|
||||
|
||||
@@ -7,9 +7,13 @@ class Grid(object):
|
||||
def __init__(self):
|
||||
self._factor = gtk.gdk.screen_width() / COLS
|
||||
|
||||
def point(self, x, y):
|
||||
return [x * self._factor, y * self._factor]
|
||||
def point(self, grid_x, grid_y):
|
||||
return [grid_x * self._factor, grid_y * self._factor]
|
||||
|
||||
def rectangle(self, x, y, width, height):
|
||||
return [x * self._factor, y * self._factor,
|
||||
width * self._factor, height * self._factor]
|
||||
def rectangle(self, grid_x, grid_y, grid_w, grid_h):
|
||||
return [grid_x * self._factor, grid_y * self._factor,
|
||||
grid_w * self._factor, grid_h * self._factor]
|
||||
|
||||
def fit_point(self, x, y):
|
||||
return [int(x / self._factor), int(y / self._factor)]
|
||||
|
||||
|
||||
@@ -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)
|
||||
@@ -4,26 +4,14 @@ import gobject
|
||||
from sugar.graphics.canvasicon import CanvasIcon
|
||||
|
||||
class _MenuStrategy:
|
||||
def get_menu_position(self, menu, grid_x1, grid_y1, grid_x2, grid_y2):
|
||||
grid_x = grid_x2
|
||||
if grid_x + menu.get_width() > Grid.COLS:
|
||||
grid_x = grid_x1 - menu.get_width() + 1
|
||||
|
||||
grid_y = grid_y1
|
||||
|
||||
if grid_y < 0:
|
||||
grid_y = 0
|
||||
if grid_y + menu.get_width() > Grid.ROWS:
|
||||
grid_y = Grid.ROWS - menu.get_width()
|
||||
|
||||
return [grid_x, grid_y]
|
||||
def get_menu_position(self, menu, x1, y1, x2, y2):
|
||||
return [x1, y1]
|
||||
|
||||
class MenuIcon(CanvasIcon):
|
||||
def __init__(self, menu_shell, **kwargs):
|
||||
CanvasIcon.__init__(self, **kwargs)
|
||||
|
||||
self._menu_shell = menu_shell
|
||||
self._grid = menu_shell.get_grid()
|
||||
self._menu = None
|
||||
self._hover_menu = False
|
||||
self._popdown_on_leave = False
|
||||
@@ -46,24 +34,16 @@ class MenuIcon(CanvasIcon):
|
||||
|
||||
self._menu_shell.set_active(None)
|
||||
|
||||
grid = self._shell.get_grid()
|
||||
self._menu = self.create_menu()
|
||||
self._menu.connect('enter-notify-event',
|
||||
self._menu_enter_notify_event_cb)
|
||||
self._menu.connect('leave-notify-event',
|
||||
self._menu_leave_notify_event_cb)
|
||||
|
||||
[grid_x1, grid_y1] = grid.convert_from_screen(x1, y1)
|
||||
[grid_x2, grid_y2] = grid.convert_from_screen(x2, y2)
|
||||
|
||||
strategy = self._menu_strategy
|
||||
[grid_x, grid_y] = strategy.get_menu_position(self._menu,
|
||||
grid_x1, grid_y1,
|
||||
grid_x2, grid_y2)
|
||||
|
||||
grid.set_constraints(self._menu, grid_x, grid_y,
|
||||
self._menu.get_width(), self._menu.get_height())
|
||||
[x, y] = strategy.get_menu_position(self._menu, x1, y1, x2, y2)
|
||||
|
||||
self._menu.move(x, y)
|
||||
self._menu.show()
|
||||
|
||||
self._menu_shell.set_active(self)
|
||||
|
||||
Reference in New Issue
Block a user