:right-sidebar: True Menu =================================================================== .. currentmodule:: gi.repository.Gio .. versionadded:: 2.32 .. class:: Menu(**properties: ~typing.Any) :no-contents-entry: Superclasses: :class:`~gi.repository.Gio.MenuModel`, :class:`~gi.repository.GObject.Object` ``GMenu`` is a simple implementation of :obj:`~gi.repository.Gio.MenuModel`. You populate a ``GMenu`` by adding :obj:`~gi.repository.Gio.MenuItem` instances to it. There are some convenience functions to allow you to directly add items (avoiding :obj:`~gi.repository.Gio.MenuItem`) for the common cases. To add a regular item, use :obj:`~gi.repository.Gio.Menu.insert`. To add a section, use :obj:`~gi.repository.Gio.Menu.insert_section`. To add a submenu, use :obj:`~gi.repository.Gio.Menu.insert_submenu`. Constructors ------------ .. rst-class:: interim-class .. class:: Menu :no-index: .. classmethod:: new() -> ~gi.repository.Gio.Menu Creates a new :obj:`~gi.repository.Gio.Menu`. The new menu has no items. .. versionadded:: 2.32 Methods ------- .. rst-class:: interim-class .. class:: Menu :no-index: .. method:: append(label: str | None = None, detailed_action: str | None = None) -> None Convenience function for appending a normal menu item to the end of ``menu``. Combine :func:`~gi.repository.Gio.MenuItem.new` and :func:`~gi.repository.Gio.Menu.insert_item` for a more flexible alternative. .. versionadded:: 2.32 :param label: the section label, or :const:`None` :param detailed_action: the detailed action string, or :const:`None` .. method:: append_item(item: ~gi.repository.Gio.MenuItem) -> None Appends ``item`` to the end of ``menu``. See :func:`~gi.repository.Gio.Menu.insert_item` for more information. .. versionadded:: 2.32 :param item: a :obj:`~gi.repository.Gio.MenuItem` to append .. method:: append_section(label: str | None, section: ~gi.repository.Gio.MenuModel) -> None Convenience function for appending a section menu item to the end of ``menu``. Combine :func:`~gi.repository.Gio.MenuItem.new_section` and :func:`~gi.repository.Gio.Menu.insert_item` for a more flexible alternative. .. versionadded:: 2.32 :param label: the section label, or :const:`None` :param section: a :obj:`~gi.repository.Gio.MenuModel` with the items of the section .. method:: append_submenu(label: str | None, submenu: ~gi.repository.Gio.MenuModel) -> None Convenience function for appending a submenu menu item to the end of ``menu``. Combine :func:`~gi.repository.Gio.MenuItem.new_submenu` and :func:`~gi.repository.Gio.Menu.insert_item` for a more flexible alternative. .. versionadded:: 2.32 :param label: the section label, or :const:`None` :param submenu: a :obj:`~gi.repository.Gio.MenuModel` with the items of the submenu .. method:: freeze() -> None 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 :obj:`~gi.repository.Gio.Menu` API must no longer be used. This function causes :func:`~gi.repository.Gio.MenuModel.is_mutable` to begin returning :const:`False`, which has some positive performance implications. .. versionadded:: 2.32 .. method:: insert(position: int, label: str | None = None, detailed_action: str | None = None) -> None Convenience function for inserting a normal menu item into ``menu``. Combine :func:`~gi.repository.Gio.MenuItem.new` and :func:`~gi.repository.Gio.Menu.insert_item` for a more flexible alternative. .. versionadded:: 2.32 :param position: the position at which to insert the item :param label: the section label, or :const:`None` :param detailed_action: the detailed action string, or :const:`None` .. method:: insert_item(position: int, item: ~gi.repository.Gio.MenuItem) -> None 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 :func:`~gi.repository.Gio.Menu.insert`, :func:`~gi.repository.Gio.Menu.insert_section` and :func:`~gi.repository.Gio.Menu.insert_submenu` as well as "prepend" and "append" variants of each of these functions. .. versionadded:: 2.32 :param position: the position at which to insert the item :param item: the :obj:`~gi.repository.Gio.MenuItem` to insert .. method:: insert_section(position: int, label: str | None, section: ~gi.repository.Gio.MenuModel) -> None Convenience function for inserting a section menu item into ``menu``. Combine :func:`~gi.repository.Gio.MenuItem.new_section` and :func:`~gi.repository.Gio.Menu.insert_item` for a more flexible alternative. .. versionadded:: 2.32 :param position: the position at which to insert the item :param label: the section label, or :const:`None` :param section: a :obj:`~gi.repository.Gio.MenuModel` with the items of the section .. method:: insert_submenu(position: int, label: str | None, submenu: ~gi.repository.Gio.MenuModel) -> None Convenience function for inserting a submenu menu item into ``menu``. Combine :func:`~gi.repository.Gio.MenuItem.new_submenu` and :func:`~gi.repository.Gio.Menu.insert_item` for a more flexible alternative. .. versionadded:: 2.32 :param position: the position at which to insert the item :param label: the section label, or :const:`None` :param submenu: a :obj:`~gi.repository.Gio.MenuModel` with the items of the submenu .. method:: prepend(label: str | None = None, detailed_action: str | None = None) -> None Convenience function for prepending a normal menu item to the start of ``menu``. Combine :func:`~gi.repository.Gio.MenuItem.new` and :func:`~gi.repository.Gio.Menu.insert_item` for a more flexible alternative. .. versionadded:: 2.32 :param label: the section label, or :const:`None` :param detailed_action: the detailed action string, or :const:`None` .. method:: prepend_item(item: ~gi.repository.Gio.MenuItem) -> None Prepends ``item`` to the start of ``menu``. See :func:`~gi.repository.Gio.Menu.insert_item` for more information. .. versionadded:: 2.32 :param item: a :obj:`~gi.repository.Gio.MenuItem` to prepend .. method:: prepend_section(label: str | None, section: ~gi.repository.Gio.MenuModel) -> None Convenience function for prepending a section menu item to the start of ``menu``. Combine :func:`~gi.repository.Gio.MenuItem.new_section` and :func:`~gi.repository.Gio.Menu.insert_item` for a more flexible alternative. .. versionadded:: 2.32 :param label: the section label, or :const:`None` :param section: a :obj:`~gi.repository.Gio.MenuModel` with the items of the section .. method:: prepend_submenu(label: str | None, submenu: ~gi.repository.Gio.MenuModel) -> None Convenience function for prepending a submenu menu item to the start of ``menu``. Combine :func:`~gi.repository.Gio.MenuItem.new_submenu` and :func:`~gi.repository.Gio.Menu.insert_item` for a more flexible alternative. .. versionadded:: 2.32 :param label: the section label, or :const:`None` :param submenu: a :obj:`~gi.repository.Gio.MenuModel` with the items of the submenu .. method:: remove(position: int) -> None 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). .. versionadded:: 2.32 :param position: the position of the item to remove .. method:: remove_all() -> None Removes all items in the menu. .. versionadded:: 2.38