Gtk.ComboBox¶
Example¶
- Subclasses:
Methods¶
- Inherited:
Gtk.Bin (1), Gtk.Container (35), Gtk.Widget (278), GObject.Object (37), Gtk.Buildable (10), Gtk.CellEditable (3), Gtk.CellLayout (9)
- Structs:
Gtk.ContainerClass (5), Gtk.WidgetClass (12), GObject.ObjectClass (5)
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
- Inherited:
Gtk.Container (10), Gtk.Widget (82), GObject.Object (7), Gtk.Buildable (10), Gtk.CellEditable (3), Gtk.CellLayout (9)
|
|
|
Properties¶
- Inherited:
Name |
Type |
Flags |
Short Description |
---|---|---|---|
r/w/en |
The item which is currently active |
||
r/w/en |
The value of the id column for the active row |
||
d/r/w/en |
Whether dropdowns should have a tearoff menu item |
||
r/w/en |
Whether the dropdown button is sensitive when the model is empty |
||
r/w/co |
The |
||
r/w/en |
TreeModel column containing the column span values |
||
r/w/en |
The column in the combo box’s model to associate with strings from the entry if the combo was created with |
||
r/w/co |
Whether combo box has an entry |
||
r/w/en |
Whether the combo box draws a frame around the child |
||
r/w/en |
The column in the combo box’s model that provides string IDs for the values in the model |
||
r/w/en |
The model for the combo box |
||
r/w/en |
Whether the popup’s width should be a fixed width matching the allocated width of the combo box |
||
r |
Whether the combo’s dropdown is shown |
||
r/w/en |
TreeModel column containing the row span values |
||
d/r/w/en |
A title that may be displayed by the window manager when the popup is torn-off |
||
r/w/en |
Wrap width for laying out the items in a grid |
Style Properties¶
- Inherited:
Name |
Type |
Default |
Flags |
Short Description |
---|---|---|---|---|
|
r |
Whether dropdowns should look like lists rather than menus |
||
|
|
d/r |
The amount of space used by the arrow |
|
|
|
d/r |
The minimum size of the arrow in the combo box |
|
|
d/r |
Which kind of shadow to draw around the combo box |
Signals¶
Name |
Short Description |
---|---|
The changed signal is emitted when the active item is changed. |
|
For combo boxes that are created with an entry (See |
|
The |
|
The |
|
The |
Fields¶
Name |
Type |
Access |
Description |
---|---|---|---|
parent_instance |
r |
Class Details¶
- class Gtk.ComboBox(**kwargs)¶
- Bases:
- Abstract:
No
- Structure:
A
Gtk.ComboBox
is a widget that allows the user to choose from a list of valid choices. TheGtk.ComboBox
displays the selected choice. When activated, theGtk.ComboBox
displays a popup which allows the user to make a new choice. The style in which the selected value is displayed, and the style of the popup is determined by the current theme. It may be similar to a Windows-style combo box.The
Gtk.ComboBox
uses the model-view pattern; the list of valid choices is specified in the form of a tree model, and the display of the choices can be adapted to the data in the model by using cell renderers, as you would in a tree view. This is possible sinceGtk.ComboBox
implements theGtk.CellLayout
interface. The tree model holding the valid choices is not restricted to a flat list, it can be a real tree, and the popup will reflect the tree structure.To allow the user to enter values not in the model, the “has-entry” property allows the
Gtk.ComboBox
to contain aGtk.Entry
. This entry can be accessed by callingGtk.Bin.get_child
() on the combo box.For a simple list of textual choices, the model-view API of
Gtk.ComboBox
can be a bit overwhelming. In this case,Gtk.ComboBoxText
offers a simple alternative. BothGtk.ComboBox
andGtk.ComboBoxText
can contain an entry.- CSS nodes
combobox ├── box.linked │ ╰── button.combo │ ╰── box │ ├── cellview │ ╰── arrow ╰── window.popup
A normal combobox contains a box with the .linked class, a button with the .combo class and inside those buttons, there are a cellview and an arrow.
combobox ├── box.linked │ ├── entry.combo │ ╰── button.combo │ ╰── box │ ╰── arrow ╰── window.popup
A
Gtk.ComboBox
with an entry has a single CSS node with name combobox. It contains a box with the .linked class. That box contains an entry and a button, both with the .combo class added. The button also contains another node with name arrow.- classmethod new()[source]¶
- Returns:
A new
Gtk.ComboBox
.- Return type:
Creates a new empty
Gtk.ComboBox
.New in version 2.4.
- classmethod new_with_area(area)[source]¶
- Parameters:
area (
Gtk.CellArea
) – theGtk.CellArea
to use to layout cell renderers- Returns:
A new
Gtk.ComboBox
.- Return type:
Creates a new empty
Gtk.ComboBox
using area to layout cells.
- classmethod new_with_area_and_entry(area)[source]¶
- Parameters:
area (
Gtk.CellArea
) – theGtk.CellArea
to use to layout cell renderers- Returns:
A new
Gtk.ComboBox
.- Return type:
Creates a new empty
Gtk.ComboBox
with an entry.The new combo box will use area to layout cells.
- classmethod new_with_entry()[source]¶
- Returns:
A new
Gtk.ComboBox
.- Return type:
Creates a new empty
Gtk.ComboBox
with an entry.New in version 2.24.
- classmethod new_with_model(model)[source]¶
- Parameters:
model (
Gtk.TreeModel
) – AGtk.TreeModel
.- Returns:
A new
Gtk.ComboBox
.- Return type:
Creates a new
Gtk.ComboBox
with the model initialized to model.New in version 2.4.
- classmethod new_with_model_and_entry(model)[source]¶
- Parameters:
model (
Gtk.TreeModel
) – AGtk.TreeModel
- Returns:
A new
Gtk.ComboBox
- Return type:
Creates a new empty
Gtk.ComboBox
with an entry and with the model initialized to model.New in version 2.24.
- get_active()[source]¶
- Returns:
An integer which is the index of the currently active item, or -1 if there’s no active item.
- Return type:
Returns the index of the currently active item, or -1 if there’s no active item. If the model is a non-flat treemodel, and the active item is not an immediate child of the root of the tree, this function returns
gtk_tree_path_get_indices (path)[0]
, wherepath
is theGtk.TreePath
of the active item.New in version 2.4.
- get_active_id()[source]¶
-
Returns the ID of the active row of self. This value is taken from the active row and the column specified by the
Gtk.ComboBox
:id-column
property of self (seeGtk.ComboBox.set_id_column
()).The returned value is an interned string which means that you can compare the pointer by value to other interned strings and that you must not free it.
If the
Gtk.ComboBox
:id-column
property of self is not set, or if no row is active, or if the active row has aNone
ID value, thenNone
is returned.New in version 3.0.
- get_active_iter()[source]¶
- Returns:
a
Gtk.TreeIter
orNone
if there is no active item- Return type:
Gtk.TreeIter
orNone
Returns the iter for the current active item, if it exists.
New in version 2.4.
- get_add_tearoffs()[source]¶
- Returns:
the current value of the
:add-tearoffs
property.- Return type:
Gets the current value of the
:add-tearoffs
property.Deprecated since version 3.10.
- get_button_sensitivity()[source]¶
- Returns:
Gtk.SensitivityType.ON
if the dropdown button is sensitive when the model is empty,Gtk.SensitivityType.OFF
if the button is always insensitive orGtk.SensitivityType.AUTO
if it is only sensitive as long as the model has one item to be selected.- Return type:
Returns whether the combo box sets the dropdown button sensitive or not when there are no items in the model.
New in version 2.14.
- get_column_span_column()[source]¶
- Returns:
the column span column.
- Return type:
Returns the column with column span information for self.
New in version 2.6.
- get_entry_text_column()[source]¶
- Returns:
A column in the data source model of self.
- Return type:
Returns the column which self is using to get the strings from to display in the internal entry.
New in version 2.24.
- get_focus_on_click()[source]¶
-
Returns whether the combo box grabs focus when it is clicked with the mouse. See
Gtk.ComboBox.set_focus_on_click
().New in version 2.6.
Deprecated since version 3.20: Use
Gtk.Widget.get_focus_on_click
() instead
- get_has_entry()[source]¶
- Returns:
whether there is an entry in self.
- Return type:
Returns whether the combo box has an entry.
New in version 2.24.
- get_id_column()[source]¶
- Returns:
A column in the data source model of self.
- Return type:
Returns the column which self is using to get string IDs for values from.
New in version 3.0.
- get_model()[source]¶
- Returns:
A
Gtk.TreeModel
which was passed during construction.- Return type:
Returns the
Gtk.TreeModel
which is acting as data source for self.New in version 2.4.
- get_popup_accessible()[source]¶
- Returns:
the accessible object corresponding to the combo box’s popup.
- Return type:
Gets the accessible object corresponding to the combo box’s popup.
This function is mostly intended for use by accessibility technologies; applications should have little use for it.
New in version 2.6.
- get_popup_fixed_width()[source]¶
-
Gets whether the popup uses a fixed width matching the allocated width of the combo box.
New in version 3.0.
- get_row_span_column()[source]¶
- Returns:
the row span column.
- Return type:
Returns the column with row span information for self.
New in version 2.6.
- get_title()[source]¶
- Returns:
the menu’s title in tearoff mode. This is an internal copy of the string which must not be freed.
- Return type:
Gets the current title of the menu in tearoff mode. See
Gtk.ComboBox.set_add_tearoffs
().New in version 2.10.
Deprecated since version 3.10.
- get_wrap_width()[source]¶
- Returns:
the wrap width.
- Return type:
Returns the wrap width which is used to determine the number of columns for the popup menu. If the wrap width is larger than 1, the combo box is in table mode.
New in version 2.6.
- popdown()[source]¶
Hides the menu or dropdown list of self.
This function is mostly intended for use by accessibility technologies; applications should have little use for it.
New in version 2.4.
- popup()[source]¶
Pops up the menu or dropdown list of self.
This function is mostly intended for use by accessibility technologies; applications should have little use for it.
Before calling this, self must be mapped, or nothing will happen.
New in version 2.4.
- popup_for_device(device)[source]¶
- Parameters:
device (
Gdk.Device
) – aGdk.Device
Pops up the menu or dropdown list of self, the popup window will be grabbed so only device and its associated pointer/keyboard are the only
Gdk.Devices
able to send events to it.New in version 3.0.
- set_active(index_)[source]¶
- Parameters:
index (
int
) – An index in the model passed during construction, or -1 to have no active item
Sets the active item of self to be the item at index.
New in version 2.4.
- set_active_id(active_id)[source]¶
- Parameters:
active_id (
str
orNone
) – the ID of the row to select, orNone
- Returns:
True
if a row with a matching ID was found. If aNone
active_id was given to unset the active row, the function always returnsTrue
.- Return type:
Changes the active row of self to the one that has an ID equal to active_id, or unsets the active row if active_id is
None
. Rows having aNone
ID string cannot be made active by this function.If the
Gtk.ComboBox
:id-column
property of self is unset or if no row has the given ID then the function does nothing and returnsFalse
.New in version 3.0.
- set_active_iter(iter)[source]¶
- Parameters:
iter (
Gtk.TreeIter
orNone
) – TheGtk.TreeIter
, orNone
Sets the current active item to be the one referenced by iter, or unsets the active item if iter is
None
.New in version 2.4.
- set_add_tearoffs(add_tearoffs)[source]¶
-
Sets whether the popup menu should have a tearoff menu item.
New in version 2.6.
Deprecated since version 3.10.
- set_button_sensitivity(sensitivity)[source]¶
- Parameters:
sensitivity (
Gtk.SensitivityType
) – specify the sensitivity of the dropdown button
Sets whether the dropdown button of the combo box should be always sensitive (
Gtk.SensitivityType.ON
), never sensitive (Gtk.SensitivityType.OFF
) or only if there is at least one item to display (Gtk.SensitivityType.AUTO
).New in version 2.14.
- set_column_span_column(column_span)[source]¶
- Parameters:
column_span (
int
) – A column in the model passed during construction
Sets the column with column span information for self to be column_span. The column span column contains integers which indicate how many columns an item should span.
New in version 2.4.
- set_entry_text_column(text_column)[source]¶
- Parameters:
text_column (
int
) – A column in model to get the strings from for the internal entry
Sets the model column which self should use to get strings from to be text_column. The column text_column in the model of self must be of type
GObject.TYPE_STRING
.This is only relevant if self has been created with
Gtk.ComboBox
:has-entry
asTrue
.New in version 2.24.
- set_focus_on_click(focus_on_click)[source]¶
- Parameters:
focus_on_click (
bool
) – whether the combo box grabs focus when clicked with the mouse
Sets whether the combo box will grab focus when it is clicked with the mouse. Making mouse clicks not grab focus is useful in places like toolbars where you don’t want the keyboard focus removed from the main area of the application.
New in version 2.6.
Deprecated since version 3.20: Use
Gtk.Widget.set_focus_on_click
() instead
- set_id_column(id_column)[source]¶
- Parameters:
id_column (
int
) – A column in model to get string IDs for values from
Sets the model column which self should use to get string IDs for values from. The column id_column in the model of self must be of type
GObject.TYPE_STRING
.New in version 3.0.
- set_model(model)[source]¶
- Parameters:
model (
Gtk.TreeModel
orNone
) – AGtk.TreeModel
Sets the model used by self to be model. Will unset a previously set model (if applicable). If model is
None
, then it will unset the model.Note that this function does not clear the cell renderers, you have to call
Gtk.CellLayout.clear
() yourself if you need to set up different cell renderers for the new model.New in version 2.4.
- set_popup_fixed_width(fixed)[source]¶
- Parameters:
fixed (
bool
) – whether to use a fixed popup width
Specifies whether the popup’s width should be a fixed width matching the allocated width of the combo box.
New in version 3.0.
- set_row_separator_func(func, *data)[source]¶
- Parameters:
Sets the row separator function, which is used to determine whether a row should be drawn as a separator. If the row separator function is
None
, no separators are drawn. This is the default value.New in version 2.6.
- set_row_span_column(row_span)[source]¶
- Parameters:
row_span (
int
) – A column in the model passed during construction.
Sets the column with row span information for self to be row_span. The row span column contains integers which indicate how many rows an item should span.
New in version 2.4.
- set_title(title)[source]¶
- Parameters:
title (
str
) – a title for the menu in tearoff mode
Sets the menu’s title in tearoff mode.
New in version 2.10.
Deprecated since version 3.10.
- set_wrap_width(width)[source]¶
- Parameters:
width (
int
) – Preferred number of columns
Sets the wrap width of self to be width. The wrap width is basically the preferred number of columns when you want the popup to be layed out in a table.
New in version 2.4.
- do_changed() virtual¶
Signal is emitted when the active item is changed.
Signal Details¶
- Gtk.ComboBox.signals.changed(combo_box)¶
- Signal Name:
changed
- Flags:
- Parameters:
combo_box (
Gtk.ComboBox
) – The object which received the signal
The changed signal is emitted when the active item is changed. The can be due to the user selecting a different item from the list, or due to a call to
Gtk.ComboBox.set_active_iter
(). It will also be emitted while typing into the entry of a combo box with an entry.New in version 2.4.
- Gtk.ComboBox.signals.format_entry_text(combo_box, path)¶
- Signal Name:
format-entry-text
- Flags:
- Parameters:
combo_box (
Gtk.ComboBox
) – The object which received the signalpath (
str
) – theGtk.TreePath
string from the combo box’s current model to format text for
- Returns:
a newly allocated string representing path for the current
Gtk.ComboBox
model.- Return type:
For combo boxes that are created with an entry (See
Gtk.ComboBox
:has-entry
).A signal which allows you to change how the text displayed in a combo box’s entry is displayed.
Connect a signal handler which returns an allocated string representing path. That string will then be used to set the text in the combo box’s entry. The default signal handler uses the text from the
Gtk.ComboBox
::entry-text-column
model column.Here’s an example signal handler which fetches data from the model and displays it in the entry.
static gchar* format_entry_text_callback (GtkComboBox *combo, const gchar *path, gpointer user_data) { GtkTreeIter iter; GtkTreeModel model; gdouble value; model = gtk_combo_box_get_model (combo); gtk_tree_model_get_iter_from_string (model, &iter, path); gtk_tree_model_get (model, &iter, THE_DOUBLE_VALUE_COLUMN, &value, -1); return g_strdup_printf ("%g", value); }
New in version 3.4.
- Gtk.ComboBox.signals.move_active(combo_box, scroll_type)¶
- Signal Name:
move-active
- Flags:
- Parameters:
combo_box (
Gtk.ComboBox
) – The object which received the signalscroll_type (
Gtk.ScrollType
) – aGtk.ScrollType
The
::move-active
signal is akeybinding signal
which gets emitted to move the active selection.New in version 2.12.
- Gtk.ComboBox.signals.popdown(combo_box)¶
- Signal Name:
popdown
- Flags:
- Parameters:
combo_box (
Gtk.ComboBox
) – The object which received the signal- Return type:
The
::popdown
signal is akeybinding signal
which gets emitted to popdown the combo box list.The default bindings for this signal are Alt+Up and Escape.
New in version 2.12.
- Gtk.ComboBox.signals.popup(combo_box)¶
- Signal Name:
popup
- Flags:
- Parameters:
combo_box (
Gtk.ComboBox
) – The object which received the signal
The
::popup
signal is akeybinding signal
which gets emitted to popup the combo box list.The default binding for this signal is Alt+Down.
New in version 2.12.
Property Details¶
- Gtk.ComboBox.props.active¶
- Name:
active
- Type:
- Default Value:
-1
- Flags:
The item which is currently active. If the model is a non-flat treemodel, and the active item is not an immediate child of the root of the tree, this property has the value
gtk_tree_path_get_indices (path)[0]
, wherepath
is theGtk.TreePath
of the active item.New in version 2.4.
- Gtk.ComboBox.props.active_id¶
- Name:
active-id
- Type:
- Default Value:
- Flags:
The value of the ID column of the active row.
New in version 3.0.
- Gtk.ComboBox.props.add_tearoffs¶
- Name:
add-tearoffs
- Type:
- Default Value:
- Flags:
The add-tearoffs property controls whether generated menus have tearoff menu items.
Note that this only affects menu style combo boxes.
New in version 2.6.
Deprecated since version 3.10.
- Gtk.ComboBox.props.button_sensitivity¶
- Name:
button-sensitivity
- Type:
- Default Value:
- Flags:
Whether the dropdown button is sensitive when the model is empty.
New in version 2.14.
- Gtk.ComboBox.props.cell_area¶
- Name:
cell-area
- Type:
- Default Value:
- Flags:
The
Gtk.CellArea
used to layout cell renderers for this combo box.If no area is specified when creating the combo box with
Gtk.ComboBox.new_with_area
() a horizontally orientedGtk.CellAreaBox
will be used.New in version 3.0.
- Gtk.ComboBox.props.column_span_column¶
- Name:
column-span-column
- Type:
- Default Value:
-1
- Flags:
If this is set to a non-negative value, it must be the index of a column of type
GObject.TYPE_INT
in the model. The value in that column for each item will determine how many columns that item will span in the popup. Therefore, values in this column must be greater than zero, and the sum of an item’s column position + span should not exceedGtk.ComboBox
:wrap-width
.New in version 2.4.
- Gtk.ComboBox.props.entry_text_column¶
- Name:
entry-text-column
- Type:
- Default Value:
-1
- Flags:
The column in the combo box’s model to associate with strings from the entry if the combo was created with
Gtk.ComboBox
:has-entry
=True
.New in version 2.24.
- Gtk.ComboBox.props.has_entry¶
- Name:
has-entry
- Type:
- Default Value:
- Flags:
Whether the combo box has an entry.
New in version 2.24.
- Gtk.ComboBox.props.has_frame¶
- Name:
has-frame
- Type:
- Default Value:
- Flags:
The has-frame property controls whether a frame is drawn around the entry.
New in version 2.6.
- Gtk.ComboBox.props.id_column¶
- Name:
id-column
- Type:
- Default Value:
-1
- Flags:
The column in the combo box’s model that provides string IDs for the values in the model, if != -1.
New in version 3.0.
- Gtk.ComboBox.props.model¶
- Name:
model
- Type:
- Default Value:
- Flags:
The model from which the combo box takes the values shown in the list.
New in version 2.4.
- Gtk.ComboBox.props.popup_fixed_width¶
- Name:
popup-fixed-width
- Type:
- Default Value:
- Flags:
Whether the popup’s width should be a fixed width matching the allocated width of the combo box.
New in version 3.0.
- Gtk.ComboBox.props.popup_shown¶
-
Whether the combo boxes dropdown is popped up. Note that this property is mainly useful, because it allows you to connect to notify::popup-shown.
New in version 2.10.
- Gtk.ComboBox.props.row_span_column¶
- Name:
row-span-column
- Type:
- Default Value:
-1
- Flags:
If this is set to a non-negative value, it must be the index of a column of type
GObject.TYPE_INT
in the model. The value in that column for each item will determine how many rows that item will span in the popup. Therefore, values in this column must be greater than zero.New in version 2.4.
- Gtk.ComboBox.props.tearoff_title¶
- Name:
tearoff-title
- Type:
- Default Value:
- Flags:
A title that may be displayed by the window manager when the popup is torn-off.
New in version 2.10.
Deprecated since version 3.10.
- Gtk.ComboBox.props.wrap_width¶
- Name:
wrap-width
- Type:
- Default Value:
0
- Flags:
If wrap-width is set to a positive value, items in the popup will be laid out along multiple columns, starting a new row on reaching the wrap width.
New in version 2.4.