def run(self):
     # TODO: This needs to be redone; maybe use string.template?
     try:
         attribute = Attribute(str(self.model) + "/State")
         if attribute:
             value = attribute.read()
             html = json.dumps('Value: ' +
                               '<span class="value">%s</span>'
                               % value.value)
         self.finished.emit(self.model, html)
     except PyTango.DevFailed as e:
         print e
 def run(self):
     # TODO: This needs to be redone; maybe use string.template?
     try:
         attribute = Attribute(str(self.model) + "/State")
         if attribute:
             value = attribute.read()
             html = json.dumps('Value:&nbsp;' +
                               '<span class="value">%s</span>'
                               % value.value)
         self.finished.emit(self.model, html)
     except PyTango.DevFailed as e:
         print e
예제 #3
0
class SardanaChannel(ChannelObject, SardanaObject):
    def __init__(self,
                 name,
                 attribute_name,
                 username=None,
                 uribase=None,
                 polling=None,
                 **kwargs):

        super(SardanaChannel, self).__init__(name, username, **kwargs)

        class ChannelInfo(object):
            def __init__(self):
                super(ChannelInfo, self).__init__()

        self.attributeName = attribute_name
        self.model = os.path.join(uribase, attribute_name)
        self.attribute = None

        self.value = None
        self.polling = polling

        self.info = ChannelInfo()
        self.info.minval = None
        self.info.maxval = None

        self.init_device()

    def init_device(self):

        try:
            self.attribute = Attribute(self.model)
            #
            # DIRTY FIX to make compatible taurus listeners and existence of Tango channels/commands
            # as defined in Command/Tango.py
            #
            # if self.attribute.__class__ == taurus.core.tango.tangoattribute.TangoAttribute:
            #    dev = self.attribute.getParentObj()
            #    dp = dev.getHWObj()
            #    try:
            #        dp.subscribe_event = dp._subscribe_event
            #    except AttributeError:
            #        pass
            # logging.getLogger("HWR").debug("initialized")
        except DevFailed as traceback:
            self.imported = False
            return

        # read information
        try:
            if taurus.Release.version_info[0] == 3:
                ranges = self.attribute.getConfig().getRanges()
                if ranges is not None and ranges[0] != "Not specified":
                    self.info.minval = float(ranges[0])
                if ranges is not None and ranges[-1] != "Not specified":
                    self.info.maxval = float(ranges[-1])
            elif taurus.Release.version_info[0] > 3:  # taurus 4 and beyond
                minval, maxval = self.attribute.ranges()
                self.info.minval = minval.magnitude
                self.info.maxval = maxval.magnitude
        except BaseException:
            import traceback

            logging.getLogger("HWR").info(
                "info initialized. Cannot get limits")
            logging.getLogger("HWR").info("%s" % traceback.format_exc())

        # prepare polling
        # if the polling value is a number set it as the taurus polling period

        if self.polling:
            if isinstance(self.polling, types.IntType):
                self.attribute.changePollingPeriod(self.polling)

            self.attribute.addListener(self.objectListener)

    def getValue(self):
        return self._readValue()

    def setValue(self, newValue):
        self._writeValue(newValue)

    def _writeValue(self, newValue):
        self.attribute.write(newValue)

    def _readValue(self):
        value = self.attribute.read().value
        return value

    def getInfo(self):
        try:
            b = dir(self.attribute)
            self.info.minval, self.info.maxval = (
                self.attribute._TangoAttribute__attr_config.getLimits())
        except BaseException:
            import traceback

            logging.getLogger("HWR").info("%s" % traceback.format_exc())
        return self.info

    def update(self, event):

        data = event.event[2]

        try:
            newvalue = data.value

            if newvalue is None:
                newvalue = self.getValue()

            if isinstance(newvalue, types.TupleType):
                newvalue = list(newvalue)

            self.value = newvalue
            self.emit("update", self.value)
        except AttributeError:
            # No value in data... this is probably a connection error
            pass

    def isConnected(self):
        return self.attribute is not None

    def channelListener(self, *args):
        ev = AttributeEvent(args)
        SardanaChannel._eventReceivers[id(ev)] = saferef.safe_ref(self.update)
        SardanaChannel._eventsQueue.put(ev)
        SardanaChannel._eventsProcessingTimer.send()
예제 #4
0
 def ReadOne(self, axis):
     attr = Attribute(self._axes_taurus_attr[axis])
     return attr.read().value
예제 #5
0
class SardanaChannel(ChannelObject, SardanaObject):

    def __init__(self, name, attribute_name, username=None, uribase = None, polling=None, **kwargs):

        super(SardanaChannel, self).__init__(name,username,**kwargs)
 
        class ChannelInfo(object):
            def __init__(self):
                super(ChannelInfo, self).__init__()

        self.attributeName = attribute_name
        self.model = os.path.join( uribase, attribute_name )
        self.attribute = None

        self.value = None
        self.polling = polling

        self.info = ChannelInfo()
        self.info.minval = None
        self.info.maxval = None

        logging.getLogger("HWR").debug("creating Sardana model %s, polling=%s", self.model, polling)

        self.init_device()

    def init_device(self):

        try:
            self.attribute = Attribute(self.model)
            # 
            # DIRTY FIX to make compatible taurus listeners and existence of Tango channels/commands
            # as defined in Command/Tango.py
            # 
            #if self.attribute.__class__ == taurus.core.tango.tangoattribute.TangoAttribute:
            #    dev = self.attribute.getParentObj()
            #    dp = dev.getHWObj()
            #    try:
            #        dp.subscribe_event = dp._subscribe_event
            #    except AttributeError:
            #        pass
            logging.getLogger("HWR").info("initialized")
        except DevFailed as traceback:
            self.imported = False
            return
        
        # read information
        try:
            self.info.minval, self.info.maxval = self.attribute._TangoAttribute__attr_config.getLimits()
            logging.getLogger("HWR").info("info initialized. Got minval=%s, maxval=%s" %(self.info.minval, self.info.maxval))
        except:
            logging.getLogger("HWR").info("info initialized. Cannot get limits")
       
        
        # prepare polling
        # if the polling value is a number set it as the taurus polling period
        if self.polling:
             if type(self.polling) == int:
                  self.attribute.changePollingPeriod(self.polling)
             
             self.attribute.addListener(self.objectListener)

    def getValue(self):
        return self._readValue()

    def setValue(self, newValue, wait=False):
        self._writeValue(newValue)
 
    def _writeValue(self, newValue):
        self.attribute.write(newValue)
            
    def _readValue(self):
        value = self.attribute.read().value
        return value
            
    def getInfo(self):
        return self.info

    def update(self, event):

        data = event.event[2]
        
        try:
            newvalue = data.value

            if newvalue == None:
                newvalue = self.getValue()
    
            if type(newvalue) == tuple:
                newvalue = list(newvalue)
    
            self.value = newvalue
            self.emit('update', self.value)
        except AttributeError:
            # No value in data... this is probably a connection error
            pass

    def isConnected(self):
        return self.attribute is not None

    def channelListener(self,*args):
        ev = AttributeEvent(args)
        SardanaChannel._eventReceivers[id(ev)] = saferef.safe_ref(self.update)
        SardanaChannel._eventsQueue.put(ev)
        SardanaChannel._eventsProcessingTimer.send()
class TaurusPlotDataItem(PlotDataItem, TaurusBaseComponent):
    """A taurus-ified PlotDataItem"""
    def __init__(self, *args, **kwargs):
        """
        Accepts same args and kwargs as PlotDataItem, plus:
        :param xModel: (str) Taurus model name for abscissas values.
                       Default=None
        :param yModel: (str) Taurus model name for ordinate values.
                       Default=None
        """
        xModel = kwargs.pop('xModel', None)
        yModel = kwargs.pop('yModel', None)
        PlotDataItem.__init__(self, *args, **kwargs)
        TaurusBaseComponent.__init__(self, 'TaurusBaseComponent')
        self._x = None
        self._y = None
        self.xModel = None
        if xModel is not None:
            self.setXModel(xModel)
        if yModel is not None:
            self.setModel(yModel)

        self.registerConfigProperty(self.getOpts, self.setOpts, 'opts')
        self.setModelInConfig(True)
        self.registerConfigProperty(self.getXModelName, self.setXModel,
                                    'XModel')

    def setXModel(self, xModel):
        if not xModel:
            if self.xModel is not None:
                self.xModel.removeListener(self)
            self.xModel = None
            return
        self.xModel = Attribute(xModel)
        self._x = self.xModel.read().rvalue
        self.xModel.addListener(self)

    def getXModelName(self):
        if self.xModel is None:
            return None
        else:
            return self.xModel.getFullName()

    def handleEvent(self, evt_src, evt_type, evt_value):
        if evt_type not in (TaurusEventType.Change, TaurusEventType.Periodic):
            return
        yModel = self.getModelObj()
        if yModel == evt_src and yModel is not None:
            self._y = evt_value.rvalue
        if self.xModel == evt_src and self.xModel is not None:
            self._x = evt_value.rvalue
        self.setData(x=self._x, y=self._y)

    def getOpts(self):
        from taurus.qt.qtgui.tpg import serialize_opts
        return serialize_opts(copy.copy(self.opts))

    def setOpts(self, opts):
        # creates QPainters (QPen or QBrush) from a pickle loaded file
        # for adapt the serialized objects into PlotDataItem properties

        from taurus.qt.qtgui.tpg import deserialize_opts
        self.opts = deserialize_opts(opts)

        # This is a workaround for the following pyqtgraph's bug:
        # https://github.com/pyqtgraph/pyqtgraph/issues/531
        if opts['connect'] == 'all':
            self.opts['connect'] = 'all'
        elif opts['connect'] == 'pairs':
            self.opts['connect'] = 'pairs'
        elif opts['connect'] == 'finite':
            self.opts['connect'] = 'finite'

    def getFullModelNames(self):
        return (self.getXModelName(), self.getFullModelName())
예제 #7
0
    def image(self, taurusmodel=None, **kwargs):
        """
        Extension to meth:`guiqwt.builder.PlotItemBuilder.image` to support passing a
        'taurusmodel' as a keyword argument instead passing 'data' or 'filename'.
        """
        if taurusmodel is None:
            image = guiqwt.builder.PlotItemBuilder.image(self, **kwargs)
        else:
            title = kwargs.get('title', taurusmodel)
            data = kwargs.get('data', None)
            filename = kwargs.get('filename', None)
            alpha_mask = kwargs.get('alpha_mask', None)
            alpha = kwargs.get('alpha', None)
            background_color = kwargs.get('background_color', None)
            colormap = kwargs.get('colormap', None)
            xdata = kwargs.get('xdata', [None, None])
            ydata = kwargs.get('ydata', [None, None])
            pixel_size = kwargs.get('pixel_size', None)
            interpolation = kwargs.get('interpolation', 'linear')
            eliminate_outliers = kwargs.get('eliminate_outliers', None)
            xformat = kwargs.get('xformat', '%.1f')
            yformat = kwargs.get('yformat', '%.1f')
            zformat = kwargs.get('zformat', '%.1f')
            forceRGB = kwargs.get('force_rgb', False)

            assert isinstance(xdata, (tuple, list)) and len(xdata) == 2
            assert isinstance(ydata, (tuple, list)) and len(ydata) == 2
            assert filename is None
            assert data is None

            param = ImageParam(title=_("Image"), icon='image.png')

            from taurus import Attribute
            if pixel_size is None:
                xmin, xmax = xdata
                ymin, ymax = ydata
            else:
                attr = Attribute(taurusmodel)
                valueobj = attr.read()
                data = getattr(valueobj, 'rvalue', numpy.zeros((1, 1)))
                attrdata = data
                if isinstance(data, Quantity):
                    attrdata = data.magnitude
                xmin, xmax, ymin, ymax = self.compute_bounds(attrdata,
                                                             pixel_size)

            self.set_image_param(param, title, alpha_mask, alpha, interpolation,
                                 background=background_color,
                                 colormap=colormap,
                                 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
                                 xformat=xformat, yformat=yformat,
                                 zformat=zformat)

            from taurus.core import DataType
            if forceRGB:
                if Attribute(taurusmodel).getType() == DataType.DevEncoded:
                    image = TaurusEncodedRGBImageItem(param)
                else:
                    image = TaurusRGBImageItem(param)
            else:
                if Attribute(taurusmodel).getType() == DataType.DevEncoded:
                    image = TaurusEncodedImageItem(param)
                else:
                    image = TaurusImageItem(param)
            image.setModel(taurusmodel)
            if eliminate_outliers is not None:
                image.set_lut_range(lut_range_threshold(image, 256,
                                                        eliminate_outliers))

        return image
예제 #8
0
class SardanaChannel(ChannelObject, SardanaObject):
    def __init__(
        self, name, attribute_name, username=None, uribase=None, polling=None, **kwargs
    ):

        super(SardanaChannel, self).__init__(name, username, **kwargs)

        class ChannelInfo(object):
            def __init__(self):
                super(ChannelInfo, self).__init__()

        self.attributeName = attribute_name
        self.model = os.path.join(uribase, attribute_name)
        self.attribute = None

        self.value = None
        self.polling = polling

        self.info = ChannelInfo()
        self.info.minval = None
        self.info.maxval = None

        self.init_device()

    def init_device(self):

        try:
            self.attribute = Attribute(self.model)
            #
            # DIRTY FIX to make compatible taurus listeners and existence of Tango channels/commands
            # as defined in Command/Tango.py
            #
            # if self.attribute.__class__ == taurus.core.tango.tangoattribute.TangoAttribute:
            #    dev = self.attribute.getParentObj()
            #    dp = dev.getHWObj()
            #    try:
            #        dp.subscribe_event = dp._subscribe_event
            #    except AttributeError:
            #        pass
            # logging.getLogger("HWR").debug("initialized")
        except DevFailed as traceback:
            self.imported = False
            return

        # read information
        try:
            if taurus.Release.version_info[0] == 3:
                ranges = self.attribute.getConfig().getRanges()
                if ranges is not None and ranges[0] != "Not specified":
                    self.info.minval = float(ranges[0])
                if ranges is not None and ranges[-1] != "Not specified":
                    self.info.maxval = float(ranges[-1])
            elif taurus.Release.version_info[0] > 3:  # taurus 4 and beyond
                minval, maxval = self.attribute.ranges()
                self.info.minval = minval.magnitude
                self.info.maxval = maxval.magnitude
        except BaseException:
            import traceback

            logging.getLogger("HWR").info("info initialized. Cannot get limits")
            logging.getLogger("HWR").info("%s" % traceback.format_exc())

        # prepare polling
        # if the polling value is a number set it as the taurus polling period

        if self.polling:
            if isinstance(self.polling, types.IntType):
                self.attribute.changePollingPeriod(self.polling)

            self.attribute.addListener(self.objectListener)

    def getValue(self):
        return self._readValue()

    def setValue(self, newValue):
        self._writeValue(newValue)

    def _writeValue(self, newValue):
        self.attribute.write(newValue)

    def _readValue(self):
        value = self.attribute.read().value
        return value

    def getInfo(self):
        try:
            b = dir(self.attribute)
            self.info.minval, self.info.maxval = (
                self.attribute._TangoAttribute__attr_config.getLimits()
            )
        except BaseException:
            import traceback

            logging.getLogger("HWR").info("%s" % traceback.format_exc())
        return self.info

    def update(self, event):

        data = event.event[2]

        try:
            newvalue = data.value

            if newvalue is None:
                newvalue = self.getValue()

            if isinstance(newvalue, types.TupleType):
                newvalue = list(newvalue)

            self.value = newvalue
            self.emit("update", self.value)
        except AttributeError:
            # No value in data... this is probably a connection error
            pass

    def isConnected(self):
        return self.attribute is not None

    def channelListener(self, *args):
        ev = AttributeEvent(args)
        SardanaChannel._eventReceivers[id(ev)] = saferef.safe_ref(self.update)
        SardanaChannel._eventsQueue.put(ev)
        SardanaChannel._eventsProcessingTimer.send()
예제 #9
0
 def ReadOne(self, axis):
     attr = Attribute(self._axes_taurus_attr[axis])
     return attr.read().value
예제 #10
0
class SardanaChannel(ChannelObject, SardanaObject):
    def __init__(self,
                 name,
                 attribute_name,
                 username=None,
                 uribase=None,
                 polling=None,
                 **kwargs):

        super(SardanaChannel, self).__init__(name, username, **kwargs)

        class ChannelInfo(object):
            def __init__(self):
                super(ChannelInfo, self).__init__()

        self.attributeName = attribute_name
        self.model = os.path.join(uribase, attribute_name)
        self.attribute = None

        self.value = None
        self.polling = polling

        self.info = ChannelInfo()
        self.info.minval = None
        self.info.maxval = None

        logging.getLogger("HWR").debug("creating Sardana model %s, polling=%s",
                                       self.model, polling)

        self.init_device()

    def init_device(self):

        try:
            self.attribute = Attribute(self.model)
            #
            # DIRTY FIX to make compatible taurus listeners and existence of Tango channels/commands
            # as defined in Command/Tango.py
            #
            #if self.attribute.__class__ == taurus.core.tango.tangoattribute.TangoAttribute:
            #    dev = self.attribute.getParentObj()
            #    dp = dev.getHWObj()
            #    try:
            #        dp.subscribe_event = dp._subscribe_event
            #    except AttributeError:
            #        pass
            logging.getLogger("HWR").info("initialized")
        except DevFailed as traceback:
            self.imported = False
            return

        # read information
        try:
            self.info.minval, self.info.maxval = self.attribute._TangoAttribute__attr_config.getLimits(
            )
            logging.getLogger("HWR").info(
                "info initialized. Got minval=%s, maxval=%s" %
                (self.info.minval, self.info.maxval))
        except:
            logging.getLogger("HWR").info(
                "info initialized. Cannot get limits")

        # prepare polling
        # if the polling value is a number set it as the taurus polling period
        if self.polling:
            if type(self.polling) == int:
                self.attribute.changePollingPeriod(self.polling)

            self.attribute.addListener(self.objectListener)

    def getValue(self):
        return self._readValue()

    def setValue(self, newValue, wait=False):
        self._writeValue(newValue)

    def _writeValue(self, newValue):
        self.attribute.write(newValue)

    def _readValue(self):
        value = self.attribute.read().value
        return value

    def getInfo(self):
        return self.info

    def update(self, event):

        data = event.event[2]

        try:
            newvalue = data.value

            if newvalue == None:
                newvalue = self.getValue()

            if type(newvalue) == tuple:
                newvalue = list(newvalue)

            self.value = newvalue
            self.emit('update', self.value)
        except AttributeError:
            # No value in data... this is probably a connection error
            pass

    def isConnected(self):
        return self.attribute is not None

    def channelListener(self, *args):
        ev = AttributeEvent(args)
        SardanaChannel._eventReceivers[id(ev)] = saferef.safe_ref(self.update)
        SardanaChannel._eventsQueue.put(ev)
        SardanaChannel._eventsProcessingTimer.send()