pyface.application module

This module defines the Application class for Pyface, Tasks and similar applications. Although the primary use cases are for GUI applications, the Application class does not have any explicit dependency on GUI code, and can be used for CLI or server applications.

Usual usage is to subclass Application, overriding at least the Application._run() method, but usually the Application.start() and Application.stop() methods as well.

However the class can be used as-is by listening to the Application.application_initialized event and performing appropriate work there:

def do_work(event):
    print("Hello world")

app = Application()
app.observe(do_work, 'application_initialized')
exception pyface.application.ApplicationException[source]

Bases: Exception

Exception subclass for Application-centric exceptions

exception pyface.application.ApplicationExit[source]

Bases: ApplicationException

Exception which indicates application should try to exit.

If no arguments, then assumed to be a normal exit, otherwise the arguments give information about the problem.

class pyface.application.ApplicationEvent[source]

Bases: HasStrictTraits

An event associated with an application

application = ReadOnly

The application that the event happened to.

event_type = ReadOnly

The type of application event.

class pyface.application.Application[source]

Bases: HasStrictTraits

A base class for applications.

This class handles the basic lifecycle of an application and a few fundamental facilities. It is suitable as a base for any application, not just GUI applications.

name = Str("Pyface Application")

Human-readable application name

company = Str()

Human-readable company name

description = Str()

Human-readable description of the application

id = Str()

The application’s globally unique identifier.

home = Directory()

Application home directory (for preferences, logging, etc.)

user_data = Directory()

User data directory (for user files, projects, etc)

starting = Event(Instance(ApplicationEvent))

Fired when the application is starting. Called immediately before the start method is run.

started = Event(Instance(ApplicationEvent))

Upon successful completion of the start method.

application_initialized = Event(Instance(ApplicationEvent))

Fired after the GUI event loop has been started during the run method.

exiting = VetoableEvent()

Fired when the application is starting. Called immediately before the stop method is run.

stopping = Event(Instance(ApplicationEvent))

Fired when the application is starting. Called immediately before the stop method is run.

stopped = Event(Instance(ApplicationEvent))

Upon successful completion of the stop method.

start()[source]

Start the application, setting up things that are required

Subclasses should call the superclass start() method before doing any work themselves.

stop()[source]

Stop the application, cleanly releasing resources if possible.

Subclasses should call the superclass stop() method after doing any work themselves.

run()[source]

Run the application.

Returns

status – Whether or not the application ran normally

Return type

bool

exit(force=False)[source]

Exits the application.

This method handles a request to shut down the application by the user, eg. from a menu. If force is False, the application can potentially veto the close event, leaving the application in the state that it was before the exit method was called.

Parameters

force (bool, optional (default False)) – If set, windows will receive no closing events and will be destroyed unconditionally. This can be useful for reliably tearing down regression tests, but should be used with caution.

Raises

ApplicationExit – Some subclasses may trigger the exit by raising ApplicationExit.

initialize_application_home()[source]

Set up the home directory for the application

This is where logs, preference files and other config files will be stored.