enaml.application

Functions

deferred_call Invoke a callable on the next cycle of the main event loop thread.
is_main_thread Indicates whether the caller is on the main gui thread.
schedule Schedule a callable to be executed on the event loop thread.
timed_call Invoke a callable on the main event loop thread at a specified time in the future.

Classes

Application The application object which manages the top-level communication protocol for serving Enaml views.
ProxyResolver An object which resolves requests for proxy objects.
ScheduledTask An object representing a task in the scheduler.
enaml.application.deferred_call(callback, *args, **kwargs)[source]

Invoke a callable on the next cycle of the main event loop thread.

This is a convenience function for invoking the same method on the current application instance. If an application instance does not exist, a RuntimeError will be raised.

Parameters:
  • callback (callable) – The callable object to execute at some point in the future.
  • kwargs (args,) – Any additional positional and keyword arguments to pass to the callback.
enaml.application.is_main_thread()[source]

Indicates whether the caller is on the main gui thread.

This is a convenience function for invoking the same method on the current application instance. If an application instance does not exist, a RuntimeError will be raised.

Returns:result – True if called from the main gui thread. False otherwise.
Return type:bool
enaml.application.schedule(callback, args=None, kwargs=None, priority=0)[source]

Schedule a callable to be executed on the event loop thread.

This call is thread-safe.

This is a convenience function for invoking the same method on the current application instance. If an application instance does not exist, a RuntimeError will be raised.

Parameters:
  • callback (callable) – The callable object to be executed.
  • args (tuple, optional) – The positional arguments to pass to the callable.
  • kwargs (dict, optional) – The keyword arguments to pass to the callable.
  • priority (int, optional) – The queue priority for the callable. Smaller values indicate lower priority, larger values indicate higher priority. The default priority is zero.
Returns:

result – A task object which can be used to unschedule the task or retrieve the results of the callback after the task has been executed.

Return type:

ScheduledTask

enaml.application.timed_call(ms, callback, *args, **kwargs)[source]

Invoke a callable on the main event loop thread at a specified time in the future.

This is a convenience function for invoking the same method on the current application instance. If an application instance does not exist, a RuntimeError will be raised.

Parameters:
  • ms (int) – The time to delay, in milliseconds, before executing the callable.
  • callback (callable) – The callable object to execute at some point in the future.
  • kwargs (args,) – Any additional positional and keyword arguments to pass to the callback.
class enaml.application.Application[source]

Bases: atom.atom.Atom

The application object which manages the top-level communication protocol for serving Enaml views.

resolver

The proxy resolver to use for the application. This will normally be supplied by application subclasses, but can also be supplied by the developer to supply custom proxy resolution behavior.

style_sheet

The style sheet to apply to the entire application.

static instance()[source]

Get the global Application instance.

Returns:result – The global application instance, or None if one has not yet been created.
Return type:Application or None
static __new__(cls, *args, **kwargs)[source]

Create a new Enaml Application.

There may be only one application instance in existence at any point in time. Attempting to create a new Application when one exists will raise an exception.

start()[source]

Start the application’s main event loop.

stop()[source]

Stop the application’s main event loop.

deferred_call(callback, *args, **kwargs)[source]

Invoke a callable on the next cycle of the main event loop thread.

Parameters:
  • callback (callable) – The callable object to execute at some point in the future.
  • kwargs (args,) – Any additional positional and keyword arguments to pass to the callback.
timed_call(ms, callback, *args, **kwargs)[source]

Invoke a callable on the main event loop thread at a specified time in the future.

Parameters:
  • ms (int) – The time to delay, in milliseconds, before executing the callable.
  • callback (callable) – The callable object to execute at some point in the future.
  • kwargs (args,) – Any additional positional and keyword arguments to pass to the callback.
is_main_thread()[source]

Indicates whether the caller is on the main gui thread.

Returns:result – True if called from the main gui thread. False otherwise.
Return type:bool
create_mime_data()[source]

Create a new mime data object to be filled by the user.

Returns:result – A concrete implementation of the MimeData class.
Return type:MimeData
resolve_proxy_class(declaration_class)[source]

Resolve the proxy implementation class for a declaration.

This can be reimplemented by Application subclasses if more control is needed.

Parameters:declaration_class (type) – A ToolkitObject subclass for which the proxy implementation class should be resolved.
Returns:result – A ProxyToolkitObject subclass for the given class, or None if one could not be resolved.
Return type:type
create_proxy(declaration)[source]

Create the proxy object for the given declaration.

This can be reimplemented by Application subclasses if more control is needed.

Parameters:declaration (ToolkitObject) – The object for which a toolkit proxy should be created.
Returns:result – An appropriate toolkit proxy object, or None if one cannot be create for the given declaration object.
Return type:ProxyToolkitObject or None
schedule(callback, args=None, kwargs=None, priority=0)[source]

Schedule a callable to be executed on the event loop thread.

This call is thread-safe.

Parameters:
  • callback (callable) – The callable object to be executed.
  • args (tuple, optional) – The positional arguments to pass to the callable.
  • kwargs (dict, optional) – The keyword arguments to pass to the callable.
  • priority (int, optional) – The queue priority for the callable. Smaller values indicate lower priority, larger values indicate higher priority. The default priority is zero.
Returns:

result – A task object which can be used to unschedule the task or retrieve the results of the callback after the task has been executed.

Return type:

ScheduledTask

has_pending_tasks()[source]

Get whether or not the application has pending tasks.

Returns:result – True if there are pending tasks. False otherwise.
Return type:bool
destroy()[source]

Destroy this application instance.

Once an application is created, it must be destroyed before a new application can be instantiated.

class enaml.application.ProxyResolver[source]

Bases: atom.atom.Atom

An object which resolves requests for proxy objects.

factories

A dictionary of factories functions to use when resolving the proxy. The function should take no arguments, and return the proxy class when called.

resolve(name)[source]

Resolve the given name to a proxy calls.

For example, ‘Field’ should resolve to a class which implements the ProxyField interface.

Parameters:name (string) – The name of the proxy object to resolve.
Returns:result – A class which implements the proxy interface, or None if no class can be found for the given name.
Return type:type or None
class enaml.application.ScheduledTask(callback, args, kwargs)[source]

Bases: atom.atom.Atom

An object representing a task in the scheduler.

__init__(callback, args, kwargs)[source]

Initialize a ScheduledTask.

Parameters:
  • callback (callable) – The callable to run when the task is executed.
  • args (tuple) – The tuple of positional arguments to pass to the callback.
  • kwargs (dict) – The dict of keyword arguments to pass to the callback.
notify(callback)[source]

Set a callback to be run when the task is executed.

Parameters:callback (callable) – A callable which accepts a single argument which is the results of the task. It will be invoked immediate after the task is executed, on the main event loop thread.
pending()[source]

Returns True if this task is pending execution, False otherwise.

unschedule()[source]

Unschedule the task so that it will not be executed. If the task has already been executed, this call has no effect.

result()[source]

Returns the result of the task, or ScheduledTask.undefined if the task has not yet been executed, was unscheduled before execution, or raised an exception on execution.