Refactor button a bit to support different sizes. Use it for the overlaybox.

This commit is contained in:
Marco Pesenti Gritti 2007-02-16 15:24:02 +01:00
parent 086a8e90eb
commit c9b103dfef
5 changed files with 41 additions and 26 deletions

View File

@ -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)

View File

@ -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),

View File

@ -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:

View File

@ -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)

View File

@ -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)