Panel.MenuManager

g GObject.Object GObject.Object Panel.MenuManager Panel.MenuManager GObject.Object->Panel.MenuManager

Subclasses:

None

Methods

Inherited:

GObject.Object (37)

Structs:

GObject.ObjectClass (5)

class

new ()

add_filename (filename)

add_resource (resource)

find_item_by_id (id)

get_menu_by_id (menu_id)

get_menu_ids ()

merge (menu_id, menu_model)

remove (merge_id)

set_attribute_string (menu, position, attribute, value)

Virtual Methods

Inherited:

GObject.Object (7)

Properties

None

Signals

Inherited:

GObject.Object (1)

Fields

Inherited:

GObject.Object (1)

Class Details

class Panel.MenuManager(**kwargs)
Bases:

GObject.Object

Abstract:

No

Structure:

Panel.MenuManagerClass

The goal of Panel.MenuManager is to simplify the process of merging multiple Gtk.Builder .ui files containing menus into a single representation of the application menus. Additionally, it provides the ability to “unmerge” previously merged menus.

This allows for an application to have plugins which seemlessly extends the core application menus.

Implementation notes:

To make this work, we don’t use the Gio.Menu instances created by a Gtk.Builder instance. Instead, we create the menus ourself and recreate section and submenu links. This allows the Panel.MenuManager to be in full control of the generated menus.

Panel.MenuManager.get_menu_by_id() will always return a Gio.Menu, however that menu may contain no children until something has extended it later on during the application process.

classmethod new()
Return type:

Panel.MenuManager

add_filename(filename)
Parameters:

filename (str) –

Raises:

GLib.Error

Return type:

int

add_resource(resource)
Parameters:

resource (str) –

Raises:

GLib.Error

Returns:

the merge id

Return type:

int

New in version 1.4.

find_item_by_id(id)
Parameters:

id (str) – the identifier of the menu item

Returns:

a Gio.Menu if successful; otherwise None and position is unset.

position:

the position within the resulting menu

Return type:

(Gio.Menu or None, position: int)

Locates a menu item that matches id and sets the position within the resulting Gio.Menu to position.

If no match is found, None is returned.

New in version 1.4.

get_menu_by_id(menu_id)
Parameters:

menu_id (str) –

Returns:

A Gio.Menu.

Return type:

Gio.Menu

New in version 1.4.

get_menu_ids()
Return type:

[str]

Gets the known menu ids as a string array.

New in version 1.4.

merge(menu_id, menu_model)
Parameters:
  • menu_id (str) – the identifier of the menu

  • menu_model (Gio.MenuModel) – the menu model to merge

Returns:

the merge-id which can be used with Panel.MenuManager.remove()

Return type:

int

Note that menu_model is not retained, a copy of it is made.

New in version 1.4.

remove(merge_id)
Parameters:

merge_id (int) – A previously registered merge id

This removes items from menus that were added as part of a previous menu merge. Use the value returned from Panel.MenuManager.merge() as the merge_id.

New in version 1.4.

set_attribute_string(menu, position, attribute, value)
Parameters:

Overwrites an attribute for a menu that was created by Panel.MenuManager.

This can be useful when you want to update an attribute such as “accel” when an accelerator has changed due to user mappings.

New in version 1.4.