From ec929eb0ad5bb740f0eb5436ebc7a9e15a55f517 Mon Sep 17 00:00:00 2001 From: Eduardo Silva Date: Fri, 6 Jul 2007 10:51:18 -0400 Subject: [PATCH 1/2] New frameinvoker --- shell/view/frame/ActivitiesBox.py | 2 ++ shell/view/frame/Makefile.am | 1 + shell/view/frame/frame.py | 1 + sugar/graphics/canvasicon.py | 3 ++- sugar/graphics/palette.py | 27 ++++++++++++++++++++++----- 5 files changed, 28 insertions(+), 6 deletions(-) diff --git a/shell/view/frame/ActivitiesBox.py b/shell/view/frame/ActivitiesBox.py index 034ccabd..8cd4e876 100644 --- a/shell/view/frame/ActivitiesBox.py +++ b/shell/view/frame/ActivitiesBox.py @@ -24,12 +24,14 @@ from sugar.graphics.iconbutton import IconButton from sugar import profile from model import bundleregistry +from frameinvoker import FrameCanvasInvoker class ActivityButton(IconButton): def __init__(self, activity): IconButton.__init__(self, icon_name=activity.get_icon()) palette = Palette(activity.get_name()) + palette.props.invoker = FrameCanvasInvoker(self) palette.set_group_id('frame') self.set_palette(palette) diff --git a/shell/view/frame/Makefile.am b/shell/view/frame/Makefile.am index 09ab303c..ff2bff35 100644 --- a/shell/view/frame/Makefile.am +++ b/shell/view/frame/Makefile.am @@ -4,6 +4,7 @@ sugar_PYTHON = \ ActivitiesBox.py \ clipboardbox.py \ clipboardpanelwindow.py \ + frameinvoker.py \ FriendsBox.py \ eventarea.py \ frame.py \ diff --git a/shell/view/frame/frame.py b/shell/view/frame/frame.py index 3f3367b3..5210f57a 100644 --- a/shell/view/frame/frame.py +++ b/shell/view/frame/frame.py @@ -336,3 +336,4 @@ class Frame(object): def notify_key_release(self): self._key_listener.key_release() + diff --git a/sugar/graphics/canvasicon.py b/sugar/graphics/canvasicon.py index 9d9fc833..c7e318bf 100644 --- a/sugar/graphics/canvasicon.py +++ b/sugar/graphics/canvasicon.py @@ -373,7 +373,8 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem): def set_palette(self, palette): self._palette = palette - self._palette.props.invoker = CanvasInvoker(self) + if not self._palette.props.invoker: + self._palette.props.invoker = CanvasInvoker(self) def set_tooltip(self, text): self.set_palette(Palette(text)) diff --git a/sugar/graphics/palette.py b/sugar/graphics/palette.py index dc51fe59..1a019b82 100644 --- a/sugar/graphics/palette.py +++ b/sugar/graphics/palette.py @@ -62,6 +62,7 @@ class Palette(gobject.GObject): def __init__(self, label, accel_path=None): gobject.GObject.__init__(self) + self._invoker = None self._group_id = None self._up = False self._position = self.AUTOMATIC @@ -151,6 +152,14 @@ class Palette(gobject.GObject): else: raise AssertionError + def do_get_property(self, pspec): + if pspec.name == 'invoker': + return self._invoker + elif pspec.name == 'position': + return self._position + else: + raise AssertionError + def _get_position(self, alignment): # Invoker: x, y, width and height inv_rect = self._invoker.get_rect() @@ -185,12 +194,12 @@ class Palette(gobject.GObject): def _in_screen(self, x, y): [width, height] = self._menu.size_request() - screen_width = gtk.gdk.screen_width() - units.grid_to_pixels(1) - screen_height = gtk.gdk.screen_height() - units.grid_to_pixels(1) + screen_area = self._invoker.get_screen_area() - return x + width <= screen_width and \ - y + height <= screen_height and \ - x >= units.grid_to_pixels(1) and y >= units.grid_to_pixels(1) + return x >= screen_area.x and \ + y >= screen_area.y and \ + x + width <= screen_area.width and \ + y + height <= screen_area.height def _get_automatic_position(self): alignments = [ _BOTTOM_LEFT, _BOTTOM_RIGHT, @@ -203,6 +212,9 @@ class Palette(gobject.GObject): if self._in_screen(x, y): return x, y + # We fail + return (0, 0) + def _show(self): x = y = 0 @@ -381,6 +393,11 @@ class Invoker(object): for listener in self._listeners: listener.invoker_mouse_leave() + def get_screen_area(self): + width = gtk.gdk.screen_width() + height = gtk.gdk.screen_height() + return gtk.gdk.Rectangle(0, 0, width, height) + class WidgetInvoker(Invoker): def __init__(self, widget): Invoker.__init__(self) From 3680dcdaa9f2f75890d955f38f37c45f109b8d0f Mon Sep 17 00:00:00 2001 From: Eduardo Silva Date: Fri, 6 Jul 2007 11:27:19 -0400 Subject: [PATCH 2/2] Push frameinvoker.py --- shell/view/frame/frameinvoker.py | 33 ++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 shell/view/frame/frameinvoker.py diff --git a/shell/view/frame/frameinvoker.py b/shell/view/frame/frameinvoker.py new file mode 100644 index 00000000..0062f062 --- /dev/null +++ b/shell/view/frame/frameinvoker.py @@ -0,0 +1,33 @@ +# Copyright (C) 2007, Eduardo Silva +# +# 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 + +from sugar.graphics import units +from sugar.graphics.palette import CanvasInvoker + +class FrameCanvasInvoker(CanvasInvoker): + def __init__(self, item): + CanvasInvoker.__init__(self, item) + + def get_screen_area(self): + x = units.grid_to_pixels(1) + y = units.grid_to_pixels(1) + width = gtk.gdk.screen_width() - units.grid_to_pixels(1) + height = gtk.gdk.screen_height() - units.grid_to_pixels(1) + + return gtk.gdk.Rectangle(x, y, width, height)