From 7e96b1afb71f9532ad62f9615085787613f2159f Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Tue, 20 Feb 2007 16:23:49 +0100 Subject: [PATCH] Get rid of the old grid. Never use absolute positioning. --- shell/view/frame/PanelWindow.py | 15 ++- shell/view/frame/clipboardpanelwindow.py | 4 +- shell/view/frame/frame.py | 115 +++++++++++++---------- sugar/activity/Activity.py | 8 -- sugar/graphics/Makefile.am | 1 - sugar/graphics/grid.py | 39 -------- 6 files changed, 79 insertions(+), 103 deletions(-) delete mode 100644 sugar/graphics/grid.py diff --git a/shell/view/frame/PanelWindow.py b/shell/view/frame/PanelWindow.py index 7a27bc06..ab0e4eaa 100644 --- a/shell/view/frame/PanelWindow.py +++ b/shell/view/frame/PanelWindow.py @@ -18,9 +18,10 @@ import gtk import hippo from sugar.graphics.menushell import MenuShell +from sugar.graphics import units class PanelWindow(gtk.Window): - def __init__(self, width, height): + def __init__(self, width, height, orientation): gtk.Window.__init__(self) self.set_decorated(False) @@ -28,7 +29,17 @@ class PanelWindow(gtk.Window): self._canvas = hippo.Canvas() - self._bg = hippo.CanvasBox(background_color=0x414141ff) + self._bg = hippo.CanvasBox(background_color=0x414141ff, + orientation=orientation) + + padding = units.grid_to_pixels(1) + if orientation == hippo.ORIENTATION_HORIZONTAL: + self._bg.props.padding_left = padding + self._bg.props.padding_right = padding + else: + self._bg.props.padding_top = padding + self._bg.props.padding_bottom = padding + self._canvas.set_root(self._bg) self.add(self._canvas) diff --git a/shell/view/frame/clipboardpanelwindow.py b/shell/view/frame/clipboardpanelwindow.py index 1871f7d0..4babc8d8 100644 --- a/shell/view/frame/clipboardpanelwindow.py +++ b/shell/view/frame/clipboardpanelwindow.py @@ -8,8 +8,8 @@ from sugar.clipboard import clipboardservice from sugar import util class ClipboardPanelWindow(PanelWindow): - def __init__(self, frame, width, height): - PanelWindow.__init__(self, width, height) + def __init__(self, frame, width, height, orientation): + PanelWindow.__init__(self, width, height, orientation) self._frame = frame diff --git a/shell/view/frame/frame.py b/shell/view/frame/frame.py index 1e921803..88b918f0 100644 --- a/shell/view/frame/frame.py +++ b/shell/view/frame/frame.py @@ -29,8 +29,8 @@ from view.frame.clipboardpanelwindow import ClipboardPanelWindow from view.frame.notificationtray import NotificationTray from model.ShellModel import ShellModel from sugar.graphics.timeline import Timeline -from sugar.graphics.grid import Grid from sugar.graphics.menushell import MenuShell +from sugar.graphics import units _ANIMATION = False @@ -50,7 +50,6 @@ class Frame: self._hover_frame = False self._shell = shell self._mode = Frame.INACTIVE - self._grid = Grid() self._timeline = Timeline(self) self._timeline.add_tag('slide_in', 18, 24) @@ -63,96 +62,95 @@ class Frame: self._event_frame.connect('leave', self._event_frame_leave_cb) self._event_frame.show() - self._create_top_panel() - self._create_bottom_panel() - self._create_left_panel() - self._create_right_panel() + self._top_panel = self._create_top_panel() + self._bottom_panel = self._create_bottom_panel() + self._left_panel = self._create_left_panel() + self._right_panel = self._create_right_panel() shell.get_model().connect('notify::state', self._shell_state_changed_cb) def _create_top_panel(self): - self._top_panel = self._create_panel(16, 1) - menu_shell = self._top_panel.get_menu_shell() - root = self._top_panel.get_root() + top_panel = self._create_panel(gtk.gdk.screen_width(), + units.grid_to_pixels(1), + hippo.ORIENTATION_HORIZONTAL) + menu_shell = top_panel.get_menu_shell() + root = top_panel.get_root() menu_shell.set_position(MenuShell.BOTTOM) box = ZoomBox(self._shell, menu_shell) - - [x, y] = self._grid.point(1, 0) - root.append(box, hippo.PACK_FIXED) - root.set_position(box, x, y) + root.append(box) tray = NotificationTray() - tray_box = hippo.CanvasBox(box_width=self._grid.dimension(1), - box_height=self._grid.dimension(1), + tray_box = hippo.CanvasBox(box_width=units.grid_to_pixels(1), + box_height=units.grid_to_pixels(1), xalign=hippo.ALIGNMENT_END) tray_widget = hippo.CanvasWidget() tray_widget.props.widget = tray tray_box.append(tray_widget, gtk.EXPAND) - - [x, y] = self._grid.point(13, 0) - root.append(tray_box, hippo.PACK_FIXED) - root.set_position(tray_box, x, y) + root.append(tray_box) box = OverlayBox(self._shell) - - [x, y] = self._grid.point(14, 0) root.append(box, hippo.PACK_FIXED) - root.set_position(box, x, y) + + return top_panel def _create_bottom_panel(self): - self._bottom_panel = self._create_panel(16, 1) - menu_shell = self._bottom_panel.get_menu_shell() - root = self._bottom_panel.get_root() + bottom_panel = self._create_panel(gtk.gdk.screen_width(), + units.grid_to_pixels(1), + hippo.ORIENTATION_HORIZONTAL) + menu_shell = bottom_panel.get_menu_shell() + root = bottom_panel.get_root() menu_shell.set_position(MenuShell.TOP) box = ActivitiesBox(self._shell) - root.append(box, hippo.PACK_FIXED) + root.append(box) - [x, y] = self._grid.point(1, 0) - root.set_position(box, x, y) + return bottom_panel def _create_right_panel(self): - self._right_panel = self._create_panel(1, 10) - menu_shell = self._right_panel.get_menu_shell() - root = self._right_panel.get_root() + right_panel = self._create_panel(units.grid_to_pixels(1), + gtk.gdk.screen_height(), + hippo.ORIENTATION_VERTICAL) + menu_shell = right_panel.get_menu_shell() + root = right_panel.get_root() menu_shell.set_position(MenuShell.LEFT) box = FriendsBox(self._shell, menu_shell) root.append(box) - def _create_left_panel(self): - self._left_panel = ClipboardPanelWindow( - self, self._grid.dimension(1), self._grid.dimension(10)) + return right_panel - self._connect_to_panel(self._left_panel) - self._left_panel.connect('drag-motion', self._drag_motion_cb) - self._left_panel.connect('drag-leave', self._drag_leave_cb) + def _create_left_panel(self): + left_panel = ClipboardPanelWindow(self, units.grid_to_pixels(1), + gtk.gdk.screen_height(), + hippo.ORIENTATION_VERTICAL) + + self._connect_to_panel(left_panel) + left_panel.connect('drag-motion', self._drag_motion_cb) + left_panel.connect('drag-leave', self._drag_leave_cb) + + return left_panel def _shell_state_changed_cb(self, model, pspec): if model.props.state == ShellModel.STATE_SHUTDOWN: self._timeline.goto('slide_out', True) - def _create_panel(self, width, height): - panel = PanelWindow(self._grid.dimension(width), - self._grid.dimension(height)) + def _create_panel(self, width, height, orientation): + panel = PanelWindow(width, height, orientation) self._connect_to_panel(panel) return panel - def _move_panel(self, panel, x1, y1, x2, y2, pos): - [screen_x1, screen_y1] = self._grid.point(x1, y1) - [screen_x2, screen_y2] = self._grid.point(x2, y2) + def _move_panel(self, panel, pos, x1, y1, x2, y2): + x = (x2 - x1) * pos + x1 + y = (y2 - y1) * pos + y1 - screen_x = (screen_x2 - screen_x1) * pos + screen_x1 - screen_y = (screen_y2 - screen_y1) * pos + screen_y1 - - panel.move(int(screen_x), int(screen_y)) + panel.move(x, y) # FIXME we should hide and show as necessary to free memory if not panel.props.visible: @@ -240,10 +238,25 @@ class Frame: self._timeline.play('before_slide_out', 'slide_out') def _move(self, pos): - self._move_panel(self._top_panel, 0, -1, 0, 0, pos) - self._move_panel(self._bottom_panel, 0, 12, 0, 11, pos) - self._move_panel(self._left_panel, -1, 1, 0, 1, pos) - self._move_panel(self._right_panel, 16, 1, 15, 1, pos) + screen_h = gtk.gdk.screen_height() + screen_w = gtk.gdk.screen_width() + + self._move_panel(self._top_panel, pos, + 0, units.grid_to_pixels(-1), + 0, 0) + + self._move_panel(self._bottom_panel, pos, + 0, screen_h, + 0, screen_h - units.grid_to_pixels(1)) + + self._move_panel(self._left_panel, pos, + units.grid_to_pixels(-1), 0, + 0, 0) + + self._move_panel(self._right_panel, pos, + screen_w, 0, + screen_w - units.grid_to_pixels(1), + 0) def do_slide_in(self, current=0, n_frames=0): if _ANIMATION: diff --git a/sugar/activity/Activity.py b/sugar/activity/Activity.py index b5a47639..7926daed 100644 --- a/sugar/activity/Activity.py +++ b/sugar/activity/Activity.py @@ -34,14 +34,6 @@ ACTIVITY_SERVICE_NAME = "org.laptop.Activity" ACTIVITY_SERVICE_PATH = "/org/laptop/Activity" ACTIVITY_INTERFACE = "org.laptop.Activity" -from sugar.graphics.grid import Grid - -settings = gtk.settings_get_default() - -grid = Grid() -sizes = 'gtk-large-toolbar=%d, %d' % (grid.dimension(1), grid.dimension(1)) -settings.set_string_property('gtk-icon-sizes', sizes, '') - def get_service_name(xid): return ACTIVITY_SERVICE_NAME + '%d' % xid diff --git a/sugar/graphics/Makefile.am b/sugar/graphics/Makefile.am index ff71448d..fb586620 100644 --- a/sugar/graphics/Makefile.am +++ b/sugar/graphics/Makefile.am @@ -9,7 +9,6 @@ sugar_PYTHON = \ entry.py \ font.py \ frame.py \ - grid.py \ iconcolor.py \ label.py \ menu.py \ diff --git a/sugar/graphics/grid.py b/sugar/graphics/grid.py deleted file mode 100644 index cfbdf67d..00000000 --- a/sugar/graphics/grid.py +++ /dev/null @@ -1,39 +0,0 @@ -# Copyright (C) 2006, Red Hat, Inc. -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2 of the License, or (at your option) any later version. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the -# Free Software Foundation, Inc., 59 Temple Place - Suite 330, -# Boston, MA 02111-1307, USA. - -import gtk - -COLS = 16 -ROWS = 12 - -class Grid(object): - def __init__(self): - self._factor = gtk.gdk.screen_width() / COLS - - def point(self, grid_x, grid_y): - return [grid_x * self._factor, grid_y * 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 dimension(self, grid_dimension): - return grid_dimension * self._factor - - def fit_point(self, x, y): - return [int(x / self._factor), int(y / self._factor)] -