From 5988a895176e662dc0a1b0629bb7da1441cfe107 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Thu, 7 Sep 2006 19:03:40 +0200 Subject: [PATCH] Write a GridModel, with correct size and layout, and use it --- shell/frame/Frame.py | 15 ++++----------- sugar/canvas/CanvasWindow.py | 2 +- sugar/canvas/GridModel.py | 30 ++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 12 deletions(-) create mode 100644 sugar/canvas/GridModel.py diff --git a/shell/frame/Frame.py b/shell/frame/Frame.py index 70873bab..bdd250d7 100644 --- a/shell/frame/Frame.py +++ b/shell/frame/Frame.py @@ -11,30 +11,24 @@ from sugar.canvas.ScreenContainer import ScreenContainer from sugar.canvas.GridLayout import GridLayout from sugar.canvas.GridLayout import GridConstraints from sugar.canvas.GridLayout import GridGroup +from sugar.canvas.GridModel import GridModel class Frame: def __init__(self, shell, owner): self._windows = [] - self._model = goocanvas.CanvasModelSimple() - item = goocanvas.Rect(x=0, y=0, width=800, height=600, - line_width=0, fill_color="#4f4f4f") - self._model.get_root_item().add_child(item) + self._model = GridModel("#4f4f4f") + layout = self._model.get_layout() self._screen_layout = GridLayout() self._screen_container = ScreenContainer(self._windows) - group = GridGroup() - group.props.width = 800 - group.props.height = 600 - layout = group.get_layout() - constraints = GridConstraints(0, 11, 16, 1) self._create_window(constraints) panel = BottomPanel(shell, owner.get_invites()) layout.set_constraints(panel, constraints) - group.add_child(panel) + self._model.add(panel) # Top constraints = GridConstraints(0, 0, 16, 1) @@ -48,7 +42,6 @@ class Frame: constraints = GridConstraints(15, 1, 1, 10) self._create_window(constraints) - self._model.get_root_item().add_child(group) self._screen_container.set_layout(self._screen_layout) def _create_window(self, constraints): diff --git a/sugar/canvas/CanvasWindow.py b/sugar/canvas/CanvasWindow.py index 1afd731c..5034eb14 100644 --- a/sugar/canvas/CanvasWindow.py +++ b/sugar/canvas/CanvasWindow.py @@ -6,7 +6,7 @@ class CanvasWindow(gtk.Window): gtk.Window.__init__(self) self._view = goocanvas.CanvasView() - self._view.set_model(model) + self._view.set_model(model.get()) self.add(self._view) self._view.show() diff --git a/sugar/canvas/GridModel.py b/sugar/canvas/GridModel.py new file mode 100644 index 00000000..c930519a --- /dev/null +++ b/sugar/canvas/GridModel.py @@ -0,0 +1,30 @@ +import goocanvas + +from sugar.canvas.GridLayout import GridGroup + +# FIXME model subclassing doesn't work in pygoocanvas + +class GridModel: + def __init__(self, bg_color): + self._model = goocanvas.CanvasModelSimple() + + self._width = 800 + self._height = 600 + + item = goocanvas.Rect(width=self._width, height=self._height, + line_width=0, fill_color=bg_color) + self._model.get_root_item().add_child(item) + + self._root = GridGroup() + self._root.props.width = self._width + self._root.props.height = self._height + self._model.get_root_item().add_child(self._root) + + def add(self, child): + self._root.add_child(child) + + def get(self): + return self._model + + def get_layout(self): + return self._root.get_layout()