From 717bdd66f45e31074952bbf49c78e14153f92c57 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Wed, 4 Oct 2006 00:25:03 +0200 Subject: [PATCH] Get rid of the old Grid and CanvasBox --- shell/view/Shell.py | 5 --- shell/view/frame/Frame.py | 2 +- shell/view/frame/ZoomBox.py | 4 +- shell/view/home/HomeWindow.py | 2 +- sugar/canvas/CanvasBox.py | 51 --------------------- sugar/canvas/Grid.py | 83 ----------------------------------- sugar/canvas/MenuShell.py | 6 +-- 7 files changed, 5 insertions(+), 148 deletions(-) delete mode 100644 sugar/canvas/CanvasBox.py delete mode 100644 sugar/canvas/Grid.py diff --git a/shell/view/Shell.py b/shell/view/Shell.py index c9a2c4da..b4f69747 100644 --- a/shell/view/Shell.py +++ b/shell/view/Shell.py @@ -2,7 +2,6 @@ import gtk import gobject import wnck -from sugar.canvas.Grid import Grid from view.home.HomeWindow import HomeWindow from sugar.presence import PresenceService from view.ActivityHost import ActivityHost @@ -28,7 +27,6 @@ class Shell(gobject.GObject): self._model = model self._hosts = {} self._screen = wnck.screen_get_default() - self._grid = Grid() self._key_grabber = KeyGrabber() self._key_grabber.connect('key-pressed', @@ -108,9 +106,6 @@ class Shell(gobject.GObject): def get_model(self): return self._model - def get_grid(self): - return self._grid - def join_activity(self, bundle_id, activity_id): pservice = PresenceService.get_instance() diff --git a/shell/view/frame/Frame.py b/shell/view/frame/Frame.py index bd7e51f4..1c82b49b 100644 --- a/shell/view/frame/Frame.py +++ b/shell/view/frame/Frame.py @@ -123,7 +123,7 @@ class Frame: grid = Grid() - self._menu_shell = MenuShell(grid) + self._menu_shell = MenuShell() self._menu_shell.connect('activated', self._menu_shell_activated_cb) self._menu_shell.connect('deactivated', self._menu_shell_deactivated_cb) diff --git a/shell/view/frame/ZoomBox.py b/shell/view/frame/ZoomBox.py index 26fda37c..9dabf8b5 100644 --- a/shell/view/frame/ZoomBox.py +++ b/shell/view/frame/ZoomBox.py @@ -12,7 +12,7 @@ class ActivityMenu(Menu): ACTION_SHARE = 1 ACTION_CLOSE = 2 - def __init__(self, grid, activity_host): + def __init__(self, activity_host): Menu.__init__(self, activity_host.get_title()) icon = CanvasIcon(icon_name='stock-share-mesh') @@ -37,7 +37,7 @@ class ActivityIcon(MenuIcon): self.set_menu_strategy(MenuStrategy()) def create_menu(self): - menu = ActivityMenu(self._shell.get_grid(), self._activity_host) + menu = ActivityMenu(self._activity_host) menu.connect('action', self._action_cb) return menu diff --git a/shell/view/home/HomeWindow.py b/shell/view/home/HomeWindow.py index 163ddb74..fad4476f 100644 --- a/shell/view/home/HomeWindow.py +++ b/shell/view/home/HomeWindow.py @@ -25,7 +25,7 @@ class HomeWindow(gtk.Window): self.add(self._nb) self._nb.show() - menu_shell = MenuShell(shell.get_grid()) + menu_shell = MenuShell() self._add_page(HomeGroup(shell)) diff --git a/sugar/canvas/CanvasBox.py b/sugar/canvas/CanvasBox.py deleted file mode 100644 index b990b895..00000000 --- a/sugar/canvas/CanvasBox.py +++ /dev/null @@ -1,51 +0,0 @@ -import goocanvas - -class CanvasBox(goocanvas.Group): - VERTICAL = 0 - HORIZONTAL = 1 - - def __init__(self, grid, orientation, padding=0): - goocanvas.Group.__init__(self) - - self._grid = grid - self._orientation = orientation - self._padding = padding - self._constraints = {} - - self.connect('child-added', self._child_added_cb) - self.connect('child-removed', self._child_removed_cb) - - def set_constraints(self, item, width, height): - self._constraints[item] = [width, height] - - def _layout(self, start_item): - if start_item == -1: - start_item = self.get_n_children() - 1 - - pos = 0 - i = 0 - while i < self.get_n_children(): - item = self.get_child(i) - [width, height] = self._constraints[item] - - pos += self._padding - - if self._orientation == CanvasBox.VERTICAL: - x = self._padding - y = pos - pos += height + self._padding - else: - x = pos - y = self._padding - pos += width + self._padding - - if i >= start_item: - self._grid.set_constraints(item, x, y, width, height) - - i += 1 - - def _child_added_cb(self, item, position): - self._layout(position) - - def _child_removed_cb(self, item, position): - self._layout(position) diff --git a/sugar/canvas/Grid.py b/sugar/canvas/Grid.py deleted file mode 100644 index 5a488905..00000000 --- a/sugar/canvas/Grid.py +++ /dev/null @@ -1,83 +0,0 @@ -import gtk -import goocanvas -import cairo - -from sugar.canvas.IconItem import IconItem - -class Grid: - COLS = 80.0 - ROWS = 60.0 - MACRO_CELL_FACTOR = 5.0 - - def get_macro_rows(self): - return Grid.ROWS / Grid.MACRO_CELL_FACTOR - - def get_macro_cols(self): - return Grid.COLS / Grid.MACRO_CELL_FACTOR - - def macro_to_micro(self, x, y): - return [round(x * Grid.MACRO_CELL_FACTOR), - round(y * Grid.MACRO_CELL_FACTOR)] - - def micro_to_macro(self, x, y): - return [round(x / Grid.MACRO_CELL_FACTOR), - round(y / Grid.MACRO_CELL_FACTOR)] - - def convert_from_screen(self, x, y): - factor = Grid.COLS / gtk.gdk.screen_width() - - grid_x = round(x * factor) - grid_y = round(y * factor) - - return [grid_x, grid_y] - - def convert_to_canvas(self, grid_x, grid_y): - scale = 1200 / Grid.COLS - return [grid_x * scale, grid_y * scale] - - def set_constraints(self, component, x, y, width=-1, height=-1): - if isinstance(component, gtk.Window): - self._layout_window(component, x, y, width, height) - elif isinstance(component, goocanvas.Item): - self._layout_item(component, x, y, width, height) - elif isinstance(component, goocanvas.CanvasView): - self._layout_canvas(component, x, y, width, height) - - def _layout_window(self, window, x, y, width, height): - scale = gtk.gdk.screen_width() / Grid.COLS - - window.move(int(x * scale), int(y * scale)) - window.resize(int(width * scale), int(height * scale)) - - def _layout_item(self, item, x, y, width, height): - scale = 1200 / Grid.COLS - - self._allocate_item_position(item, x * scale, y * scale) - if width > 0 and height > 0: - self._allocate_item_size(item, width * scale, height * scale) - - # FIXME We really need layout support in goocanvas - def _allocate_item_size(self, item, width, height): - if isinstance(item, goocanvas.Rect): - item.props.width = width - (item.props.line_width - 1) * 2 - item.props.height = height - (item.props.line_width - 1) * 2 - elif isinstance(item, goocanvas.Text): - item.props.width = width - elif isinstance(item, goocanvas.Image): - item.props.width = width - item.props.height = height - elif isinstance(item, IconItem): - item.props.size = width - - def _allocate_item_position(self, item, x, y): - if isinstance(item, goocanvas.Rect): - x = x + (item.props.line_width - 1) - y = y + (item.props.line_width - 1) - - matrix = cairo.Matrix(1, 0, 0, 1, 0, 0) - matrix.translate(x, y) - item.set_transform(matrix) - - def _layout_canvas(self, canvas, x, y, width, height): - scale = 1200 / Grid.COLS - canvas.set_bounds(x * scale, y * scale, width * scale, height * scale) diff --git a/sugar/canvas/MenuShell.py b/sugar/canvas/MenuShell.py index 9b869023..58358fbd 100644 --- a/sugar/canvas/MenuShell.py +++ b/sugar/canvas/MenuShell.py @@ -8,10 +8,9 @@ class MenuShell(gobject.GObject): gobject.TYPE_NONE, ([])), } - def __init__(self, grid): + def __init__(self): gobject.GObject.__init__(self) self._menu_controller = None - self._grid = grid def is_active(self): return (self._menu_controller != None) @@ -25,6 +24,3 @@ class MenuShell(gobject.GObject): if self._menu_controller: self._menu_controller.popdown() self._menu_controller = controller - - def get_grid(self): - return self._grid