sugar3.graphics.radiotoolbutton module¶
Provides a RadioToolButton class, similar to a “push” button. A group of RadioToolButtons can be set, so that only one can be selected at a time. When a button is clicked, it depresses and is shaded darker.
It is also possible to set a tooltip to be dispalyed when the user scrolls over it with their cursor as well as an accelerator keyboard shortcut.
Example
from gi.repository import Gtk
from sugar3.graphics.radiotoolbutton import RadioToolButton
from sugar3.graphics.radiopalette import RadioPalette, RadioMenuButton
from sugar3.graphics.xocolor import XoColor
from common import set_theme
set_theme()
window = Gtk.Window()
window.show()
window.connect("delete-event", Gtk.main_quit)
box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
window.add(box)
box.show()
def echo(button, label):
if not button.props.active:
return
print(label)
palette = RadioPalette()
# Adding 3 RadioToolButtons to a palette
button1 = RadioToolButton(icon_name='document-save', accelerator="<ctrl>S",
xo_color=XoColor("white"))
button1.connect('toggled', lambda button: echo(button, 'document-save'))
palette.append(button1, 'menu.document-save')
button2 = RadioToolButton(icon_name='document-open', accelerator="<ctrl>O",
xo_color=XoColor("white"), group=button1)
button2.connect('toggled', lambda button: echo(button, 'document-open'))
palette.append(button2, 'menu.document-open')
button3 = RadioToolButton(icon_name='document-send', accelerator="<ctrl>F",
xo_color=XoColor("white"), group=button1)
button3.connect('toggled', lambda button: echo(button, 'document-send'))
palette.append(button3, 'menu.document-send')
button = RadioMenuButton(palette=palette)
box.pack_start(button, False, False, 1)
button.show()
if __name__ == '__main__':
Gtk.main()
- class sugar3.graphics.radiotoolbutton.RadioToolButton(icon_name=None, **kwargs)¶
Bases:
gi.repository.Gtk.RadioToolButton
The RadioToolButton class manages a Gtk.RadioToolButton styled for Sugar.
- Parameters
icon_name (string) – name of icon to be used.
- Keyword Arguments
accelerator (string) – keyboard shortcut to be used to activate this button.
tooltip (string) – tooltip to be displayed when user hovers over button.
xo_color (sugar3.graphics.xocolor.XoColor) – XoColor of button.
hide_tooltip_on_click (bool) – Whether or not the tooltip is hidden when user clicks on button.
- accelerator¶
Return accelerator string.
- create_palette()¶
- do_clicked()¶
Implementation method for hiding the tooltip when the button is clicked.
- do_draw(cr)¶
Implementation method for drawing the button.
- do_get_property(pspec)¶
- do_set_property(pspec, value)¶
- get_accelerator()¶
Return accelerator string.
- get_hide_tooltip_on_click()¶
Return True if the tooltip is hidden when a user clicks on the button, otherwise return False.
- get_icon_name()¶
Return icon name, or None if there is no icon name.
- get_palette()¶
- get_palette_invoker()¶
- get_tooltip()¶
Return the tooltip.
- get_xo_color()¶
Return xocolor.
- hide_tooltip_on_click¶
Return True if the tooltip is hidden when a user clicks on the button, otherwise return False.
- icon_name¶
Return icon name, or None if there is no icon name.
- palette¶
- palette_invoker¶
- set_accelerator(accelerator)¶
Set keyboard shortcut that activates this button.
- Parameters
accelerator (string) – accelerator to be set. Should be in
<modifier>Letter. (form) –
- set_hide_tooltip_on_click(hide_tooltip_on_click)¶
Set whether or not the tooltip is hidden when a user clicks on the button.
- Parameters
hide_tooltip_on_click (bool) – True if the tooltip is
otherwise. (hidden on click, and False) –
- set_icon_name(icon_name)¶
Set name of icon.
- Parameters
icon_name (string) – name of icon
- set_palette(palette)¶
- set_palette_invoker(palette_invoker)¶
- set_tooltip(tooltip)¶
Set the tooltip.
- Parameters
tooltip (string) – tooltip to be set.
- set_xo_color(xo_color)¶
Set XoColor of button icon.
- Parameters
xo_color (sugar3.graphics.xocolor.XoColor) – xocolor to be set.
- tooltip¶
Return the tooltip.
- xo_color¶
Return xocolor.