Gtk.UIManager - Classes - Gtk 3.0 (original) (raw)
g GObject.GInterface GObject.GInterface Gtk.Buildable Gtk.Buildable GObject.GInterface->Gtk.Buildable GObject.Object GObject.Object Gtk.UIManager Gtk.UIManager GObject.Object->Gtk.UIManager Gtk.Buildable->Gtk.UIManager
Subclasses:
None
Methods¶
Inherited:
GObject.Object (37), Gtk.Buildable (10)
Structs:
class | new () |
---|---|
add_ui (merge_id, path, name, action, type, top) | |
add_ui_from_file (filename) | |
add_ui_from_resource (resource_path) | |
add_ui_from_string (buffer) | |
ensure_update () | |
get_accel_group () | |
get_action (path) | |
get_action_groups () | |
get_add_tearoffs () | |
get_toplevels (types) | |
get_ui () | |
get_widget (path) | |
insert_action_group (action_group, pos) | |
new_merge_id () | |
remove_action_group (action_group) | |
remove_ui (merge_id) | |
set_add_tearoffs (add_tearoffs) |
Virtual Methods¶
Inherited:
GObject.Object (7), Gtk.Buildable (10)
do_actions_changed () |
---|
do_add_widget (widget) |
do_connect_proxy (action, proxy) |
do_disconnect_proxy (action, proxy) |
do_get_action (path) |
do_get_widget (path) |
do_post_activate (action) |
do_pre_activate (action) |
Properties¶
Name | Type | Flags | Short Description |
---|---|---|---|
add-tearoffs | bool | d/r/w | Whether tearoff menu items should be added to menus deprecated |
ui | str | r | An XML string describing the merged UI |
Signals¶
Inherited:
Name | Short Description |
---|---|
actions-changed | The ::actions-changed signal is emitted whenever the set of actions changes. deprecated |
add-widget | The ::add-widget signal is emitted for each generated menubar and toolbar. deprecated |
connect-proxy | The ::connect-proxy signal is emitted after connecting a proxy to an action in the group. deprecated |
disconnect-proxy | The ::disconnect-proxy signal is emitted after disconnecting a proxy from an action in the group. deprecated |
post-activate | The ::post-activate signal is emitted just after the action is activated. deprecated |
pre-activate | The ::pre-activate signal is emitted just before the action is activated. deprecated |
Fields¶
Inherited:
Name | Type | Access | Description |
---|---|---|---|
parent | GObject.Object | r |
Class Details¶
class Gtk.UIManager(**kwargs)¶
Bases:
Abstract:
No
Structure:
A Gtk.UIManager constructs a user interface (menus and toolbars) from one or more UI definitions, which reference actions from one or more action groups.
Gtk.UIManager is deprecated since GTK+ 3.10. To construct user interfaces from XML definitions, you should use Gtk.Builder, Gio.MenuModel, et al. To work with actions, use Gio.Action, Gtk.Actionable et al. These newer classes support richer functionality and integration with various desktop shells. It should be possible to migrate most/all functionality from Gtk.UIManager.
UI Definitions
The UI definitions are specified in an XML format which can be roughly described by the following DTD.
Do not confuse the Gtk.UIManager UI Definitions described here with the similarly named GtkBuilder UI Definitions.
There are some additional restrictions beyond those specified in the DTD, e.g. every toolitem must have a toolbar in its anchestry and every menuitem must have a menubar or popup in its anchestry. Since a GLib.MarkupParser is used to parse the UI description, it must not only be valid XML, but valid markup.
If a name is not specified, it defaults to the action. If an action is not specified either, the element name is used. The name and action attributes must not contain “/” characters after parsing (since that would mess up path lookup) and must be usable as XML attributes when enclosed in doublequotes, thus they must not “”” characters or references to the “ entity.
A UI definition
The constructed widget hierarchy is very similar to the element tree of the XML, with the exception that placeholders are merged into their parents. The correspondence of XML elements to widgets should be almost obvious:
- menubar
a Gtk.MenuBar - toolbar
a Gtk.Toolbar - popup
a toplevel Gtk.Menu - menu
a Gtk.Menu attached to a menuitem - menuitem
a Gtk.MenuItem subclass, the exact type depends on the action - toolitem
a Gtk.ToolItem subclass, the exact type depends on the action. Note that toolitem elements may contain a menu element, but only if their associated action specifies aGtk.MenuToolButton as proxy. - separator
a Gtk.SeparatorMenuItem or Gtk.SeparatorToolItem - accelerator
a keyboard accelerator
The “position” attribute determines where a constructed widget is positioned wrt. to its siblings in the partially constructed tree. If it is “top”, the widget is prepended, otherwise it is appended.
UI Merging
The most remarkable feature of Gtk.UIManager is that it can overlay a set of menuitems and toolitems over another one, and demerge them later.
Merging is done based on the names of the XML elements. Each element is identified by a path which consists of the names of its anchestors, separated by slashes. For example, the menuitem named “Left” in the example above has the path /ui/menubar/JustifyMenu/Left
and the toolitem with the same name has path/ui/toolbar1/JustifyToolItems/Left
.
Accelerators
Every action has an accelerator path. Accelerators are installed together with menuitem proxies, but they can also be explicitly added with<accelerator>
elements in the UI definition. This makes it possible to have accelerators for actions even if they have no visible proxies.
Smart Separators
The separators created by Gtk.UIManager are “smart”, i.e. they do not show up in the UI unless they end up between two visible menu or tool items. Separators which are located at the very beginning or end of the menu or toolbar containing them, or multiple separators next to each other, are hidden. This is a useful feature, since the merging of UI elements from multiple sources can make it hard or impossible to determine in advance whether a separator will end up in such an unfortunate position.
For separators in toolbars, you can set expand="true"
to turn them from a small, visible separator to an expanding, invisible one. Toolitems following an expanding separator are effectively right-aligned.
Empty Menus
Submenus pose similar problems to separators inconnection with merging. It is impossible to know in advance whether they will end up empty after merging.Gtk.UIManager offers two ways to treat empty submenus:
- make them disappear by hiding the menu item they’re attached to
- add an insensitive “Empty” item
The behaviour is chosen based on the “hide_if_empty” property of the action to which the submenu is associated.
Gtk.UIManager as Gtk.Buildable
The Gtk.UIManager implementation of the Gtk.Buildable interface acceptsGtk.ActionGroup objects as <child>
elements in UI definitions.
A Gtk.UIManager UI definition as described above can be embedded in an Gtk.UIManager <object>
element in a Gtk.Builder UI definition.
The widgets that are constructed by a Gtk.UIManager can be embedded in other parts of the constructed user interface with the help of the “constructor” attribute. See the example below.
An embedded Gtk.UIManager UI definition
_FileReturns:
a new ui manager object.
Return type:
Creates a new ui manager object.
New in version 2.4.
Deprecated since version 3.10.
add_ui(merge_id, path, name, action, type, top)[source]¶
Parameters:
- merge_id (int) – the merge id for the merged UI, see Gtk.UIManager.new_merge_id()
- path (str) – a path
- name (str) – the name for the added UI element
- action (str or None) – the name of the action to be proxied, or None to add a separator
- type (Gtk.UIManagerItemType) – the type of UI element to add.
- top (bool) – if True, the UI element is added before its siblings, otherwise it is added after its siblings.
Adds a UI element to the current contents of self.
If type is Gtk.UIManagerItemType.AUTO, GTK+ inserts a menuitem, toolitem or separator if such an element can be inserted at the place determined bypath. Otherwise type must indicate an element that can be inserted at the place determined by path.
If path points to a menuitem or toolitem, the new element will be inserted before or after this item, depending on top.
New in version 2.4.
Deprecated since version 3.10.
add_ui_from_file(filename)[source]¶
Parameters:
filename (str) – the name of the file to parse
Raises:
Returns:
The merge id for the merged UI. The merge id can be used to unmerge the UI with Gtk.UIManager.remove_ui(). If an error occurred, the return value is 0.
Return type:
Parses a file containing a UI definition and merges it with the current contents of self.
New in version 2.4.
Deprecated since version 3.10.
add_ui_from_resource(resource_path)[source]¶
Parameters:
resource_path (str) – the resource path of the file to parse
Raises:
Returns:
The merge id for the merged UI. The merge id can be used to unmerge the UI with Gtk.UIManager.remove_ui(). If an error occurred, the return value is 0.
Return type:
Parses a resource file containing a UI definition and merges it with the current contents of self.
New in version 3.4.
Deprecated since version 3.10.
add_ui_from_string(buffer)[source]¶
Parameters:
- buffer (str) – the string to parse
- length (int) – the length of buffer (may be -1 if buffer is nul-terminated)
Raises:
Returns:
The merge id for the merged UI. The merge id can be used to unmerge the UI with Gtk.UIManager.remove_ui(). If an error occurred, the return value is 0.
Return type:
Parses a string containing a UI definition and merges it with the current contents of self. An enclosing <ui>
element is added if it is missing.
New in version 2.4.
Deprecated since version 3.10.
Makes sure that all pending updates to the UI have been completed.
This may occasionally be necessary, since Gtk.UIManager updates the UI in an idle function. A typical example where this function is useful is to enforce that the menubar and toolbar have been added to the main window before showing it:
gtk_container_add (GTK_CONTAINER (window), vbox); g_signal_connect (merge, "add-widget", G_CALLBACK (add_widget), vbox); gtk_ui_manager_add_ui_from_file (merge, "my-menus"); gtk_ui_manager_add_ui_from_file (merge, "my-toolbars"); gtk_ui_manager_ensure_update (merge); gtk_widget_show (window);
New in version 2.4.
Deprecated since version 3.10.
Returns:
the Gtk.AccelGroup.
Return type:
Returns the Gtk.AccelGroup associated with self.
New in version 2.4.
Deprecated since version 3.10.
Parameters:
path (str) – a path
Returns:
the action whose proxy widget is found by following the path, or None if no widget was found.
Return type:
Looks up an action by following a path. See Gtk.UIManager.get_widget() for more information about paths.
New in version 2.4.
Deprecated since version 3.10.
Returns:
a GLib.List of action groups. The list is owned by GTK+ and should not be modified.
Return type:
Returns the list of action groups associated with self.
New in version 2.4.
Deprecated since version 3.10.
Returns:
whether tearoff menu items are added
Return type:
Returns whether menus generated by this Gtk.UIManagerwill have tearoff menu items.
New in version 2.4.
Deprecated since version 3.4: Tearoff menus are deprecated and should not be used in newly written code.
Parameters:
types (Gtk.UIManagerItemType) – specifies the types of toplevel widgets to include. Allowed types are Gtk.UIManagerItemType.MENUBAR, Gtk.UIManagerItemType.TOOLBAR andGtk.UIManagerItemType.POPUP.
Returns:
a newly-allocated GLib.SList of all toplevel widgets of the requested types. Free the returned list with g_slist_free().
Return type:
Obtains a list of all toplevel widgets of the requested types.
New in version 2.4.
Deprecated since version 3.10.
Returns:
A newly allocated string containing an XML representation of the merged UI.
Return type:
Creates a UI definition of the merged UI.
New in version 2.4.
Deprecated since version 3.10.
Parameters:
path (str) – a path
Returns:
the widget found by following the path, or None if no widget was found
Return type:
Looks up a widget by following a path. The path consists of the names specified in the XML description of the UI. separated by “/”. Elements which don’t have a name or action attribute in the XML (e.g. <popup>
) can be addressed by their XML element name (e.g. “popup”). The root element (“/ui”) can be omitted in the path.
Note that the widget found by following a path that ends in a <menu>
; element is the menuitem to which the menu is attached, not the menu it manages.
Also note that the widgets constructed by a ui manager are not tied to the lifecycle of the ui manager. If you add the widgets returned by this function to some container or explicitly ref them, they will survive the destruction of the ui manager.
New in version 2.4.
Deprecated since version 3.10.
insert_action_group(action_group, pos)[source]¶
Parameters:
- action_group (Gtk.ActionGroup) – the action group to be inserted
- pos (int) – the position at which the group will be inserted.
Inserts an action group into the list of action groups associated with self. Actions in earlier groups hide actions with the same name in later groups.
If pos is larger than the number of action groups in self, or negative, action_group will be inserted at the end of the internal list.
New in version 2.4.
Deprecated since version 3.10.
Returns:
an unused merge id.
Return type:
Returns an unused merge id, suitable for use withGtk.UIManager.add_ui().
New in version 2.4.
Deprecated since version 3.10.
remove_action_group(action_group)[source]¶
Parameters:
action_group (Gtk.ActionGroup) – the action group to be removed
Removes an action group from the list of action groups associated with self.
New in version 2.4.
Deprecated since version 3.10.
Parameters:
merge_id (int) – a merge id as returned by Gtk.UIManager.add_ui_from_string()
Unmerges the part of self's content identified by merge_id.
New in version 2.4.
Deprecated since version 3.10.
set_add_tearoffs(add_tearoffs)[source]¶
Parameters:
add_tearoffs (bool) – whether tearoff menu items are added
Sets the “add_tearoffs” property, which controls whether menus generated by this Gtk.UIManager will have tearoff menu items.
Note that this only affects regular menus. Generated popup menus never have tearoff menu items.
New in version 2.4.
Deprecated since version 3.4: Tearoff menus are deprecated and should not be used in newly written code.
do_actions_changed() virtual¶
do_add_widget(widget) virtual¶
Parameters:
widget (Gtk.Widget) –
do_connect_proxy(action, proxy) virtual¶
Parameters:
- action (Gtk.Action) –
- proxy (Gtk.Widget) –
do_disconnect_proxy(action, proxy) virtual¶
Parameters:
- action (Gtk.Action) –
- proxy (Gtk.Widget) –
do_get_action(path) virtual¶
Parameters:
path (str) – a path
Returns:
the action whose proxy widget is found by following the path, or None if no widget was found.
Return type:
Looks up an action by following a path. See Gtk.UIManager.get_widget() for more information about paths.
New in version 2.4.
Deprecated since version 3.10.
do_get_widget(path) virtual¶
Parameters:
path (str) – a path
Returns:
the widget found by following the path, or None if no widget was found
Return type:
Looks up a widget by following a path. The path consists of the names specified in the XML description of the UI. separated by “/”. Elements which don’t have a name or action attribute in the XML (e.g. <popup>
) can be addressed by their XML element name (e.g. “popup”). The root element (“/ui”) can be omitted in the path.
Note that the widget found by following a path that ends in a <menu>
; element is the menuitem to which the menu is attached, not the menu it manages.
Also note that the widgets constructed by a ui manager are not tied to the lifecycle of the ui manager. If you add the widgets returned by this function to some container or explicitly ref them, they will survive the destruction of the ui manager.
New in version 2.4.
Deprecated since version 3.10.
do_post_activate(action) virtual¶
Parameters:
action (Gtk.Action) –
do_pre_activate(action) virtual¶
Parameters:
action (Gtk.Action) –
Signal Details¶
Gtk.UIManager.signals.actions_changed(u_i_manager)¶
Signal Name:
actions-changed
Flags:
Parameters:
u_i_manager (Gtk.UIManager) – The object which received the signal
The ::actions-changed signal is emitted whenever the set of actions changes.
New in version 2.4.
Deprecated since version 3.10.
Gtk.UIManager.signals.add_widget(u_i_manager, widget)¶
Signal Name:
add-widget
Flags:
Parameters:
- u_i_manager (Gtk.UIManager) – The object which received the signal
- widget (Gtk.Widget) – the added widget
The ::add-widget signal is emitted for each generated menubar and toolbar. It is not emitted for generated popup menus, which can be obtained byGtk.UIManager.get_widget().
New in version 2.4.
Deprecated since version 3.10.
Gtk.UIManager.signals.connect_proxy(u_i_manager, action, proxy)¶
Signal Name:
connect-proxy
Flags:
Parameters:
- u_i_manager (Gtk.UIManager) – The object which received the signal
- action (Gtk.Action) – the action
- proxy (Gtk.Widget) – the proxy
The ::connect-proxy signal is emitted after connecting a proxy to an action in the group.
This is intended for simple customizations for which a custom action class would be too clumsy, e.g. showing tooltips for menuitems in the statusbar.
New in version 2.4.
Deprecated since version 3.10.
Gtk.UIManager.signals.disconnect_proxy(u_i_manager, action, proxy)¶
Signal Name:
disconnect-proxy
Flags:
Parameters:
- u_i_manager (Gtk.UIManager) – The object which received the signal
- action (Gtk.Action) – the action
- proxy (Gtk.Widget) – the proxy
The ::disconnect-proxy signal is emitted after disconnecting a proxy from an action in the group.
New in version 2.4.
Deprecated since version 3.10.
Gtk.UIManager.signals.post_activate(u_i_manager, action)¶
Signal Name:
post-activate
Flags:
Parameters:
- u_i_manager (Gtk.UIManager) – The object which received the signal
- action (Gtk.Action) – the action
The ::post-activate signal is emitted just after the actionis activated.
This is intended for applications to get notification just after any action is activated.
New in version 2.4.
Deprecated since version 3.10.
Gtk.UIManager.signals.pre_activate(u_i_manager, action)¶
Signal Name:
pre-activate
Flags:
Parameters:
- u_i_manager (Gtk.UIManager) – The object which received the signal
- action (Gtk.Action) – the action
The ::pre-activate signal is emitted just before the actionis activated.
This is intended for applications to get notification just before any action is activated.
New in version 2.4.
Deprecated since version 3.10.
Property Details¶
Gtk.UIManager.props.add_tearoffs¶
Name:
add-tearoffs
Type:
Default Value:
Flags:
DEPRECATED, READABLE, WRITABLE
The “add-tearoffs” property controls whether generated menus have tearoff menu items.
Note that this only affects regular menus. Generated popup menus never have tearoff menu items.
New in version 2.4.
Deprecated since version 3.4: Tearoff menus are deprecated and should not be used in newly written code.
Gtk.UIManager.props.ui¶
Name:
ui
Type:
Default Value:
'<ui>\n</ui>\n'
Flags:
An XML string describing the merged UI