Skip to content

Gdk.Popup

interface

A surface that is attached to another surface.

The GdkPopup is positioned relative to its parent surface.

GdkPopups are typically used to implement menus and similar popups. They can be modal, which is indicated by the Popup.autohide property.

Methods

get_autohide

def get_autohide(self) -> bool

Returns whether this popup is set to hide on outside clicks.

get_parent

def get_parent(self) -> Surface | None

Returns the parent surface of a popup.

get_position_x

def get_position_x(self) -> int

Obtains the position of the popup relative to its parent.

get_position_y

def get_position_y(self) -> int

Obtains the position of the popup relative to its parent.

get_rect_anchor

def get_rect_anchor(self) -> Gravity

Gets the current popup rectangle anchor.

The value returned may change after calling Popup.present, or after the Surface.layout signal is emitted.

get_surface_anchor

def get_surface_anchor(self) -> Gravity

Gets the current popup surface anchor.

The value returned may change after calling Popup.present, or after the Surface.layout signal is emitted.

present

def present(self, width: int, height: int, layout: PopupLayout) -> bool

Present popup after having processed the GdkPopupLayout rules.

If the popup was previously not showing, it will be shown, otherwise it will change position according to layout.

After calling this function, the result should be handled in response to the Surface.layout signal being emitted. The resulting popup position can be queried using Popup.get_position_x, Popup.get_position_y, and the resulting size will be sent as parameters in the layout signal. Use Popup.get_rect_anchor and Popup.get_surface_anchor to get the resulting anchors.

Presenting may fail, for example if the popup is set to autohide and is immediately hidden upon being presented. If presenting failed, the Surface.layout signal will not me emitted.

Parameters:

  • width — the unconstrained popup width to layout
  • height — the unconstrained popup height to layout
  • layout — the GdkPopupLayout object used to layout

Properties

autohide

autohide: bool  # read/write

Whether to hide on outside clicks.

parent

parent: Surface  # read/write

The parent surface.