Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/sugar/graphics
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <marco@localhost.localdomain>2006-10-02 14:37:30 (GMT)
committer Marco Pesenti Gritti <marco@localhost.localdomain>2006-10-02 14:37:30 (GMT)
commita951b36347bfb5350c4c6031ba1126c25b94f44d (patch)
tree63db8d067f78bdfe53d69b3eb472cbdffeba08ad /sugar/graphics
parent4958c43b33f3a02982b58f612f2ba46b069d12bf (diff)
Reimplement menu using hippo and hook it up for the
activity menu.
Diffstat (limited to 'sugar/graphics')
-rw-r--r--sugar/graphics/__init__.py5
-rw-r--r--sugar/graphics/grid.py14
-rw-r--r--sugar/graphics/menu.py50
-rw-r--r--sugar/graphics/menuicon.py28
4 files changed, 68 insertions, 29 deletions
diff --git a/sugar/graphics/__init__.py b/sugar/graphics/__init__.py
index 8bfa7eb..b494b9f 100644
--- a/sugar/graphics/__init__.py
+++ b/sugar/graphics/__init__.py
@@ -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)
diff --git a/sugar/graphics/grid.py b/sugar/graphics/grid.py
index 8ee124a..8d8d2ab 100644
--- a/sugar/graphics/grid.py
+++ b/sugar/graphics/grid.py
@@ -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)]
+
diff --git a/sugar/graphics/menu.py b/sugar/graphics/menu.py
new file mode 100644
index 0000000..9a85bcf
--- /dev/null
+++ b/sugar/graphics/menu.py
@@ -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)
diff --git a/sugar/graphics/menuicon.py b/sugar/graphics/menuicon.py
index 88a8d56..3f6d477 100644
--- a/sugar/graphics/menuicon.py
+++ b/sugar/graphics/menuicon.py
@@ -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)