Example #1
0
 def neXusPreviewWidgetFactory(self, ddict):
     '''returns a widget showing a preview of a node in a NeXus file'''
     #@todo: check if this is the root group and it has a valid nexus data directory, in which case the default plot should be returned
     if ddict['type'] == 'Dataset':
         node = ddict['name']
         data = self.__nexusFile[node]
         if len(data.shape) == 1 and isinstance(data[0], (numpy.floating, numpy.integer, int, float)):
             w = TaurusPlot()
             w.attachRawData({"x": numpy.arange(len(data)), "y": data})
         else:
             w = HDF5DatasetTable.HDF5DatasetTable()
             w.setDataset(data)
     else:
         info = HDF5Info.getInfo(self.__nexusFile, ddict["name"])
         w = HDF5Info.HDF5InfoWidget()
         w.setInfoDict(info)
     return w
Example #2
0
 def neXusPreviewWidgetFactory(self, ddict):
     """returns a widget showing a preview of a node in a NeXus file"""
     # @todo: check if this is the root group and it has a valid nexus data directory, in which case the default plot should be returned
     if ddict["type"] == "Dataset":
         node = ddict["name"]
         data = self.__nexusFile[node]
         if len(data.shape) == 1 and isinstance(data[0], (numpy.floating, numpy.integer, int, float)):
             w = TaurusPlot()
             w.attachRawData({"x": numpy.arange(len(data)), "y": data})
         else:
             w = HDF5DatasetTable.HDF5DatasetTable()
             w.setDataset(data)
     else:
         info = HDF5Info.getInfo(self.__nexusFile, ddict["name"])
         w = HDF5Info.HDF5InfoWidget()
         w.setInfoDict(info)
     return w
from taurus.qt import Qwt5

panel = TaurusPlot()

rawdata1 = {"y": 5 * numpy.random.random(10), "name": "Random"}
rawdata2 = {"x": [1, 2, 5, 7], "y": [2, 3, 1, 4], "name": "Hand-written"}
rawdata3 = {"x": numpy.arange(0, 10, 0.1), "f(x)": "sqrt(x)"}

p1 = CurveAppearanceProperties(sStyle=Qwt5.QwtSymbol.Rect,
                               sSize=5,
                               sColor="green",
                               sFill=False,
                               lStyle=Qt.Qt.NoPen)

p2 = CurveAppearanceProperties(sStyle=Qwt5.QwtSymbol.Triangle,
                               sSize=8,
                               sColor="red",
                               sFill=True,
                               lColor="red",
                               lStyle=Qt.Qt.DashLine)

panel.attachRawData(rawdata1, properties=p1)
panel.attachRawData(rawdata2, properties=p2)
panel.attachRawData(rawdata3)

########################
# END EXAMPLE CODE
########################
panel.show()
sys.exit(app.exec_())
class Ui_MainWindow(QtGui.QMainWindow):
    def setupUi(self, MainWindow):
        MainWindow.resize(1000, 600)
        MainWindow.setMinimumSize(700,400)
        self.centralwidget = QtGui.QWidget(MainWindow)

        self.widgets(MainWindow)

        MainWindow.setCentralWidget(self.centralwidget)
        self.centerOnScreen(MainWindow)
        self.layouts(MainWindow)
        self.readTangoData()
        self.signals()
        if MDEBUG:
            self.plotSett() # ??? debug

    def widgets(self,MainWindow):
        #3
        self.xPlot = TaurusPlot(self.centralwidget)
        # data = range(0,20)
        # self.xPlot.setGeometry(QtCore.QRect(30, 100, 300, 200))

        #4
        self.yPlot = TaurusPlot(self.centralwidget)
        # marker = self.yPlot.getPickedMarker()
        # marker.setShowQuality
        # self.yPlot.setGeometry(QtCore.QRect(520, 100, 300, 200))

        #1
        self.xLabel = QtGui.QLabel()
        self.xLabel.setText("X")
        #2
        self.yLabel = QtGui.QLabel()
        self.yLabel.setText("Y")
        #5
        self.baseXLabel = QtGui.QLabel()
        self.baseXLabel.setText("Baseline X")
        #6
        self.baseYLabel = QtGui.QLabel()
        self.baseYLabel.setText("Baseline Y")
        #7
        self.baseXLineEdit = QtGui.QLineEdit()
        self.baseXLineEdit.setReadOnly(True)
        #8
        self.baseYLineEdit = QtGui.QLineEdit()
        self.baseYLineEdit.setReadOnly(True)
        #9
        self.timeStampLabel = QtGui.QLabel()
        self.timeStampLabel.setText("time")
        #10
        self.timeStampLineEdit = QtGui.QLineEdit()
        self.timeStampLineEdit.setReadOnly(True)
        #11
        self.rangeAILabel = QtGui.QLabel()
        self.rangeAILabel.setText("range:")
        #12
        # self.rangeAICommand = QtGui.QLineEdit()
        # self.rangeAICommand = TaurusValueComboBox()
        self.rangeAICommand = QtGui.QComboBox()
        namesItems = ['Range 0.1','Range 0.2','Range 0.5','Range 1','Range 2','Range 5','Range 10']
        self.rangeAICommand.addItems(namesItems)
        # self.rangeAICommand.addValueNames(names)
        #13
        self.valueEdit = QtGui.QTextEdit()
        self.valueEdit.setReadOnly(True)
        self.valueEdit.setMaximumWidth(180)

    def plotSett(self):
        print("PLOT SETT")

        # curveSymbol = Qwt.QwtSymbol(Qwt.QwtSymbol.Ellipse,
        #                             Qt.QBrush(Qt.Qt.red),
        #                             Qt.QPen(Qt.Qt.black, 2),
        #                             Qt.QSize(9, 9))

        p1 = CurveAppearanceProperties(sStyle=Qwt.QwtSymbol.Ellipse,
                               sSize=5,
                               sColor="blue",
                               sFill=True,
                               lStyle=Qt.Qt.NoPen)

        self.xPlot.setCurveAppearanceProperties({'wireX':p1})
        self.yPlot.setCurveAppearanceProperties({'wireY':p1})

        # sd = self.xPlot.getCurveNames()
        # self.xPlot.getCurveNames().setSymbol(curveSymbol)
        # sd = self.yPlot.setSymbol
        # print sd
        # self.yPlot.

    def layouts(self, MainWindow):
        mainLayout = QtGui.QGridLayout()
        mainLayout.setSpacing(30)

        layout1 = QtGui.QHBoxLayout()
        layout1.addWidget(self.baseXLabel)
        layout1.addWidget(self.baseXLineEdit)

        layout2 = QtGui.QHBoxLayout()
        layout2.addWidget(self.baseYLabel)
        layout2.addWidget(self.baseYLineEdit)

        layout3 = QtGui.QHBoxLayout()
        layout3.addWidget(self.timeStampLabel)
        layout3.addWidget(self.timeStampLineEdit)

        layout4 = QtGui.QHBoxLayout()
        layout4.addWidget(self.rangeAILabel)
        layout4.addWidget(self.rangeAICommand)

        labelLayout = QtGui.QHBoxLayout()
        labelLayout.addStretch(0)
        labelLayout.addWidget(self.xLabel)
        labelLayout.addStretch(0)

        mainLayout.addLayout(labelLayout,0,0)

        labelLayout = QtGui.QHBoxLayout()
        labelLayout.addStretch(0)
        labelLayout.addWidget(self.yLabel)
        labelLayout.addStretch(0)

        mainLayout.addLayout(labelLayout,0,2)

        mainLayout.addWidget(self.xPlot,1,0)
        mainLayout.addWidget(self.yPlot,1,2)
        mainLayout.addLayout(layout1,2,0)
        mainLayout.addLayout(layout2,2,2)
        mainLayout.addLayout(layout3,3,0)
        mainLayout.addLayout(layout4,3,2)
        mainLayout.addWidget(self.valueEdit,1,1)

        centralWidget = MainWindow.centralWidget()
        centralWidget.setLayout(mainLayout)

    def commandRange(self,it):
        commands = ['SetAIRange0_1','SetAIRange0_2','SetAIRange0_5',
                    'SetAIRange1','SetAIRange2','SetAIRange5','SetAIRange10']
        command = commands[it]
        self.chTangoData()
        if MDEBUG:
            print(command)
        else:
			try:
				tango_test.command_inout(command)
			except PyTango.DevFailed as exc:
				self.setBeginAIRange()
				print(str(exc))

    def signals(self):
        self.connect(self.rangeAICommand,QtCore.SIGNAL("activated(int)"),self.commandRange)

    def readTangoData(self):
        self.chTangoData()
        self.readPR1Avg()
        self.setBeginAIRange()

    def readPR1Avg(self):
        pr1avgData = tango_test.read_attribute("pr1avg").value
        # wiresX = pr1avgData
        pnt1=self.nWiresX
        pnt2=pnt1+self.nWiresY
        pnt3=self.nWiresX
        pnt4=pnt3+self.nWiresY

        dataX = pr1avgData[0][0:pnt1]
        dataY = pr1avgData[0][pnt1:pnt2]
        sclX = pr1avgData[1][0:pnt3]
        sclY = pr1avgData[1][pnt3:pnt4]

        # p1 = CurveAppearanceProperties(sStyle=Qwt.QwtSymbol.Ellipse,
        #                sSize=5,
        #                sColor="blue",
        #                sFill=True,
        #                lStyle=Qt.Qt.NoPen)
        # self.xPlot.attachRawData({"x":sclX, "y":dataX},properties=p1)
        # self.yPlot.attachRawData({"x":sclY, "y":dataY},properties=p1)

        self.xPlot.attachRawData({"x":sclX, "y":dataX, 'title':"wireX"})
        self.yPlot.attachRawData({"x":sclY, "y":dataY, 'title':"wireY"})


        # self.xPlot.getPickedMarker()

        if MDEBUG:
            print("1: " + str(pnt1) + "  2: " + str(pnt2) + "  3: "  + str(pnt3) + "  4: " + str(pnt4))
            # tt = self.xPlot.createConfigDict()
            # print(tt)

    def chTangoData(self):
        baselineX = tango_test.read_attribute("baselineX")
        baselineY = tango_test.read_attribute("baselineY")
        timestamp = tango_test.read_attribute("PR_Timestamp")
        dt = datetime.fromtimestamp(timestamp.value).strftime('%d-%m-%Y %H:%M:%S')
        self.baseXLineEdit.setText(str(baselineX.value))
        self.baseYLineEdit.setText(str(baselineY.value))
        self.timeStampLineEdit.setText(dt)

        prX0 = tango_test.read_attribute("prX0")
        prX0val = prX0.value
        prY0 = tango_test.read_attribute("prY0")
        prY0val = prY0.value
        prWX = tango_test.read_attribute("prWX")
        prWXval = prWX.value
        prWY = tango_test.read_attribute("prWY")
        prWYval = prWY.value

        self.valueEdit.clear()
        self.valueEdit.append("X0 = " + str(round(prX0val[0],3)))
        self.valueEdit.append("")
        self.valueEdit.append("Y0 = " + str(round(prY0val[0],3)))
        self.valueEdit.append("")
        self.valueEdit.append("Wx = " + str(round(prWXval[0],3)))
        self.valueEdit.append("")
        self.valueEdit.append("Wy = " + str(round(prWYval[0],3)))
        self.valueEdit.append("")

        self.nWiresX = tango_test.read_attribute("wiresX").value
        self.nWiresY = tango_test.read_attribute("wiresY").value
        if MDEBUG:
            print("WiresX=" + str(self.nWiresX))
            print("WiresY=" + str(self.nWiresY))

    def setBeginAIRange(self):
        airange = tango_test.read_attribute("AI_Range")
        if airange.value == 10.0:
            self.rangeAICommand.setCurrentIndex(6)
        if airange.value == 5.0:
            self.rangeAICommand.setCurrentIndex(5)
        if airange.value == 2.0:
            self.rangeAICommand.setCurrentIndex(4)
        if airange.value == 1.0:
            self.rangeAICommand.setCurrentIndex(3)
        if airange.value == 0.5:
            self.rangeAICommand.setCurrentIndex(2)
        if airange.value == 0.2:
            self.rangeAICommand.setCurrentIndex(1)
        if airange.value == 0.1:
            self.rangeAICommand.setCurrentIndex(0)

    def centerOnScreen(self,MainWindow):
        resolution = QtGui.QDesktopWidget().screenGeometry()
        MainWindow.move((resolution.width() / 2) - (self.frameSize().width() / 2),
                  (resolution.height() / 2) - (self.frameSize().height() / 2))
Example #5
0
class Ui_MainWindow(QtGui.QMainWindow):
    def setupUi(self, MainWindow):
        MainWindow.resize(1000, 600)
        MainWindow.setMinimumSize(700, 400)
        self.centralwidget = QtGui.QWidget(MainWindow)

        self.widgets(MainWindow)

        MainWindow.setCentralWidget(self.centralwidget)
        self.centerOnScreen(MainWindow)
        self.layouts(MainWindow)
        self.readTangoData()
        self.signals()
        if MDEBUG:
            self.plotSett()  # ??? debug

    def widgets(self, MainWindow):
        #3
        self.xPlot = TaurusPlot(self.centralwidget)
        # data = range(0,20)
        # self.xPlot.setGeometry(QtCore.QRect(30, 100, 300, 200))

        #4
        self.yPlot = TaurusPlot(self.centralwidget)
        # marker = self.yPlot.getPickedMarker()
        # marker.setShowQuality
        # self.yPlot.setGeometry(QtCore.QRect(520, 100, 300, 200))

        #1
        self.xLabel = QtGui.QLabel()
        self.xLabel.setText("X")
        #2
        self.yLabel = QtGui.QLabel()
        self.yLabel.setText("Y")
        #5
        self.baseXLabel = QtGui.QLabel()
        self.baseXLabel.setText("Baseline X")
        #6
        self.baseYLabel = QtGui.QLabel()
        self.baseYLabel.setText("Baseline Y")
        #7
        self.baseXLineEdit = QtGui.QLineEdit()
        self.baseXLineEdit.setReadOnly(True)
        #8
        self.baseYLineEdit = QtGui.QLineEdit()
        self.baseYLineEdit.setReadOnly(True)
        #9
        self.timeStampLabel = QtGui.QLabel()
        self.timeStampLabel.setText("time")
        #10
        self.timeStampLineEdit = QtGui.QLineEdit()
        self.timeStampLineEdit.setReadOnly(True)
        #11
        self.rangeAILabel = QtGui.QLabel()
        self.rangeAILabel.setText("range:")
        #12
        # self.rangeAICommand = QtGui.QLineEdit()
        # self.rangeAICommand = TaurusValueComboBox()
        self.rangeAICommand = QtGui.QComboBox()
        namesItems = [
            'Range 0.1', 'Range 0.2', 'Range 0.5', 'Range 1', 'Range 2',
            'Range 5', 'Range 10'
        ]
        self.rangeAICommand.addItems(namesItems)
        # self.rangeAICommand.addValueNames(names)
        #13
        self.valueEdit = QtGui.QTextEdit()
        self.valueEdit.setReadOnly(True)
        self.valueEdit.setMaximumWidth(180)

    def plotSett(self):
        print("PLOT SETT")

        # curveSymbol = Qwt.QwtSymbol(Qwt.QwtSymbol.Ellipse,
        #                             Qt.QBrush(Qt.Qt.red),
        #                             Qt.QPen(Qt.Qt.black, 2),
        #                             Qt.QSize(9, 9))

        p1 = CurveAppearanceProperties(sStyle=Qwt.QwtSymbol.Ellipse,
                                       sSize=5,
                                       sColor="blue",
                                       sFill=True,
                                       lStyle=Qt.Qt.NoPen)

        self.xPlot.setCurveAppearanceProperties({'wireX': p1})
        self.yPlot.setCurveAppearanceProperties({'wireY': p1})

        # sd = self.xPlot.getCurveNames()
        # self.xPlot.getCurveNames().setSymbol(curveSymbol)
        # sd = self.yPlot.setSymbol
        # print sd
        # self.yPlot.

    def layouts(self, MainWindow):
        mainLayout = QtGui.QGridLayout()
        mainLayout.setSpacing(30)

        layout1 = QtGui.QHBoxLayout()
        layout1.addWidget(self.baseXLabel)
        layout1.addWidget(self.baseXLineEdit)

        layout2 = QtGui.QHBoxLayout()
        layout2.addWidget(self.baseYLabel)
        layout2.addWidget(self.baseYLineEdit)

        layout3 = QtGui.QHBoxLayout()
        layout3.addWidget(self.timeStampLabel)
        layout3.addWidget(self.timeStampLineEdit)

        layout4 = QtGui.QHBoxLayout()
        layout4.addWidget(self.rangeAILabel)
        layout4.addWidget(self.rangeAICommand)

        labelLayout = QtGui.QHBoxLayout()
        labelLayout.addStretch(0)
        labelLayout.addWidget(self.xLabel)
        labelLayout.addStretch(0)

        mainLayout.addLayout(labelLayout, 0, 0)

        labelLayout = QtGui.QHBoxLayout()
        labelLayout.addStretch(0)
        labelLayout.addWidget(self.yLabel)
        labelLayout.addStretch(0)

        mainLayout.addLayout(labelLayout, 0, 2)

        mainLayout.addWidget(self.xPlot, 1, 0)
        mainLayout.addWidget(self.yPlot, 1, 2)
        mainLayout.addLayout(layout1, 2, 0)
        mainLayout.addLayout(layout2, 2, 2)
        mainLayout.addLayout(layout3, 3, 0)
        mainLayout.addLayout(layout4, 3, 2)
        mainLayout.addWidget(self.valueEdit, 1, 1)

        centralWidget = MainWindow.centralWidget()
        centralWidget.setLayout(mainLayout)

    def commandRange(self, it):
        commands = [
            'SetAIRange0_1', 'SetAIRange0_2', 'SetAIRange0_5', 'SetAIRange1',
            'SetAIRange2', 'SetAIRange5', 'SetAIRange10'
        ]
        command = commands[it]
        self.chTangoData()
        if MDEBUG:
            print(command)
        else:
            try:
                tango_test.command_inout(command)
            except PyTango.DevFailed as exc:
                self.setBeginAIRange()
                print(str(exc))

    def signals(self):
        self.connect(self.rangeAICommand, QtCore.SIGNAL("activated(int)"),
                     self.commandRange)

    def readTangoData(self):
        self.chTangoData()
        self.readPR1Avg()
        self.setBeginAIRange()

    def readPR1Avg(self):
        pr1avgData = tango_test.read_attribute("pr1avg").value
        # wiresX = pr1avgData
        pnt1 = self.nWiresX
        pnt2 = pnt1 + self.nWiresY
        pnt3 = self.nWiresX
        pnt4 = pnt3 + self.nWiresY

        dataX = pr1avgData[0][0:pnt1]
        dataY = pr1avgData[0][pnt1:pnt2]
        sclX = pr1avgData[1][0:pnt3]
        sclY = pr1avgData[1][pnt3:pnt4]

        # p1 = CurveAppearanceProperties(sStyle=Qwt.QwtSymbol.Ellipse,
        #                sSize=5,
        #                sColor="blue",
        #                sFill=True,
        #                lStyle=Qt.Qt.NoPen)
        # self.xPlot.attachRawData({"x":sclX, "y":dataX},properties=p1)
        # self.yPlot.attachRawData({"x":sclY, "y":dataY},properties=p1)

        self.xPlot.attachRawData({"x": sclX, "y": dataX, 'title': "wireX"})
        self.yPlot.attachRawData({"x": sclY, "y": dataY, 'title': "wireY"})

        # self.xPlot.getPickedMarker()

        if MDEBUG:
            print("1: " + str(pnt1) + "  2: " + str(pnt2) + "  3: " +
                  str(pnt3) + "  4: " + str(pnt4))
            # tt = self.xPlot.createConfigDict()
            # print(tt)

    def chTangoData(self):
        baselineX = tango_test.read_attribute("baselineX")
        baselineY = tango_test.read_attribute("baselineY")
        timestamp = tango_test.read_attribute("PR_Timestamp")
        dt = datetime.fromtimestamp(
            timestamp.value).strftime('%d-%m-%Y %H:%M:%S')
        self.baseXLineEdit.setText(str(baselineX.value))
        self.baseYLineEdit.setText(str(baselineY.value))
        self.timeStampLineEdit.setText(dt)

        prX0 = tango_test.read_attribute("prX0")
        prX0val = prX0.value
        prY0 = tango_test.read_attribute("prY0")
        prY0val = prY0.value
        prWX = tango_test.read_attribute("prWX")
        prWXval = prWX.value
        prWY = tango_test.read_attribute("prWY")
        prWYval = prWY.value

        self.valueEdit.clear()
        self.valueEdit.append("X0 = " + str(round(prX0val[0], 3)))
        self.valueEdit.append("")
        self.valueEdit.append("Y0 = " + str(round(prY0val[0], 3)))
        self.valueEdit.append("")
        self.valueEdit.append("Wx = " + str(round(prWXval[0], 3)))
        self.valueEdit.append("")
        self.valueEdit.append("Wy = " + str(round(prWYval[0], 3)))
        self.valueEdit.append("")

        self.nWiresX = tango_test.read_attribute("wiresX").value
        self.nWiresY = tango_test.read_attribute("wiresY").value
        if MDEBUG:
            print("WiresX=" + str(self.nWiresX))
            print("WiresY=" + str(self.nWiresY))

    def setBeginAIRange(self):
        airange = tango_test.read_attribute("AI_Range")
        if airange.value == 10.0:
            self.rangeAICommand.setCurrentIndex(6)
        if airange.value == 5.0:
            self.rangeAICommand.setCurrentIndex(5)
        if airange.value == 2.0:
            self.rangeAICommand.setCurrentIndex(4)
        if airange.value == 1.0:
            self.rangeAICommand.setCurrentIndex(3)
        if airange.value == 0.5:
            self.rangeAICommand.setCurrentIndex(2)
        if airange.value == 0.2:
            self.rangeAICommand.setCurrentIndex(1)
        if airange.value == 0.1:
            self.rangeAICommand.setCurrentIndex(0)

    def centerOnScreen(self, MainWindow):
        resolution = QtGui.QDesktopWidget().screenGeometry()
        MainWindow.move(
            (resolution.width() / 2) - (self.frameSize().width() / 2),
            (resolution.height() / 2) - (self.frameSize().height() / 2))
Example #6
0
panel = TaurusPlot()

rawdata1 = {"y": 5 * numpy.random.random(10), "name": "Random"}
rawdata2 = {"x": [1, 2, 5, 7], "y": [2, 3, 1, 4], "name": "Hand-written"}
rawdata3 = {"x": numpy.arange(0, 10, 0.1), "f(x)": "sqrt(x)"}

p1 = CurveAppearanceProperties(sStyle=Qwt5.QwtSymbol.Rect,
                               sSize=5,
                               sColor="green",
                               sFill=False,
                               lStyle=Qt.Qt.NoPen)

p2 = CurveAppearanceProperties(sStyle=Qwt5.QwtSymbol.Triangle,
                               sSize=8,
                               sColor="red",
                               sFill=True,
                               lColor="red",
                               lStyle=Qt.Qt.DashLine)

panel.attachRawData(rawdata1, properties=p1)
panel.attachRawData(rawdata2, properties=p2)
panel.attachRawData(rawdata3)


########################
# END EXAMPLE CODE
########################
panel.show()
sys.exit(app.exec_())