From b04c19efb41f39f578e558031fa89f81559d89e2 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Tue, 27 Feb 2007 13:41:51 +0100 Subject: [PATCH] Add a window class to graphics, it contains a canvas. --- shell/view/frame/PanelWindow.py | 17 +++++------------ shell/view/frame/clipboardpanelwindow.py | 5 ++++- sugar/graphics/Makefile.am | 1 + sugar/graphics/window.py | 14 ++++++++++++++ 4 files changed, 24 insertions(+), 13 deletions(-) create mode 100644 sugar/graphics/window.py diff --git a/shell/view/frame/PanelWindow.py b/shell/view/frame/PanelWindow.py index 6edd4bd7..cf3fc417 100644 --- a/shell/view/frame/PanelWindow.py +++ b/shell/view/frame/PanelWindow.py @@ -18,34 +18,27 @@ import gtk import hippo from sugar.graphics import units +from sugar.graphics.window import Window -class PanelWindow(gtk.Window): +class PanelWindow(Window): def __init__(self, orientation): - gtk.Window.__init__(self) + Window.__init__(self) self._orientation = orientation self.set_decorated(False) self.connect('realize', self._realize_cb) - self._canvas = hippo.Canvas() - self._bg = hippo.CanvasBox(background_color=0x414141ff, orientation=self._orientation) + self.set_root(self._bg) self._update_size() - self._canvas.set_root(self._bg) - - self.add(self._canvas) - self._canvas.show() - + screen = gtk.gdk.screen_get_default() screen.connect('size-changed', self._size_changed_cb) def get_root(self): return self._bg - - def get_canvas(self): - return self._canvas def _update_size(self): padding = units.grid_to_pixels(1) diff --git a/shell/view/frame/clipboardpanelwindow.py b/shell/view/frame/clipboardpanelwindow.py index 30b9cb2e..cfdb4d55 100644 --- a/shell/view/frame/clipboardpanelwindow.py +++ b/shell/view/frame/clipboardpanelwindow.py @@ -33,7 +33,10 @@ class ClipboardPanelWindow(PanelWindow): self.add_events(gtk.gdk.BUTTON_PRESS_MASK | gtk.gdk.POINTER_MOTION_HINT_MASK) self.connect("motion_notify_event", box.motion_notify_event_cb) - self.get_canvas().connect("button_press_event", box.button_press_event_cb) + + # FIXME I'm not sure we should expose the canvas in the Window API + self._canvas.connect("button_press_event", box.button_press_event_cb) + self.connect("drag_end", box.drag_end_cb) self.connect("drag_data_get", box.drag_data_get_cb) diff --git a/sugar/graphics/Makefile.am b/sugar/graphics/Makefile.am index ea115fae..6a45b3c7 100644 --- a/sugar/graphics/Makefile.am +++ b/sugar/graphics/Makefile.am @@ -22,4 +22,5 @@ sugar_PYTHON = \ timeline.py \ toolbar.py \ units.py \ + window.py \ xocolor.py diff --git a/sugar/graphics/window.py b/sugar/graphics/window.py new file mode 100644 index 00000000..f3854e35 --- /dev/null +++ b/sugar/graphics/window.py @@ -0,0 +1,14 @@ +import hippo +import gtk + +class Window(gtk.Window): + def __init__(self, window_type=gtk.WINDOW_TOPLEVEL): + gtk.Window.__init__(self, window_type) + + self._canvas = hippo.Canvas() + self.add(self._canvas) + self._canvas.show() + + def set_root(self, root): + self._canvas.set_root(root) +