Gio.Menu¶
class — extends MenuModel
GMenu is a simple implementation of MenuModel.
You populate a GMenu by adding MenuItem instances to it.
There are some convenience functions to allow you to directly
add items (avoiding MenuItem) for the common cases. To add
a regular item, use Menu.insert. To add a section, use
Menu.insert_section. To add a submenu, use
Menu.insert_submenu.
Constructors¶
new¶
Creates a new Menu.
The new menu has no items.
Methods¶
append¶
Convenience function for appending a normal menu item to the end of
menu. Combine MenuItem.new and Menu.insert_item for a more
flexible alternative.
Parameters:
label— the section label, orNonedetailed_action— the detailed action string, orNone
append_item¶
Appends item to the end of menu.
See Menu.insert_item for more information.
Parameters:
item— aMenuItemto append
append_section¶
Convenience function for appending a section menu item to the end of
menu. Combine MenuItem.new_section and Menu.insert_item for a
more flexible alternative.
Parameters:
label— the section label, orNonesection— aMenuModelwith the items of the section
append_submenu¶
Convenience function for appending a submenu menu item to the end of
menu. Combine MenuItem.new_submenu and Menu.insert_item for a
more flexible alternative.
Parameters:
label— the section label, orNonesubmenu— aMenuModelwith the items of the submenu
freeze¶
Marks menu 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 Menu API must no
longer be used.
This function causes MenuModel.is_mutable to begin returning
False, which has some positive performance implications.
insert¶
Convenience function for inserting a normal menu item into menu.
Combine MenuItem.new and Menu.insert_item for a more flexible
alternative.
Parameters:
position— the position at which to insert the itemlabel— the section label, orNonedetailed_action— the detailed action string, orNone
insert_item¶
Inserts item into menu.
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 menu.
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 Menu.insert, Menu.insert_section and
Menu.insert_submenu as well as "prepend" and "append" variants of
each of these functions.
Parameters:
position— the position at which to insert the itemitem— theMenuItemto insert
insert_section¶
Convenience function for inserting a section menu item into menu.
Combine MenuItem.new_section and Menu.insert_item for a more
flexible alternative.
Parameters:
position— the position at which to insert the itemlabel— the section label, orNonesection— aMenuModelwith the items of the section
insert_submenu¶
Convenience function for inserting a submenu menu item into menu.
Combine MenuItem.new_submenu and Menu.insert_item for a more
flexible alternative.
Parameters:
position— the position at which to insert the itemlabel— the section label, orNonesubmenu— aMenuModelwith the items of the submenu
prepend¶
Convenience function for prepending a normal menu item to the start
of menu. Combine MenuItem.new and Menu.insert_item for a more
flexible alternative.
Parameters:
label— the section label, orNonedetailed_action— the detailed action string, orNone
prepend_item¶
Prepends item to the start of menu.
See Menu.insert_item for more information.
Parameters:
item— aMenuItemto prepend
prepend_section¶
Convenience function for prepending a section menu item to the start
of menu. Combine MenuItem.new_section and Menu.insert_item for
a more flexible alternative.
Parameters:
label— the section label, orNonesection— aMenuModelwith the items of the section
prepend_submenu¶
Convenience function for prepending a submenu menu item to the start
of menu. Combine MenuItem.new_submenu and Menu.insert_item for
a more flexible alternative.
Parameters:
label— the section label, orNonesubmenu— aMenuModelwith the items of the submenu
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).
Parameters:
position— the position of the item to remove
remove_all¶
Removes all items in the menu.