Gio.Menu

g GObject.Object GObject.Object Gio.MenuModel Gio.MenuModel GObject.Object->Gio.MenuModel Gio.Menu Gio.Menu Gio.MenuModel->Gio.Menu

Subclasses:

None

Methods

Inherited:

Gio.MenuModel (7), GObject.Object (37)

Structs:

GObject.ObjectClass (5)

class

new ()

append (label, detailed_action)

append_item (item)

append_section (label, section)

append_submenu (label, submenu)

freeze ()

insert (position, label, detailed_action)

insert_item (position, item)

insert_section (position, label, section)

insert_submenu (position, label, submenu)

prepend (label, detailed_action)

prepend_item (item)

prepend_section (label, section)

prepend_submenu (label, submenu)

remove (position)

remove_all ()

Virtual Methods

Inherited:

Gio.MenuModel (8), GObject.Object (7)

Properties

None

Signals

Inherited:

Gio.MenuModel (1), GObject.Object (1)

Fields

Inherited:

Gio.MenuModel (1), GObject.Object (1)

Class Details

class Gio.Menu(**kwargs)
Bases:

Gio.MenuModel

Abstract:

No

GMenu is a simple implementation of [class`Gio`.MenuModel]. You populate a GMenu by adding [class`Gio`.MenuItem] instances to it.

There are some convenience functions to allow you to directly add items (avoiding [class`Gio`.MenuItem]) for the common cases. To add a regular item, use [method`Gio`.Menu.insert]. To add a section, use [method`Gio`.Menu.insert_section]. To add a submenu, use [method`Gio`.Menu.insert_submenu].

New in version 2.32.

classmethod new()[source]
Returns:

a new Gio.Menu

Return type:

Gio.Menu

Creates a new Gio.Menu.

The new menu has no items.

New in version 2.32.

append(label, detailed_action)[source]
Parameters:
  • label (str or None) – the section label, or None

  • detailed_action (str or None) – the detailed action string, or None

Convenience function for appending a normal menu item to the end of self. Combine Gio.MenuItem.new() and Gio.Menu.insert_item() for a more flexible alternative.

New in version 2.32.

append_item(item)[source]
Parameters:

item (Gio.MenuItem) – a Gio.MenuItem to append

Appends item to the end of self.

See Gio.Menu.insert_item() for more information.

New in version 2.32.

append_section(label, section)[source]
Parameters:

Convenience function for appending a section menu item to the end of self. Combine Gio.MenuItem.new_section() and Gio.Menu.insert_item() for a more flexible alternative.

New in version 2.32.

append_submenu(label, submenu)[source]
Parameters:

Convenience function for appending a submenu menu item to the end of self. Combine Gio.MenuItem.new_submenu() and Gio.Menu.insert_item() for a more flexible alternative.

New in version 2.32.

freeze()[source]

Marks self as frozen.

After the menu is frozen, it is an error to attempt to make any changes to it. In effect this means that the Gio.Menu API must no longer be used.

This function causes Gio.MenuModel.is_mutable() to begin returning False, which has some positive performance implications.

New in version 2.32.

insert(position, label, detailed_action)[source]
Parameters:
  • position (int) – the position at which to insert the item

  • label (str or None) – the section label, or None

  • detailed_action (str or None) – the detailed action string, or None

Convenience function for inserting a normal menu item into self. Combine Gio.MenuItem.new() and Gio.Menu.insert_item() for a more flexible alternative.

New in version 2.32.

insert_item(position, item)[source]
Parameters:

Inserts item into self.

The “insertion” is actually done by copying all of the attribute and link values of item and using them to form a new item within self. As such, item itself is not really inserted, but rather, a menu item that is exactly the same as the one presently described by item.

This means that item is essentially useless after the insertion occurs. Any changes you make to it are ignored unless it is inserted again (at which point its updated values will be copied).

You should probably just free item once you’re done.

There are many convenience functions to take care of common cases. See Gio.Menu.insert(), Gio.Menu.insert_section() and Gio.Menu.insert_submenu() as well as “prepend” and “append” variants of each of these functions.

New in version 2.32.

insert_section(position, label, section)[source]
Parameters:

Convenience function for inserting a section menu item into self. Combine Gio.MenuItem.new_section() and Gio.Menu.insert_item() for a more flexible alternative.

New in version 2.32.

insert_submenu(position, label, submenu)[source]
Parameters:

Convenience function for inserting a submenu menu item into self. Combine Gio.MenuItem.new_submenu() and Gio.Menu.insert_item() for a more flexible alternative.

New in version 2.32.

prepend(label, detailed_action)[source]
Parameters:
  • label (str or None) – the section label, or None

  • detailed_action (str or None) – the detailed action string, or None

Convenience function for prepending a normal menu item to the start of self. Combine Gio.MenuItem.new() and Gio.Menu.insert_item() for a more flexible alternative.

New in version 2.32.

prepend_item(item)[source]
Parameters:

item (Gio.MenuItem) – a Gio.MenuItem to prepend

Prepends item to the start of self.

See Gio.Menu.insert_item() for more information.

New in version 2.32.

prepend_section(label, section)[source]
Parameters:

Convenience function for prepending a section menu item to the start of self. Combine Gio.MenuItem.new_section() and Gio.Menu.insert_item() for a more flexible alternative.

New in version 2.32.

prepend_submenu(label, submenu)[source]
Parameters:

Convenience function for prepending a submenu menu item to the start of self. Combine Gio.MenuItem.new_submenu() and Gio.Menu.insert_item() for a more flexible alternative.

New in version 2.32.

remove(position)[source]
Parameters:

position (int) – the position of the item to remove

Removes an item from the menu.

position gives the index of the item to remove.

It is an error if position is not in range the range from 0 to one less than the number of items in the menu.

It is not possible to remove items by identity since items are added to the menu simply by copying their links and attributes (ie: identity of the item itself is not preserved).

New in version 2.32.

remove_all()[source]

Removes all items in the menu.

New in version 2.38.