예제 #1
0
 def onSelectionChanged(self, models):
     if self._oldModels in [None, []]:
         for model in models:
             attr = Attribute(model)
             #force a read -> attr.read()
             attr.addListener(self)
         self._oldModels = models
     else:
         keptModels = []
         newModels = []
         for model in models:
             if model in self._oldModels:
                 keptModels.append(model)
             else:
                 newModels.append(model)
         for model in self._oldModels:
             if model not in newModels:
                 attr = Attribute(model)
                 attr.removeListener(self)
                 legend = attr.getNormalName()
                 print("Trying to remove ", legend)
                 self.removeCurve(legend, replot=False)
         for model in newModels:
             attr = Attribute(model)
             # attr.read()
             attr.addListener(self)
         self._oldModels = keptModels + newModels
예제 #2
0
class TaurusWebAttribute(object):
    def __init__(self, name, keeper):
        self.name = name
        self.keepers = [keeper]
        self._last_time = 0
        self.last_value_event = None
        self.last_config_event = None
        self.attribute = Attribute(self.name)
        self.attribute.addListener(self)

    def eventReceived(self, evt_src, evt_type, evt_value):

        # print(evt_value)

        if evt_type == TaurusEventType.Error:
            action = "ERROR"
            value = error_str(evt_value)
        else:
            if evt_type == TaurusEventType.Config:
                action = "CONFIG"
                value = format_config_event(evt_src)
                self.last_config_event = value
            else:
                self._last_time = evt_value.time.tv_sec
                action = "CHANGE"
                value = format_value_event(evt_value)
                self.last_value_event = value

        # self.callback(self.name, {"type": action, "data": {self.name: value}})
        # event = {"type": action, "data": value}
        try:
            for keeper in self.keepers:
                keeper.put(self.name, action, value)
        except QueueFull:
            print("Queue full!")
        # print(event)

    def addKeeper(self, keeper):
        self.keepers.append(keeper)

    def removeKeeper(self, keeper):
        self.keepers.remove(keeper)

    def clear(self):
        self.attribute.removeListener(self)
예제 #3
0
 def onSelectionChanged(self, models):
     if self._oldModels in [None, []]:
         self._attrDict = {}
         for model in models:
             try:
                 attr = Attribute(model)
             except:
                 # old PyTango versions do not handle unicode
                 attr = Attribute(str(model))
             #force a read -> attr.read()
             attr.addListener(self)
             legend = qt.safe_str(attr.getNormalName())
             self._attrDict[legend] = attr
         self._oldModels = models
     else:
         keptModels = []
         newModels = []
         for model in models:
             if model in self._oldModels:
                 keptModels.append(model)
             else:
                 newModels.append(model)
         for model in self._oldModels:
             if model not in keptModels:
                 attr = Attribute(model)
                 attr.removeListener(self)
                 legend = qt.safe_str(attr.getNormalName())
                 if legend in self._attrDict:
                     del self._attrDict[legend]
                 print("Trying to remove ", legend)
                 self.removeCurve(legend, replot=False)
         for model in newModels:
             attr = Attribute(model)
             # attr.read()
             attr.addListener(self)
             legend = qt.safe_str(attr.getNormalName())
             self._attrDict[legend] = attr
         self._oldModels = keptModels + newModels
예제 #4
0
 def onSelectionChanged(self, models):
     if self._oldModels in [None, []]:
         self._attrDict = {}
         for model in models:
             try:
                 attr = Attribute(model)
             except:
                 # old PyTango versions do not handle unicode
                 attr = Attribute(str(model))
             #force a read -> attr.read()
             attr.addListener(self)
             legend = qt.safe_str(attr.getNormalName())
             self._attrDict[legend] = attr
         self._oldModels = models
     else:
         keptModels = []
         newModels = []
         for model in models:
             if model in self._oldModels:
                 keptModels.append(model)
             else:
                 newModels.append(model)
         for model in self._oldModels:
             if model not in keptModels:
                 attr = Attribute(model)
                 attr.removeListener(self)
                 legend = qt.safe_str(attr.getNormalName())
                 if legend in self._attrDict:
                     del self._attrDict[legend]
                 print("Trying to remove ", legend)
                 self.removeCurve(legend, replot=False)
         for model in newModels:
             attr = Attribute(model)
             # attr.read()
             attr.addListener(self)
             legend = qt.safe_str(attr.getNormalName())
             self._attrDict[legend] = attr
         self._oldModels = keptModels + newModels
예제 #5
0
class StatusArea(TaurusWidget):

    """A (scrolling) text area that displays device status, or any other
    string attribute."""

    statusTrigger = QtCore.pyqtSignal(str)

    def __init__(self, parent=None, down_command=None, up_command=None, state=None):
        TaurusWidget.__init__(self, parent)
        self._setup_ui()

    def _setup_ui(self):

        hbox = QtGui.QVBoxLayout(self)
        self.setLayout(hbox)

        self.status_label = QtGui.QLabel("(No status has been read.)")
        self.status_label.setTextInteractionFlags(QtCore.Qt.TextSelectableByMouse)
        self.status_label.setWordWrap(True)
        self.status_label.setAlignment(QtCore.Qt.AlignTop)
        status_scroll_area = QtGui.QScrollArea()
        status_scroll_area.setMaximumSize(QtCore.QSize(100000, 100))
        status_scroll_area.setWidgetResizable(True)
        status_scroll_area.setWidget(self.status_label)
        hbox.addWidget(status_scroll_area)
        self.status = None

        self.statusTrigger.connect(self.updateStatus)

    def setModel(self, model):
        if model:
            split_model = model.split("/")
            if len(split_model) < 4:
                self.status = Attribute("%s/Status" % model)
            else:
                self.status = Attribute(model)
            self.status.addListener(self.onStatusChange)
        else:
            self.status and self.status.removeListener(self.onStatusChange)

    def onStatusChange(self, evt_src, evt_type, evt_value):
        if evt_type in [PyTango.EventType.CHANGE_EVENT,
                        PyTango.EventType.PERIODIC_EVENT]:
            self.statusTrigger.emit(evt_value.value)

    def updateStatus(self, status):
        self.status_label.setText(status)
예제 #6
0
class TaurusAttribute(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
        self.attribute = Attribute(self.name)
        self.attribute.addListener(self)

    def eventReceived(self, evt_src, evt_type, evt_value):
        """Transforms the event into a JSON encoded string and sends this
        string into the web socket"""

        modelObj = evt_src
        data = {}
        if evt_type == TaurusEventType.Error:
            data["event_type"] = "error"
            data["error"] = error_str(evt_value)
        else:
            if evt_type == TaurusEventType.Config:
                modelObj = evt_src.getParentObj()
                data['event_type'] = "config"
                data['description'] = evt_src.description
                data['label'] = evt_src.label
                data[
                    "unit"] = evt_src.unit if evt_src.unit != "No unit" else ""
                data["format"] = evt_src.format
                self.last_config_event = data
            else:
                self._last_time = evt_value.time.tv_sec
                data["event_type"] = "value"
                value = evt_value.value
                quality = evt_value.quality
                fmt = evt_value.data_format
                if fmt == DataFormat._0D:
                    html = modelObj.displayValue(value)
                    if isinstance(value, PyTango._PyTango.DevState):
                        value = value.name
                    if isinstance(value, str):
                        html = value.replace("\n", "<br>")
                elif fmt in (DataFormat._1D, DataFormat._2D):
                    # bad, very bad performance! Don't worry for now
                    value = value.tolist()
                    html = "[...]"
                data['value'] = value
                data['html'] = html
                data['quality'] = str(quality)
                data['time'] = evt_value.time.tv_sec
                data['type'] = str(evt_value.type)  # can this change..?
                self.last_value_event = data

        data['model'] = modelObj.getNormalName()
        self.write_message(data)

    def write_message(self, message):
        self.callback(message)

    def clear(self):
        try:
            print "clear", self.attribute
            self.attribute.removeListener(self)
            del self.attribute

        except PyTango.DevFailed as e:
            print >> sys.stderr, "Could not unsubscribe %s: %r" % (self.name,
                                                                   e)
class TaurusAttribute(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
        self.attribute = Attribute(self.name)
        self.attribute.addListener(self)

    def eventReceived(self, evt_src, evt_type, evt_value):
        """Transforms the event into a JSON encoded string and sends this
        string into the web socket"""

        modelObj = evt_src
        data = {}
        if evt_type == TaurusEventType.Error:
            data["event_type"] = "error"
            data["error"] = error_str(evt_value)
        else:
            if evt_type == TaurusEventType.Config:
                modelObj = evt_src.getParentObj()
                data['event_type'] = "config"
                data['description'] = evt_src.description
                data['label'] = evt_src.label
                data["unit"] = evt_src.unit if evt_src.unit != "No unit" else ""
                data["format"] = evt_src.format
                self.last_config_event = data
            else:
                self._last_time = evt_value.time.tv_sec
                data["event_type"] = "value"
                value = evt_value.value
                quality = evt_value.quality
                fmt = evt_value.data_format
                if fmt == DataFormat._0D:
                    html = modelObj.displayValue(value)
                    if isinstance(value, PyTango._PyTango.DevState):
                        value = value.name
                    if isinstance(value, str):
                        html = value.replace("\n", "<br>")
                elif fmt in (DataFormat._1D, DataFormat._2D):
                    # bad, very bad performance! Don't worry for now
                    value = value.tolist()
                    html = "[...]"
                data['value'] = value
                data['html'] = html
                data['quality'] = str(quality)
                data['time'] = evt_value.time.tv_sec
                data['type'] = str(evt_value.type)  # can this change..?
                self.last_value_event = data

        data['model'] = modelObj.getNormalName()
        self.write_message(data)

    def write_message(self, message):
        self.callback(message)

    def clear(self):
        try:
            print "clear", self.attribute
            self.attribute.removeListener(self)
            del self.attribute

        except PyTango.DevFailed as e:
            print >>sys.stderr, "Could not unsubscribe %s: %r" % (self.name, e)