# 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)

  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.

    - args – Any additional positional and keyword arguments to pass to the callback.

    - kwargs – Any additional positional and keyword arguments to pass to the callback.

enaml.application.is_main_thread()

  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)

  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)

  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.

    - args – Any additional positional and keyword arguments to pass to the callback.

    - kwargs – Any additional positional and keyword arguments to pass to the callback.

class enaml.application.Application(*args, **kwargs)

  Bases: `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()

    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)

    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()

    Start the application’s main event loop.

  stop()

    Stop the application’s main event loop.

  deferred_call(callback, *args, **kwargs)

    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.

      - args – Any additional positional and keyword arguments to pass to the callback.

      - kwargs – Any additional positional and keyword arguments to pass to the callback.

  timed_call(ms, callback, *args, **kwargs)

    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.

      - args – Any additional positional and keyword arguments to pass to the callback.

      - kwargs – Any additional positional and keyword arguments to pass to the callback.

  is_main_thread()

    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()

    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)

    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)

    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)

    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()

    Get whether or not the application has pending tasks.

    Returns:

      result – True if there are pending tasks. False otherwise.

    Return type:

      bool

  destroy()

    Destroy this application instance.

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

class enaml.application.ProxyResolver

  Bases: `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)

    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)

  Bases: `Atom`

  An object representing a task in the scheduler.

  __init__(callback, args, kwargs)

    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)

    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()

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

  unschedule()

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

  result()

    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.