Refactor button a bit to support different sizes. Use it for the overlaybox.
This commit is contained in:
parent
086a8e90eb
commit
c9b103dfef
@ -1,7 +1,6 @@
|
|||||||
import hippo
|
import hippo
|
||||||
|
|
||||||
from sugar.graphics import style
|
from sugar.graphics.button import Button
|
||||||
from sugar.graphics.canvasicon import CanvasIcon
|
|
||||||
|
|
||||||
class OverlayBox(hippo.CanvasBox):
|
class OverlayBox(hippo.CanvasBox):
|
||||||
def __init__(self, shell):
|
def __init__(self, shell):
|
||||||
@ -9,8 +8,7 @@ class OverlayBox(hippo.CanvasBox):
|
|||||||
|
|
||||||
self._shell = shell
|
self._shell = shell
|
||||||
|
|
||||||
icon = CanvasIcon(icon_name='theme:stock-chat')
|
icon = Button(icon_name='theme:stock-chat')
|
||||||
style.apply_stylesheet(icon, 'frame.OverlayIcon')
|
|
||||||
icon.connect('activated', self._overlay_clicked_cb)
|
icon.connect('activated', self._overlay_clicked_cb)
|
||||||
self.append(icon)
|
self.append(icon)
|
||||||
|
|
||||||
|
@ -29,12 +29,6 @@ frame_ActivityIcon = {
|
|||||||
'scale' : style.standard_icon_scale
|
'scale' : style.standard_icon_scale
|
||||||
}
|
}
|
||||||
|
|
||||||
frame_OverlayIcon = {
|
|
||||||
'box-width' : grid.dimension(1),
|
|
||||||
'box-height' : grid.dimension(1),
|
|
||||||
'scale' : style.standard_icon_scale
|
|
||||||
}
|
|
||||||
|
|
||||||
frame_ZoomIcon = {
|
frame_ZoomIcon = {
|
||||||
'box-width' : grid.dimension(1),
|
'box-width' : grid.dimension(1),
|
||||||
'box-height' : grid.dimension(1),
|
'box-height' : grid.dimension(1),
|
||||||
|
@ -14,21 +14,31 @@
|
|||||||
# License along with this library; if not, write to the
|
# License along with this library; if not, write to the
|
||||||
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||||
# Boston, MA 02111-1307, USA.
|
# Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
import gobject
|
import gobject
|
||||||
import hippo
|
import hippo
|
||||||
|
|
||||||
from canvasicon import CanvasIcon
|
from canvasicon import CanvasIcon
|
||||||
from iconcolor import IconColor
|
from iconcolor import IconColor
|
||||||
|
from sugar.graphics import units
|
||||||
from sugar import profile
|
from sugar import profile
|
||||||
|
|
||||||
|
STANDARD_SIZE = 0
|
||||||
|
SMALL_SIZE = 1
|
||||||
|
|
||||||
class Button(hippo.CanvasBox):
|
class Button(hippo.CanvasBox):
|
||||||
__gtype_name__ = 'Button'
|
__gtype_name__ = 'Button'
|
||||||
|
|
||||||
__gproperties__ = {
|
__gproperties__ = {
|
||||||
'icon-name' : (str, None, None, None, gobject.PARAM_READWRITE),
|
'icon-name' : (str, None, None, None,
|
||||||
'scale' : (float, None, None, 0.0, 1024.0, 1.0,
|
|
||||||
gobject.PARAM_READWRITE),
|
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):
|
def __init__(self, icon_name):
|
||||||
@ -43,13 +53,27 @@ class Button(hippo.CanvasBox):
|
|||||||
|
|
||||||
hippo.CanvasBox.__init__(self)
|
hippo.CanvasBox.__init__(self)
|
||||||
|
|
||||||
|
self._set_size(STANDARD_SIZE)
|
||||||
|
|
||||||
self.append(self._icon, hippo.PACK_EXPAND)
|
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):
|
def do_set_property(self, pspec, value):
|
||||||
if pspec.name == 'icon-name':
|
if pspec.name == 'icon-name':
|
||||||
self._icon.props.icon_name = value
|
self._icon.props.icon_name = value
|
||||||
elif pspec.name == 'scale':
|
elif pspec.name == 'size':
|
||||||
self._icon.props.scale = value
|
self._set_size(value)
|
||||||
elif pspec.name == 'active':
|
elif pspec.name == 'active':
|
||||||
self._active = value
|
self._active = value
|
||||||
if self._active:
|
if self._active:
|
||||||
@ -62,8 +86,8 @@ class Button(hippo.CanvasBox):
|
|||||||
def do_get_property(self, pspec):
|
def do_get_property(self, pspec):
|
||||||
if pspec.name == 'icon-name':
|
if pspec.name == 'icon-name':
|
||||||
return self._icon.props.icon_name
|
return self._icon.props.icon_name
|
||||||
elif pspec.name == 'scale':
|
elif pspec.name == 'size':
|
||||||
return self._icon.props.scale
|
return self._icon.props.size
|
||||||
elif pspec.name == 'active':
|
elif pspec.name == 'active':
|
||||||
return self._active
|
return self._active
|
||||||
else:
|
else:
|
||||||
|
@ -24,7 +24,7 @@ import hippo
|
|||||||
|
|
||||||
from sugar.graphics import style
|
from sugar.graphics import style
|
||||||
from sugar.graphics.roundbox import RoundBox
|
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 color
|
||||||
from sugar.graphics import font
|
from sugar.graphics import font
|
||||||
from sugar.graphics.canvasicon import CanvasIcon
|
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)
|
self._round_box.append(self._canvas_text, hippo.PACK_EXPAND)
|
||||||
|
|
||||||
# TODO: Substitute for the right icon.
|
# TODO: Substitute for the right icon.
|
||||||
button = Button(icon_name='theme:stock-close')
|
arrow = button.Button(icon_name='theme:stock-close')
|
||||||
button.props.scale = style.small_icon_scale
|
arrow.props.size = button.SMALL_SIZE
|
||||||
button.props.yalign = hippo.ALIGNMENT_CENTER
|
arrow.props.yalign = hippo.ALIGNMENT_CENTER
|
||||||
button.props.xalign = hippo.ALIGNMENT_START
|
arrow.props.xalign = hippo.ALIGNMENT_START
|
||||||
self._round_box.append(button)
|
self._round_box.append(arrow)
|
||||||
|
|
||||||
self._menu = Menu()
|
self._menu = Menu()
|
||||||
self._menu.connect('action', self._menu_action_cb)
|
self._menu.connect('action', self._menu_action_cb)
|
||||||
|
@ -6,5 +6,4 @@ class Toolbar(hippo.CanvasBox):
|
|||||||
|
|
||||||
def __init__(self, orientation=hippo.ORIENTATION_HORIZONTAL):
|
def __init__(self, orientation=hippo.ORIENTATION_HORIZONTAL):
|
||||||
hippo.CanvasBox.__init__(self, orientation=orientation,
|
hippo.CanvasBox.__init__(self, orientation=orientation,
|
||||||
background_color=0x414141ff,
|
background_color=0x414141ff)
|
||||||
spacing=15)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user