diff --git a/force_bdss/notification_listeners/base_notification_listener_factory.py b/force_bdss/notification_listeners/base_notification_listener_factory.py index 0dfff5b74220f50c54b134c8f45cd77f19c4e203..5ebff3b92fd07219afae2890175ef018e347393c 100644 --- a/force_bdss/notification_listeners/base_notification_listener_factory.py +++ b/force_bdss/notification_listeners/base_notification_listener_factory.py @@ -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 diff --git a/force_bdss/notification_listeners/base_ui_hook_manager.py b/force_bdss/notification_listeners/base_ui_hook_manager.py deleted file mode 100644 index 52e9c47af639eca2fd468658e8633b07a680f89e..0000000000000000000000000000000000000000 --- a/force_bdss/notification_listeners/base_ui_hook_manager.py +++ /dev/null @@ -1,18 +0,0 @@ -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. - """ diff --git a/force_bdss/ui_hooks/__init__.py b/force_bdss/ui_hooks/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/force_bdss/ui_hooks/base_ui_hook_manager.py b/force_bdss/ui_hooks/base_ui_hook_manager.py new file mode 100644 index 0000000000000000000000000000000000000000..5429fa7fab8454769c491b8abb95a7246d8003b7 --- /dev/null +++ b/force_bdss/ui_hooks/base_ui_hook_manager.py @@ -0,0 +1,44 @@ +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 + """ diff --git a/force_bdss/ui_hooks/base_ui_hooks_factory.py b/force_bdss/ui_hooks/base_ui_hooks_factory.py new file mode 100644 index 0000000000000000000000000000000000000000..e9b129527f00d3d35b6eee21b459c2b05c5fda51 --- /dev/null +++ b/force_bdss/ui_hooks/base_ui_hooks_factory.py @@ -0,0 +1,44 @@ +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 + """ diff --git a/force_bdss/ui_hooks/i_ui_hooks_factory.py b/force_bdss/ui_hooks/i_ui_hooks_factory.py new file mode 100644 index 0000000000000000000000000000000000000000..dc60ae017a6ab24d6d5e20891eea33e59a2e0f41 --- /dev/null +++ b/force_bdss/ui_hooks/i_ui_hooks_factory.py @@ -0,0 +1,18 @@ +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): + """"""