def _add_channel(self, name): cdta = self.graph.curveAtIndex(-1) cbx = QCheckBox(name, self) plt = cbx.palette() plt.setColor(plt.WindowText, cdta.color) cbx.setPalette(plt) cbx.setChecked(True) self.vbl.addWidget(cbx) self.vbl.addStretch() cbx.toggled.connect(cdta.setVisible)
def generate_pv_controls(self, pv_name, curve_color): """ Generate a set of widgets to manage the appearance of a curve. The set of widgets includes: 1. A checkbox which shows the curve on the chart if checked, and hide the curve if not checked 2. Two buttons -- Modify... and Remove. Modify... will bring up the Curve Settings dialog. Remove will delete the curve from the chart This set of widgets will be hidden initially, until the first curve is plotted. Parameters ---------- pv_name: str The name of the PV the current curve is being plotted for curve_color : QColor The color of the curve to paint for the checkbox label to help the user track the curve to the checkbox """ checkbox = QCheckBox() checkbox.setObjectName(pv_name) palette = checkbox.palette() palette.setColor(QPalette.Active, QPalette.WindowText, curve_color) checkbox.setPalette(palette) display_name = pv_name.split("://")[1] if len(display_name) > MAX_DISPLAY_PV_NAME_LENGTH: # Only display max allowed number of characters of the PV Name display_name = display_name[:int(MAX_DISPLAY_PV_NAME_LENGTH / 2) - 1] + "..." + \ display_name[-int(MAX_DISPLAY_PV_NAME_LENGTH / 2) + 2:] checkbox.setText(display_name) data_text = QLabel() data_text.setObjectName(pv_name) data_text.setPalette(palette) checkbox.setChecked(True) checkbox.clicked.connect( partial(self.handle_curve_chkbox_toggled, checkbox)) curve_btn_layout = QHBoxLayout() modify_curve_btn = QPushButton("Modify...") modify_curve_btn.setObjectName(pv_name) modify_curve_btn.setMaximumWidth(100) modify_curve_btn.clicked.connect( partial(self.display_curve_settings_dialog, pv_name)) focus_curve_btn = QPushButton("Focus") focus_curve_btn.setObjectName(pv_name) focus_curve_btn.setMaximumWidth(100) focus_curve_btn.clicked.connect(partial(self.focus_curve, pv_name)) annotate_curve_btn = QPushButton("Annotate...") annotate_curve_btn.setObjectName(pv_name) annotate_curve_btn.setMaximumWidth(100) annotate_curve_btn.clicked.connect( partial(self.annotate_curve, pv_name)) remove_curve_btn = QPushButton("Remove") remove_curve_btn.setObjectName(pv_name) remove_curve_btn.setMaximumWidth(100) remove_curve_btn.clicked.connect(partial(self.remove_curve, pv_name)) curve_btn_layout.addWidget(modify_curve_btn) curve_btn_layout.addWidget(focus_curve_btn) curve_btn_layout.addWidget(annotate_curve_btn) curve_btn_layout.addWidget(remove_curve_btn) individual_curve_layout = QVBoxLayout() individual_curve_layout.addWidget(checkbox) individual_curve_layout.addWidget(data_text) individual_curve_layout.addLayout(curve_btn_layout) size_policy = QSizePolicy() size_policy.setVerticalPolicy(QSizePolicy.Fixed) individual_curve_grpbx = QGroupBox() individual_curve_grpbx.setSizePolicy(size_policy) individual_curve_grpbx.setObjectName(pv_name) individual_curve_grpbx.setLayout(individual_curve_layout) self.curve_settings_layout.addWidget(individual_curve_grpbx) self.tab_panel.show()
def generate_pv_controls(self, pv_name, curve_color): """ Generate a set of widgets to manage the appearance of a curve. The set of widgets includes: 1. A checkbox which shows the curve on the chart if checked, and hide the curve if not checked 2. Three buttons -- Modify..., Focus, and Remove. Modify... will bring up the Curve Settings dialog. Focus adjusts the chart's zooming for the current curve. Remove will delete the curve from the chart Parameters ---------- pv_name: str The name of the PV the current curve is being plotted for curve_color : QColor The color of the curve to paint for the checkbox label to help the user track the curve to the checkbox """ individual_curve_layout = QVBoxLayout() size_policy = QSizePolicy() size_policy.setVerticalPolicy(QSizePolicy.Fixed) size_policy.setHorizontalPolicy(QSizePolicy.Fixed) individual_curve_grpbx = QGroupBox() individual_curve_grpbx.setMinimumWidth(300) individual_curve_grpbx.setMinimumHeight(120) individual_curve_grpbx.setAlignment(Qt.AlignTop) individual_curve_grpbx.setSizePolicy(size_policy) individual_curve_grpbx.setObjectName(pv_name + "_grb") individual_curve_grpbx.setLayout(individual_curve_layout) checkbox = QCheckBox(parent=individual_curve_grpbx) checkbox.setObjectName(pv_name + "_chb") palette = checkbox.palette() palette.setColor(QPalette.Active, QPalette.WindowText, curve_color) checkbox.setPalette(palette) display_name = pv_name.split("://")[1] if len(display_name) > MAX_DISPLAY_PV_NAME_LENGTH: # Only display max allowed number of characters of the PV Name display_name = display_name[ :int(MAX_DISPLAY_PV_NAME_LENGTH / 2) - 1] + "..." + \ display_name[ -int(MAX_DISPLAY_PV_NAME_LENGTH / 2) + 2:] checkbox.setText(display_name) data_text = QLabel(parent=individual_curve_grpbx) data_text.setWordWrap(True) data_text.setObjectName(pv_name + "_lbl") data_text.setPalette(palette) checkbox.setChecked(True) checkbox.toggled.connect( partial(self.handle_curve_chkbox_toggled, checkbox)) if not self.chart.findCurve(pv_name).isVisible(): checkbox.setChecked(False) modify_curve_btn = QPushButton("Modify...", parent=individual_curve_grpbx) modify_curve_btn.setObjectName(pv_name + "_btn_modify") modify_curve_btn.setMaximumWidth(80) modify_curve_btn.clicked.connect( partial(self.display_curve_settings_dialog, pv_name)) focus_curve_btn = QPushButton("Focus", parent=individual_curve_grpbx) focus_curve_btn.setObjectName(pv_name + "_btn_focus") focus_curve_btn.setMaximumWidth(80) focus_curve_btn.clicked.connect(partial(self.focus_curve, pv_name)) clear_curve_btn = QPushButton("Clear", parent=individual_curve_grpbx) clear_curve_btn.setObjectName(pv_name + "_btn_clear") clear_curve_btn.setMaximumWidth(80) clear_curve_btn.clicked.connect(partial(self.clear_curve, pv_name)) # annotate_curve_btn = QPushButton("Annotate...", # parent=individual_curve_grpbx) # annotate_curve_btn.setObjectName(pv_name+"_btn_ann") # annotate_curve_btn.setMaximumWidth(80) # annotate_curve_btn.clicked.connect( # partial(self.annotate_curve, pv_name)) remove_curve_btn = QPushButton("Remove", parent=individual_curve_grpbx) remove_curve_btn.setObjectName(pv_name + "_btn_remove") remove_curve_btn.setMaximumWidth(80) remove_curve_btn.clicked.connect(partial(self.remove_curve, pv_name)) curve_btn_layout = QHBoxLayout() curve_btn_layout.setSpacing(5) curve_btn_layout.addWidget(modify_curve_btn) curve_btn_layout.addWidget(focus_curve_btn) curve_btn_layout.addWidget(clear_curve_btn) # curve_btn_layout.addWidget(annotate_curve_btn) curve_btn_layout.addWidget(remove_curve_btn) individual_curve_layout.addWidget(checkbox) individual_curve_layout.addWidget(data_text) individual_curve_layout.addLayout(curve_btn_layout) self.curve_settings_layout.addWidget(individual_curve_grpbx) self.tab_panel.setCurrentIndex(0)
def _setupUi(self): # timeplot self.title_plot = QLabel('Total Dose Rate (γ + n) [µSv/h]', self, alignment=Qt.AlignCenter) self.title_plot.setStyleSheet( 'QLabel{font-size: 52pt; font-weight: bold;}') timespan = 30 * 60 # [s] self.timeplot = SiriusTimePlot(parent=self, background='w', show_tooltip=True) self.timeplot.timeSpan = timespan self.timeplot.bufferSize = 4 * 60 * 60 * 10 self.timeplot.autoRangeY = True self.timeplot.minYRange = 0.0 self.timeplot.showXGrid = True self.timeplot.showYGrid = True self.timeplot.maxRedrawRate = 2 color = QColor(30, 30, 30) self.timeplot.plotItem.getAxis('bottom').setPen(color) self.timeplot.plotItem.getAxis('bottom').setGrid(255) self.timeplot.plotItem.getAxis('bottom').setTextPen(color) self.timeplot.plotItem.getAxis('left').setPen(color) self.timeplot.plotItem.getAxis('left').setGrid(255) self.timeplot.plotItem.getAxis('left').setTextPen(color) self.timeplot.setLabel('left', text='Dose Rate [µSv/h]') self.timeplot.setObjectName('timeplot') self.timeplot.setStyleSheet( '#timeplot{min-width:12em; min-height: 10em;}') self.timeplot.bufferReset.connect(self._fill_refline) self.timeplot.timeSpanChanged.connect(self._fill_refline) t_end = Time.now() t_init = t_end - timespan widplot = QWidget() widplot.setSizePolicy(QSzPol.Expanding, QSzPol.Expanding) layplot = QGridLayout(widplot) layplot.setHorizontalSpacing(10) layplot.setVerticalSpacing(10) layplot.addWidget(self.title_plot, 0, 0) layplot.addWidget(self.timeplot, 1, 0) # panel self.title_grid = QLabel('Integrated Dose in 4h [µSv]', self, alignment=Qt.AlignCenter) self.title_grid.setStyleSheet( 'QLabel{font-size: 52pt; font-weight: bold;}') self.lb_warn = QLabel('Restart\nwindow') self.lb_warn.setStyleSheet('color: red; border: 0.1em solid red;') self.lb_warn.setVisible(False) laytitle = QHBoxLayout() laytitle.addWidget(self.title_grid, 6) laytitle.addWidget(self.lb_warn, 1) widgrid = QWidget() widgrid.setSizePolicy(QSzPol.Maximum, QSzPol.Expanding) self.pannel = widgrid laygrid = QGridLayout(widgrid) laygrid.setHorizontalSpacing(10) laygrid.setVerticalSpacing(10) colnum = 3 laygrid.addLayout(laytitle, 0, 0, 1, colnum) for i, mon in enumerate(self._mon_order): local = self._mon2locv[mon] color = self._colors[i] pvname = self._prefix + ('-' if self._prefix else '') pvname += 'RAD:' + mon + ':TotalDoseRate' row, col = i // colnum + 1, i % colnum coloro = QColor(color) if isinstance(color, str) \ else QColor(*color) self.timeplot.addYChannel(pvname, name=pvname, color=coloro, lineWidth=6) curve = self.timeplot.curveAtIndex(-1) self._curves[mon] = curve self.timeplot.fill_curve_with_archdata(self._curves[mon], pvname, t_init=t_init.get_iso8601(), t_end=t_end.get_iso8601()) cbx = QCheckBox(self) cbx.setChecked(True) cbx.stateChanged.connect(curve.setVisible) cbx.setSizePolicy(QSzPol.Maximum, QSzPol.Maximum) pal = cbx.palette() pal.setColor(QPalette.Base, coloro) pal.setColor(QPalette.Text, Qt.white) cbx.setPalette(pal) self._cb_show[mon] = cbx lbl = PyDMLabel(self, pvname + ':Dose') lbl.alarmSensitiveBorder = False lbl.setStyleSheet('QLabel{font-size: 52pt;}') lbl.showUnits = True self._pvs_labels[mon] = lbl frame = SiriusAlarmFrame(self, pvname + ':Dose') frame.add_widget(cbx) frame.add_widget(lbl) desc = QLabel(local, self, alignment=Qt.AlignCenter) desc.setSizePolicy(QSzPol.Preferred, QSzPol.Maximum) desc.setStyleSheet( 'QLabel{background-color:black; color:white;font-size:26pt;}') self._desc_labels[mon] = desc wid = QWidget() wid.setObjectName('wid') wid.setStyleSheet('#wid{border: 1px solid black; ' 'min-width: 7.5em; max-width: 7.5em;}') widlay = QVBoxLayout(wid) widlay.setSpacing(0) widlay.setContentsMargins(1, 1, 1, 1) widlay.addWidget(frame) widlay.addWidget(desc) laygrid.addWidget(wid, row, col) laygrid.setColumnStretch(0, 1) laygrid.setColumnStretch(1, 1) laygrid.setColumnStretch(2, 1) self.timeplot.addYChannel('Reference', color='black', lineWidth=6, lineStyle=Qt.DashLine) self.refline = self.timeplot.curveAtIndex(-1) self._fill_refline() lay = QGridLayout(self) lay.setSpacing(20) lay.addWidget(widplot, 0, 0) lay.addWidget(widgrid, 0, 1) self.setStyleSheet(""" PyDMLabel{ qproperty-alignment: AlignCenter; font-weight: bold; } QCheckBox::indicator { width: 0.7em; height: 0.7em; }""") self._timer = QTimer() self._timer.timeout.connect(self._update_graph_ref) self._timer.setInterval(2000) self._timer.start()