Prompt

class Prompt(*args, **kwargs)

Implementations: SystemPrompt

A prompt displayed to the user. It is an interface with various implementations.

Various properties are set on the prompt, and then the prompt is displayed the various prompt methods like password_run.

A GcrPrompt may be used to display multiple related prompts. Most implementions do not hide the window between display of multiple related prompts, and the Prompt must be closed or destroyed in order to make it go away. This allows the user to see that the prompts are related.

Use GcrPromptDialog (part of gcr-ui) to create an in-process GTK+ dialog prompt. Use SystemPrompt to create a system prompt in a prompter process.

The prompt implementation will always display the message property, but may choose not to display the description or title properties.

Methods

class Prompt
close() None

Closes the prompt so that in can no longer be used to prompt. The various prompt methods will return results as if the user dismissed the prompt.

The prompt may also be closed by the implementor of the prompt object.

This emits the prompt_close signal on the prompt object.

confirm(cancellable: Cancellable | None = None) PromptReply

Prompts for confirmation asking a cancel/continue style question. Set the various properties on the prompt before calling this function to represent the question correctly.

This method will block until the a response is returned from the prompter.

CONTINUE will be returned if the user confirms the prompt. The return value will also be CANCEL if the user cancels or if an error occurs. Check the error argument to tell the difference.

Parameters:

cancellable – optional cancellation object

confirm_async(cancellable: Cancellable | None = None, callback: Callable[[...], None] | None = None, *user_data: Any) None

Prompts for confirmation asking a cancel/continue style question. Set the various properties on the prompt before calling this method to represent the question correctly.

This method will return immediately and complete asynchronously.

Parameters:
  • cancellable – optional cancellation object

  • callback – called when the operation completes

  • user_data – data to pass to the callback

confirm_finish(result: AsyncResult) PromptReply

Complete an operation to prompt for confirmation.

CONTINUE will be returned if the user confirms the prompt. The return value will also be CANCEL if the user cancels or if an error occurs. Check the error argument to tell the difference.

Parameters:

result – asynchronous result passed to callback

confirm_run(cancellable: Cancellable | None = None) PromptReply

Prompts for confirmation asking a cancel/continue style question. Set the various properties on the prompt before calling this function to represent the question correctly.

This method will block until the a response is returned from the prompter and will run a main loop similar to a gtk_dialog_run(). The application will remain responsive but care must be taken to handle reentrancy issues.

CONTINUE will be returned if the user confirms the prompt. The return value will also be CANCEL if the user cancels or if an error occurs. Check the error argument to tell the difference.

Parameters:

cancellable – optional cancellation object

get_caller_window() str

Get the string handle of the caller’s window.

The caller window indicates to the prompt which window is prompting the user. The prompt may choose to ignore this information or use it in whatever way it sees fit.

get_cancel_label() str

Get the label for the cancel button.

This is the button that results in a CANCEL reply from the prompt.

get_choice_chosen() bool

Get whether the additional choice was chosen or not.

The additional choice would have been setup using set_choice_label().

get_choice_label() str

Get the label for the additional choice.

This will be None if no additional choice is being displayed.

get_continue_label() str

Get the label for the continue button.

This is the button that results in a CONTINUE reply from the prompt.

get_description() str

Get the detailed description of the prompt.

A prompt implementation may choose not to display this detailed description. The prompt message should contain relevant information.

get_message() str

Gets the prompt message for the user.

A prompt implementation should always display this message.

get_password_new() bool

Get whether the prompt will prompt for a new password.

This will cause the prompt implementation to ask the user to confirm the password and/or display other relevant user interface for creating a new password.

get_password_strength() int

Get indication of the password strength.

Prompts will return a zero value if the password is empty, and a value greater than zero if the password has any characters.

This is only valid after a successful prompt for a password.

get_title() str

Gets the title of the prompt.

A prompt implementation may choose not to display the prompt title. The prompt message should contain relevant information.

get_warning() str

Get a prompt warning displayed on the prompt.

This is a warning like “The password is incorrect.” usually displayed to the user about a previous ‘unsuccessful’ prompt.

If this string is None then no warning is displayed.

password(cancellable: Cancellable | None = None) str

Prompts for password. Set the various properties on the prompt before calling this method to explain which password should be entered.

This method will block until the a response is returned from the prompter.

A password will be returned if the user enters a password successfully. The returned password is valid until the next time a method is called to display another prompt.

None will be returned if the user cancels or if an error occurs. Check the error argument to tell the difference.

Parameters:

cancellable – optional cancellation object

password_async(cancellable: Cancellable | None = None, callback: Callable[[...], None] | None = None, *user_data: Any) None

Prompts for password. Set the various properties on the prompt before calling this method to explain which password should be entered.

This method will return immediately and complete asynchronously.

Parameters:
  • cancellable – optional cancellation object

  • callback – called when the operation completes

  • user_data – data to pass to the callback

password_finish(result: AsyncResult) str

Complete an operation to prompt for a password.

A password will be returned if the user enters a password successfully. The returned password is valid until the next time a method is called to display another prompt.

None will be returned if the user cancels or if an error occurs. Check the error argument to tell the difference.

Parameters:

result – asynchronous result passed to callback

password_run(cancellable: Cancellable | None = None) str

Prompts for password. Set the various properties on the prompt before calling this method to explain which password should be entered.

This method will block until the a response is returned from the prompter and will run a main loop similar to a gtk_dialog_run(). The application will remain responsive but care must be taken to handle reentrancy issues.

A password will be returned if the user enters a password successfully. The returned password is valid until the next time a method is called to display another prompt.

None will be returned if the user cancels or if an error occurs. Check the error argument to tell the difference.

Parameters:

cancellable – optional cancellation object

reset() None

Reset the contents and properties of the prompt.

set_caller_window(window_id: str) None

Set the string handle of the caller’s window.

The caller window indicates to the prompt which window is prompting the user. The prompt may choose to ignore this information or use it in whatever way it sees fit.

Parameters:

window_id – the window id

set_cancel_label(cancel_label: str) None

Set the label for the continue button.

This is the button that results in a CANCEL reply from the prompt.

Parameters:

cancel_label – the label

set_choice_chosen(chosen: bool) None

Set whether the additional choice is chosen or not.

The additional choice should be set up using set_choice_label().

Parameters:

chosen – whether chosen

set_choice_label(choice_label: str | None = None) None

Set the label for the additional choice.

If this is a non-None value then an additional boolean choice will be displayed by the prompt allowing the user to select or deselect it.

The initial value of the choice can be set with the set_choice_label() method.

If this is None, then no additional choice is being displayed.

Parameters:

choice_label – the additional choice or None

set_continue_label(continue_label: str) None

Set the label for the continue button.

This is the button that results in a CONTINUE reply from the prompt.

Parameters:

continue_label – the label

set_description(description: str) None

Set the detailed description of the prompt.

A prompt implementation may choose not to display this detailed description. Use set_message() to set a general message containing relevant information.

Parameters:

description – the detailed description

set_message(message: str) None

Sets the prompt message for the user.

A prompt implementation should always display this message.

Parameters:

message – the prompt message

set_password_new(new_password: bool) None

Set whether the prompt will prompt for a new password.

This will cause the prompt implementation to ask the user to confirm the password and/or display other relevant user interface for creating a new password.

Parameters:

new_password – whether in new password mode or not

set_title(title: str) None

Sets the title of the prompt.

A prompt implementation may choose not to display the prompt title. The prompt message should contain relevant information.

Parameters:

title – the prompt title

set_warning(warning: str | None = None) None

Set a prompt warning displayed on the prompt.

This is a warning like “The password is incorrect.” usually displayed to the user about a previous ‘unsuccessful’ prompt.

If this string is None then no warning is displayed.

Parameters:

warning – the warning or None

Properties

class Prompt
props.caller_window: str

The string handle of the caller’s window.

The caller window indicates to the prompt which window is prompting the user. The prompt may choose to ignore this information or use it in whatever way it sees fit.

In X11, this will be a stringified version of the XWindow handle; in Wayland this is the result of an export using the XDG foreign protocol.

props.cancel_label: str

The label for the cancel button in the prompt.

props.choice_chosen: bool

Whether the additional choice is chosen or not.

The additional choice would have been setup using Prompt:choice-label.

props.choice_label: str

The label for the additional choice.

If this is a non-None value then an additional boolean choice will be displayed by the prompt allowing the user to select or deselect it.

If None, then no additional choice is displayed.

The initial value of the choice can be set with Prompt:choice-chosen.

props.continue_label: str

The label for the continue button in the prompt.

props.description: str

The detailed description of the prompt.

A prompt implementation may choose not to display this detailed description. The prompt message should contain relevant information.

props.message: str

The prompt message for the user.

A prompt implementation should always display this message.

props.password_new: bool

Whether the prompt will prompt for a new password.

This will cause the prompt implementation to ask the user to confirm the password and/or display other relevant user interface for creating a new password.

props.password_strength: int

Indication of the password strength.

Prompts will return a zero value if the password is empty, and a value greater than zero if the password has any characters.

This is only valid after a successful prompt for a password.

props.title: str

The title of the prompt.

A prompt implementation may choose not to display the prompt title. The Prompt:message should contain relevant information.

props.warning: str

A prompt warning displayed on the prompt, or None for no warning.

This is a warning like “The password is incorrect.” usually displayed to the user about a previous ‘unsuccessful’ prompt.

Signals

class Prompt.signals
prompt_close() None

Action signal fired when the prompt is to be closed. After the default handler has run, the prompt is closed. The various prompting methods will return results as if the user dismissed the prompt.

You can use the close method to emit this signal.

Virtual Methods

class Prompt
do_prompt_close() None
do_prompt_confirm_async(cancellable: Cancellable | None = None, callback: Callable[[...], None] | None = None, *user_data: Any) None

Prompts for confirmation asking a cancel/continue style question. Set the various properties on the prompt before calling this method to represent the question correctly.

This method will return immediately and complete asynchronously.

Parameters:
  • cancellable – optional cancellation object

  • callback – called when the operation completes

  • user_data – data to pass to the callback

do_prompt_confirm_finish(result: AsyncResult) PromptReply

Complete an operation to prompt for confirmation.

CONTINUE will be returned if the user confirms the prompt. The return value will also be CANCEL if the user cancels or if an error occurs. Check the error argument to tell the difference.

Parameters:

result – asynchronous result passed to callback

do_prompt_password_async(cancellable: Cancellable | None = None, callback: Callable[[...], None] | None = None, *user_data: Any) None

Prompts for password. Set the various properties on the prompt before calling this method to explain which password should be entered.

This method will return immediately and complete asynchronously.

Parameters:
  • cancellable – optional cancellation object

  • callback – called when the operation completes

  • user_data – data to pass to the callback

do_prompt_password_finish(result: AsyncResult) str

Complete an operation to prompt for a password.

A password will be returned if the user enters a password successfully. The returned password is valid until the next time a method is called to display another prompt.

None will be returned if the user cancels or if an error occurs. Check the error argument to tell the difference.

Parameters:

result – asynchronous result passed to callback