class LiberaBrilliancePlusMini(TaurusWidget): l_plot = None trigger = QtCore.pyqtSignal() def __init__(self, parent=None, designMode=False): TaurusWidget.__init__(self, parent, designMode=designMode) self._ui = Ui_LiberaBrilliancePlusMini() self._ui.setupUi(self) self._ui.taurusCurveDialog = myTaurusCurveDialog(self) self._ui.taurusCurveDialog.setObjectName("taurusCurveDialog") self._ui.gridLayout.addWidget(self._ui.taurusCurveDialog, 0, 0, 1, 1) self.l_plot = self._ui.taurusCurveDialog.get_active_plot() self.sym = QwtSymbol(QwtSymbol.Ellipse, QtGui.QBrush(QtCore.Qt.blue), QtGui.QPen(QtCore.Qt.blue), QtCore.QSize(10, 10)) self.sym_old = QwtSymbol(QwtSymbol.Ellipse, QtGui.QBrush(QtCore.Qt.gray), QtGui.QPen(QtCore.Qt.gray), QtCore.QSize(4, 4)) self.l_plot.set_axis_limits('left', -0.003, 0.003) self.l_plot.set_axis_title('left', "Y") self.l_plot.set_axis_unit('left', "mm") self.l_plot.set_axis_limits('bottom', -0.003, 0.003) self.l_plot.set_axis_title('bottom', "X") self.l_plot.set_axis_unit('bottom', "mm") self.x = 0 self.y = 0 self.list_mark = [] self.apply_color = True self.trigger.connect(self.update_plot) @classmethod def getQtDesignerPluginInfo(cls): ret = TaurusWidget.getQtDesignerPluginInfo() ret['module'] = 'liberabrillianceplusmini' ret['group'] = 'Taurus Display' ret['container'] = ':/designer/frame.png' ret['container'] = False return ret def setModel(self, models): from guiqwt.styles import style_generator self._ui.taurusTrend.style = style_generator("brmgcykG") self._ui.taurusTrend.setModel(models[:2]) index = models[0].rfind("/") self.model = models[0][:index] self.dev = PyTango.DeviceProxy(self.model) self.id1 = self.dev.subscribe_event('XPosSP', PyTango.EventType.CHANGE_EVENT, self.handle_x) self.id2 = self.dev.subscribe_event('YPosSP', PyTango.EventType.CHANGE_EVENT, self.handle_y) self._ui.taurusTrend_2.setModel(models[2]) def handle_x(self, evt): if evt.attr_value is not None: if evt.attr_value.value != self.x: self.x = evt.attr_value.value / 1e9 def handle_y(self, evt): if evt.attr_value is not None: if evt.attr_value.value != self.y: self.y = evt.attr_value.value / 1e9 self.mark = QwtPlotMarker() self.mark.setSymbol(self.sym) self.mark.attach(self.l_plot) self.mark.setValue(self.x, self.y) if len(self.list_mark) > 10: self.list_mark[0].setVisible(False) l_mark = self.list_mark[0] self.list_mark.pop(0) for mark in self.list_mark: mark.setSymbol(self.sym_old) self.list_mark.append(self.mark) self.trigger.emit() def update_plot(self): if self.l_plot is not None: self.l_plot.replot()
class ToftofProfileWindow(DlgUtils, QMainWindow): def __init__(self, parent): QMainWindow.__init__(self, parent) DlgUtils.__init__(self, 'Live data') self.panel = parent layout1 = QVBoxLayout() self.plot = QwtPlot(self) layout1.addWidget(self.plot) self.curve = QwtPlotCurve() self.curve.setRenderHint(QwtPlotCurve.RenderAntialiased) self.curve.attach(self.plot) self.marker = QwtPlotMarker() self.marker.attach(self.plot) self.markerpen = QPen(Qt.red) self.marker.setSymbol( QwtSymbol(QwtSymbol.Ellipse, QBrush(), self.markerpen, QSize(7, 7))) self.zoomer = QwtPlotZoomer(self.plot.canvas()) self.zoomer.setMousePattern(QwtPlotZoomer.MouseSelect3, Qt.NoButton) self.picker = QwtPlotPicker(self.plot.canvas()) self.picker.setSelectionFlags(QwtPlotPicker.PointSelection | QwtPlotPicker.ClickSelection) self.picker.setMousePattern(QwtPlotPicker.MouseSelect1, Qt.MidButton) self.picker.selected.connect(self.pickerSelected) layout2 = QHBoxLayout() layout2.addWidget(QLabel('Scale:', self)) self.scale = QComboBox(self) self.scale.addItems([ 'Single detectors, sorted by angle', 'Scattering angle 2theta (deg)', 'Q value (A-1)' ]) self.scale.currentIndexChanged[int].connect(self.scaleChanged) layout2.addWidget(self.scale) layout2.addStretch() self.scaleframe = QFrame(self) self.scaleframe.setLayout(layout2) self.scaleframe.setVisible(False) layout1.addWidget(self.scaleframe) mainframe = QFrame(self) mainframe.setLayout(layout1) self.setCentralWidget(mainframe) self.setContentsMargins(6, 6, 6, 6) plotfont = scaledFont(self.font(), 0.7) self.plot.setAxisFont(QwtPlot.xBottom, plotfont) self.plot.setAxisFont(QwtPlot.yLeft, plotfont) self.plot.setCanvasBackground(Qt.white) self.resize(800, 200) self._detinfo = None self._anglemap = None self._infowindow = None self._infolabel = None self._xs = self._ys = None self._type = None def _retrieve_detinfo(self): if self._detinfo is None: info = self.panel.client.eval( 'det._detinfo_parsed, ' 'det._anglemap', None) if not info: return self.showError('Cannot retrieve detector info.') self._lambda = self.panel.client.eval('chWL()', None) if not self._lambda: return self.showError('Cannot retrieve wavelength.') self._detinfo, self._anglemap = info self._inverse_anglemap = 0 self._infowindow = QMainWindow(self) self._infolabel = QLabel(self._infowindow) self._infolabel.setTextFormat(Qt.RichText) self._infowindow.setCentralWidget(self._infolabel) self._infowindow.setContentsMargins(10, 10, 10, 10) self._inv_anglemap = [[ entry for entry in self._detinfo[1:] if entry[12] == self._anglemap[detnr] + 1 ][0] for detnr in range(len(self._xs))] def scaleChanged(self, scale): self.update(self._type, self._orig_nbins, self._orig_x, self._orig_y) def update(self, proftype, nbins, x, y): self._orig_x = x self._orig_y = y self._orig_nbins = nbins x.setsize(8 * nbins) y.setsize(8 * nbins) xs = struct.unpack('d' * nbins, x) ys = struct.unpack('d' * nbins, y) if proftype == 0: if self.scale.currentIndex() == 0: xs = xs elif self.scale.currentIndex() == 1: self._retrieve_detinfo() xs = [self._inv_anglemap[int(xi)][5] for xi in xs] else: self._retrieve_detinfo() if self._lambda is None: self.showError('Could not determine wavelength.') self.scale.setCurrentIndex(1) return xs = [ 4 * pi / self._lambda * sin(radians(self._inv_anglemap[int(xi)][5] / 2.)) for xi in xs ] self._xs = xs self._ys = ys self.curve.setData(xs, ys) self.plot.setAxisAutoScale(QwtPlot.xBottom) self.plot.setAxisAutoScale(QwtPlot.yLeft) self.marker.setVisible(False) self.zoomer.setZoomBase(True) self._type = proftype if proftype == 0: self.setWindowTitle( 'Single detector view (time-channel integrated)') self.scaleframe.setVisible(True) elif proftype == 1: self.setWindowTitle('Time channel view (detector integrated)') self.scaleframe.setVisible(False) else: self.scaleframe.setVisible(False) def pickerSelected(self, point): if self._type != 0: return self._retrieve_detinfo() index = self.curve.closestPoint(self.picker.transform(point))[0] detentry = self._inv_anglemap[index][:] detentry.append(self._xs[index]) detentry.append(self._ys[index]) self.marker.setXValue(self._xs[index]) self.marker.setYValue(self._ys[index]) self.marker.setVisible(True) self.plot.replot() self._infowindow.show() entrynames = [ 'EntryNr', 'Rack', 'Plate', 'Pos', 'RPos', '2Theta', 'CableNr', 'CableType', 'CableLen', 'CableEmpty', 'Card', 'Chan', 'Total', 'DetName', 'BoxNr', 'BoxChan', 'XValue', 'Counts' ] formats = [ '%s', '%d', '%d', '%d', '%d', '%.3f', '%d', '%d', '%.2f', '%d', '%d', '%d', '%d', '%r', '%d', '%d', '%s', '%d' ] empties = [1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0] self._infolabel.setText('Detector info:<br><table>' + ''.join( '<tr><td>%s</td><td></td><td>%s</td></tr>%s' % (name, format % value, '<tr></tr>' if empty else '') for (name, format, empty, value) in zip(entrynames, formats, empties, detentry)) + '</table>') def closeEvent(self, event): if self._infowindow: self._infowindow.close()
class TestPlot(QwtPlot): def __init__(self, parent=None): super(TestPlot, self).__init__(parent) self.setWindowTitle("PyQwt" if USE_PYQWT5 else "PythonQwt") self.enableAxis(self.xTop, True) self.enableAxis(self.yRight, True) y = np.linspace(0, 10, 500) curve1 = QwtPlotCurve('Test Curve 1') curve1.setData(np.sin(y), y) curve2 = QwtPlotCurve('Test Curve 2') curve2.setData(y**3, y) if USE_PYQWT5: curve2.setAxis(self.xTop, self.yRight) else: # PythonQwt curve2.setAxes(self.xTop, self.yRight) for item, col, xa, ya in ((curve1, Qt.green, self.xBottom, self.yLeft), (curve2, Qt.red, self.xTop, self.yRight)): if not USE_PYQWT5: # PythonQwt item.setOrientation(Qt.Vertical) item.attach(self) item.setPen(QPen(col)) for axis_id in xa, ya: palette = self.axisWidget(axis_id).palette() palette.setColor(QPalette.WindowText, QColor(col)) palette.setColor(QPalette.Text, QColor(col)) self.axisWidget(axis_id).setPalette(palette) ticks_font = self.axisFont(axis_id) self.setAxisFont(axis_id, ticks_font) self.canvas().setFrameStyle(0)#QFrame.Panel|QFrame.Sunken) self.plotLayout().setCanvasMargin(0) self.axisWidget(QwtPlot.yLeft).setMargin(0) self.axisWidget(QwtPlot.xTop).setMargin(0) self.axisWidget(QwtPlot.yRight).setMargin(0) self.axisWidget(QwtPlot.xBottom).setMargin(0) self.marker = QwtPlotMarker() self.marker.setValue(0, 5) self.marker.attach(self) def resizeEvent(self, event): super(TestPlot, self).resizeEvent(event) self.show_layout_details() def show_layout_details(self): text = QwtText( "plotLayout().canvasRect():\n%r\n\n" "canvas().geometry():\n%r\n\n" "plotLayout().scaleRect(QwtPlot.yLeft):\n%r\n\n" "axisWidget(QwtPlot.yLeft).geometry():\n%r\n\n" "plotLayout().scaleRect(QwtPlot.yRight):\n%r\n\n" "axisWidget(QwtPlot.yRight).geometry():\n%r\n\n" "plotLayout().scaleRect(QwtPlot.xBottom):\n%r\n\n" "axisWidget(QwtPlot.xBottom).geometry():\n%r\n\n" "plotLayout().scaleRect(QwtPlot.xTop):\n%r\n\n" "axisWidget(QwtPlot.xTop).geometry():\n%r\n\n" % (self.plotLayout().canvasRect().getCoords(), self.canvas().geometry().getCoords(), self.plotLayout().scaleRect(QwtPlot.yLeft).getCoords(), self.axisWidget(QwtPlot.yLeft).geometry().getCoords(), self.plotLayout().scaleRect(QwtPlot.yRight).getCoords(), self.axisWidget(QwtPlot.yRight).geometry().getCoords(), self.plotLayout().scaleRect(QwtPlot.xBottom).getCoords(), self.axisWidget(QwtPlot.xBottom).geometry().getCoords(), self.plotLayout().scaleRect(QwtPlot.xTop).getCoords(), self.axisWidget(QwtPlot.xTop).geometry().getCoords(), ) ) text.setFont(QFont('Courier New')) text.setColor(Qt.blue) self.marker.setLabel(text)
class TestPlot(QwtPlot): def __init__(self, parent=None): super(TestPlot, self).__init__(parent) self.setWindowTitle("PyQwt" if USE_PYQWT5 else "PythonQwt") self.enableAxis(self.xTop, True) self.enableAxis(self.yRight, True) y = np.linspace(0, 10, 500) curve1 = QwtPlotCurve('Test Curve 1') curve1.setData(np.sin(y), y) curve2 = QwtPlotCurve('Test Curve 2') curve2.setData(y**3, y) if USE_PYQWT5: curve2.setAxis(self.xTop, self.yRight) else: # PythonQwt curve2.setAxes(self.xTop, self.yRight) for item, col, xa, ya in ((curve1, Qt.green, self.xBottom, self.yLeft), (curve2, Qt.red, self.xTop, self.yRight)): if not USE_PYQWT5: # PythonQwt item.setOrientation(Qt.Vertical) item.attach(self) item.setPen(QPen(col)) for axis_id in xa, ya: palette = self.axisWidget(axis_id).palette() palette.setColor(QPalette.WindowText, QColor(col)) palette.setColor(QPalette.Text, QColor(col)) self.axisWidget(axis_id).setPalette(palette) ticks_font = self.axisFont(axis_id) self.setAxisFont(axis_id, ticks_font) self.canvas().setFrameStyle(0) #QFrame.Panel|QFrame.Sunken) self.plotLayout().setCanvasMargin(0) self.axisWidget(QwtPlot.yLeft).setMargin(0) self.axisWidget(QwtPlot.xTop).setMargin(0) self.axisWidget(QwtPlot.yRight).setMargin(0) self.axisWidget(QwtPlot.xBottom).setMargin(0) self.marker = QwtPlotMarker() self.marker.setValue(0, 5) self.marker.attach(self) def resizeEvent(self, event): super(TestPlot, self).resizeEvent(event) self.show_layout_details() def show_layout_details(self): text = QwtText( "plotLayout().canvasRect():\n%r\n\n" "canvas().geometry():\n%r\n\n" "plotLayout().scaleRect(QwtPlot.yLeft):\n%r\n\n" "axisWidget(QwtPlot.yLeft).geometry():\n%r\n\n" "plotLayout().scaleRect(QwtPlot.yRight):\n%r\n\n" "axisWidget(QwtPlot.yRight).geometry():\n%r\n\n" "plotLayout().scaleRect(QwtPlot.xBottom):\n%r\n\n" "axisWidget(QwtPlot.xBottom).geometry():\n%r\n\n" "plotLayout().scaleRect(QwtPlot.xTop):\n%r\n\n" "axisWidget(QwtPlot.xTop).geometry():\n%r\n\n" % ( self.plotLayout().canvasRect().getCoords(), self.canvas().geometry().getCoords(), self.plotLayout().scaleRect(QwtPlot.yLeft).getCoords(), self.axisWidget(QwtPlot.yLeft).geometry().getCoords(), self.plotLayout().scaleRect(QwtPlot.yRight).getCoords(), self.axisWidget(QwtPlot.yRight).geometry().getCoords(), self.plotLayout().scaleRect(QwtPlot.xBottom).getCoords(), self.axisWidget(QwtPlot.xBottom).geometry().getCoords(), self.plotLayout().scaleRect(QwtPlot.xTop).getCoords(), self.axisWidget(QwtPlot.xTop).geometry().getCoords(), )) text.setFont(QFont('Courier New')) text.setColor(Qt.blue) self.marker.setLabel(text)
class LiberaSinglePassEMini(TaurusWidget): l_plot = None trigger = QtCore.pyqtSignal() def __init__(self, parent=None, designMode=False): TaurusWidget.__init__(self, parent, designMode=designMode) self._ui = Ui_LiberaSinglePassEMini() self._ui.setupUi(self) self._ui.taurusCurveDialog = myTaurusCurveDialog(self) self._ui.taurusCurveDialog.setObjectName("taurusCurveDialog") self._ui.gridLayout.addWidget(self._ui.taurusCurveDialog, 0, 0, 1, 1) self.l_plot = self._ui.taurusCurveDialog.get_active_plot() self.sym = QwtSymbol(QwtSymbol.Ellipse, QtGui.QBrush(QtCore.Qt.blue), QtGui.QPen(QtCore.Qt.blue), QtCore.QSize(10, 10)) self.sym_old = QwtSymbol(QwtSymbol.Ellipse, QtGui.QBrush(QtCore.Qt.gray), QtGui.QPen(QtCore.Qt.gray), QtCore.QSize(4, 4)) self.l_plot.set_axis_limits('left', -0.003, 0.003) self.l_plot.set_axis_title('left', "Y") self.l_plot.set_axis_unit('left', "mm") self.l_plot.set_axis_limits('bottom', -0.003, 0.003) self.l_plot.set_axis_title('bottom', "X") self.l_plot.set_axis_unit('bottom', "mm") self.x = 0 self.y = 0 self.list_mark = [] self.trigger.connect(self.update_plot) @classmethod def getQtDesignerPluginInfo(cls): ret = TaurusWidget.getQtDesignerPluginInfo() ret['module'] = 'liberasinglepassemini' ret['group'] = 'Taurus Display' ret['container'] = ':/designer/frame.png' ret['container'] = False return ret def setModel(self, models): self._ui.taurusTrend.setModel(models[:3]) index = models[0].rfind("/") self.dev = PyTango.DeviceProxy(models[0][:index]) self.id1 = self.dev.subscribe_event('X', PyTango.EventType.CHANGE_EVENT, self.handle_x) self.id2 = self.dev.subscribe_event('Y', PyTango.EventType.CHANGE_EVENT, self.handle_y) self._ui.taurusTrend_2.setModel(models[3]) def handle_x(self, evt): if evt.attr_value is not None: if evt.attr_value.value != self.x: self.x = evt.attr_value.value / 1e9 def handle_y(self, evt): if evt.attr_value is not None: if evt.attr_value.value != self.y: self.y = evt.attr_value.value / 1e9 self.mark = QwtPlotMarker() self.mark.setSymbol(self.sym) self.mark.attach(self.l_plot) self.mark.setValue(self.x, self.y) if len(self.list_mark) > 10: self.list_mark[0].setVisible(False) l_mark = self.list_mark[0] self.list_mark.pop(0) for mark in self.list_mark: mark.setSymbol(self.sym_old) self.list_mark.append(self.mark) self.trigger.emit() def update_plot(self): if self.l_plot is not None: self.l_plot.replot()