From c9b103dfef54d055dcac70b1a32e62420b3b8c0d Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Fri, 16 Feb 2007 15:24:02 +0100 Subject: [PATCH] Refactor button a bit to support different sizes. Use it for the overlaybox. --- shell/view/frame/overlaybox.py | 6 ++--- shell/view/stylesheet.py | 6 ----- sugar/graphics/button.py | 40 +++++++++++++++++++++++++++------- sugar/graphics/optionmenu.py | 12 +++++----- sugar/graphics/toolbar.py | 3 +-- 5 files changed, 41 insertions(+), 26 deletions(-) diff --git a/shell/view/frame/overlaybox.py b/shell/view/frame/overlaybox.py index fed1139a..2fbbf806 100644 --- a/shell/view/frame/overlaybox.py +++ b/shell/view/frame/overlaybox.py @@ -1,7 +1,6 @@ import hippo -from sugar.graphics import style -from sugar.graphics.canvasicon import CanvasIcon +from sugar.graphics.button import Button class OverlayBox(hippo.CanvasBox): def __init__(self, shell): @@ -9,8 +8,7 @@ class OverlayBox(hippo.CanvasBox): self._shell = shell - icon = CanvasIcon(icon_name='theme:stock-chat') - style.apply_stylesheet(icon, 'frame.OverlayIcon') + icon = Button(icon_name='theme:stock-chat') icon.connect('activated', self._overlay_clicked_cb) self.append(icon) diff --git a/shell/view/stylesheet.py b/shell/view/stylesheet.py index 83ea9dd5..99be593f 100644 --- a/shell/view/stylesheet.py +++ b/shell/view/stylesheet.py @@ -29,12 +29,6 @@ frame_ActivityIcon = { 'scale' : style.standard_icon_scale } -frame_OverlayIcon = { - 'box-width' : grid.dimension(1), - 'box-height' : grid.dimension(1), - 'scale' : style.standard_icon_scale -} - frame_ZoomIcon = { 'box-width' : grid.dimension(1), 'box-height' : grid.dimension(1), diff --git a/sugar/graphics/button.py b/sugar/graphics/button.py index 36ce4c00..a6bacbf7 100644 --- a/sugar/graphics/button.py +++ b/sugar/graphics/button.py @@ -14,21 +14,31 @@ # 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 sys + import gobject import hippo from canvasicon import CanvasIcon from iconcolor import IconColor +from sugar.graphics import units from sugar import profile +STANDARD_SIZE = 0 +SMALL_SIZE = 1 + class Button(hippo.CanvasBox): - __gtype_name__ = 'Button' + __gtype_name__ = 'Button' __gproperties__ = { - 'icon-name' : (str, None, None, None, gobject.PARAM_READWRITE), - 'scale' : (float, None, None, 0.0, 1024.0, 1.0, + 'icon-name' : (str, None, None, None, gobject.PARAM_READWRITE), - 'active' : (bool, None, None, True, gobject.PARAM_READWRITE) + 'size' : (int, None, None, + 0, sys.maxint, STANDARD_SIZE, + gobject.PARAM_READWRITE), + 'active' : (bool, None, None, True, + gobject.PARAM_READWRITE) } def __init__(self, icon_name): @@ -43,13 +53,27 @@ class Button(hippo.CanvasBox): hippo.CanvasBox.__init__(self) + self._set_size(STANDARD_SIZE) + self.append(self._icon, hippo.PACK_EXPAND) + def _set_size(self, size): + if size == SMALL_SIZE: + self.props.box_width = -1 + self.props.box_height = -1 + self._icon.props.scale = units.SMALL_ICON_SCALE + else: + self.props.box_width = units.grid_to_pixels(1) + self.props.box_height = units.grid_to_pixels(1) + self._icon.props.scale = units.STANDARD_ICON_SCALE + + self._size = size + def do_set_property(self, pspec, value): if pspec.name == 'icon-name': self._icon.props.icon_name = value - elif pspec.name == 'scale': - self._icon.props.scale = value + elif pspec.name == 'size': + self._set_size(value) elif pspec.name == 'active': self._active = value if self._active: @@ -62,8 +86,8 @@ class Button(hippo.CanvasBox): def do_get_property(self, pspec): if pspec.name == 'icon-name': return self._icon.props.icon_name - elif pspec.name == 'scale': - return self._icon.props.scale + elif pspec.name == 'size': + return self._icon.props.size elif pspec.name == 'active': return self._active else: diff --git a/sugar/graphics/optionmenu.py b/sugar/graphics/optionmenu.py index 13072f18..a44d9bef 100644 --- a/sugar/graphics/optionmenu.py +++ b/sugar/graphics/optionmenu.py @@ -24,7 +24,7 @@ import hippo from sugar.graphics import style from sugar.graphics.roundbox import RoundBox -from sugar.graphics.button import Button +from sugar.graphics import button from sugar.graphics import color from sugar.graphics import font from sugar.graphics.canvasicon import CanvasIcon @@ -116,11 +116,11 @@ class OptionMenu(hippo.CanvasBox, hippo.CanvasItem): self._round_box.append(self._canvas_text, hippo.PACK_EXPAND) # TODO: Substitute for the right icon. - button = Button(icon_name='theme:stock-close') - button.props.scale = style.small_icon_scale - button.props.yalign = hippo.ALIGNMENT_CENTER - button.props.xalign = hippo.ALIGNMENT_START - self._round_box.append(button) + arrow = button.Button(icon_name='theme:stock-close') + arrow.props.size = button.SMALL_SIZE + arrow.props.yalign = hippo.ALIGNMENT_CENTER + arrow.props.xalign = hippo.ALIGNMENT_START + self._round_box.append(arrow) self._menu = Menu() self._menu.connect('action', self._menu_action_cb) diff --git a/sugar/graphics/toolbar.py b/sugar/graphics/toolbar.py index 56e50e31..5cd0f65d 100644 --- a/sugar/graphics/toolbar.py +++ b/sugar/graphics/toolbar.py @@ -6,5 +6,4 @@ class Toolbar(hippo.CanvasBox): def __init__(self, orientation=hippo.ORIENTATION_HORIZONTAL): hippo.CanvasBox.__init__(self, orientation=orientation, - background_color=0x414141ff, - spacing=15) + background_color=0x414141ff)