Skip to content
Snippets Groups Projects

Introduces base class and interface for the factories

Merged Adham Hashibon requested to merge 49-base-class-for-factory into master
1 file
+ 0
2
Compare changes
  • Side-by-side
  • Inline
import logging
from traits.api import (
HasStrictTraits, Instance, Str, provides, Type, Bool
provides, Type, Bool
)
from envisage.plugin import Plugin
from force_bdss.ids import factory_id
from force_bdss.core.base_factory import BaseFactory
from force_bdss.notification_listeners.base_notification_listener import \
BaseNotificationListener
from force_bdss.notification_listeners.base_notification_listener_model \
@@ -16,17 +14,11 @@ log = logging.getLogger(__name__)
@provides(INotificationListenerFactory)
class BaseNotificationListenerFactory(HasStrictTraits):
class BaseNotificationListenerFactory(BaseFactory):
"""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 = Str()
#: Name of the factory. User friendly for UI
name = Str()
#: If the factor should be visible in the UI. Set to false to make it
#: invisible. This is normally useful for notification systems that are
#: not supposed to be configured by the user.
@@ -40,9 +32,6 @@ class BaseNotificationListenerFactory(HasStrictTraits):
#: listener model class.
model_class = Type(BaseNotificationListenerModel, allow_none=False)
#: A reference to the containing plugin
plugin = Instance(Plugin, allow_none=False)
def __init__(self, plugin, *args, **kwargs):
"""Initializes the instance.
@@ -51,25 +40,11 @@ class BaseNotificationListenerFactory(HasStrictTraits):
plugin: Plugin
The plugin that holds this factory.
"""
self.plugin = plugin
super(BaseNotificationListenerFactory, self).__init__(*args, **kwargs)
super(BaseNotificationListenerFactory, self).__init__(
plugin=plugin, *args, **kwargs)
self.listener_class = self.get_listener_class()
self.model_class = self.get_model_class()
self.name = self.get_name()
identifier = self.get_identifier()
try:
id = factory_id(self.plugin.id, identifier)
except ValueError:
raise ValueError(
"Invalid identifier {} returned by "
"{}.get_identifier()".format(
identifier,
self.__class__.__name__
)
)
self.id = id
def get_listener_class(self):
raise NotImplementedError(
@@ -81,16 +56,6 @@ class BaseNotificationListenerFactory(HasStrictTraits):
"get_model_class was not implemented in factory {}".format(
self.__class__))
def get_identifier(self):
raise NotImplementedError(
"get_identifier was not implemented in factory {}".format(
self.__class__))
def get_name(self):
raise NotImplementedError(
"get_name was not implemented in factory {}".format(
self.__class__))
def create_listener(self):
"""
Creates an instance of the listener.
Loading