Skip to main content
Ctrl+K

GNOME Python API

  • GLib
  • Gio
  • GObject
  • Gtk
  • Gdk
  • Adw
    • DBus
    • DBusGLib
    • Flatpak
    • GModule
    • Gcr
    • GdkPixbuf
    • GdkPixdata
    • GdkWayland
    • GdkX11
    • Graphene
    • Gsk
    • Gst
    • GstBase
    • GstCheck
    • GstController
    • GstNet
    • GtkSource
    • HarfBuzz
    • ICal
    • JavaScriptCore
    • Pango
    • PangoCairo
    • PangoFT2
    • PangoFc
    • PangoOT
    • PangoXft
    • Shumate
    • Soup
    • Vte
    • WebKit
    • WebKitWebProcessExtension
    • Xdp
    • XdpGtk4
    • pycairo
  • GLib
  • Gio
  • GObject
  • Gtk
  • Gdk
  • Adw
  • DBus
  • DBusGLib
  • Flatpak
  • GModule
  • Gcr
  • GdkPixbuf
  • GdkPixdata
  • GdkWayland
  • GdkX11
  • Graphene
  • Gsk
  • Gst
  • GstBase
  • GstCheck
  • GstController
  • GstNet
  • GtkSource
  • HarfBuzz
  • ICal
  • JavaScriptCore
  • Pango
  • PangoCairo
  • PangoFT2
  • PangoFc
  • PangoOT
  • PangoXft
  • Shumate
  • Soup
  • Vte
  • WebKit
  • WebKitWebProcessExtension
  • Xdp
  • XdpGtk4
  • pycairo

Section Navigation

API

  • 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
    • Action
    • ActionGroup
    • ActionMap
    • AppInfo
    • AsyncInitable
    • AsyncResult
    • Converter
    • DBusInterface
    • DBusObject
    • DBusObjectManager
    • DatagramBased
    • DebugController
    • DesktopAppInfoLookup
    • Drive
    • DtlsClientConnection
    • DtlsConnection
    • DtlsServerConnection
    • File
    • FileDescriptorBased
    • Icon
    • Initable
    • ListModel
    • LoadableIcon
    • MemoryMonitor
    • Mount
    • NetworkMonitor
    • PollableInputStream
    • PollableOutputStream
    • PowerProfileMonitor
    • Proxy
    • ProxyResolver
    • RemoteActionGroup
    • Seekable
    • SocketConnectable
    • TlsBackend
    • TlsClientConnection
    • TlsFileDatabase
    • TlsServerConnection
    • Volume
  • Structures
    • ActionEntry
    • DBusAnnotationInfo
    • DBusArgInfo
    • DBusErrorEntry
    • DBusInterfaceInfo
    • DBusInterfaceVTable
    • DBusMethodInfo
    • DBusNodeInfo
    • DBusPropertyInfo
    • DBusSignalInfo
    • DBusSubtreeVTable
    • FileAttributeInfo
    • FileAttributeInfoList
    • FileAttributeMatcher
    • IOExtension
    • IOExtensionPoint
    • IOModuleScope
    • IOSchedulerJob
    • IOStreamAdapter
    • InputMessage
    • InputVector
    • OutputMessage
    • OutputVector
    • Resource
    • SettingsSchema
    • SettingsSchemaKey
    • SettingsSchemaSource
    • SrvTarget
    • StaticResource
    • UnixMountEntry
    • UnixMountPoint
  • Enums
    • AppInfoCreateFlags
    • ApplicationFlags
    • AskPasswordFlags
    • BusNameOwnerFlags
    • BusNameWatcherFlags
    • BusType
    • ConverterFlags
    • ConverterResult
    • CredentialsType
    • DBusCallFlags
    • DBusCapabilityFlags
    • DBusConnectionFlags
    • DBusError
    • DBusInterfaceSkeletonFlags
    • DBusMessageByteOrder
    • DBusMessageFlags
    • DBusMessageHeaderField
    • DBusMessageType
    • DBusObjectManagerClientFlags
    • DBusPropertyInfoFlags
    • DBusProxyFlags
    • DBusSendMessageFlags
    • DBusServerFlags
    • DBusSignalFlags
    • DBusSubtreeFlags
    • DataStreamByteOrder
    • DataStreamNewlineType
    • DriveStartFlags
    • DriveStartStopType
    • EmblemOrigin
    • FileAttributeInfoFlags
    • FileAttributeStatus
    • FileAttributeType
    • FileCopyFlags
    • FileCreateFlags
    • FileMeasureFlags
    • FileMonitorEvent
    • FileMonitorFlags
    • FileQueryInfoFlags
    • FileType
    • FilesystemPreviewType
    • IOErrorEnum
    • IOModuleScopeFlags
    • IOStreamSpliceFlags
    • MemoryMonitorWarningLevel
    • MountMountFlags
    • MountOperationResult
    • MountUnmountFlags
    • NetworkConnectivity
    • NotificationPriority
    • OutputStreamSpliceFlags
    • PasswordSave
    • PollableReturn
    • ResolverError
    • ResolverNameLookupFlags
    • ResolverRecordType
    • ResourceError
    • ResourceFlags
    • ResourceLookupFlags
    • SettingsBindFlags
    • SocketClientEvent
    • SocketFamily
    • SocketListenerEvent
    • SocketMsgFlags
    • SocketProtocol
    • SocketType
    • SubprocessFlags
    • TestDBusFlags
    • TlsAuthenticationMode
    • TlsCertificateFlags
    • TlsCertificateRequestFlags
    • TlsChannelBindingError
    • TlsChannelBindingType
    • TlsDatabaseLookupFlags
    • TlsDatabaseVerifyFlags
    • TlsError
    • TlsInteractionResult
    • TlsPasswordFlags
    • TlsProtocolVersion
    • TlsRehandshakeMode
    • UnixSocketAddressType
    • ZlibCompressorFormat
  • Functions
  • Constants
  • Gio
  • Classes
  • Menu

Menu#

Added in version 2.32.

class Menu(**properties: Any)#

Superclasses: MenuModel, Object

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 insert. To add a section, use insert_section. To add a submenu, use insert_submenu.

Constructors#

class Menu
classmethod new() → Menu#

Creates a new Menu.

The new menu has no items.

Added in version 2.32.

Methods#

class Menu
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 new() and insert_item() for a more flexible alternative.

Added in version 2.32.

Parameters:
  • label – the section label, or None

  • detailed_action – the detailed action string, or None

append_item(item: MenuItem) → None#

Appends item to the end of menu.

See insert_item() for more information.

Added in version 2.32.

Parameters:

item – a MenuItem to append

append_section(label: str | None, section: MenuModel) → None#

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

Added in version 2.32.

Parameters:
  • label – the section label, or None

  • section – a MenuModel with the items of the section

append_submenu(label: str | None, submenu: MenuModel) → None#

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

Added in version 2.32.

Parameters:
  • label – the section label, or None

  • submenu – a MenuModel with the items of the submenu

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 Menu API must no longer be used.

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

Added in version 2.32.

insert(position: int, label: str | None = None, detailed_action: str | None = None) → None#

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

Added in version 2.32.

Parameters:
  • position – the position at which to insert the item

  • label – the section label, or None

  • detailed_action – the detailed action string, or None

insert_item(position: int, item: 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 insert(), insert_section() and insert_submenu() as well as “prepend” and “append” variants of each of these functions.

Added in version 2.32.

Parameters:
  • position – the position at which to insert the item

  • item – the MenuItem to insert

insert_section(position: int, label: str | None, section: MenuModel) → None#

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

Added in version 2.32.

Parameters:
  • position – the position at which to insert the item

  • label – the section label, or None

  • section – a MenuModel with the items of the section

insert_submenu(position: int, label: str | None, submenu: MenuModel) → None#

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

Added in version 2.32.

Parameters:
  • position – the position at which to insert the item

  • label – the section label, or None

  • submenu – a MenuModel with the items of the submenu

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 new() and insert_item() for a more flexible alternative.

Added in version 2.32.

Parameters:
  • label – the section label, or None

  • detailed_action – the detailed action string, or None

prepend_item(item: MenuItem) → None#

Prepends item to the start of menu.

See insert_item() for more information.

Added in version 2.32.

Parameters:

item – a MenuItem to prepend

prepend_section(label: str | None, section: MenuModel) → None#

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

Added in version 2.32.

Parameters:
  • label – the section label, or None

  • section – a MenuModel with the items of the section

prepend_submenu(label: str | None, submenu: MenuModel) → None#

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

Added in version 2.32.

Parameters:
  • label – the section label, or None

  • submenu – a MenuModel with the items of the submenu

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).

Added in version 2.32.

Parameters:

position – the position of the item to remove

remove_all() → None#

Removes all items in the menu.

Added in version 2.38.

On this page
  • Constructors
    • Menu.new()
  • Methods
    • Menu.append()
    • Menu.append_item()
    • Menu.append_section()
    • Menu.append_submenu()
    • Menu.freeze()
    • Menu.insert()
    • Menu.insert_item()
    • Menu.insert_section()
    • Menu.insert_submenu()
    • Menu.prepend()
    • Menu.prepend_item()
    • Menu.prepend_section()
    • Menu.prepend_submenu()
    • Menu.remove()
    • Menu.remove_all()

This Page

  • Show Source

Created using Sphinx 8.2.3.

General Index

Built with the PyData Sphinx Theme 0.16.1.