Gio.Application

g GObject.GInterface GObject.GInterface Gio.ActionGroup Gio.ActionGroup GObject.GInterface->Gio.ActionGroup Gio.ActionMap Gio.ActionMap GObject.GInterface->Gio.ActionMap GObject.Object GObject.Object Gio.Application Gio.Application GObject.Object->Gio.Application Gio.ActionGroup->Gio.Application Gio.ActionMap->Gio.Application

Subclasses:None

Methods

Inherited:GObject.Object (37), Gio.ActionGroup (14), Gio.ActionMap (4)
Structs:GObject.ObjectClass (5)
class get_default ()
class id_is_valid (application_id)
class new (application_id, flags)
  activate ()
  add_main_option (long_name, short_name, flags, arg, description, arg_description)
  add_main_option_entries (entries)
  add_option_group (group)
  bind_busy_property (object, property)
  get_application_id ()
  get_dbus_connection ()
  get_dbus_object_path ()
  get_flags ()
  get_inactivity_timeout ()
  get_is_busy ()
  get_is_registered ()
  get_is_remote ()
  get_resource_base_path ()
  hold ()
  mark_busy ()
  open (files, hint)
  quit ()
  register (cancellable)
  release ()
  run (argv)
  send_notification (id, notification)
  set_action_group (action_group)
  set_application_id (application_id)
  set_default ()
  set_flags (flags)
  set_inactivity_timeout (inactivity_timeout)
  set_option_context_description (description)
  set_option_context_parameter_string (parameter_string)
  set_option_context_summary (summary)
  set_resource_base_path (resource_path)
  unbind_busy_property (object, property)
  unmark_busy ()
  withdraw_notification (id)

Virtual Methods

Inherited:GObject.Object (7), Gio.ActionGroup (14), Gio.ActionMap (3)
  do_activate ()
  do_add_platform_data (builder)
  do_after_emit (platform_data)
  do_before_emit (platform_data)
  do_command_line (command_line)
  do_dbus_register (connection, object_path)
  do_dbus_unregister (connection, object_path)
  do_handle_local_options (options)
  do_local_command_line (arguments)
  do_open (files, hint)
  do_quit_mainloop ()
  do_run_mainloop ()
  do_shutdown ()
  do_startup ()

Properties

Name Type Flags Short Description
action-group Gio.ActionGroup d/w The group of actions that the application exports deprecated
application-id str r/w/c The unique identifier for the application
flags Gio.ApplicationFlags r/w Flags specifying the behaviour of the application
inactivity-timeout int r/w Time (ms) to stay alive after becoming idle
is-busy bool r If this application is currently marked busy
is-registered bool r If Gio.Application.register() has been called
is-remote bool r If this application instance is remote
resource-base-path str r/w The base resource path for the application

Signals

Inherited:GObject.Object (1), Gio.ActionGroup (4)
Name Short Description
activate The ::activate signal is emitted on the primary instance when an activation occurs.
command-line The ::command-line signal is emitted on the primary instance when a commandline is not handled locally.
handle-local-options The ::handle-local-options signal is emitted on the local instance after the parsing of the commandline options has occurred.
open The ::open signal is emitted on the primary instance when there are files to open.
shutdown The ::shutdown signal is emitted only on the registered primary instance immediately after the main loop terminates.
startup The ::startup signal is emitted on the primary instance immediately after registration.

Fields

Inherited:GObject.Object (1), Gio.ActionGroup (4)
Name Type Access Description
parent_instance GObject.Object r  

Class Details

class Gio.Application(**kwargs)
Bases:GObject.Object, Gio.ActionGroup, Gio.ActionMap
Abstract:No
Structure:Gio.ApplicationClass

A Gio.Application is the foundation of an application. It wraps some low-level platform-specific services and is intended to act as the foundation for higher-level application classes such as #GtkApplication or #MxApplication. In general, you should not use this class outside of a higher level framework.

Gio.Application provides convenient life cycle management by maintaining a “use count” for the primary application instance. The use count can be changed using Gio.Application.hold() and Gio.Application.release(). If it drops to zero, the application exits. Higher-level classes such as #GtkApplication employ the use count to ensure that the application stays alive as long as it has any opened windows.

Another feature that Gio.Application (optionally) provides is process uniqueness. Applications can make use of this functionality by providing a unique application ID. If given, only one application with this ID can be running at a time per session. The session concept is platform-dependent, but corresponds roughly to a graphical desktop login. When your application is launched again, its arguments are passed through platform communication to the already running program. The already running instance of the program is called the “primary instance”; for non-unique applications this is the always the current instance. On Linux, the D-Bus session bus is used for communication.

The use of Gio.Application differs from some other commonly-used uniqueness libraries (such as libunique) in important ways. The application is not expected to manually register itself and check if it is the primary instance. Instead, the main() function of a Gio.Application should do very little more than instantiating the application instance, possibly connecting signal handlers, then calling Gio.Application.run(). All checks for uniqueness are done internally. If the application is the primary instance then the startup signal is emitted and the mainloop runs. If the application is not the primary instance then a signal is sent to the primary instance and Gio.Application.run() promptly returns. See the code examples below.

If used, the expected form of an application identifier is the same as that of of a D-Bus well-known bus name. Examples include: com.example.MyApp, org.example.internal_apps.Calculator, org._7_zip.Archiver. For details on valid application identifiers, see Gio.Application.id_is_valid().

On Linux, the application identifier is claimed as a well-known bus name on the user’s session bus. This means that the uniqueness of your application is scoped to the current session. It also means that your application may provide additional services (through registration of other object paths) at that bus name. The registration of these object paths should be done with the shared GDBus session bus. Note that due to the internal architecture of GDBus, method calls can be dispatched at any time (even if a main loop is not running). For this reason, you must ensure that any object paths that you wish to register are registered before Gio.Application attempts to acquire the bus name of your application (which happens in Gio.Application.register()). Unfortunately, this means that you cannot use Gio.Application.get_is_remote() to decide if you want to register object paths.

Gio.Application also implements the Gio.ActionGroup and Gio.ActionMap interfaces and lets you easily export actions by adding them with Gio.ActionMap.add_action(). When invoking an action by calling Gio.ActionGroup.activate_action() on the application, it is always invoked in the primary instance. The actions are also exported on the session bus, and GIO provides the Gio.DBusActionGroup wrapper to conveniently access them remotely. GIO provides a Gio.DBusMenuModel wrapper for remote access to exported Gio.MenuModels.

There is a number of different entry points into a Gio.Application:

  • via ‘Activate’ (i.e. just starting the application)
  • via ‘Open’ (i.e. opening some files)
  • by handling a command-line
  • via activating an action

The Gio.Application ::startup signal lets you handle the application initialization for all of these in a single place.

Regardless of which of these entry points is used to start the application, Gio.Application passes some “platform data from the launching instance to the primary instance, in the form of a GLib.Variant dictionary mapping strings to variants. To use platform data, override the before_emit or after_emit virtual functions in your Gio.Application subclass. When dealing with Gio.ApplicationCommandLine objects, the platform data is directly available via Gio.ApplicationCommandLine.get_cwd(), Gio.ApplicationCommandLine.get_environ() and Gio.ApplicationCommandLine.get_platform_data().

As the name indicates, the platform data may vary depending on the operating system, but it always includes the current directory (key “cwd”), and optionally the environment (ie the set of environment variables and their values) of the calling process (key “environ”). The environment is only added to the platform data if the Gio.ApplicationFlags.SEND_ENVIRONMENT flag is set. Gio.Application subclasses can add their own platform data by overriding the add_platform_data virtual function. For instance, #GtkApplication adds startup notification data in this way.

To parse commandline arguments you may handle the Gio.Application ::command-line signal or override the local_command_line() vfunc, to parse them in either the primary instance or the local instance, respectively.

For an example of opening files with a Gio.Application, see gapplication-example-open.c.

For an example of using actions with Gio.Application, see gapplication-example-actions.c.

For an example of using extra D-Bus hooks with Gio.Application, see gapplication-example-dbushooks.c.

New in version 2.28.

classmethod get_default()[source]
Returns:the default application for this process, or None
Return type:Gio.Application

Returns the default Gio.Application instance for this process.

Normally there is only one Gio.Application per process and it becomes the default when it is created. You can exercise more control over this by using Gio.Application.set_default().

If there is no default application then None is returned.

New in version 2.32.

classmethod id_is_valid(application_id)[source]
Parameters:application_id (str) – a potential application identifier
Returns:True if application_id is valid
Return type:bool

Checks if application_id is a valid application identifier.

A valid ID is required for calls to Gio.Application.new() and Gio.Application.set_application_id().

Application identifiers follow the same format as D-Bus well-known bus names. For convenience, the restrictions on application identifiers are reproduced here:

  • Application identifiers are composed of 1 or more elements separated by a period (.) character. All elements must contain at least one character.
  • Each element must only contain the ASCII characters [A-Z][a-z][0-9]_-, with - discouraged in new application identifiers. Each element must not begin with a digit.
  • Application identifiers must contain at least one . (period) character (and thus at least two elements).
  • Application identifiers must not begin with a . (period) character.
  • Application identifiers must not exceed 255 characters.

Note that the hyphen (-) character is allowed in application identifiers, but is problematic or not allowed in various specifications and APIs that refer to D-Bus, such as Flatpak application IDs, the DBusActivatable interface in the Desktop Entry Specification, and the convention that an application’s “main” interface and object path resemble its application identifier and bus name. To avoid situations that require special-case handling, it is recommended that new application identifiers consistently replace hyphens with underscores.

Like D-Bus interface names, application identifiers should start with the reversed DNS domain name of the author of the interface (in lower-case), and it is conventional for the rest of the application identifier to consist of words run together, with initial capital letters.

As with D-Bus interface names, if the author’s DNS domain name contains hyphen/minus characters they should be replaced by underscores, and if it contains leading digits they should be escaped by prepending an underscore. For example, if the owner of 7-zip.org used an application identifier for an archiving application, it might be named org._7_zip.Archiver.

classmethod new(application_id, flags)[source]
Parameters:
Returns:

a new Gio.Application instance

Return type:

Gio.Application

Creates a new Gio.Application instance.

If non-None, the application id must be valid. See Gio.Application.id_is_valid().

If no application ID is given then some features of Gio.Application (most notably application uniqueness) will be disabled.

activate()[source]

Activates the application.

In essence, this results in the Gio.Application ::activate signal being emitted in the primary instance.

The application must be registered before calling this function.

New in version 2.28.

add_main_option(long_name, short_name, flags, arg, description, arg_description)[source]
Parameters:
  • long_name (str) – the long name of an option used to specify it in a commandline
  • short_name (int) – the short name of an option
  • flags (GLib.OptionFlags) – flags from GLib.OptionFlags
  • arg (GLib.OptionArg) – the type of the option, as a GLib.OptionArg
  • description (str) – the description for the option in --help output
  • arg_description (str or None) – the placeholder to use for the extra argument parsed by the option in --help output

Add an option to be handled by self.

Calling this function is the equivalent of calling Gio.Application.add_main_option_entries() with a single GLib.OptionEntry that has its arg_data member set to None.

The parsed arguments will be packed into a GLib.VariantDict which is passed to Gio.Application ::handle-local-options. If Gio.ApplicationFlags.HANDLES_COMMAND_LINE is set, then it will also be sent to the primary instance. See Gio.Application.add_main_option_entries() for more details.

See GLib.OptionEntry for more documentation of the arguments.

New in version 2.42.

add_main_option_entries(entries)[source]
Parameters:entries ([GLib.OptionEntry]) – a None-terminated list of GLib.OptionEntrys

Adds main option entries to be handled by self.

This function is comparable to GLib.OptionContext.add_main_entries().

After the commandline arguments are parsed, the Gio.Application ::handle-local-options signal will be emitted. At this point, the application can inspect the values pointed to by arg_data in the given GLib.OptionEntrys.

Unlike GLib.OptionContext, Gio.Application supports giving a None arg_data for a non-callback GLib.OptionEntry. This results in the argument in question being packed into a GLib.VariantDict which is also passed to Gio.Application ::handle-local-options, where it can be inspected and modified. If Gio.ApplicationFlags.HANDLES_COMMAND_LINE is set, then the resulting dictionary is sent to the primary instance, where Gio.ApplicationCommandLine.get_options_dict() will return it. This “packing” is done according to the type of the argument – booleans for normal flags, strings for strings, bytestrings for filenames, etc. The packing only occurs if the flag is given (ie: we do not pack a “false” GLib.Variant in the case that a flag is missing).

In general, it is recommended that all commandline arguments are parsed locally. The options dictionary should then be used to transmit the result of the parsing to the primary instance, where g_variant_dict_lookup() can be used. For local options, it is possible to either use arg_data in the usual way, or to consult (and potentially remove) the option from the options dictionary.

This function is new in GLib 2.40. Before then, the only real choice was to send all of the commandline arguments (options and all) to the primary instance for handling. Gio.Application ignored them completely on the local side. Calling this function “opts in” to the new behaviour, and in particular, means that unrecognised options will be treated as errors. Unrecognised options have never been ignored when Gio.ApplicationFlags.HANDLES_COMMAND_LINE is unset.

If Gio.Application ::handle-local-options needs to see the list of filenames, then the use of GLib.OPTION_REMAINING is recommended. If arg_data is None then GLib.OPTION_REMAINING can be used as a key into the options dictionary. If you do use GLib.OPTION_REMAINING then you need to handle these arguments for yourself because once they are consumed, they will no longer be visible to the default handling (which treats them as filenames to be opened).

It is important to use the proper GLib.Variant format when retrieving the options with g_variant_dict_lookup():

New in version 2.40.

add_option_group(group)[source]
Parameters:group (GLib.OptionGroup) – a GLib.OptionGroup

Adds a GLib.OptionGroup to the commandline handling of self.

This function is comparable to GLib.OptionContext.add_group().

Unlike Gio.Application.add_main_option_entries(), this function does not deal with None arg_data and never transmits options to the primary instance.

The reason for that is because, by the time the options arrive at the primary instance, it is typically too late to do anything with them. Taking the GTK option group as an example: GTK will already have been initialised by the time the Gio.Application ::command-line handler runs. In the case that this is not the first-running instance of the application, the existing instance may already have been running for a very long time.

This means that the options from GLib.OptionGroup are only really usable in the case that the instance of the application being run is the first instance. Passing options like --display= or --gdk-debug= on future runs will have no effect on the existing primary instance.

Calling this function will cause the options in the supplied option group to be parsed, but it does not cause you to be “opted in” to the new functionality whereby unrecognised options are rejected even if Gio.ApplicationFlags.HANDLES_COMMAND_LINE was given.

New in version 2.40.

bind_busy_property(object, property)[source]
Parameters:

Marks self as busy (see Gio.Application.mark_busy()) while property on object is True.

The binding holds a reference to self while it is active, but not to object. Instead, the binding is destroyed when object is finalized.

New in version 2.44.

get_application_id()[source]
Returns:the identifier for self, owned by self
Return type:str

Gets the unique identifier for self.

New in version 2.28.

get_dbus_connection()[source]
Returns:a Gio.DBusConnection, or None
Return type:Gio.DBusConnection

Gets the Gio.DBusConnection being used by the application, or None.

If Gio.Application is using its D-Bus backend then this function will return the Gio.DBusConnection being used for uniqueness and communication with the desktop environment and other instances of the application.

If Gio.Application is not using D-Bus then this function will return None. This includes the situation where the D-Bus backend would normally be in use but we were unable to connect to the bus.

This function must not be called before the application has been registered. See Gio.Application.get_is_registered().

New in version 2.34.

get_dbus_object_path()[source]
Returns:the object path, or None
Return type:str

Gets the D-Bus object path being used by the application, or None.

If Gio.Application is using its D-Bus backend then this function will return the D-Bus object path that Gio.Application is using. If the application is the primary instance then there is an object published at this path. If the application is not the primary instance then the result of this function is undefined.

If Gio.Application is not using D-Bus then this function will return None. This includes the situation where the D-Bus backend would normally be in use but we were unable to connect to the bus.

This function must not be called before the application has been registered. See Gio.Application.get_is_registered().

New in version 2.34.

get_flags()[source]
Returns:the flags for self
Return type:Gio.ApplicationFlags

Gets the flags for self.

See Gio.ApplicationFlags.

New in version 2.28.

get_inactivity_timeout()[source]
Returns:the timeout, in milliseconds
Return type:int

Gets the current inactivity timeout for the application.

This is the amount of time (in milliseconds) after the last call to Gio.Application.release() before the application stops running.

New in version 2.28.

get_is_busy()[source]
Returns:True if self is currenty marked as busy
Return type:bool

Gets the application’s current busy state, as set through Gio.Application.mark_busy() or Gio.Application.bind_busy_property().

New in version 2.44.

get_is_registered()[source]
Returns:True if self is registered
Return type:bool

Checks if self is registered.

An application is registered if Gio.Application.register() has been successfully called.

New in version 2.28.

get_is_remote()[source]
Returns:True if self is remote
Return type:bool

Checks if self is remote.

If self is remote then it means that another instance of application already exists (the ‘primary’ instance). Calls to perform actions on self will result in the actions being performed by the primary instance.

The value of this property cannot be accessed before Gio.Application.register() has been called. See Gio.Application.get_is_registered().

New in version 2.28.

get_resource_base_path()[source]
Returns:the base resource path, if one is set
Return type:str or None

Gets the resource base path of self.

See Gio.Application.set_resource_base_path() for more information.

New in version 2.42.

hold()[source]

Increases the use count of self.

Use this function to indicate that the application has a reason to continue to run. For example, Gio.Application.hold() is called by GTK+ when a toplevel window is on the screen.

To cancel the hold, call Gio.Application.release().

mark_busy()[source]

Increases the busy count of self.

Use this function to indicate that the application is busy, for instance while a long running operation is pending.

The busy state will be exposed to other processes, so a session shell will use that information to indicate the state to the user (e.g. with a spinner).

To cancel the busy indication, use Gio.Application.unmark_busy().

New in version 2.38.

open(files, hint)[source]
Parameters:

Opens the given files.

In essence, this results in the Gio.Application ::open signal being emitted in the primary instance.

n_files must be greater than zero.

hint is simply passed through to the ::open signal. It is intended to be used by applications that have multiple modes for opening files (eg: “view” vs “edit”, etc). Unless you have a need for this functionality, you should use “”.

The application must be registered before calling this function and it must have the Gio.ApplicationFlags.HANDLES_OPEN flag set.

New in version 2.28.

quit()[source]

Immediately quits the application.

Upon return to the mainloop, Gio.Application.run() will return, calling only the ‘shutdown’ function before doing so.

The hold count is ignored. Take care if your code has called Gio.Application.hold() on the application and is therefore still expecting it to exist. (Note that you may have called Gio.Application.hold() indirectly, for example through gtk_application_add_window().)

The result of calling Gio.Application.run() again after it returns is unspecified.

New in version 2.32.

register(cancellable)[source]
Parameters:cancellable (Gio.Cancellable or None) – a Gio.Cancellable, or None
Raises:GLib.Error
Returns:True if registration succeeded
Return type:bool

Attempts registration of the application.

This is the point at which the application discovers if it is the primary instance or merely acting as a remote for an already-existing primary instance. This is implemented by attempting to acquire the application identifier as a unique bus name on the session bus using GDBus.

If there is no application ID or if Gio.ApplicationFlags.NON_UNIQUE was given, then this process will always become the primary instance.

Due to the internal architecture of GDBus, method calls can be dispatched at any time (even if a main loop is not running). For this reason, you must ensure that any object paths that you wish to register are registered before calling this function.

If the application has already been registered then True is returned with no work performed.

The Gio.Application ::startup signal is emitted if registration succeeds and self is the primary instance (including the non-unique case).

In the event of an error (such as cancellable being cancelled, or a failure to connect to the session bus), False is returned and error is set appropriately.

Note: the return value of this function is not an indicator that this instance is or is not the primary instance of the application. See Gio.Application.get_is_remote() for that.

New in version 2.28.

release()[source]

Decrease the use count of self.

When the use count reaches zero, the application will stop running.

Never call this function except to cancel the effect of a previous call to Gio.Application.hold().

run(argv)[source]
Parameters:argv ([str] or None) – the argv from main(), or None
Returns:the exit status
Return type:int

Runs the application.

This function is intended to be run from main() and its return value is intended to be returned by main(). Although you are expected to pass the argc, argv parameters from main() to this function, it is possible to pass None if argv is not available or commandline handling is not required. Note that on Windows, argc and argv are ignored, and g_win32_get_command_line() is called internally (for proper support of Unicode commandline arguments).

Gio.Application will attempt to parse the commandline arguments. You can add commandline flags to the list of recognised options by way of Gio.Application.add_main_option_entries(). After this, the Gio.Application ::handle-local-options signal is emitted, from which the application can inspect the values of its GLib.OptionEntrys.

Gio.Application ::handle-local-options is a good place to handle options such as --version, where an immediate reply from the local process is desired (instead of communicating with an already-running instance). A Gio.Application ::handle-local-options handler can stop further processing by returning a non-negative value, which then becomes the exit status of the process.

What happens next depends on the flags: if Gio.ApplicationFlags.HANDLES_COMMAND_LINE was specified then the remaining commandline arguments are sent to the primary instance, where a Gio.Application ::command-line signal is emitted. Otherwise, the remaining commandline arguments are assumed to be a list of files. If there are no files listed, the application is activated via the Gio.Application ::activate signal. If there are one or more files, and Gio.ApplicationFlags.HANDLES_OPEN was specified then the files are opened via the Gio.Application ::open signal.

If you are interested in doing more complicated local handling of the commandline then you should implement your own Gio.Application subclass and override local_command_line(). In this case, you most likely want to return True from your local_command_line() implementation to suppress the default handling. See ‘gapplication-example-cmdline2.c [gapplication-example-cmdline2]’ for an example.

If, after the above is done, the use count of the application is zero then the exit status is returned immediately. If the use count is non-zero then the default main context is iterated until the use count falls to zero, at which point 0 is returned.

If the Gio.ApplicationFlags.IS_SERVICE flag is set, then the service will run for as much as 10 seconds with a use count of zero while waiting for the message that caused the activation to arrive. After that, if the use count falls to zero the application will exit immediately, except in the case that Gio.Application.set_inactivity_timeout() is in use.

This function sets the prgname (GLib.set_prgname()), if not already set, to the basename of argv[0].

Much like GLib.MainLoop.run(), this function will acquire the main context for the duration that the application is running.

Since 2.40, applications that are not explicitly flagged as services or launchers (ie: neither Gio.ApplicationFlags.IS_SERVICE or Gio.ApplicationFlags.IS_LAUNCHER are given as flags) will check (from the default handler for local_command_line) if “–gapplication-service” was given in the command line. If this flag is present then normal commandline processing is interrupted and the Gio.ApplicationFlags.IS_SERVICE flag is set. This provides a “compromise” solution whereby running an application directly from the commandline will invoke it in the normal way (which can be useful for debugging) while still allowing applications to be D-Bus activated in service mode. The D-Bus service file should invoke the executable with “–gapplication-service” as the sole commandline argument. This approach is suitable for use by most graphical applications but should not be used from applications like editors that need precise control over when processes invoked via the commandline will exit and what their exit status will be.

New in version 2.28.

send_notification(id, notification)[source]
Parameters:

Sends a notification on behalf of self to the desktop shell. There is no guarantee that the notification is displayed immediately, or even at all.

Notifications may persist after the application exits. It will be D-Bus-activated when the notification or one of its actions is activated.

Modifying notification after this call has no effect. However, the object can be reused for a later call to this function.

id may be any string that uniquely identifies the event for the application. It does not need to be in any special format. For example, “new-message” might be appropriate for a notification about new messages.

If a previous notification was sent with the same id, it will be replaced with notification and shown again as if it was a new notification. This works even for notifications sent from a previous execution of the application, as long as id is the same string.

id may be None, but it is impossible to replace or withdraw notifications without an id.

If notification is no longer relevant, it can be withdrawn with Gio.Application.withdraw_notification().

New in version 2.40.

set_action_group(action_group)[source]
Parameters:action_group (Gio.ActionGroup or None) – a Gio.ActionGroup, or None

This used to be how actions were associated with a Gio.Application. Now there is Gio.ActionMap for that.

New in version 2.28.

Deprecated since version 2.32: Use the Gio.ActionMap interface instead. Never ever mix use of this API with use of Gio.ActionMap on the same application or things will go very badly wrong. This function is known to introduce buggy behaviour (ie: signals not emitted on changes to the action group), so you should really use Gio.ActionMap instead.

set_application_id(application_id)[source]
Parameters:application_id (str or None) – the identifier for self

Sets the unique identifier for self.

The application id can only be modified if self has not yet been registered.

If non-None, the application id must be valid. See Gio.Application.id_is_valid().

New in version 2.28.

set_default()[source]

Sets or unsets the default application for the process, as returned by Gio.Application.get_default().

This function does not take its own reference on self. If self is destroyed then the default application will revert back to None.

New in version 2.32.

set_flags(flags)[source]
Parameters:flags (Gio.ApplicationFlags) – the flags for self

Sets the flags for self.

The flags can only be modified if self has not yet been registered.

See Gio.ApplicationFlags.

New in version 2.28.

set_inactivity_timeout(inactivity_timeout)[source]
Parameters:inactivity_timeout (int) – the timeout, in milliseconds

Sets the current inactivity timeout for the application.

This is the amount of time (in milliseconds) after the last call to Gio.Application.release() before the application stops running.

This call has no side effects of its own. The value set here is only used for next time Gio.Application.release() drops the use count to zero. Any timeouts currently in progress are not impacted.

New in version 2.28.

set_option_context_description(description)[source]
Parameters:description (str or None) – a string to be shown in --help output after the list of options, or None

Adds a description to the self option context.

See GLib.OptionContext.set_description() for more information.

New in version 2.56.

set_option_context_parameter_string(parameter_string)[source]
Parameters:parameter_string (str or None) – a string which is displayed in the first line of --help output, after the usage summary programname [OPTION...].

Sets the parameter string to be used by the commandline handling of self.

This function registers the argument to be passed to g_option_context_new() when the internal GLib.OptionContext of self is created.

See g_option_context_new() for more information about parameter_string.

New in version 2.56.

set_option_context_summary(summary)[source]
Parameters:summary (str or None) – a string to be shown in --help output before the list of options, or None

Adds a summary to the self option context.

See GLib.OptionContext.set_summary() for more information.

New in version 2.56.

set_resource_base_path(resource_path)[source]
Parameters:resource_path (str or None) – the resource path to use

Sets (or unsets) the base resource path of self.

The path is used to automatically load various ‘application resources [gresource]’ such as menu layouts and action descriptions. The various types of resources will be found at fixed names relative to the given base path.

By default, the resource base path is determined from the application ID by prefixing ‘/’ and replacing each ‘.’ with ‘/’. This is done at the time that the Gio.Application object is constructed. Changes to the application ID after that point will not have an impact on the resource base path.

As an example, if the application has an ID of “org.example.app” then the default resource base path will be “/org/example/app”. If this is a #GtkApplication (and you have not manually changed the path) then Gtk will then search for the menus of the application at “/org/example/app/gtk/menus.ui”.

See Gio.Resource for more information about adding resources to your application.

You can disable automatic resource loading functionality by setting the path to None.

Changing the resource base path once the application is running is not recommended. The point at which the resource path is consulted for forming paths for various purposes is unspecified. When writing a sub-class of Gio.Application you should either set the Gio.Application :resource-base-path property at construction time, or call this function during the instance initialization. Alternatively, you can call this function in the Gio.ApplicationClass.startup virtual function, before chaining up to the parent implementation.

New in version 2.42.

unbind_busy_property(object, property)[source]
Parameters:

Destroys a binding between property and the busy state of self that was previously created with Gio.Application.bind_busy_property().

New in version 2.44.

unmark_busy()[source]

Decreases the busy count of self.

When the busy count reaches zero, the new state will be propagated to other processes.

This function must only be called to cancel the effect of a previous call to Gio.Application.mark_busy().

New in version 2.38.

withdraw_notification(id)[source]
Parameters:id (str) – id of a previously sent notification

Withdraws a notification that was sent with Gio.Application.send_notification().

This call does nothing if a notification with id doesn’t exist or the notification was never sent.

This function works even for notifications sent in previous executions of this application, as long id is the same as it was for the sent notification.

Note that notifications are dismissed when the user clicks on one of the buttons in a notification or triggers its default action, so there is no need to explicitly withdraw the notification in that case.

New in version 2.40.

do_activate() virtual

Activates the application.

In essence, this results in the Gio.Application ::activate signal being emitted in the primary instance.

The application must be registered before calling this function.

New in version 2.28.

do_add_platform_data(builder) virtual
Parameters:builder (GLib.VariantBuilder) –
do_after_emit(platform_data) virtual
Parameters:platform_data (GLib.Variant) –
do_before_emit(platform_data) virtual
Parameters:platform_data (GLib.Variant) –
do_command_line(command_line) virtual
Parameters:command_line (Gio.ApplicationCommandLine) –
Return type:int
do_dbus_register(connection, object_path) virtual
Parameters:
Return type:

bool

do_dbus_unregister(connection, object_path) virtual
Parameters:
do_handle_local_options(options) virtual
Parameters:options (GLib.VariantDict) –
Return type:int
do_local_command_line(arguments) virtual
Parameters:arguments ([str]) – array of command line arguments
Returns:True if the commandline has been completely handled
arguments:array of command line arguments
exit_status:exit status to fill after processing the command line.
Return type:(bool, arguments: [str], exit_status: int)

This virtual function is always invoked in the local instance. It gets passed a pointer to a None-terminated copy of argv and is expected to remove arguments that it handled (shifting up remaining arguments).

The last argument to local_command_line() is a pointer to the status variable which can used to set the exit status that is returned from Gio.Application.run().

See Gio.Application.run() for more details on Gio.Application startup.

do_open(files, hint) virtual
Parameters:

Opens the given files.

In essence, this results in the Gio.Application ::open signal being emitted in the primary instance.

n_files must be greater than zero.

hint is simply passed through to the ::open signal. It is intended to be used by applications that have multiple modes for opening files (eg: “view” vs “edit”, etc). Unless you have a need for this functionality, you should use “”.

The application must be registered before calling this function and it must have the Gio.ApplicationFlags.HANDLES_OPEN flag set.

New in version 2.28.

do_quit_mainloop() virtual
do_run_mainloop() virtual
do_shutdown() virtual
do_startup() virtual

Signal Details

Gio.Application.signals.activate(application)
Signal Name:activate
Flags:RUN_LAST
Parameters:application (Gio.Application) – The object which received the signal

The ::activate signal is emitted on the primary instance when an activation occurs. See Gio.Application.activate().

Gio.Application.signals.command_line(application, command_line)
Signal Name:

command-line

Flags:

RUN_LAST

Parameters:
Returns:

An integer that is set as the exit status for the calling process. See Gio.ApplicationCommandLine.set_exit_status().

Return type:

int

The ::command-line signal is emitted on the primary instance when a commandline is not handled locally. See Gio.Application.run() and the Gio.ApplicationCommandLine documentation for more information.

Gio.Application.signals.handle_local_options(application, options)
Signal Name:

handle-local-options

Flags:

RUN_LAST

Parameters:
Returns:

an exit code. If you have handled your options and want to exit the process, return a non-negative option, 0 for success, and a positive value for failure. To continue, return -1 to let the default option processing continue.

Return type:

int

The ::handle-local-options signal is emitted on the local instance after the parsing of the commandline options has occurred.

You can add options to be recognised during commandline option parsing using Gio.Application.add_main_option_entries() and Gio.Application.add_option_group().

Signal handlers can inspect options (along with values pointed to from the arg_data of an installed GLib.OptionEntrys) in order to decide to perform certain actions, including direct local handling (which may be useful for options like –version).

In the event that the application is marked Gio.ApplicationFlags.HANDLES_COMMAND_LINE the “normal processing” will send the options dictionary to the primary instance where it can be read with Gio.ApplicationCommandLine.get_options_dict(). The signal handler can modify the dictionary before returning, and the modified dictionary will be sent.

In the event that Gio.ApplicationFlags.HANDLES_COMMAND_LINE is not set, “normal processing” will treat the remaining uncollected command line arguments as filenames or URIs. If there are no arguments, the application is activated by Gio.Application.activate(). One or more arguments results in a call to Gio.Application.open().

If you want to handle the local commandline arguments for yourself by converting them to calls to Gio.Application.open() or Gio.ActionGroup.activate_action() then you must be sure to register the application first. You should probably not call Gio.Application.activate() for yourself, however: just return -1 and allow the default handler to do it for you. This will ensure that the --gapplication-service switch works properly (i.e. no activation in that case).

Note that this signal is emitted from the default implementation of local_command_line(). If you override that function and don’t chain up then this signal will never be emitted.

You can override local_command_line() if you need more powerful capabilities than what is provided here, but this should not normally be required.

New in version 2.40.

Gio.Application.signals.open(application, files, hint)
Signal Name:

open

Flags:

RUN_LAST

Parameters:

The ::open signal is emitted on the primary instance when there are files to open. See Gio.Application.open() for more information.

Gio.Application.signals.shutdown(application)
Signal Name:shutdown
Flags:RUN_LAST
Parameters:application (Gio.Application) – The object which received the signal

The ::shutdown signal is emitted only on the registered primary instance immediately after the main loop terminates.

Gio.Application.signals.startup(application)
Signal Name:startup
Flags:RUN_FIRST
Parameters:application (Gio.Application) – The object which received the signal

The ::startup signal is emitted on the primary instance immediately after registration. See Gio.Application.register().

Property Details

Gio.Application.props.action_group
Name:action-group
Type:Gio.ActionGroup
Default Value:None
Flags:DEPRECATED, WRITABLE

The group of actions that the application exports

Deprecated since version ???.

Gio.Application.props.application_id
Name:application-id
Type:str
Default Value:None
Flags:READABLE, WRITABLE, CONSTRUCT

The unique identifier for the application

Gio.Application.props.flags
Name:flags
Type:Gio.ApplicationFlags
Default Value:Gio.ApplicationFlags.FLAGS_NONE
Flags:READABLE, WRITABLE

Flags specifying the behaviour of the application

Gio.Application.props.inactivity_timeout
Name:inactivity-timeout
Type:int
Default Value:0
Flags:READABLE, WRITABLE

Time (ms) to stay alive after becoming idle

Gio.Application.props.is_busy
Name:is-busy
Type:bool
Default Value:False
Flags:READABLE

Whether the application is currently marked as busy through Gio.Application.mark_busy() or Gio.Application.bind_busy_property().

New in version 2.44.

Gio.Application.props.is_registered
Name:is-registered
Type:bool
Default Value:False
Flags:READABLE

If Gio.Application.register() has been called

Gio.Application.props.is_remote
Name:is-remote
Type:bool
Default Value:False
Flags:READABLE

If this application instance is remote

Gio.Application.props.resource_base_path
Name:resource-base-path
Type:str
Default Value:None
Flags:READABLE, WRITABLE

The base resource path for the application