Skip to content
Snippets Groups Projects
Commit 5a894eff authored by Stefano Borini's avatar Stefano Borini
Browse files

Introduced UIHooksFactory

parent 689ee0a1
No related branches found
No related tags found
1 merge request!93UI Hooks
......@@ -49,9 +49,11 @@ class BaseNotificationListenerFactory(ABCHasStrictTraits):
Data to use to fill the model.
"""
@abc.abstractmethod
def create_ui_hook_manager(self):
"""Creates an instance of the hook manager
The hook manager contains a set of methods that are applicable in
various moments of the UI application lifetime.
By default, it returns None, meaning that no hook managers are
installed, and no action will take place.
"""
return None
import abc
from traits.api import ABCHasStrictTraits
class BaseUIHookManager(ABCHasStrictTraits):
@abc.abstractmethod
def before_execution(self, application, model):
"""Hook that is called before execution of a given model.
Gives a chance to alter the model before the temporary file is created
with its contents and the calculation invoked.
"""
@abc.abstractmethod
def before_save(self, application, model):
"""Hook that is called just before saving a given model to disk
in response to a user action. This does not apply to saving of
temporary files before execution.
"""
import abc
from traits.api import ABCHasStrictTraits, Instance
from .i_ui_hooks_factory import IUIHooksFactory
class BaseUIHookManager(ABCHasStrictTraits):
#: A reference to the factory
factory = Instance(IUIHooksFactory)
def __init__(self, factory, *args, **kwargs):
"""Initializes the notification listener.
Parameters
----------
factory: BaseNotificationListener
The factory this Notification Listener belongs to
"""
self.factory = factory
super(BaseUIHookManager, self).__init__(*args, **kwargs)
@abc.abstractmethod
def before_execution(self, task):
"""Hook that is called before execution of a given evaluation.
Gives a chance to perform operations before the temporary file is
created with its contents and the calculation invoked.
Parameters
----------
task:
The pyface envisage task.
"""
@abc.abstractmethod
def before_save(self, task):
"""Hook that is called just before saving a given model to disk
in response to a user action. This does not apply to saving of
temporary files before execution.
Parameters
----------
task:
The pyface envisage task
"""
import abc
from traits.api import ABCHasStrictTraits, Instance, String, provides
from envisage.plugin import Plugin
from .i_ui_hooks_factory import IUIHooksFactory
@provides(IUIHooksFactory)
class BaseUIHooksFactory(ABCHasStrictTraits):
"""Base class for notification listeners.
Notification listeners are extensions that receive event notifications
from the MCO and perform an associated action.
"""
#: identifier of the factory
id = String()
#: Name of the factory. User friendly for UI
name = String()
#: A reference to the containing plugin
plugin = Instance(Plugin)
def __init__(self, plugin, *args, **kwargs):
"""Initializes the instance.
Parameters
----------
plugin: Plugin
The plugin that holds this factory.
"""
self.plugin = plugin
super(BaseUIHooksFactory, self).__init__(*args, **kwargs)
@abc.abstractmethod
def create_ui_hook_manager(self):
"""Creates an instance of the hook manager
The hook manager contains a set of methods that are applicable in
various moments of the UI application lifetime.
Returns
-------
BaseUIHookManager
"""
from traits.api import Interface, String, Instance
from envisage.plugin import Plugin
class IUIHooksFactory(Interface):
"""Envisage required interface for the BaseUIHooksFactory.
You should not need to use this directly.
Refer to the BaseUIHooksFactory for documentation.
"""
id = String()
name = String()
plugin = Instance(Plugin)
def create_hook_manager(self):
""""""
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment