sugar4.graphics.toolbutton

The toolbutton module provides the ToolButton class, which is a Gtk.Button styled as a toolbar button with icon and tooltip for sugar4.

Example

Add a tool button to a window:

from gi.repository import Gtk
from sugar4.graphics.toolbutton import ToolButton

def __clicked_cb(button):
    print("tool button was clicked")

app = Gtk.Application()

def on_activate(app):
    w = Gtk.ApplicationWindow(application=app)
    b = ToolButton(icon_name='dialog-ok', tooltip='a tooltip')
    b.connect('clicked', __clicked_cb)
    w.set_child(b)
    w.present()

app.connect('activate', on_activate)
app.run()

STABLE.

Attributes

print

Classes

ToolButton

The ToolButton class manages a Gtk.Button styled as a toolbar button for sugar4.

Functions

setup_accelerator(tool_button)

Module Contents

sugar4.graphics.toolbutton.print[source]
sugar4.graphics.toolbutton.setup_accelerator(tool_button)[source]
class sugar4.graphics.toolbutton.ToolButton(icon_name=None, **kwargs)[source]

Bases: gi.repository.Gtk.Button

The ToolButton class manages a Gtk.Button styled as a toolbar button for sugar4.

This replaces deprecated ToolButton with a modern Button implementation styled to look and behave like a traditional toolbar button.

Parameters:
  • icon_name (str, optional) – name of themed icon.

  • accelerator (str, optional) – keyboard shortcut to activate this button.

  • tooltip (str, optional) – tooltip displayed on hover.

  • hide_tooltip_on_click (bool, optional) – Whether tooltip is hidden on click.

set_tooltip(tooltip: str | None)[source]

Set the tooltip.

Parameters:

tooltip (string) – tooltip to be set.

get_tooltip() str | None[source]
tooltip[source]
get_hide_tooltip_on_click() bool[source]

Return True if the tooltip is hidden when a user clicks on the button, otherwise return False.

set_hide_tooltip_on_click(hide_tooltip_on_click: bool)[source]

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

  • click (hidden on)

  • otherwise. (and False)

hide_tooltip_on_click[source]
set_accelerator(accelerator: str | None)[source]

Set accelerator that activates the button.

Parameters:

accelerator (string) – accelerator to be set.

get_accelerator() str | None[source]

Return accelerator that activates the button.

accelerator[source]
set_icon_name(icon_name: str | None)[source]
get_icon_name() str | None[source]

Get the icon name.

Returns:

The icon name or None if no icon is set.

icon_name[source]
set_icon_widget(icon_widget: gi.repository.Gtk.Widget | None)[source]

Set a custom icon widget.

Parameters:

icon_widget – widget to use as icon.

get_icon_widget() gi.repository.Gtk.Widget | None[source]
set_label(label: str | None)[source]
get_label() str | None[source]
create_palette() sugar4.graphics.palette.Palette | None[source]
get_palette() sugar4.graphics.palette.Palette | None[source]

Get the current palette.

set_palette(palette: sugar4.graphics.palette.Palette | None)[source]
palette[source]
get_palette_invoker() sugar4.graphics.palette.ToolInvoker | None[source]
set_palette_invoker(palette_invoker: sugar4.graphics.palette.ToolInvoker | None)[source]
palette_invoker[source]
do_snapshot(snapshot)[source]

Render tool button using snapshot-based drawing.

set_active(active: bool)[source]
get_active() bool[source]

Get the active state of the button.