Gtk.FlowBox
Gtk.FlowBox — A container that allows reflowing its children
Object Hierarchy:
GObject
╰── GInitiallyUnowned
╰── Gtk.Widget
╰── Gtk.Container
├── Gtk.Bin
│ ╰── Gtk.FlowBoxChild
╰── Gtk.FlowBox
Functions:
- new
() -> Gtk.Widget
- insert
(self, widget:Gtk.Widget, position:int)
- get_child_at_index
(self, idx:int) -> Gtk.FlowBoxChild or None
- set_hadjustment
(self, adjustment:Gtk.Adjustment)
- set_vadjustment
(self, adjustment:Gtk.Adjustment)
- set_homogeneous
(self, homogeneous:bool)
- get_homogeneous
(self) -> bool
- set_row_spacing
(self, spacing:int)
- get_row_spacing
(self) -> int
- set_column_spacing
(self, spacing:int)
- get_column_spacing
(self) -> int
- set_min_children_per_line
(self, n_children:int)
- get_min_children_per_line
(self) -> int
- set_max_children_per_line
(self, n_children:int)
- get_max_children_per_line
(self) -> int
- set_activate_on_single_click
(self, single:bool)
- get_activate_on_single_click
(self) -> bool
- selected_foreach
(self, func:Gtk.FlowBoxForeachFunc, data=None)
- get_selected_children
(self) -> list
- select_child
(self, child:Gtk.FlowBoxChild)
- unselect_child
(self, child:Gtk.FlowBoxChild)
- select_all
(self)
- unselect_all
(self)
- set_selection_mode
(self, mode:Gtk.SelectionMode)
- get_selection_mode
(self) -> Gtk.SelectionMode
- set_filter_func
(self, filter_func:Gtk.FlowBoxFilterFunc=None, user_data=None)
- invalidate_filter
(self)
- set_sort_func
(self, sort_func:Gtk.FlowBoxSortFunc=None, user_data=None)
- invalidate_sort
(self)
Signals:
- “activate-cursor-child”
(box, user_data)
- “child-activated”
(box, child, user_data)
- “move-cursor”
(box, step, count, user_data)
- “select-all”
(box, user_data)
- “selected-children-changed”
(box, user_data)
- “toggle-cursor-child”
(box, user_data)
- “unselect-all”
(box, user_data)
- “activate”
(child, user_data)
Description:
A Gtk.FlowBox
positions child widgets in sequence according to its orientation.
For instance, with the horizontal orientation, the widgets will be arranged from left to right, starting a new row under the previous row when necessary. Reducing the width in this case will require more rows, so a larger height will be requested.
Likewise, with the vertical orientation, the widgets will be arranged from top to bottom, starting a new column to the right when necessary.
Reducing the height will require more columns, so a larger width will be requested.
The children of a Gtk.FlowBox
can be dynamically sorted and filtered.
Although a Gtk.FlowBox
must have only Gtk.FlowBox
Child children, you can add any kind of widget to it via Gtk.Container::add()
, and a Gtk.FlowBox
Child widget will automatically be inserted between the box and the widget.
Also see Gtk.ListBox.
Gtk.FlowBox
was added in GTK+ 3.12.
Function Details:
new()
new () -> Gtk.Widget
Creates a Gtk.FlowBox
.
Returns: a new
Gtk.FlowBox
containerSince: 3.12
insert()
insert (self, widget:Gtk.Widget, position:int)
Inserts the widget
into box
at position
.
If a sort function is set, the widget will actually be insertedat the calculated position and this function has the same effectas `Gtk.Container:add
().
If
positionis -1, or larger than the total number of childrenin the
box, then the
widget` will be appended to the end.
- Since: 3.12
get_child_at_index()
get_child_at_index (self, idx:int) -> Gtk.FlowBoxChild or None
Gets the nth child in the box
.
Returns: the child widget, which willalways be a
Gtk.FlowBoxChild
orNone
in case no child widgetwith the given index exists.Since: 3.12
set_hadjustment()
set_hadjustment (self, adjustment:Gtk.Adjustment)
Hooks up an adjustment to focus handling in box
.The adjustment is also used for autoscrolling duringrubberband selection. See `Gtk.ScrolledWindow:get_hadjustment
()for a typical way of obtaining the adjustment, and
Gtk.FlowBox:set_vadjustment()`for setting the verticaladjustment.
The adjustments have to be in pixel units and in the samecoordinate system as the allocation for immediate childrenof the box.
- Since: 3.12
set_vadjustment()
set_vadjustment (self, adjustment:Gtk.Adjustment)
Hooks up an adjustment to focus handling in box
.The adjustment is also used for autoscrolling duringrubberband selection. See `Gtk.ScrolledWindow:get_vadjustment
()for a typical way of obtaining the adjustment, and
Gtk.FlowBox:set_hadjustment()`for setting the horizontaladjustment.
The adjustments have to be in pixel units and in the samecoordinate system as the allocation for immediate childrenof the box.
- Since: 3.12
set_homogeneous()
set_homogeneous (self, homogeneous:bool)
Sets the “homogeneous” property of box
, controllingwhether or not all children of box
are given equal spacein the box.
- Since: 3.12
get_homogeneous()
get_homogeneous (self) -> bool
Returns whether the box is homogeneous (all children are thesame size). See `Gtk.Box:set_homogeneous
()`.
Returns:
True
if the box is homogeneous.Since: 3.12
set_row_spacing()
set_row_spacing (self, spacing:int)
Sets the vertical space to add between children.See the “row-spacing” property.
- Since: 3.12
get_row_spacing()
get_row_spacing (self) -> int
Gets the vertical spacing.
Returns: the vertical spacing
Since: 3.12
set_column_spacing()
set_column_spacing (self, spacing:int)
Sets the horizontal space to add between children.See the “column-spacing” property.
- Since: 3.12
get_column_spacing()
get_column_spacing (self) -> int
Gets the horizontal spacing.
Returns: the horizontal spacing
Since: 3.12
set_min_children_per_line()
set_min_children_per_line (self, n_children:int)
Sets the minimum number of children to line upin box
’s orientation before flowing.
- Since: 3.12
get_min_children_per_line()
get_min_children_per_line (self) -> int
Gets the minimum number of children per line.
Returns: the minimum number of children per line
Since: 3.12
set_max_children_per_line()
set_max_children_per_line (self, n_children:int)
Sets the maximum number of children to request andallocate space for in box
’s orientation.
Setting the maximum number of children per linelimits the overall natural size request to be no morethan n_children
children long in the given orientation.
- Since: 3.12
get_max_children_per_line()
get_max_children_per_line (self) -> int
Gets the maximum number of children per line.
Returns: the maximum number of children per line
Since: 3.12
set_activate_on_single_click()
set_activate_on_single_click (self, single:bool)
If single
is True
, children will be activated when you clickon them, otherwise you need to double-click.
- Since: 3.12
get_activate_on_single_click()
get_activate_on_single_click (self) -> bool
Returns whether children activate on single clicks.
Returns:
True
if children are activated on single click,FALSE
otherwiseSince: 3.12
selected_foreach()
selected_foreach (self, func:Gtk.FlowBoxForeachFunc, data=None)
Calls a function for each selected child. Note that the selection cannot be modified from withinthis function.
- Since: 3.12
get_selected_children()
get_selected_children (self) -> list
Creates a list of all selected children.
Returns: A GList containing the
Gtk.Widget
for each selected child.Free withg_list_free()
when done.Since: 3.12
select_child()
select_child (self, child:Gtk.FlowBoxChild)
Selects a single child of box
, if the selectionmode allows it.
- Since: 3.12
unselect_child()
unselect_child (self, child:Gtk.FlowBoxChild)
Unselects a single child of box
, if the selectionmode allows it.
- Since: 3.12
select_all()
select_all (self)
Select all children of box
, if the selectionmode allows it.
- Since: 3.12
unselect_all()
unselect_all (self)
Unselect all children of box
, if the selectionmode allows it.
- Since: 3.12
set_selection_mode()
set_selection_mode (self, mode:Gtk.SelectionMode)
Sets how selection works in box
.See Gtk.SelectionMode
for details.
- Since: 3.12
get_selection_mode()
get_selection_mode (self) -> Gtk.SelectionMode
Gets the selection mode of box
.
Returns: the Gtk.SelectionMode
Since: 3.12
set_filter_func()
set_filter_func (self, filter_func:Gtk.FlowBoxFilterFunc=None, user_data=None)
By setting a filter function on the box
one can decide dynamicallywhich of the children to show. For instance, to implement a searchfunction that only shows the children matching the search terms.
The filter_func
will be called for each child after the call, andit will continue to be called each time a child changes (viaGtk.FlowBox:child_changed()
) or when Gtk.FlowBox:invalidate_filter()
is called.
Note that using a filter function is incompatible with using a model(see Gtk.FlowBox:bind_model()
).
- Since: 3.12
invalidate_filter()
invalidate_filter (self)
Updates the filtering for all children.
Call this function when the result of the filterfunction on the box
is changed due ot an externalfactor. For instance, this would be used if thefilter function just looked for a specific searchterm, and the entry with the string has changed.
- Since: 3.12
set_sort_func()
set_sort_func (self, sort_func:Gtk.FlowBoxSortFunc=None, user_data=None)
By setting a sort function on the box
, one can dynamicallyreorder the children of the box, based on the contents ofthe children.
The sort_func
will be called for each child after the call,and will continue to be called each time a child changes (viaGtk.FlowBox:child_changed()
) and when Gtk.FlowBox:invalidate_sort()
is called.
Note that using a sort function is incompatible with using a model(see Gtk.FlowBox:bind_model()
).
- Since: 3.12
invalidate_sort()
invalidate_sort (self)
Updates the sorting for all children.
Call this when the result of the sort function onbox
is changed due to an external factor.
- Since: 3.12
Example:
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
class FlowBox(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self)
self.set_title("FlowBox")
self.set_default_size(200, 200)
self.connect("destroy", Gtk.main_quit)
flowbox = Gtk.FlowBox()
flowbox.connect("child-activated", self.on_child_activated)
self.add(flowbox)
for count in range(0, 9):
label = Gtk.Label("Row %i" % (count))
flowbox.add(label)
def on_child_activated(self, flowbox, flowboxchild):
print("Child %i activated" % (flowboxchild.get_index()))
window = FlowBox()
window.show_all()
Gtk.main()