GNOME Python API

References

  • PyGObject Docs
  • GNOME Developer Documentation

Libraries

  • Adw
  • DBus
  • DBusGLib
  • Flatpak
  • GLib
  • GModule
  • GObject
  • Gcr
  • Gdk
  • GdkPixbuf
  • GdkPixdata
  • GdkWayland
  • GdkX11
  • Gio
    • Classes
      • AppInfoMonitor
      • AppLaunchContext
      • Application
      • ApplicationCommandLine
      • BufferedInputStream
      • BufferedOutputStream
      • BytesIcon
      • Cancellable
      • CharsetConverter
      • ConverterInputStream
      • ConverterOutputStream
      • Credentials
      • DBusActionGroup
      • DBusAuthObserver
      • DBusConnection
      • DBusInterfaceSkeleton
      • DBusMenuModel
      • DBusMessage
      • DBusMethodInvocation
      • DBusObjectManagerClient
      • DBusObjectManagerServer
      • DBusObjectProxy
      • DBusObjectSkeleton
      • DBusProxy
      • DBusServer
      • DataInputStream
      • DataOutputStream
      • DebugControllerDBus
      • DesktopAppInfo
      • Emblem
      • EmblemedIcon
      • FileEnumerator
      • FileIOStream
      • FileIcon
      • FileInfo
      • FileInputStream
      • FileMonitor
      • FileOutputStream
      • FilenameCompleter
      • FilterInputStream
      • FilterOutputStream
      • IOModule
      • IOStream
      • InetAddress
      • InetAddressMask
      • InetSocketAddress
      • InputStream
      • ListStore
      • MemoryInputStream
      • MemoryOutputStream
      • Menu
      • MenuAttributeIter
      • MenuItem
      • MenuLinkIter
      • MenuModel
      • MountOperation
      • NativeSocketAddress
      • NativeVolumeMonitor
      • NetworkAddress
      • NetworkService
      • Notification
      • OutputStream
      • Permission
      • PropertyAction
      • ProxyAddress
      • ProxyAddressEnumerator
      • Resolver
      • Settings
      • SettingsBackend
      • SimpleAction
      • SimpleActionGroup
      • SimpleAsyncResult
      • SimpleIOStream
      • SimplePermission
      • SimpleProxyResolver
      • Socket
      • SocketAddress
      • SocketAddressEnumerator
      • SocketClient
      • SocketConnection
      • SocketControlMessage
      • SocketListener
      • SocketService
      • Subprocess
      • SubprocessLauncher
      • Task
      • TcpConnection
      • TcpWrapperConnection
      • TestDBus
      • ThemedIcon
      • ThreadedResolver
      • ThreadedSocketService
      • TlsCertificate
      • TlsConnection
      • TlsDatabase
      • TlsInteraction
      • TlsPassword
      • UnixConnection
      • UnixCredentialsMessage
      • UnixFDList
      • UnixFDMessage
      • UnixInputStream
      • UnixMountMonitor
      • UnixOutputStream
      • UnixSocketAddress
      • Vfs
      • VolumeMonitor
      • ZlibCompressor
      • ZlibDecompressor
    • Interfaces
    • Structures
    • Enums
    • Functions
    • Constants
    • Dependencies
  • Graphene
  • Gsk
  • Gst
  • GstBase
  • GstCheck
  • GstController
  • GstNet
  • Gtk
  • GtkSource
  • HarfBuzz
  • Pango
  • PangoCairo
  • PangoFT2
  • PangoFc
  • PangoOT
  • PangoXft
  • Shumate
  • Soup
  • Vte
  • WebKit
  • WebKitWebProcessExtension
  • Xdp
  • XdpGtk4
  • pycairo
GNOME Python API
  • Gio
  • Classes
  • MenuModel
  • View page source

MenuModel

Added in version 2.32.

class MenuModel(**properties: Any)

Superclasses: Object

Subclasses: DBusMenuModel, Menu

Constructors:

MenuModel(**properties)

Methods

class MenuModel
get_item_attribute_value(item_index: int, attribute: str, expected_type: VariantType | None = None) → Variant | None

Queries the item at position item_index in model for the attribute specified by attribute.

If expected_type is non-None then it specifies the expected type of the attribute. If it is 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 None is returned.

Added in version 2.32.

Parameters:
  • item_index – the index of the item

  • attribute – the attribute to query

  • expected_type – the expected type of the attribute, or None

get_item_link(item_index: int, link: str) → MenuModel | None

Queries the item at position item_index in model for the link specified by link.

If the link exists, the linked MenuModel is returned. If the link does not exist, None is returned.

Added in version 2.32.

Parameters:
  • item_index – the index of the item

  • link – the link to query

get_n_items() → int

Query the number of items in model.

Added in version 2.32.

is_mutable() → bool

Queries if model is mutable.

An immutable MenuModel will never emit the MenuModel::items-changed signal. Consumers of the model may make optimisations accordingly.

Added in version 2.32.

items_changed(position: int, removed: int, added: int) → None

Requests emission of the MenuModel::items-changed signal on model.

This function should never be called except by 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 MenuModel API. Said another way: the menu must not change while user code is running without returning to the mainloop.

Added in version 2.32.

Parameters:
  • position – the position of the change

  • removed – the number of items removed

  • added – the number of items added

iterate_item_attributes(item_index: int) → MenuAttributeIter

Creates a MenuAttributeIter to iterate over the attributes of the item at position item_index in model.

You must free the iterator with unref() when you are done.

Added in version 2.32.

Parameters:

item_index – the index of the item

iterate_item_links(item_index: int) → MenuLinkIter

Creates a MenuLinkIter to iterate over the links of the item at position item_index in model.

You must free the iterator with unref() when you are done.

Added in version 2.32.

Parameters:

item_index – the index of the item

Signals

class MenuModel.signals
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.

Parameters:
  • position – the position of the change

  • removed – the number of items removed

  • added – the number of items added

Virtual Methods

class MenuModel
do_get_item_attribute_value(item_index: int, attribute: str, expected_type: VariantType | None = None) → Variant | None

Queries the item at position item_index in model for the attribute specified by attribute.

If expected_type is non-None then it specifies the expected type of the attribute. If it is 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 None is returned.

Added in version 2.32.

Parameters:
  • item_index – the index of the item

  • attribute – the attribute to query

  • expected_type – the expected type of the attribute, or None

do_get_item_attributes(item_index: int) → dict[str, Variant]

Gets all the attributes associated with the item in the menu model.

Parameters:

item_index – The MenuItem to query

do_get_item_link(item_index: int, link: str) → MenuModel | None

Queries the item at position item_index in model for the link specified by link.

If the link exists, the linked MenuModel is returned. If the link does not exist, None is returned.

Added in version 2.32.

Parameters:
  • item_index – the index of the item

  • link – the link to query

do_get_item_links(item_index: int) → dict[str, MenuModel]

Gets all the links associated with the item in the menu model.

Parameters:

item_index – The MenuItem to query

do_get_n_items() → int

Query the number of items in model.

Added in version 2.32.

do_is_mutable() → bool

Queries if model is mutable.

An immutable MenuModel will never emit the MenuModel::items-changed signal. Consumers of the model may make optimisations accordingly.

Added in version 2.32.

do_iterate_item_attributes(item_index: int) → MenuAttributeIter

Creates a MenuAttributeIter to iterate over the attributes of the item at position item_index in model.

You must free the iterator with unref() when you are done.

Added in version 2.32.

Parameters:

item_index – the index of the item

do_iterate_item_links(item_index: int) → MenuLinkIter

Creates a MenuLinkIter to iterate over the links of the item at position item_index in model.

You must free the iterator with unref() when you are done.

Added in version 2.32.

Parameters:

item_index – the index of the item

Fields

class MenuModel
parent_instance
priv

Built with Sphinx using a theme provided by Read the Docs.
  • MenuModel
    • Methods
      • MenuModel.get_item_attribute_value()
      • MenuModel.get_item_link()
      • MenuModel.get_n_items()
      • MenuModel.is_mutable()
      • MenuModel.items_changed()
      • MenuModel.iterate_item_attributes()
      • MenuModel.iterate_item_links()
    • Signals
      • MenuModel.signals.items_changed()
    • Virtual Methods
      • MenuModel.do_get_item_attribute_value()
      • MenuModel.do_get_item_attributes()
      • MenuModel.do_get_item_link()
      • MenuModel.do_get_item_links()
      • MenuModel.do_get_n_items()
      • MenuModel.do_is_mutable()
      • MenuModel.do_iterate_item_attributes()
      • MenuModel.do_iterate_item_links()
    • Fields
      • MenuModel.parent_instance
      • MenuModel.priv