sugar3.graphics.combobox module

The combobox module provides a combo box; a button like widget which creates a list popup when clicked. It’s best used outside of a toolbar when the user needs to choose from a short list of items.

Example:

from gi.repository import Gtk

from sugar3.graphics.combobox import ComboBox


def __combo_changed_cb(combo):
    print 'Combo changed to %r' % combo.get_value()

w = Gtk.Window()
w.connect("destroy", Gtk.main_quit)

combo = ComboBox()
combo.append_item(True, 'one')
combo.append_item(2, 'two', 'go-next')
combo.append_item('3', 'three')
# This will make 'two' active (zero indexed)
combo.set_active(1)
combo.connect('changed', __combo_changed_cb)
w.add(combo)

w.show_all()
Gtk.main()
class sugar3.graphics.combobox.ComboBox

Bases: gi.overrides.Gtk.ComboBox

This class provides a simple wrapper based on the Gtk.ComboBox. This lets you make a list of items, with a value, label and optionally an icon.

append_item(value, text, icon_name=None, file_name=None)

This function adds another item to the bottom of the combo box list.

If either icon_name or file_name are supplied and icon column will be added to the combo box list.

Parameters:
  • value (object) – the value that will be returned by get_value, when this item is selected
  • text (str) – the user visible label for the item
  • icon_name (str) – the name of the icon in the theme to use for this item, optional and conflicting with file_name
  • file_name (str) – the path to a sugar (svg) icon to use for this item, optional and conflicting with icon_name
append_separator()

Add a separator to the bottom of the combo box list. The separator can not be selected.

do_get_property(pspec)
do_set_property(pspec, value)
get_active_item()

Get the row of data for the currently selected item.

Returns:row of data in the format:
[value, text, pixbuf, is_separator]
get_value()

The value of the currently selected item; the same as the value argument that was passed to the append_item func.

Returns:object, value of selected item
remove_all()

Remove all list items from the combo box.

value

The value of the currently selected item; the same as the value argument that was passed to the append_item func.

Returns:object, value of selected item

Previous topic

sugar3.graphics.colorbutton module

Next topic

sugar3.graphics.icon module

This Page