:right-sidebar: True MenuModel =================================================================== .. currentmodule:: gi.repository.Gio .. versionadded:: 2.32 .. class:: MenuModel(**properties: ~typing.Any) :no-contents-entry: Superclasses: :class:`~gi.repository.GObject.Object` Subclasses: :class:`~gi.repository.Gio.DBusMenuModel`, :class:`~gi.repository.Gio.Menu` :Constructors: :: MenuModel(**properties) Methods ------- .. rst-class:: interim-class .. class:: MenuModel :no-index: .. method:: get_item_attribute_value(item_index: int, attribute: str, expected_type: ~gi.repository.GLib.VariantType | None = None) -> ~gi.repository.GLib.Variant | None Queries the item at position ``item_index`` in ``model`` for the attribute specified by ``attribute``. If ``expected_type`` is non-:const:`None` then it specifies the expected type of the attribute. If it is :const:`None` then any type will be accepted. If the attribute exists and matches ``expected_type`` (or if the expected type is unspecified) then the value is returned. If the attribute does not exist, or does not match the expected type then :const:`None` is returned. .. versionadded:: 2.32 :param item_index: the index of the item :param attribute: the attribute to query :param expected_type: the expected type of the attribute, or :const:`None` .. method:: get_item_link(item_index: int, link: str) -> ~gi.repository.Gio.MenuModel | None Queries the item at position ``item_index`` in ``model`` for the link specified by ``link``. If the link exists, the linked :obj:`~gi.repository.Gio.MenuModel` is returned. If the link does not exist, :const:`None` is returned. .. versionadded:: 2.32 :param item_index: the index of the item :param link: the link to query .. method:: get_n_items() -> int Query the number of items in ``model``. .. versionadded:: 2.32 .. method:: is_mutable() -> bool Queries if ``model`` is mutable. An immutable :obj:`~gi.repository.Gio.MenuModel` will never emit the :obj:`~gi.repository.Gio.MenuModel`::items-changed signal. Consumers of the model may make optimisations accordingly. .. versionadded:: 2.32 .. method:: items_changed(position: int, removed: int, added: int) -> None Requests emission of the :obj:`~gi.repository.Gio.MenuModel`::items-changed signal on ``model``. This function should never be called except by :obj:`~gi.repository.Gio.MenuModel` subclasses. Any other calls to this function will very likely lead to a violation of the interface of the model. The implementation should update its internal representation of the menu before emitting the signal. The implementation should further expect to receive queries about the new state of the menu (and particularly added menu items) while signal handlers are running. The implementation must dispatch this call directly from a mainloop entry and not in response to calls -- particularly those from the :obj:`~gi.repository.Gio.MenuModel` API. Said another way: the menu must not change while user code is running without returning to the mainloop. .. versionadded:: 2.32 :param position: the position of the change :param removed: the number of items removed :param added: the number of items added .. method:: iterate_item_attributes(item_index: int) -> ~gi.repository.Gio.MenuAttributeIter Creates a :obj:`~gi.repository.Gio.MenuAttributeIter` to iterate over the attributes of the item at position ``item_index`` in ``model``. You must free the iterator with :func:`~gi.repository.GObject.GObject.Object.unref` when you are done. .. versionadded:: 2.32 :param item_index: the index of the item .. method:: iterate_item_links(item_index: int) -> ~gi.repository.Gio.MenuLinkIter Creates a :obj:`~gi.repository.Gio.MenuLinkIter` to iterate over the links of the item at position ``item_index`` in ``model``. You must free the iterator with :func:`~gi.repository.GObject.GObject.Object.unref` when you are done. .. versionadded:: 2.32 :param item_index: the index of the item Signals ------- .. rst-class:: interim-class .. class:: MenuModel.signals :no-index: .. method:: items_changed(position: int, removed: int, added: int) -> None Emitted when a change has occurred to the menu. The only changes that can occur to a menu is that items are removed or added. Items may not change (except by being removed and added back in the same location). This signal is capable of describing both of those changes (at the same time). The signal means that starting at the index ``position``, ``removed`` items were removed and ``added`` items were added in their place. If ``removed`` is zero then only items were added. If ``added`` is zero then only items were removed. As an example, if the menu contains items a, b, c, d (in that order) and the signal (2, 1, 3) occurs then the new composition of the menu will be a, b, *, *, *, d (with each * representing some new item). Signal handlers may query the model (particularly the added items) and expect to see the results of the modification that is being reported. The signal is emitted after the modification. :param position: the position of the change :param removed: the number of items removed :param added: the number of items added Virtual Methods --------------- .. rst-class:: interim-class .. class:: MenuModel :no-index: .. method:: do_get_item_attribute_value(item_index: int, attribute: str, expected_type: ~gi.repository.GLib.VariantType | None = None) -> ~gi.repository.GLib.Variant | None Queries the item at position ``item_index`` in ``model`` for the attribute specified by ``attribute``. If ``expected_type`` is non-:const:`None` then it specifies the expected type of the attribute. If it is :const:`None` then any type will be accepted. If the attribute exists and matches ``expected_type`` (or if the expected type is unspecified) then the value is returned. If the attribute does not exist, or does not match the expected type then :const:`None` is returned. .. versionadded:: 2.32 :param item_index: the index of the item :param attribute: the attribute to query :param expected_type: the expected type of the attribute, or :const:`None` .. method:: do_get_item_attributes(item_index: int) -> dict[str, ~gi.repository.GLib.Variant] Gets all the attributes associated with the item in the menu model. :param item_index: The :obj:`~gi.repository.Gio.MenuItem` to query .. method:: do_get_item_link(item_index: int, link: str) -> ~gi.repository.Gio.MenuModel | None Queries the item at position ``item_index`` in ``model`` for the link specified by ``link``. If the link exists, the linked :obj:`~gi.repository.Gio.MenuModel` is returned. If the link does not exist, :const:`None` is returned. .. versionadded:: 2.32 :param item_index: the index of the item :param link: the link to query .. method:: do_get_item_links(item_index: int) -> dict[str, ~gi.repository.Gio.MenuModel] Gets all the links associated with the item in the menu model. :param item_index: The :obj:`~gi.repository.Gio.MenuItem` to query .. method:: do_get_n_items() -> int Query the number of items in ``model``. .. versionadded:: 2.32 .. method:: do_is_mutable() -> bool Queries if ``model`` is mutable. An immutable :obj:`~gi.repository.Gio.MenuModel` will never emit the :obj:`~gi.repository.Gio.MenuModel`::items-changed signal. Consumers of the model may make optimisations accordingly. .. versionadded:: 2.32 .. method:: do_iterate_item_attributes(item_index: int) -> ~gi.repository.Gio.MenuAttributeIter Creates a :obj:`~gi.repository.Gio.MenuAttributeIter` to iterate over the attributes of the item at position ``item_index`` in ``model``. You must free the iterator with :func:`~gi.repository.GObject.GObject.Object.unref` when you are done. .. versionadded:: 2.32 :param item_index: the index of the item .. method:: do_iterate_item_links(item_index: int) -> ~gi.repository.Gio.MenuLinkIter Creates a :obj:`~gi.repository.Gio.MenuLinkIter` to iterate over the links of the item at position ``item_index`` in ``model``. You must free the iterator with :func:`~gi.repository.GObject.GObject.Object.unref` when you are done. .. versionadded:: 2.32 :param item_index: the index of the item Fields ------ .. rst-class:: interim-class .. class:: MenuModel :no-index: .. attribute:: parent_instance .. attribute:: priv