Gtk.Popover

g Atk.ImplementorIface Atk.ImplementorIface Gtk.Widget Gtk.Widget Atk.ImplementorIface->Gtk.Widget GObject.GInterface GObject.GInterface GObject.GInterface->Atk.ImplementorIface Gtk.Buildable Gtk.Buildable GObject.GInterface->Gtk.Buildable GObject.InitiallyUnowned GObject.InitiallyUnowned GObject.InitiallyUnowned->Gtk.Widget GObject.Object GObject.Object GObject.Object->GObject.InitiallyUnowned Gtk.Bin Gtk.Bin Gtk.Popover Gtk.Popover Gtk.Bin->Gtk.Popover Gtk.Buildable->Gtk.Widget Gtk.Container Gtk.Container Gtk.Container->Gtk.Bin Gtk.Widget->Gtk.Container

Subclasses:

Gtk.PopoverMenu

Methods

Inherited:

Gtk.Bin (1), Gtk.Container (35), Gtk.Widget (278), GObject.Object (37), Gtk.Buildable (10)

Structs:

Gtk.ContainerClass (5), Gtk.WidgetClass (12), GObject.ObjectClass (5)

class

new (relative_to)

class

new_from_model (relative_to, model)

bind_model (model, action_namespace)

get_constrain_to ()

get_default_widget ()

get_modal ()

get_pointing_to ()

get_position ()

get_relative_to ()

get_transitions_enabled ()

popdown ()

popup ()

set_constrain_to (constraint)

set_default_widget (widget)

set_modal (modal)

set_pointing_to (rect)

set_position (position)

set_relative_to (relative_to)

set_transitions_enabled (transitions_enabled)

Virtual Methods

Inherited:

Gtk.Container (10), Gtk.Widget (82), GObject.Object (7), Gtk.Buildable (10)

do_closed ()

Properties

Inherited:

Gtk.Container (3), Gtk.Widget (39)

Name

Type

Flags

Short Description

constrain-to

Gtk.PopoverConstraint

r/w/en

Constraint for the popover position

modal

bool

r/w/en

Whether the popover is modal

pointing-to

Gdk.Rectangle

r/w

Rectangle the bubble window points to

position

Gtk.PositionType

r/w/en

Position to place the bubble window

relative-to

Gtk.Widget

r/w

Widget the bubble window points to

transitions-enabled

bool

d/r/w/en

Whether show/hide transitions are enabled or not deprecated

Style Properties

Inherited:

Gtk.Widget (17)

Signals

Inherited:

Gtk.Container (4), Gtk.Widget (69), GObject.Object (1)

Name

Short Description

closed

This signal is emitted when the popover is dismissed either through API or user interaction.

Fields

Inherited:

Gtk.Container (4), Gtk.Widget (69), GObject.Object (1)

Name

Type

Access

Description

parent_instance

Gtk.Bin

r

Class Details

class Gtk.Popover(**kwargs)
Bases:

Gtk.Bin

Abstract:

No

Structure:

Gtk.PopoverClass

Gtk.Popover is a bubble-like context window, primarily meant to provide context-dependent information or options. Popovers are attached to a widget, passed at construction time on Gtk.Popover.new(), or updated afterwards through Gtk.Popover.set_relative_to(), by default they will point to the whole widget area, although this behavior can be changed through Gtk.Popover.set_pointing_to().

The position of a popover relative to the widget it is attached to can also be changed through Gtk.Popover.set_position().

By default, Gtk.Popover performs a GTK+ grab, in order to ensure input events get redirected to it while it is shown, and also so the popover is dismissed in the expected situations (clicks outside the popover, or the Esc key being pressed). If no such modal behavior is desired on a popover, Gtk.Popover.set_modal() may be called on it to tweak its behavior.

Gtk.Popover as menu replacement

Gtk.Popover is often used to replace menus. To facilitate this, it supports being populated from a Gio.MenuModel, using Gtk.Popover.new_from_model(). In addition to all the regular menu model features, this function supports rendering sections in the model in a more compact form, as a row of icon buttons instead of menu items.

To use this rendering, set the ”display-hint” attribute of the section to ”horizontal-buttons” and set the icons of your items with the ”verb-icon” attribute.

<section>
  <attribute name="display-hint">horizontal-buttons</attribute>
  <item>
    <attribute name="label">Cut</attribute>
    <attribute name="action">app.cut</attribute>
    <attribute name="verb-icon">edit-cut-symbolic</attribute>
  </item>
  <item>
    <attribute name="label">Copy</attribute>
    <attribute name="action">app.copy</attribute>
    <attribute name="verb-icon">edit-copy-symbolic</attribute>
  </item>
  <item>
    <attribute name="label">Paste</attribute>
    <attribute name="action">app.paste</attribute>
    <attribute name="verb-icon">edit-paste-symbolic</attribute>
  </item>
</section>
CSS nodes

Gtk.Popover has a single css node called popover. It always gets the .background style class and it gets the .menu style class if it is menu-like (e.g. Gtk.PopoverMenu or created using Gtk.Popover.new_from_model().

Particular uses of Gtk.Popover, such as touch selection popups or magnifiers in Gtk.Entry or Gtk.TextView get style classes like .touch-selection or .magnifier to differentiate from plain popovers.

New in version 3.12.

classmethod new(relative_to)[source]
Parameters:

relative_to (Gtk.Widget or None) – Gtk.Widget the popover is related to

Returns:

a new Gtk.Popover

Return type:

Gtk.Widget

Creates a new popover to point to relative_to

New in version 3.12.

classmethod new_from_model(relative_to, model)[source]
Parameters:
Returns:

the new Gtk.Popover

Return type:

Gtk.Widget

Creates a Gtk.Popover and populates it according to model. The popover is pointed to the relative_to widget.

The created buttons are connected to actions found in the Gtk.ApplicationWindow to which the popover belongs - typically by means of being attached to a widget that is contained within the Gtk.ApplicationWindows widget hierarchy.

Actions can also be added using Gtk.Widget.insert_action_group() on the menus attach widget or on any of its parent widgets.

New in version 3.12.

bind_model(model, action_namespace)[source]
Parameters:

Establishes a binding between a Gtk.Popover and a Gio.MenuModel.

The contents of self are removed and then refilled with menu items according to model. When model changes, self is updated. Calling this function twice on self with different model will cause the first binding to be replaced with a binding to the new model. If model is None then any previous binding is undone and all children are removed.

If action_namespace is non-None then the effect is as if all actions mentioned in the model have their names prefixed with the namespace, plus a dot. For example, if the action “quit” is mentioned and action_namespace is “app” then the effective action name is “app.quit”.

This function uses Gtk.Actionable to define the action name and target values on the created menu items. If you want to use an action group other than “app” and “win”, or if you want to use a Gtk.MenuShell outside of a Gtk.ApplicationWindow, then you will need to attach your own action group to the widget hierarchy using Gtk.Widget.insert_action_group(). As an example, if you created a group with a “quit” action and inserted it with the name “mygroup” then you would use the action name “mygroup.quit” in your Gio.MenuModel.

New in version 3.12.

get_constrain_to()[source]
Returns:

the constraint for placing this popover.

Return type:

Gtk.PopoverConstraint

Returns the constraint for placing this popover. See Gtk.Popover.set_constrain_to().

New in version 3.20.

get_default_widget()[source]
Returns:

the default widget, or None if there is none

Return type:

Gtk.Widget or None

Gets the widget that should be set as the default while the popover is shown.

New in version 3.18.

get_modal()[source]
Returns:

True if self is modal

Return type:

bool

Returns whether the popover is modal, see Gtk.Popover.set_modal to see the implications of this.

New in version 3.12.

get_pointing_to()[source]
Returns:

True if a rectangle to point to was set.

rect:

location to store the rectangle

Return type:

(bool, rect: Gdk.Rectangle)

If a rectangle to point to has been set, this function will return True and fill in rect with such rectangle, otherwise it will return False and fill in rect with the attached widget width and height if a widget exists, otherwise it will zero-out rect.

get_position()[source]
Returns:

The preferred position.

Return type:

Gtk.PositionType

Returns the preferred position of self.

get_relative_to()[source]
Returns:

a Gtk.Widget

Return type:

Gtk.Widget

Returns the widget self is currently attached to

New in version 3.12.

get_transitions_enabled()[source]
Returns:

True if the show and hide transitions of the given popover are enabled, False otherwise.

Return type:

bool

Returns whether show/hide transitions are enabled on this popover.

New in version 3.16.

Deprecated since version 3.22: You can show or hide the popover without transitions using Gtk.Widget.show() and Gtk.Widget.hide() while Gtk.Popover.popup() and Gtk.Popover.popdown() will use transitions.

popdown()[source]

Pops self down.This is different than a Gtk.Widget.hide() call in that it shows the popover with a transition. If you want to hide the popover without a transition, use Gtk.Widget.hide().

New in version 3.22.

popup()[source]

Pops self up. This is different than a Gtk.Widget.show() call in that it shows the popover with a transition. If you want to show the popover without a transition, use Gtk.Widget.show().

New in version 3.22.

set_constrain_to(constraint)[source]
Parameters:

constraint (Gtk.PopoverConstraint) – the new constraint

Sets a constraint for positioning this popover.

Note that not all platforms support placing popovers freely, and may already impose constraints.

New in version 3.20.

set_default_widget(widget)[source]
Parameters:

widget (Gtk.Widget or None) – the new default widget, or None

Sets the widget that should be set as default widget while the popover is shown (see Gtk.Window.set_default()). Gtk.Popover remembers the previous default widget and reestablishes it when the popover is dismissed.

New in version 3.18.

set_modal(modal)[source]
Parameters:

modal (bool) – True to make popover claim all input within the toplevel

Sets whether self is modal, a modal popover will grab all input within the toplevel and grab the keyboard focus on it when being displayed. Clicking outside the popover area or pressing Esc will dismiss the popover and ungrab input.

New in version 3.12.

set_pointing_to(rect)[source]
Parameters:

rect (Gdk.Rectangle) – rectangle to point to

Sets the rectangle that self will point to, in the coordinate space of the widget self is attached to, see Gtk.Popover.set_relative_to().

New in version 3.12.

set_position(position)[source]
Parameters:

position (Gtk.PositionType) – preferred popover position

Sets the preferred position for self to appear. If the self is currently visible, it will be immediately updated.

This preference will be respected where possible, although on lack of space (eg. if close to the window edges), the Gtk.Popover may choose to appear on the opposite side

New in version 3.12.

set_relative_to(relative_to)[source]
Parameters:

relative_to (Gtk.Widget or None) – a Gtk.Widget

Sets a new widget to be attached to self. If self is visible, the position will be updated.

Note: the ownership of popovers is always given to their relative_to widget, so if relative_to is set to None on an attached self, it will be detached from its previous widget, and consequently destroyed unless extra references are kept.

New in version 3.12.

set_transitions_enabled(transitions_enabled)[source]
Parameters:

transitions_enabled (bool) – Whether transitions are enabled

Sets whether show/hide transitions are enabled on this popover

New in version 3.16.

Deprecated since version 3.22: You can show or hide the popover without transitions using Gtk.Widget.show() and Gtk.Widget.hide() while Gtk.Popover.popup() and Gtk.Popover.popdown() will use transitions.

do_closed() virtual

Signal Details

Gtk.Popover.signals.closed(popover)
Signal Name:

closed

Flags:

RUN_LAST

Parameters:

popover (Gtk.Popover) – The object which received the signal

This signal is emitted when the popover is dismissed either through API or user interaction.

New in version 3.12.

Property Details

Gtk.Popover.props.constrain_to
Name:

constrain-to

Type:

Gtk.PopoverConstraint

Default Value:

Gtk.PopoverConstraint.WINDOW

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Sets a constraint for the popover position.

New in version 3.20.

Gtk.Popover.props.modal
Name:

modal

Type:

bool

Default Value:

True

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Sets whether the popover is modal (so other elements in the window do not receive input while the popover is visible).

New in version 3.12.

Gtk.Popover.props.pointing_to
Name:

pointing-to

Type:

Gdk.Rectangle

Default Value:

None

Flags:

READABLE, WRITABLE

Marks a specific rectangle to be pointed.

New in version 3.12.

Gtk.Popover.props.position
Name:

position

Type:

Gtk.PositionType

Default Value:

Gtk.PositionType.TOP

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Sets the preferred position of the popover.

New in version 3.12.

Gtk.Popover.props.relative_to
Name:

relative-to

Type:

Gtk.Widget

Default Value:

None

Flags:

READABLE, WRITABLE

Sets the attached widget.

New in version 3.12.

Gtk.Popover.props.transitions_enabled
Name:

transitions-enabled

Type:

bool

Default Value:

True

Flags:

DEPRECATED, READABLE, WRITABLE, EXPLICIT_NOTIFY

Whether show/hide transitions are enabled for this popover.

New in version 3.16.

Deprecated since version 3.22: You can show or hide the popover without transitions using Gtk.Widget.show() and Gtk.Widget.hide() while Gtk.Popover.popup() and Gtk.Popover.popdown() will use transitions.