App

The App class is the heart of Simpleline. It holds the event loop instance and scheduler which are used by Simpleline. Both can be replaced if needed in the initialization phase by calling the App.initialize() method. However, by replacing the scheduler you are replacing most of the logic in Simpleline. Replacing the scheduler is not supported, since it is currently not a part of the public API.

All Simpleline applications must be run by the App.run() method. This method will start the event loop instance created in the initialization process.

If a reaction on application quit is required, please set set_quit_callback in the used event loop. This can be done by:

loop = App.get_event_loop()
loop.set_quit_callback(callback_function)

Do not instantiate the App class! It is designed to be used in a purely static way.

Application configuration

Configuration of the application is saved in the GlobalConfiguration class. This class can be created before App.initialize() is called and passed in as a parameter. This way the same configuration can be used between re-initialization of the application. The configuration can easily be changed, even while an application is running, by setting desired properties.

Look at the GlobalConfiguration to find out all the configuration possibilities.

App class

class simpleline.App

This is the main class for Simpleline library.

Do not create instance of this class. Use this class as static! The initialize() method must be called before use.

It is giving you access to the scheduler and event loop. You can have only one instance of this class in your application.

To create this instance call App.initialize() method. This method can also be used to reset settings in the App class to start with new event loop or scheduler.

classmethod get_configuration()

Get application defaults configuration object.

classmethod get_event_loop()

Get instance of class responsible for processing asynchronous events.

classmethod get_scheduler()

Get instance of class responsible for rendering of the screen.

classmethod initialize(scheduler=None, event_loop=None, global_configuration=None)

Create app instance inside of this class.

This method can be called multiple times to reset App settings.

Parameters:
  • scheduler (instance of simpleline.render.screen_scheduler.ScreenScheduler.) – scheduler used for rendering screens; if not specified use simpleline.render.screen_scheduler.ScreenScheduler.
  • event_loop (object based on class simpleline.event_loop.AbstractEventLoop.) – event loop used for asynchronous tasks; if not specified use simpleline.event_loop.main_loop.MainLoop.
  • global_configuration (object based on class simpleline.global_configuration.GlobalConfiguration) – instance of the global configuration object; if not specified use simpleline.global_configuration.GlobalConfiguration
classmethod is_initialized()

Is the App already initialized?

Returns:True if the App.initialized() method was called, False otherwise.
classmethod run()

Run event loop.

Raise an exception if no screen is scheduled. This behavior can be changed by should_run_with_empty_stack global configuration option.

This is shortcut to App.event_loop().run(). :raises NothingScheduledError: when there is no screen scheduled

GlobalConfiguration class

class simpleline.global_configuration.GlobalConfiguration

Class for global configuration of application defaults.

All stored data are persistent between App.initialize() calls and can be used before this call.

clear_password_function()

Clear user defined password function and set the default.

Default: getpass.getpass function

clear_should_run_with_empty_stack()

Clear user defined test to run with an empty screen stack.

Default: False

clear_width()

Clear user defined width and set the default.

Default: 80 characters

password_function

Get function to get user passwords from a console.

Returns:Function with one argument which is text representation of prompt.
should_run_with_empty_stack

Should test on empty screen stack when starting event loop.

Returns:If False the App.run() call will end with an exception (default), True otherwise.
width

Get width of the application.

Returns:int