Implement ToggleIconButton
This commit is contained in:
parent
e9f3099635
commit
cda47a41f4
@ -20,6 +20,7 @@ sugar_PYTHON = \
|
|||||||
snowflakebox.py \
|
snowflakebox.py \
|
||||||
spreadbox.py \
|
spreadbox.py \
|
||||||
timeline.py \
|
timeline.py \
|
||||||
|
toggleiconbutton.py \
|
||||||
toolbar.py \
|
toolbar.py \
|
||||||
units.py \
|
units.py \
|
||||||
window.py \
|
window.py \
|
||||||
|
@ -21,7 +21,8 @@ _system_colors = {
|
|||||||
'button-hover' : '#808080',
|
'button-hover' : '#808080',
|
||||||
'button-background-hover' : '#000000',
|
'button-background-hover' : '#000000',
|
||||||
'icon-stroke-inactive' : '#757575',
|
'icon-stroke-inactive' : '#757575',
|
||||||
'icon-fill-inactive' : '#9D9FA1'
|
'icon-fill-inactive' : '#9D9FA1',
|
||||||
|
'toggle-button-background' : '#A1A5A8'
|
||||||
}
|
}
|
||||||
|
|
||||||
def _html_to_rgb(html_color):
|
def _html_to_rgb(html_color):
|
||||||
@ -100,3 +101,4 @@ BUTTON_HOVER = SystemColor('button-hover')
|
|||||||
BUTTON_BACKGROUND_HOVER = SystemColor('button-background-hover')
|
BUTTON_BACKGROUND_HOVER = SystemColor('button-background-hover')
|
||||||
ICON_FILL_INACTIVE = SystemColor('icon-fill-inactive')
|
ICON_FILL_INACTIVE = SystemColor('icon-fill-inactive')
|
||||||
ICON_STROKE_INACTIVE = SystemColor('icon-stroke-inactive')
|
ICON_STROKE_INACTIVE = SystemColor('icon-stroke-inactive')
|
||||||
|
TOGGLE_BUTTON_BACKGROUND = SystemColor('toggle-button-background')
|
||||||
|
@ -45,7 +45,7 @@ class IconButton(CanvasIcon):
|
|||||||
|
|
||||||
self._set_size(STANDARD_SIZE)
|
self._set_size(STANDARD_SIZE)
|
||||||
|
|
||||||
self.connect('button-press-event',
|
self.connect_after('button-press-event',
|
||||||
self._icon_button_button_press_event_cb)
|
self._icon_button_button_press_event_cb)
|
||||||
|
|
||||||
def _set_size(self, size):
|
def _set_size(self, size):
|
||||||
|
71
sugar/graphics/toggleiconbutton.py
Normal file
71
sugar/graphics/toggleiconbutton.py
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
# Copyright (C) 2007, Red Hat
|
||||||
|
#
|
||||||
|
# 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 gobject
|
||||||
|
|
||||||
|
from sugar.graphics.iconbutton import IconButton
|
||||||
|
from sugar.graphics import color
|
||||||
|
|
||||||
|
class ToggleIconButton(IconButton):
|
||||||
|
__gtype_name__ = 'SugarToggleIconButton'
|
||||||
|
|
||||||
|
__gproperties__ = {
|
||||||
|
'toggled' : (bool, None, None, False,
|
||||||
|
gobject.PARAM_READWRITE)
|
||||||
|
}
|
||||||
|
|
||||||
|
def __init__(self, **kwargs):
|
||||||
|
self._toggled = False
|
||||||
|
|
||||||
|
IconButton.__init__(self, **kwargs)
|
||||||
|
|
||||||
|
self.connect('button-press-event',
|
||||||
|
self._toggle_icon_button_press_event_cb)
|
||||||
|
|
||||||
|
def _get_bg_color(self):
|
||||||
|
if self._toggled:
|
||||||
|
col = color.TOGGLE_BUTTON_BACKGROUND
|
||||||
|
else:
|
||||||
|
col = color.BUTTON_BACKGROUND_NORMAL
|
||||||
|
|
||||||
|
return col.get_int()
|
||||||
|
|
||||||
|
def _set_toggled(self, toggled):
|
||||||
|
self._toggled = toggled
|
||||||
|
self.props.background_color = self._get_bg_color()
|
||||||
|
|
||||||
|
def do_set_property(self, pspec, value):
|
||||||
|
if pspec.name == 'toggled':
|
||||||
|
self._set_toggled(value)
|
||||||
|
else:
|
||||||
|
IconButton.do_set_property(self, pspec, value)
|
||||||
|
|
||||||
|
def do_get_property(self, pspec):
|
||||||
|
if pspec.name == 'toggled':
|
||||||
|
return self._toggled
|
||||||
|
|
||||||
|
return IconButton.do_get_property(self, pspec)
|
||||||
|
|
||||||
|
def _toggle_icon_button_press_event_cb(self, widget, event):
|
||||||
|
self.props.toggled = not self._toggled
|
||||||
|
return True
|
||||||
|
|
||||||
|
def prelight(self, enter):
|
||||||
|
if enter:
|
||||||
|
IconButton.prelight(self, enter)
|
||||||
|
else:
|
||||||
|
self.props.background_color = self._get_bg_color()
|
@ -23,12 +23,16 @@ import hippo
|
|||||||
|
|
||||||
from sugar.graphics.toolbar import Toolbar
|
from sugar.graphics.toolbar import Toolbar
|
||||||
from sugar.graphics.iconbutton import IconButton
|
from sugar.graphics.iconbutton import IconButton
|
||||||
|
from sugar.graphics.toggleiconbutton import ToggleIconButton
|
||||||
from sugar.graphics.button import Button
|
from sugar.graphics.button import Button
|
||||||
from sugar.graphics.entry import Entry
|
from sugar.graphics.entry import Entry
|
||||||
|
|
||||||
def _button_activated_cb(button):
|
def _button_activated_cb(button):
|
||||||
print "_button_activated_cb"
|
print "_button_activated_cb"
|
||||||
|
|
||||||
|
def _toggled_changed_cb(button, pspec):
|
||||||
|
print "Toggle state: %d" % button.props.toggled
|
||||||
|
|
||||||
window = gtk.Window()
|
window = gtk.Window()
|
||||||
window.connect("destroy", lambda w: gtk.main_quit())
|
window.connect("destroy", lambda w: gtk.main_quit())
|
||||||
window.show()
|
window.show()
|
||||||
@ -48,6 +52,10 @@ for i in [1, 2]:
|
|||||||
icon_button = IconButton(icon_name='theme:stock-close')
|
icon_button = IconButton(icon_name='theme:stock-close')
|
||||||
toolbar.append(icon_button)
|
toolbar.append(icon_button)
|
||||||
|
|
||||||
|
toggle = ToggleIconButton(icon_name='theme:stock-back')
|
||||||
|
toggle.connect('notify::toggled', _toggled_changed_cb)
|
||||||
|
toolbar.append(toggle)
|
||||||
|
|
||||||
button = Button(text='Click me!', icon_name='theme:stock-close')
|
button = Button(text='Click me!', icon_name='theme:stock-close')
|
||||||
button.connect('activated', _button_activated_cb)
|
button.connect('activated', _button_activated_cb)
|
||||||
toolbar.append(button)
|
toolbar.append(button)
|
||||||
|
Loading…
Reference in New Issue
Block a user