gtk.Container — a base class for widgets that contain other widgets
class gtk.Container(gtk.Widget): |
Class Methodsdef install_child_property(
property_id
,pspec
)def list_child_properties()
Functionsdef gtk.container_class_install_child_property(
klass
,property_id
,pspec
)def gtk.container_class_list_child_properties(
klass
)
|
|
"add" | def callback( |
def callback( | |
"remove" | def callback( |
def callback( |
The gtk.Container
class provides common attributes and methods for a large number of widget
subclasses that manage the layout of other widgets within the area of a
window.
A PyGTK
user interface is constructed by
nesting widgets inside widgets. Container widgets are the inner nodes in the
resulting tree of widgets: they contain other widgets. So, for example, you
might have a gtk.Window
containing a gtk.Frame
containing
a gtk.Label
. If
you wanted an image instead of a textual label inside the frame, you might
replace the gtk.Label
widget with
a gtk.Image
widget.
There are two major kinds of container widgets. Both are
subclasses of the abstract gtk.Container
base class.
The first type of container widget has a single child widget and
derives from gtk.Bin
. These
containers are decorators, that add some kind of functionality to the
child. For example, a gtk.Button
makes its
child into a clickable button; a gtk.Frame
draws a
frame around its child and a gtk.Window
places
its child widget inside a top-level window.
The second type of container can have more than one child; its
purpose is to manage layout. This means that these containers assign sizes
and positions to their children. For example, a gtk.HBox
arranges its
children in a horizontal row, and a gtk.Table
arranges
the widgets it contains in a two-dimensional grid.
To fulfill its task, a layout container must negotiate the size requirements with its parent and its children. This negotiation is carried out in two phases, size requisition and size allocation.
The size requisition of a widget is it's desired width and
height. This is represented by a gtk.Requisition
.
How a widget determines its desired size depends on the
widget. A gtk.Label
, for
example, requests enough space to display all its text. Container widgets
generally base their size request on the requisitions of their
children.
The size requisition phase of the widget layout process operates top-down. It starts at a top-level widget, typically a GtkWindow. The top-level widget asks its child for its size requisition by calling gtk_widget_size_request(). To determine its requisition, the child asks its own children for their requisitions and so on. Finally, the top-level widget will get a requisition back from its child.
When the top-level widget has determined how much space its
child would like to have, the second phase of the size negotiation, size
allocation, begins. Depending on its configuration (see the gtk.Window.set_resizable
()
method), the top-level widget may be able to expand in order to satisfy the
size request or it may have to ignore the size request and keep its fixed
size. It then tells its child widget how much space it gets by calling the
size_allocate
()
method. The child widget divides the space among its children and tells each
child how much space it got, and so on. Under normal circumstances, a gtk.Window
will
always give its child the amount of space the child requested.
A child's size allocation is represented by a gtk.gdk.Rectangle
that contains not only a width and height, but also a position (i.e. X and Y
coordinates), so that containers can tell their children not only how much
space is available, but also where they are positioned inside the space
available to the container.
Widgets are required to honor the size allocation they receive; a size request is only a request, and widgets must be able to cope with any size.
gtk.Container
introduces child properties - these are object properties that are not
specific to either the container or the contained widget, but rather to
their relation. Typical examples of child properties are the "position" or
"pack-type" of a widget which is contained in a gtk.Box
.
Use the install_child_property
()
method to install child properties for a container class and the list_child_properties
()
function to get information about existing child properties.
To set the value of a child property, use the child_set_property
(),
or child_set
()
methods. To obtain the value of a child property, use the child_get_property
(),
or child_get
()
methods. To emit notification about child property changes, use the gtk.Widget.child_notify
()
method.
def set_border_width(border_width
)
| The amount of blank space to leave outside the container. Valid values are in the range 0-65535 pixels. |
The set_border_width
() method sets the
"border-width" property of the container. The border width of a container is
the amount of space to leave around the outside of the container. The only
exception to this is gtk.Window
; because
toplevel windows can't leave space outside, they leave the space inside. The
border is added on all sides of the container.
def get_border_width()
Returns : | the current border width |
The get_border_width
() method retrieves
the value of the "border-width" property of the container. See set_border_width
().
def add(widget
)
| a widget to be placed inside the container |
The add
() method adds
widget
to the container. This method is typically
used for simple containers such as gtk.Window
, gtk.Frame
, or gtk.Button
that hold
a single child widget. For layout containers that handle multiple children
such as gtk.Box
or gtk.Table
,
this function will pick default packing parameters that may not be correct.
Containers that handle multiple children usually have additional methods
such as gtk.Box.pack_start
()
and gtk.Table.attach
()
as an alternative to add
(). Adding a widget to a
container usually results in the resizing and redrawing of the container
contents.
def remove(widget
)
| a current child of
container |
The remove
() method removes
widget
from the container.
widget
must be inside the container. Note that the
container will own a reference to widget
, and that
this may be the last reference held; so removing a widget from its container
can cause that widget to be destroyed. If you want to use
widget
again, you should add a reference to
it.
def set_resize_mode(resize_mode
)
| the new resize mode. |
The set-resize_mode
() method sets the
"resize=mode" property of the container. The resize mode of a container
determines whether a resize request will be passed to the container's parent
(gtk.RESIZE_PARENT
), queued for later execution
(gtk.RESIZE_QUEUE
) or executed immediately
(gtk.RESIZE_IMMEDIATE
).
def get_resize_mode()
Returns : | the current resize mode |
The get_resize_mode() method returns the value of the
"resize-mode" property for of the container. See set_resize_mode()
.
def check_resize()
The check_resize
() method emits the
"check-resize" signal on the container.
def forall(callback
, callback_data
=None)
| a callback |
| the callback user data |
The forall
() method arranges to invoke
callback
on each child of the container including
children that are considered "internal" (implementation details of the
container). "Internal" children generally weren't added by the user of the
container, but were added by the container implementation itself. Most
applications should use the foreach
()
method, rather than the forall
() method.
def foreach(callback
, callback_data
=None)
| a callback |
| the callback user data |
The foreach
() method arranges to invoke
callback
on each non-internal child of the
container.
def get_children()
Returns : | a list of the container's non-internal children. |
The get_children
() method returns
the container's non-internal children.
def propagate_expose(child
, event
)
| a child of the container |
| a expose event sent to the container |
The propagate_expose
() method sends
synthetic expose events to all children that don't have their own gtk.gdk.Window
s when
the container receives an expose event.
The propagate_expose
()
takes care of deciding whether an expose event needs to be sent to the
child, intersecting the event's area with the child area, and sending the
event.
In most cases, a container can simply either simply inherit the
expose implementation from gtk.Container
,
or, do some drawing and then chain to the expose implementation from gtk.Container
.
def set_focus_chain(focusable_widgets
)
| a list or tuple containing a chain of focusable widgets. |
The set_focus_chain
() method sets a
focus chain, overriding the one computed automatically by GTK. In principle
each widget in the chain should be a descendant of the container, but this
is not enforced by this method, since it's allowed to set the focus chain
before you pack the widgets, or have a widget in the chain that isn't always
packed. The necessary checks are done when the focus chain is actually
traversed.
def get_focus_chain()
Returns : | a list containing the widgets in the focus chain if the focus chain of the container has been set explicitly or None if no focus chain has been explicitly set. |
The get_focus_chain
() method retrieves
the focus chain of the container, if one has been set explicitly. If no
focus chain has been explicitly set, GTK computes the focus chain based on
the positions of the children. In that case, the method returns None.
def unset_focus_chain()
The unset_focus_chain
() method removes
a focus chain explicitly set with set_focus_chain
().
def set_reallocate_redraws(needs_redraws
)
| the new value for the container's reallocate_redraws attribute. |
The set_reallocate_redraws
() method
sets the reallocate_redraws attribute of the container to the value of
needs_redraws
. Containers requesting reallocation
redraws get automatically redrawn if any of their children change
allocation.
def set_focus_child(child
)
| the child widget that will get the focus. |
The set_focus_child
() method emits the
"set-focus-child" signal that arranges for the child widget referenced by
child
to get the focus and recalculates the container
adjustments.
def get_focus_child()
Returns : | The child widget which has the focus inside container,
or None if none is set. |
This method is available in PyGTK 2.14 and above.
The get_focus_child
() method returns the
current focus child widget inside container.
def set_focus_vadjustment(adjustment
)
| The new vertical focus adjustment |
The set_focus_vadjustment
() method sets
the vertical focus adjustment to the value of
adjustment
.
def get_focus_vadjustment()
Returns : | the vertical focus adjustment, or
None if none has been set. |
The get_focus_vadjustment() method retrieves the vertical focus
adjustment for the container. See the set_focus_vadjustment
()
method.
def set_focus_hadjustment(adjustment
)
| The new horizontal focus adjustment |
The set_focus_hadjustment
() method sets
the horizontal focus adjustment to the value of
adjustment
.
def get_focus_hadjustment()
Returns : | the horizontal focus adjustment, or
None if none has been set. |
The get_focus_hadjustment
() method
retrieves the horizontal focus adjustment for the container. See set_focus_hadjustment
().
def resize_children()
The resize_children
() method causes the
container to recalculate its size and its children's sizes.
def child_type()
Returns : | a type. |
The child_type
() method returns the
type of the children that can be added to the container. Note that this may
return a void type to indicate that no more children can be added, e.g. for
a gtk.Paned
which already has two children or a gtk.Window
that
already has a child.
def add_with_properties(widget
, first_prop_name
, first_prop_value
, ...
)
| a widget to be added |
| the first property name |
| a value for the first property |
| additional property name and value pairs |
The add_with_properties
() method adds
the child widget specified by widget
to the container
while allowing the setting of zero or more container child property values
at the same time. Containers supporting add with settable child properties
are: gtk.Box
,
gtk.Fixed
,
gtk.Notebook
and gtk.Table
.
For example the following adds a button to a gtk.Fixed
layout
widget and sets the child properties "x" and "y" specifying the child
position in the layout:
fixed.add_with_properties(button, "x", 10, "y", 20")
def child_set(child
, first_prop_name
, ...
)
| the child widget |
| the first property name |
| the value of the first property |
| additional property name and value pairs |
The child_set
() method sets the
properties for child
using the given property name
and value pairs.
def child_get(child
, first_prop_name
, ...
)
| the child widget to get the child properties for |
| the first property name |
| additional property names |
Returns : | a tuple containing the property values requested |
The child_get
() method retrieves the
requested container child properties for
child
.
def child_set_property(child
, property_name
, value
)
| the child widget |
| the child property name |
| a value to associate with the property |
The child_set_property
() method sets
the property name specified by property_name
with the
value specified in value
.
def child_get_property(child
, property_name
)
| the child widget |
| the child property name |
Returns : | the value of the child property for the widget |
The child_get_property
() method
retrieves the value of the child property specified by
property_name
for the widget
child
.
def install_child_property(property_id
, pspec
)
| an integer property ID |
| a tuple containing a parameter specifications |
This method is available in PyGTK 2.10 and above.
The install_child_property
() method
installs a child property for the container class using the integer ID
specified by
property_id
. pspec
is a
tuple containing at least 5 items. The first 4 items contain the
following parameter specification items:
None
None
The last item must be a integer containing a combination of the
| minimum, maximum and default values |
| minimum, maximum and default values |
| default value |
| minimum, maximum and default values |
| minimum, maximum and default values |
| minimum, maximum and default values |
| minimum, maximum and default values |
| minimum, maximum and default values |
| minimum, maximum and default values |
| default value |
| default value |
| minimum, maximum and default values |
| minimum, maximum and default values |
| default value |
| Not applicable |
| Not applicable |
| Not applicable |
| Not applicable |
def list_child_properties()
Returns : | the list of child properties |
This method is available in PyGTK 2.10 and above.
The list_child_properties
() method
returns a list containing the child properties of the container
class. See the install_child_property
()
method for more information.
def gtk.container_class_install_child_property(klass
, property_id
, pspec
)
| a gtk.Container
class or instance. |
| an integer property ID |
| a tuple containing a parameter specification |
This function is available in PyGTK 2.4 and above.
This function is deprecated in PyGTK 2.10 and above.
The
gtk.container_class_install_child_property
()
function installs a child property for the container class specified
by klass
using the integer ID specified by
property_id
. pspec
is a
tuple containing at least 5 items. The first 4 items contain the
following parameter specification items:
None
None
The last item must be a integer containing a combination of the
| minimum, maximum and default values |
| minimum, maximum and default values |
| default value |
| minimum, maximum and default values |
| minimum, maximum and default values |
| minimum, maximum and default values |
| minimum, maximum and default values |
| minimum, maximum and default values |
| minimum, maximum and default values |
| default value |
| default value |
| minimum, maximum and default values |
| minimum, maximum and default values |
| default value |
| Not applicable |
| Not applicable |
| Not applicable |
| Not applicable |
def gtk.container_class_list_child_properties(klass
)
| a gtk.Container
class or instance. |
Returns : | a tuple containing the list of child properties |
This function is available in PyGTK 2.4 and above.
This function is deprecated in PyGTK 2.10 and above.
The
gtk.container_class_list_child_properties
()
function returns a tuple containing the child properties of the
container class specified by klass
.
def callback(container
, widget
, user_param1
, ...
)
| the container that received the signal |
| the child widget |
| the first user parameter (if any) specified
with the connect () |
| additional user parameters (if any) |
The "add" signal is emitted when widget
is added to the container
.
def callback(container
, user_param1
, ...
)
| the container that received the signal |
| the first user parameter (if any) specified
with the connect () |
| additional user parameters (if any) |
The "check-resize" signal is emitted when the
check_resize
() method is called forcing the
recalculation of the container and its children. See the set_resize_mode
()
method for details.
def callback(container
, widget
, user_param1
, ...
)
| the container that received the signal |
| the child widget |
| the first user parameter (if any) specified
with the connect () |
| additional user parameters (if any) |
The "remove" signal is emitted when
widget
is removed from
container
.
def callback(container
, widget
, user_param1
, ...
)
| the container that received the signal |
| the child widget |
| the first user parameter (if any) specified
with the connect () |
| additional user parameters (if any) |
The "set-focus-child" signal is emitted when the set_focus_child
()
method is called. widget
is set as the child in
container
with the focus.