Skip to content

Gtk.NativeDialog

class — extends GObject.Object

Base class for platform dialogs that don't use GtkDialog.

Native dialogs are used in order to integrate better with a platform, by looking the same as other native applications and supporting platform specific features.

The Dialog functions cannot be used on such objects, but we need a similar API in order to drive them. The GtkNativeDialog object is an API that allows you to do this. It allows you to set various common properties on the dialog, as well as show and hide it and get a NativeDialog.response signal when the user finished with the dialog.

Note that unlike GtkDialog, GtkNativeDialog objects are not toplevel widgets, and GTK does not keep them alive. It is your responsibility to keep a reference until you are done with the object.

Methods

destroy

def destroy(self) -> None

Destroys a dialog.

When a dialog is destroyed, it will break any references it holds to other objects.

If it is visible it will be hidden and any underlying window system resources will be destroyed.

Note that this does not release any reference to the object (as opposed to destroying a GtkWindow) because there is no reference from the windowing system to the GtkNativeDialog.

get_modal

def get_modal(self) -> bool

Returns whether the dialog is modal.

get_title

def get_title(self) -> str | None

Gets the title of the GtkNativeDialog.

get_transient_for

def get_transient_for(self) -> Window | None

Fetches the transient parent for this window.

get_visible

def get_visible(self) -> bool

Determines whether the dialog is visible.

hide

def hide(self) -> None

Hides the dialog if it is visible, aborting any interaction.

Once this is called the NativeDialog.response signal will not be emitted until after the next call to NativeDialog.show.

If the dialog is not visible this does nothing.

set_modal

def set_modal(self, modal: bool) -> None

Sets a dialog modal or non-modal.

Modal dialogs prevent interaction with other windows in the same application. To keep modal dialogs on top of main application windows, use NativeDialog.set_transient_for to make the dialog transient for the parent; most window managers will then disallow lowering the dialog below the parent.

Parameters:

  • modal — whether the window is modal

set_title

def set_title(self, title: str) -> None

Sets the title of the GtkNativeDialog.

Parameters:

  • title — title of the dialog

set_transient_for

def set_transient_for(self, parent: Window | None = ...) -> None

Dialog windows should be set transient for the main application window they were spawned from.

This allows window managers to e.g. keep the dialog on top of the main window, or center the dialog over the main window.

Passing None for parent unsets the current transient window.

Parameters:

  • parent — parent window

show

def show(self) -> None

Shows the dialog on the display.

When the user accepts the state of the dialog the dialog will be automatically hidden and the NativeDialog.response signal will be emitted.

Multiple calls while the dialog is visible will be ignored.

Virtual methods

do_hide

def do_hide(self) -> None

Hides the dialog if it is visible, aborting any interaction.

Once this is called the NativeDialog.response signal will not be emitted until after the next call to NativeDialog.show.

If the dialog is not visible this does nothing.

do_response

def do_response(self, response_id: int) -> None

class handler for the GtkNativeDialog::response signal

do_show

def do_show(self) -> None

Shows the dialog on the display.

When the user accepts the state of the dialog the dialog will be automatically hidden and the NativeDialog.response signal will be emitted.

Multiple calls while the dialog is visible will be ignored.

Properties

modal

modal: bool  # read/write

Whether the window should be modal with respect to its transient parent.

title

title: str  # read/write

The title of the dialog window

transient_for

transient_for: Window  # read/write

The transient parent of the dialog, or None for none.

visible

visible: bool  # read/write

Whether the window is currently visible.

Signals

response

def on_response(self, response_id: int) -> None: ...

Emitted when the user responds to the dialog.

When this is called the dialog has been hidden.

If you call NativeDialog.hide before the user responds to the dialog this signal will not be emitted.