示例#1
0
    def push_event(self, event):
        """Method invoked by the PyTango layer when an event occurs.
        It propagates the event to listeners and delegates other tasks to
        specific handlers for different event types.
        """
        # if it is a configuration event
        if isinstance(event, PyTango.AttrConfEventData):
            etype, evalue = self._pushConfEvent(event)
        # if it is an attribute event
        else:
            etype, evalue = self._pushAttrEvent(event)

        # notify the listeners if required (i.e, if etype is not None)
        if etype is None:
            return
        manager = Manager()
        sm = self.getSerializationMode()
        listeners = tuple(self._listeners)
        if sm == TaurusSerializationMode.Concurrent:
            manager.addJob(self.fireEvent,
                           None,
                           etype,
                           evalue,
                           listeners=listeners)
        else:
            self.fireEvent(etype, evalue, listeners=listeners)
    def addListener(self, listener):
        """ Add a TaurusListener object in the listeners list.
            If it is the first element and Polling is enabled starts the
            polling mechanism.
            If the listener is already registered nothing happens."""

        listeners = self._listeners
        initial_subscription_state = self.__subscription_state

        ret = TaurusAttribute.addListener(self, listener)
        if not ret:
            return ret

        assert len(listeners) >= 1

        if self.__subscription_state == SubscriptionState.Unsubscribed and len(
                listeners) == 1:
            self._subscribeEvents()

        # if initial_subscription_state == SubscriptionState.Subscribed:
        if len(listeners) > 1 and (initial_subscription_state
                                   == SubscriptionState.Subscribed
                                   or self.isPollingActive()):
            sm = self.getSerializationMode()
            if sm == TaurusSerializationMode.Concurrent:
                Manager().addJob(self.__fireRegisterEvent, None, (listener, ))
            else:
                self.__fireRegisterEvent((listener, ))
        return ret
示例#3
0
    def getGraphicsItem(self, type_, params):
        name = params.get(self.getNameParam())
        #applying alias
        for k, v in getattr(self, 'alias', {}).items():
            if k in name:
                name = str(name).replace(k, v)
                params[self.getNameParam()] = name
        cls = None
        if '/' in name:
            #replacing Taco identifiers in %s'%name
            if name.lower().startswith('tango:') and (
                    name.count('/') == 2 or not 'tango:/' in name.lower()):
                nname = name.split(':', 1)[-1]
                params[self.getNameParam()] = name = nname
            if name.lower().endswith('/state'): name = name.rsplit('/', 1)[0]
            cls = Manager().findObjectClass(name)
        else:
            if name: self.debug('%s does not match a tango name' % name)
        klass = self.getGraphicsClassItem(cls, type_)

        self.debug(str((cls, type_, klass, klass.__name__)))
        if not hasattr(klass, 'getExtensions'):
            klass = GetClassWithExtensions(klass)

        item = klass()
        ## It's here were Attributes are subscribed
        self.set_common_params(item, params)
        if hasattr(item, 'getExtensions'):
            item.getExtensions(
            )  #<= must be called here to take extensions from params

        return item
示例#4
0
    def push_event(self, event):
        """Method invoked by the PyTango layer when a change event occurs.
           Default implementation propagates the event to all listeners."""

        curr_time = time.time()
        manager = Manager()
        sm = self.getSerializationMode()
        if not event.err:
            # if it is a configuration event
            if isinstance(event, PyTango.AttrConfEventData):
                event_type = TaurusEventType.Config
                self._decodeAttrInfoEx(event.attr_conf)
                # make sure that there is a self.__attr_value
                if self.__attr_value is None:
                    # TODO: maybe we can avoid this read?
                    self.__attr_value = self.getValueObj(cache=False)
            # if it is an attribute event
            else:
                event_type = TaurusEventType.Change
                self.__attr_value, self.__attr_err = self.decode(event.attr_value), None
                self.__subscription_state = SubscriptionState.Subscribed
                self.__subscription_event.set()
                if not self.isPollingForced():
                    self._deactivatePolling()
            # notify the listeners
            listeners = tuple(self._listeners)
            if sm == TaurusSerializationMode.Concurrent:
                manager.addJob(self.fireEvent, None, event_type, self.__attr_value, listeners=listeners)
            else:
                self.fireEvent(event_type, self.__attr_value, listeners=listeners)
        elif event.errors[0].reason in EVENT_TO_POLLING_EXCEPTIONS:
            if self.isPollingActive():
                return
            self.info("Activating polling. Reason: %s", event.errors[0].reason)
            self.__subscription_state = SubscriptionState.PendingSubscribe
            self._activatePolling()
        else:
            self.__attr_value, self.__attr_err = None, PyTango.DevFailed(*event.errors)
            self.__subscription_state = SubscriptionState.Subscribed
            self.__subscription_event.set()
            self._deactivatePolling()
            listeners = tuple(self._listeners)
            if sm == TaurusSerializationMode.Concurrent:
                manager.addJob(self.fireEvent, None, TaurusEventType.Error, self.__attr_err, listeners=listeners)
            else:
                self.fireEvent(TaurusEventType.Error, self.__attr_err, listeners=listeners)
    def push_event(self, event):
        """Method invoked by the PyTango layer when a change event occurs.
           Default implementation propagates the event to all listeners."""

        curr_time = time.time()
        manager = Manager()
        sm = self.getSerializationMode()
        if not event.err:
            # if it is a configuration event
            if isinstance(event, PyTango.AttrConfEventData):
                event_type = TaurusEventType.Config
                self._decodeAttrInfoEx(event.attr_conf)
                # make sure that there is a self.__attr_value
                if self.__attr_value is None:
                    # TODO: maybe we can avoid this read?
                    self.__attr_value = self.getValueObj(cache=False)
            # if it is an attribute event
            else:
                event_type = TaurusEventType.Change
                self.__attr_value, self.__attr_err = self.decode(
                    event.attr_value), None
                self.__subscription_state = SubscriptionState.Subscribed
                self.__subscription_event.set()
                if not self.isPollingForced():
                    self._deactivatePolling()
            # notify the listeners
            listeners = tuple(self._listeners)
            if sm == TaurusSerializationMode.Concurrent:
                manager.addJob(self.fireEvent,
                               None,
                               event_type,
                               self.__attr_value,
                               listeners=listeners)
            else:
                self.fireEvent(event_type,
                               self.__attr_value,
                               listeners=listeners)
        elif event.errors[0].reason in EVENT_TO_POLLING_EXCEPTIONS:
            if self.isPollingActive():
                return
            self.info("Activating polling. Reason: %s", event.errors[0].reason)
            self.__subscription_state = SubscriptionState.PendingSubscribe
            self._activatePolling()
        else:
            self.__attr_value, self.__attr_err = None, PyTango.DevFailed(
                *event.errors)
            self.__subscription_state = SubscriptionState.Subscribed
            self.__subscription_event.set()
            self._deactivatePolling()
            listeners = tuple(self._listeners)
            if sm == TaurusSerializationMode.Concurrent:
                manager.addJob(self.fireEvent,
                               None,
                               TaurusEventType.Error,
                               self.__attr_err,
                               listeners=listeners)
            else:
                self.fireEvent(TaurusEventType.Error,
                               self.__attr_err,
                               listeners=listeners)
 def __init__(self, parent=None, **kwargs):
     super(TaurusSynopticWidget, self).__init__(parent=parent)
     Manager().setSerializationMode(TaurusSerializationMode.Concurrent)
     self.tooltip_trigger.connect(self._update_device_tooltip)
     self._panels = {}
示例#7
0
from taurus import Attribute, Manager
from taurus.core.taurusbasetypes import AttrQuality, TaurusEventType, DataFormat
import PyTango

Manager().changeDefaultPollingPeriod(1000)


def error_str(err):
    if isinstance(err, PyTango.DevFailed):
        err = err[0]
        #return "[{0}] {1}".format(err.reason, err.desc.replace("\n", "<br>"))
        return "error"
    return str(err)


# Based on code from the taurus-web project
class TaurusWebAttribute(object):
    """This object is a listener for the taurus attribute value.
    When a attribute changes it sends an event. The event
    triggers a call to *eventReceived*. *eventReceived* will transform
    the change event into a JSON encoded string and sends this
    string through the web socket to the client"""

    def __init__(self, name, callback):
        print self.__class__.__name__, name
        self.name = name
        self.callback = callback
        self._last_time = 0
        self.last_value_event = None
        self.last_config_event = None
        try: