def main(): app = QtWidgets.QApplication(sys.argv) form = Form() form.show() app.exec_()
self.addToolBar(QtCore.Qt.BottomToolBarArea, NavigationToolbar(dynamic_canvas, self)) self._static_ax = static_canvas.figure.subplots() t = np.linspace(0, 10, 501) self._static_ax.plot(t, np.tan(t), ".") self._dynamic_ax = dynamic_canvas.figure.subplots() self._timer = dynamic_canvas.new_timer( 100, [(self._update_canvas, (), {})]) self._timer.start() def _update_canvas(self): self._dynamic_ax.clear() t = np.linspace(0, 10, 101) # Shift the sinusoid as a function of time. self._dynamic_ax.plot(t, np.sin(t + time.time())) self._dynamic_ax.figure.canvas.draw() if __name__ == "__main__": # Check whether there is already a running QApplication (e.g., if running # from an IDE). qapp = QtWidgets.QApplication.instance() if not qapp: qapp = QtWidgets.QApplication(sys.argv) app = ApplicationWindow() app.show() qapp.exec_()
def __init__(self, fig_dispatch, text_dispatch): super().__init__(fig_dispatch, text_dispatch) self._window = QtWidgets.QMainWindow() self._window.setCentralWidget(self.widget) self._window.show()
from matplotlib.backends.qt_compat import QtWidgets, QtCore, is_pyqt5 if is_pyqt5(): from PyQt5.QtTest import QTest from PyQt5.QtCore import Qt else: from PyQt4.QtTest import QTest from PyQt4.QtCore import Qt from inspector import Inspector from inspector.constants import Labels from inspector import plugins app = QtWidgets.QApplication([]) failure_ = False sys._excepthook = sys.excepthook class ExceptionHandler(QtCore.QObject): errorSignal = QtCore.pyqtSignal() silentSignal = QtCore.pyqtSignal() def __init__(self): super(ExceptionHandler, self).__init__() def handler(self, exctype, value, traceback): global failure_ self.errorSignal.emit()
def setup(self): for label, value in self.data: if label is None and value is None: # Separator: (None, None) self.formlayout.addRow(QtWidgets.QLabel(" "), QtWidgets.QLabel(" ")) self.widgets.append(None) continue elif label is None: # Comment self.formlayout.addRow(QtWidgets.QLabel(value)) self.widgets.append(None) continue elif tuple_to_qfont(value) is not None: field = FontLayout(value, self) elif (label.lower() not in BLACKLIST and mcolors.is_color_like(value)): field = ColorLayout(to_qcolor(value), self) elif isinstance(value, str): field = QtWidgets.QLineEdit(value, self) elif isinstance(value, (list, tuple)): if isinstance(value, tuple): value = list(value) # Note: get() below checks the type of value[0] in self.data so # it is essential that value gets modified in-place. # This means that the code is actually broken in the case where # value is a tuple, but fortunately we always pass a list... selindex = value.pop(0) field = QtWidgets.QComboBox(self) if isinstance(value[0], (list, tuple)): keys = [key for key, _val in value] value = [val for _key, val in value] else: keys = value field.addItems(value) if selindex in value: selindex = value.index(selindex) elif selindex in keys: selindex = keys.index(selindex) elif not isinstance(selindex, Integral): _log.warning( "index '%s' is invalid (label: %s, value: %s)", selindex, label, value) selindex = 0 field.setCurrentIndex(selindex) elif isinstance(value, bool): field = QtWidgets.QCheckBox(self) if value: field.setCheckState(QtCore.Qt.Checked) else: field.setCheckState(QtCore.Qt.Unchecked) elif isinstance(value, Integral): field = QtWidgets.QSpinBox(self) field.setRange(-1e9, 1e9) field.setValue(value) elif isinstance(value, Real): field = QtWidgets.QLineEdit(repr(value), self) field.setCursorPosition(0) field.setValidator(QtGui.QDoubleValidator(field)) field.validator().setLocale(QtCore.QLocale("C")) dialog = self.get_dialog() dialog.register_float_field(field) field.textChanged.connect(lambda text: dialog.update_buttons()) elif isinstance(value, datetime.datetime): field = QtWidgets.QDateTimeEdit(self) field.setDateTime(value) elif isinstance(value, datetime.date): field = QtWidgets.QDateEdit(self) field.setDate(value) else: field = QtWidgets.QLineEdit(repr(value), self) self.formlayout.addRow(label, field) self.widgets.append(field)
def initManualtab(self): self._manu.gridlayout = QtWidgets.QGridLayout() self._manu.setLayout(self._manu.gridlayout) measurebutton = QtWidgets.QPushButton('Start measurement', self) measurebutton.setToolTip("Start a measurement") self._manu.gridlayout.addWidget(measurebutton, 0, 0, 1, 1, QtCore.Qt.AlignLeft) measurebutton.clicked.connect(self.start_measure) # stopmeasurebutton = QtWidgets.QPushButton('Stop measurement', self) stopmeasurebutton.setToolTip("Stop a measurement") self._manu.gridlayout.addWidget(stopmeasurebutton, 0, 1, 1, 1, QtCore.Qt.AlignLeft) stopmeasurebutton.clicked.connect(self.stop_measure) # savemeasurebutton = QtWidgets.QPushButton('Save measurement', self) savemeasurebutton.setToolTip("Save the last measurement") self._manu.gridlayout.addWidget(savemeasurebutton, 0, 2, 1, 1, QtCore.Qt.AlignLeft) savemeasurebutton.clicked.connect(self.save_measurement) # self.setsr80textbox = QtWidgets.QLineEdit(self) self.setsr80textbox.setText('20') self._manu.gridlayout.addWidget(self.setsr80textbox, 1, 0, 1, 1, QtCore.Qt.AlignLeft) setsr80button = QtWidgets.QPushButton('Set SR80 temperature', self) self._manu.gridlayout.addWidget(setsr80button, 1, 1, 1, 1, QtCore.Qt.AlignLeft) setsr80button.clicked.connect(self.set_sr80temp) # self.setsr800textbox = QtWidgets.QLineEdit(self) self.setsr800textbox.setText('20') self._manu.gridlayout.addWidget(self.setsr800textbox, 2, 0, 1, 1, QtCore.Qt.AlignLeft) setsr800button = QtWidgets.QPushButton('Set SR800 temperature', self) self._manu.gridlayout.addWidget(setsr800button, 2, 1, 1, 1, QtCore.Qt.AlignLeft) setsr800button.clicked.connect(self.set_sr800temp) # reinitmotorbutton = QtWidgets.QPushButton('Reinit motor', self) reinitmotorbutton.setToolTip("Re-Initialize Mirror") self._manu.gridlayout.addWidget(reinitmotorbutton, 3, 0, 1, 1, QtCore.Qt.AlignLeft) reinitmotorbutton.clicked.connect(self.reinitmotor) # roofbutton = QtWidgets.QPushButton('Point to roof', self) roofbutton.setToolTip("Point mirror to roof") self._manu.gridlayout.addWidget(roofbutton, 4, 0, 1, 1, QtCore.Qt.AlignLeft) roofbutton.clicked.connect(self.motor_roof) # sr80button = QtWidgets.QPushButton('Point to SR80', self) sr80button.setToolTip("Point mirror to SR80 black body") self._manu.gridlayout.addWidget(sr80button, 5, 0, 1, 1, QtCore.Qt.AlignLeft) sr80button.clicked.connect(self.motor_sr80) # sr800button = QtWidgets.QPushButton('Point to SR800', self) sr800button.setToolTip("Point mirror to SR800 black body") self._manu.gridlayout.addWidget(sr800button, 6, 0, 1, 1, QtCore.Qt.AlignLeft) sr800button.clicked.connect(self.motor_sr800) # ht1button = QtWidgets.QPushButton('Point to ht1', self) ht1button.setToolTip("Point mirror to self build heat bed black body") self._manu.gridlayout.addWidget(ht1button, 7, 0, 1, 1, QtCore.Qt.AlignLeft) ht1button.clicked.connect(self.motor_ht1) # rtbutton = QtWidgets.QPushButton('Point to rt', self) rtbutton.setToolTip( "Point mirror to self built room temperature black body") self._manu.gridlayout.addWidget(rtbutton, 8, 0, 1, 1, QtCore.Qt.AlignLeft) rtbutton.clicked.connect(self.motor_rt) # ir301button = QtWidgets.QPushButton('Point to IR301', self) ir301button.setToolTip("Point mirror to IR301 black body") self._manu.gridlayout.addWidget(ir301button, 9, 0, 1, 1, QtCore.Qt.AlignLeft) ir301button.clicked.connect(self.motor_ir301) # parkbutton = QtWidgets.QPushButton('Park mirror', self) parkbutton.setToolTip("Point mirror to park position") self._manu.gridlayout.addWidget(parkbutton, 10, 0, 1, 1, QtCore.Qt.AlignLeft) parkbutton.clicked.connect(self.motor_park) # sr800onbutton = QtWidgets.QPushButton('Switch SR800 on', self) sr800onbutton.setToolTip("Switch SR800 on") self._manu.gridlayout.addWidget(sr800onbutton, 3, 1, 1, 1, QtCore.Qt.AlignLeft) sr800onbutton.clicked.connect(self.switch_sr800_on) # sr800offbutton = QtWidgets.QPushButton('Switch SR800 off', self) sr800offbutton.setToolTip("Switch SR800 off") self._manu.gridlayout.addWidget(sr800offbutton, 4, 1, 1, 1, QtCore.Qt.AlignLeft) sr800offbutton.clicked.connect(self.switch_sr800_off) # # ir301onbutton = QtWidgets.QPushButton('Switch IR301 on', self) ir301onbutton.setToolTip("Switch IR301 on") self._manu.gridlayout.addWidget(ir301onbutton, 5, 1, 1, 1, QtCore.Qt.AlignLeft) ir301onbutton.clicked.connect(self.switch_ir301_on) # ir301offbutton = QtWidgets.QPushButton('Switch IR301 off', self) ir301offbutton.setToolTip("Switch IR301 off") self._manu.gridlayout.addWidget(ir301offbutton, 6, 1, 1, 1, QtCore.Qt.AlignLeft) ir301offbutton.clicked.connect(self.switch_ir301_off) # emailbutton = QtWidgets.QPushButton('Send diagnostics email', self) emailbutton.setToolTip("Send diagnostics emai") self._manu.gridlayout.addWidget(emailbutton, 7, 1, 1, 1, QtCore.Qt.AlignLeft) emailbutton.clicked.connect(self.send_diag_email) # self.paramtextbox = QtWidgets.QLineEdit(self) self.paramtextbox.setText(' | '.join( [k + ':' + str(j) for k, j in self.v80.meas_params.items()])) self._manu.gridlayout.addWidget(self.paramtextbox, 0, 3, 1, 4) parambutton = QtWidgets.QPushButton('Update params', self) parambutton.setToolTip("Set Vertex80 measurement parameters") self._manu.gridlayout.addWidget(parambutton, 1, 5, 1, 1, QtCore.Qt.AlignRight) parambutton.clicked.connect(self.setv80param) # self.v80commcheckbox = QtWidgets.QCheckBox( 'Block Vertex80 communications') self.v80commcheckbox.stateChanged.connect(self.set_blockv80comm) self._manu.gridlayout.addWidget(self.v80commcheckbox, 2, 3, 1, 1, QtCore.Qt.AlignLeft) # self.sr80commcheckbox = QtWidgets.QCheckBox( 'Block SR80 communications') self.sr80commcheckbox.stateChanged.connect(self.set_blocksr80comm) self._manu.gridlayout.addWidget(self.sr80commcheckbox, 3, 3, 1, 1, QtCore.Qt.AlignLeft) # # # self.dirlistwidget = QtWidgets.QListWidget() # self.make_listwidget() ##import ipdb; ipdb.set_trace() # self.dirlistwidget.itemClicked.connect(self.listclick) # self.gridlayout.addWidget(self.dirlistwidget, 1,3,3,2, QtCore.Qt.AlignRight) # # self.show_seq = QtWidgets.QTextEdit(self._main) # self._main.gridlayout.addWidget(self.show_seq) # Status Box self.Init_StatusBox()
def initMaintab(self): self._main.gridlayout = QtWidgets.QGridLayout() self.sequence_box = QtWidgets.QPlainTextEdit(self._main) self.vertex_box = QtWidgets.QPlainTextEdit(self._main) self.condition_box = QtWidgets.QPlainTextEdit(self._main) self.condition_box.resize(32, 8) self.actual_line = QtWidgets.QLabel(self._main) self.actual_line.setText('No sequence started') self.write_sequence() self.write_v80parms() self.write_conditions() self._main.gridlayout.addWidget(self.actual_line, 0, 1, 1, 2) self._main.gridlayout.addWidget(self.sequence_box, 1, 1, 5, 2) self._main.gridlayout.addWidget(self.vertex_box, 6, 1, 5, 2) self._main.gridlayout.addWidget(self.condition_box, 11, 1, 2, 2) loadseq_button = QtWidgets.QPushButton('Load sequence', self._main) loadseq_button.setToolTip("Load Sequence") self._main.gridlayout.addWidget(loadseq_button, 0, 0, 1, 1) loadseq_button.clicked.connect(self.Choose_SequenceFile) run_button = QtWidgets.QPushButton('Run Sequence', self._main) run_button.setToolTip("Run Sequence") self._main.gridlayout.addWidget(run_button, 1, 0, 1, 1) run_button.clicked.connect(self.start_sequence) stop_button = QtWidgets.QPushButton('Stop Sequence', self._main) stop_button.setToolTip("Stop Sequence immediately") self._main.gridlayout.addWidget(stop_button, 2, 0, 1, 1) stop_button.clicked.connect(self.stop_sequence) term_button = QtWidgets.QPushButton('Terminate Sequence', self._main) term_button.setToolTip("Stop Sequence immediately") self._main.gridlayout.addWidget(term_button, 3, 0, 1, 1) term_button.clicked.connect(self.terminate_sequence) self.ht1textbox = QtWidgets.QLineEdit(self) self.ht1textbox.setText('%3i' % self.preset_temps['ht1']) self._main.gridlayout.addWidget(self.ht1textbox, 5, 0, 1, 1) ht1tempbutton = QtWidgets.QPushButton('HT1 temp:', self) ht1tempbutton.setToolTip("Enter the current HT1 preset temperature") self._main.gridlayout.addWidget(ht1tempbutton, 4, 0, 1, 1, QtCore.Qt.AlignRight) ht1tempbutton.clicked.connect(self.setht1param) self.ir301textbox = QtWidgets.QLineEdit(self) self.ir301textbox.setText('%3.1f' % self.preset_temps['ir301']) self._main.gridlayout.addWidget(self.ir301textbox, 7, 0, 1, 1) ir301tempbutton = QtWidgets.QPushButton('IR301 temp:', self) ir301tempbutton.setToolTip( "Enter the current IR301 preset temperature") self._main.gridlayout.addWidget(ir301tempbutton, 6, 0, 1, 1, QtCore.Qt.AlignRight) ir301tempbutton.clicked.connect(self.setir301param) ##matplotlib integration from: ##https://matplotlib.org/gallery/user_interfaces/embedding_in_qt_sgskip.html#sphx-glr-gallery-user-interfaces-embedding-in-qt-sgskip-py plot_box = QtWidgets.QGroupBox(self._main) plot_box.gridlayout = QtWidgets.QGridLayout() self._main.gridlayout.addWidget(plot_box, 1, 4, 12, 4) self.dynamic_canvas = FigureCanvas(Figure(figsize=(6, 5))) # self.addToolBar(QtCore.Qt.BottomToolBarArea, NavigationToolbar(self.dynamic_canvas,plot_box)) plot_box.nav = NavigationToolbar(self.dynamic_canvas, plot_box) plot_box.gridlayout.addWidget(plot_box.nav, 1, 0, 1, 1) self._dynamic_ax1, self._dynamic_ax2 = self.dynamic_canvas.figure.subplots( 2) plot_box.gridlayout.addWidget(self.dynamic_canvas, 0, 0, 1, 1) plot_box.setLayout(plot_box.gridlayout) self._main.setLayout(self._main.gridlayout)
def __init__(self, *args, **kwargs): super(UiSubplotTool, self).__init__(*args, **kwargs) self.setObjectName('SubplotTool') self.resize(450, 265) gbox = QtWidgets.QGridLayout(self) self.setLayout(gbox) # groupbox borders groupbox = QtWidgets.QGroupBox('Borders', self) gbox.addWidget(groupbox, 6, 0, 1, 1) self.verticalLayout = QtWidgets.QVBoxLayout(groupbox) self.verticalLayout.setSpacing(0) # slider top self.hboxtop = QtWidgets.QHBoxLayout() self.labeltop = QtWidgets.QLabel('top', self) self.labeltop.setMinimumSize(QtCore.QSize(50, 0)) self.labeltop.setAlignment( QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter) self.slidertop = QtWidgets.QSlider(self) self.slidertop.setMouseTracking(False) self.slidertop.setProperty("value", 0) self.slidertop.setOrientation(QtCore.Qt.Horizontal) self.slidertop.setInvertedAppearance(False) self.slidertop.setInvertedControls(False) self.slidertop.setTickPosition(QtWidgets.QSlider.TicksAbove) self.slidertop.setTickInterval(100) self.topvalue = QtWidgets.QLabel('0', self) self.topvalue.setMinimumSize(QtCore.QSize(30, 0)) self.topvalue.setAlignment( QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter) self.verticalLayout.addLayout(self.hboxtop) self.hboxtop.addWidget(self.labeltop) self.hboxtop.addWidget(self.slidertop) self.hboxtop.addWidget(self.topvalue) # slider bottom hboxbottom = QtWidgets.QHBoxLayout() labelbottom = QtWidgets.QLabel('bottom', self) labelbottom.setMinimumSize(QtCore.QSize(50, 0)) labelbottom.setAlignment( QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter) self.sliderbottom = QtWidgets.QSlider(self) self.sliderbottom.setMouseTracking(False) self.sliderbottom.setProperty("value", 0) self.sliderbottom.setOrientation(QtCore.Qt.Horizontal) self.sliderbottom.setInvertedAppearance(False) self.sliderbottom.setInvertedControls(False) self.sliderbottom.setTickPosition(QtWidgets.QSlider.TicksAbove) self.sliderbottom.setTickInterval(100) self.bottomvalue = QtWidgets.QLabel('0', self) self.bottomvalue.setMinimumSize(QtCore.QSize(30, 0)) self.bottomvalue.setAlignment( QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter) self.verticalLayout.addLayout(hboxbottom) hboxbottom.addWidget(labelbottom) hboxbottom.addWidget(self.sliderbottom) hboxbottom.addWidget(self.bottomvalue) # slider left hboxleft = QtWidgets.QHBoxLayout() labelleft = QtWidgets.QLabel('left', self) labelleft.setMinimumSize(QtCore.QSize(50, 0)) labelleft.setAlignment( QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter) self.sliderleft = QtWidgets.QSlider(self) self.sliderleft.setMouseTracking(False) self.sliderleft.setProperty("value", 0) self.sliderleft.setOrientation(QtCore.Qt.Horizontal) self.sliderleft.setInvertedAppearance(False) self.sliderleft.setInvertedControls(False) self.sliderleft.setTickPosition(QtWidgets.QSlider.TicksAbove) self.sliderleft.setTickInterval(100) self.leftvalue = QtWidgets.QLabel('0', self) self.leftvalue.setMinimumSize(QtCore.QSize(30, 0)) self.leftvalue.setAlignment( QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter) self.verticalLayout.addLayout(hboxleft) hboxleft.addWidget(labelleft) hboxleft.addWidget(self.sliderleft) hboxleft.addWidget(self.leftvalue) # slider right hboxright = QtWidgets.QHBoxLayout() self.labelright = QtWidgets.QLabel('right', self) self.labelright.setMinimumSize(QtCore.QSize(50, 0)) self.labelright.setAlignment( QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter) self.sliderright = QtWidgets.QSlider(self) self.sliderright.setMouseTracking(False) self.sliderright.setProperty("value", 0) self.sliderright.setOrientation(QtCore.Qt.Horizontal) self.sliderright.setInvertedAppearance(False) self.sliderright.setInvertedControls(False) self.sliderright.setTickPosition(QtWidgets.QSlider.TicksAbove) self.sliderright.setTickInterval(100) self.rightvalue = QtWidgets.QLabel('0', self) self.rightvalue.setMinimumSize(QtCore.QSize(30, 0)) self.rightvalue.setAlignment( QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter) self.verticalLayout.addLayout(hboxright) hboxright.addWidget(self.labelright) hboxright.addWidget(self.sliderright) hboxright.addWidget(self.rightvalue) # groupbox spacings groupbox = QtWidgets.QGroupBox('Spacings', self) gbox.addWidget(groupbox, 7, 0, 1, 1) self.verticalLayout = QtWidgets.QVBoxLayout(groupbox) self.verticalLayout.setSpacing(0) # slider hspace hboxhspace = QtWidgets.QHBoxLayout() self.labelhspace = QtWidgets.QLabel('hspace', self) self.labelhspace.setMinimumSize(QtCore.QSize(50, 0)) self.labelhspace.setAlignment( QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter) self.sliderhspace = QtWidgets.QSlider(self) self.sliderhspace.setMouseTracking(False) self.sliderhspace.setProperty("value", 0) self.sliderhspace.setOrientation(QtCore.Qt.Horizontal) self.sliderhspace.setInvertedAppearance(False) self.sliderhspace.setInvertedControls(False) self.sliderhspace.setTickPosition(QtWidgets.QSlider.TicksAbove) self.sliderhspace.setTickInterval(100) self.hspacevalue = QtWidgets.QLabel('0', self) self.hspacevalue.setMinimumSize(QtCore.QSize(30, 0)) self.hspacevalue.setAlignment( QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter) self.verticalLayout.addLayout(hboxhspace) hboxhspace.addWidget(self.labelhspace) hboxhspace.addWidget(self.sliderhspace) hboxhspace.addWidget(self.hspacevalue) # slider hspace # slider wspace hboxwspace = QtWidgets.QHBoxLayout() self.labelwspace = QtWidgets.QLabel('wspace', self) self.labelwspace.setMinimumSize(QtCore.QSize(50, 0)) self.labelwspace.setAlignment( QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter) self.sliderwspace = QtWidgets.QSlider(self) self.sliderwspace.setMouseTracking(False) self.sliderwspace.setProperty("value", 0) self.sliderwspace.setOrientation(QtCore.Qt.Horizontal) self.sliderwspace.setInvertedAppearance(False) self.sliderwspace.setInvertedControls(False) self.sliderwspace.setTickPosition(QtWidgets.QSlider.TicksAbove) self.sliderwspace.setTickInterval(100) self.wspacevalue = QtWidgets.QLabel('0', self) self.wspacevalue.setMinimumSize(QtCore.QSize(30, 0)) self.wspacevalue.setAlignment( QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter) self.verticalLayout.addLayout(hboxwspace) hboxwspace.addWidget(self.labelwspace) hboxwspace.addWidget(self.sliderwspace) hboxwspace.addWidget(self.wspacevalue) # button bar hbox2 = QtWidgets.QHBoxLayout() gbox.addLayout(hbox2, 8, 0, 1, 1) self.tightlayout = QtWidgets.QPushButton('Tight Layout', self) spacer = QtWidgets.QSpacerItem( 5, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) self.resetbutton = QtWidgets.QPushButton('Reset', self) self.donebutton = QtWidgets.QPushButton('Close', self) self.donebutton.setFocus() hbox2.addWidget(self.tightlayout) hbox2.addItem(spacer) hbox2.addWidget(self.resetbutton) hbox2.addWidget(self.donebutton) self.donebutton.clicked.connect(self.accept)
def setup(self): for label, value in self.data: if DEBUG: print("value:", value) if label is None and value is None: # Separator: (None, None) self.formlayout.addRow(QtWidgets.QLabel(" "), QtWidgets.QLabel(" ")) self.widgets.append(None) continue elif label is None: # Comment self.formlayout.addRow(QtWidgets.QLabel(value)) self.widgets.append(None) continue elif tuple_to_qfont(value) is not None: field = FontLayout(value, self) elif is_color_like(value): field = ColorLayout(to_qcolor(value), self) elif isinstance(value, six.string_types): field = QtWidgets.QLineEdit(value, self) elif isinstance(value, (list, tuple)): if isinstance(value, tuple): value = list(value) selindex = value.pop(0) field = QtWidgets.QComboBox(self) if isinstance(value[0], (list, tuple)): keys = [key for key, _val in value] value = [val for _key, val in value] else: keys = value field.addItems(value) if selindex in value: selindex = value.index(selindex) elif selindex in keys: selindex = keys.index(selindex) elif not isinstance(selindex, int): print("Warning: '%s' index is invalid (label: " "%s, value: %s)" % (selindex, label, value), file=STDERR) selindex = 0 field.setCurrentIndex(selindex) elif isinstance(value, bool): field = QtWidgets.QCheckBox(self) if value: field.setCheckState(QtCore.Qt.Checked) else: field.setCheckState(QtCore.Qt.Unchecked) elif isinstance(value, float): field = QtWidgets.QLineEdit(repr(value), self) field.setValidator(QtGui.QDoubleValidator(field)) dialog = self.get_dialog() dialog.register_float_field(field) field.textChanged.connect(lambda text: dialog.update_buttons()) elif isinstance(value, int): field = QtWidgets.QSpinBox(self) field.setRange(-1e9, 1e9) field.setValue(value) elif isinstance(value, datetime.datetime): field = QtWidgets.QDateTimeEdit(self) field.setDateTime(value) elif isinstance(value, datetime.date): field = QtWidgets.QDateEdit(self) field.setDate(value) else: field = QtWidgets.QLineEdit(repr(value), self) self.formlayout.addRow(label, field) self.widgets.append(field)
def _init_toolbar(self): for text, tooltip_text, image_file, callback in self.toolitems: if text is None: # bug fix to avoid duplicated separators in the task bar continue if text == 'Home': home_action = self.addAction(self._icon('home.png'), 'Reset view', self.home) home_action.setToolTip('Reset view') self._actions['home'] = home_action elif text == 'Back': back_action = self.addAction(self._icon('back.png'), 'Back', self.back) back_action.setToolTip('Previous view') self._actions['back'] = back_action elif text == 'Forward': forward_action = self.addAction(self._icon('forward.png'), 'Forward', self.forward) forward_action.setToolTip('Next view') self._actions['forward'] = forward_action self.addSeparator() elif text == 'Pan': pan_action = self.addAction(self._icon('pan.png'), 'Pan', self.pan) pan_action.setToolTip('Pan on plot') pan_action.setCheckable(True) self._actions['pan'] = pan_action scale_action = self.addAction(self._icon('scale.png'), 'Scale', self.scale) scale_action.setToolTip('Scale plot') scale_action.setCheckable(True) self._actions['scale'] = scale_action elif text == 'Zoom': zoom_in_action = self.addAction(self._icon('zoomin.png'), 'Zoom in', self.zoom_in) zoom_in_action.setToolTip('Zoom in area') zoom_in_action.setCheckable(True) self._actions['zoom_in'] = zoom_in_action zoom_out_action = self.addAction(self._icon('zoomout.png'), 'Zoom out', self.zoom_out) zoom_out_action.setToolTip('Zoom out area') zoom_out_action.setCheckable(True) self._actions['zoom_out'] = zoom_out_action # flag/unflag actions self.flag_action = self.addAction(self._icon("flag.png"), 'Flag', self.flag) self.flag_action.setToolTip('Flag samples') self.flag_action.setCheckable(True) self._actions['flag'] = self.flag_action self.unflag_action = self.addAction(self._icon("unflag.png"), 'Unflag', self.unflag) self.unflag_action.setToolTip('Unflag samples') self.unflag_action.setCheckable(True) self._actions['unflag'] = self.unflag_action self.insert_action = self.addAction(self._icon("insert.png"), 'Insert', self.insert) self.insert_action.setToolTip('Insert samples') self.insert_action.setCheckable(True) self._actions['insert'] = self.insert_action self.addSeparator() elif text == 'Subplots': self.flagged_action = self.addAction(self._icon("flagged.png"), 'Flagged', self.flagged_plot) self.flagged_action.setToolTip('Hide flagged') self.flagged_action.setCheckable(True) self.flagged_action.setChecked(True) self._actions['flagged'] = self.flagged_action self.grid_action = self.addAction(self._icon("plot_grid.png"), 'Grid', self.grid_plot) self.grid_action.setToolTip('Toggle grids') self.grid_action.setCheckable(True) self.grid_action.setChecked(True) self._actions['grid'] = self.grid_action self.legend_action = self.addAction(self._icon("plot_legend.png"), 'Legend', self.legend_plot) self.legend_action.setToolTip('Toggle legends') self.legend_action.setCheckable(True) self.legend_action.setChecked(False) self._actions['legend'] = self.legend_action subplots_action = self.addAction(self._icon('subplots.png'), 'Subplots', self.configure_subplots) subplots_action.setToolTip('Configure subplots') self._actions['subplots'] = subplots_action if figureoptions is not None: a = self.addAction(self._icon("qt5_editor_options.png"), 'Customize', self.edit_parameters) a.setToolTip('Edit curves line and axes parameters') elif text == 'Save': self.addSeparator() save_action = self.addAction(self._icon('filesave.png'), 'Save', self.save_figure) save_action.setToolTip('Save the figure') self._actions['save'] = save_action else: a = self.addAction(self._icon(image_file + '.png'), text, getattr(self, callback)) self._actions[callback] = a if tooltip_text is not None: a.setToolTip(tooltip_text) # Add the x,y location widget at the right side of the toolbar if self.coordinates: frame = QtWidgets.QFrame() # policy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Ignored) # frame.setSizePolicy(policy) self.addWidget(frame) hbox = QtWidgets.QHBoxLayout() frame.setLayout(hbox) hbox.addStretch() vbox = QtWidgets.QVBoxLayout() hbox.addLayout(vbox) # - location label self.locLabel = QtWidgets.QLabel("", self) self.locLabel.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignTop) vbox.addWidget(self.locLabel) # - insert label self.mon_label = QtWidgets.QLabel("", self) self.mon_label.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignTop) self.mon_label.setStyleSheet("QLabel { color : red; }") vbox.addWidget(self.mon_label)
def main(): global app app = QtWidgets.QApplication(sys.argv) gui = Window() sys.exit(app.exec_())
def main(): app = QtWidgets.QApplication(sys.argv) w = Program() w.show() sys.exit(app.exec_())
def __init__(self): super().__init__() self.T = 60 self.invertible_model = InvertibleModel(self.T) self._main = QtWidgets.QFrame(self) self.vertical_layout = QtWidgets.QVBoxLayout(self._main) self._main.setLayout(self.vertical_layout) self.setCentralWidget(self._main) self.toolbar = self.addToolBar('Toolbar') combo = QtWidgets.QComboBox(self) combo.addItem('Simple Example') combo.addItem('Complex Example 1') combo.addItem('Complex Example 2') combo.setCurrentIndex(0) combo.activated.connect(self.combo_activated) self.toolbar.addWidget(combo) compute_encode_action = QtWidgets.QAction('encode f(x) -> y,z', self) compute_encode_action.triggered.connect(self.compute_encode) self.toolbar.addAction(compute_encode_action) compute_decode_action = QtWidgets.QAction('decode f_inv(y,z) -> x', self) compute_decode_action.triggered.connect(self.compute_decode) self.toolbar.addAction(compute_decode_action) denoise_action = QtWidgets.QAction('denoise [y, yz_pad, z]', self) denoise_action.triggered.connect(self.denoise) self.toolbar.addAction(denoise_action) # zero_yz_pad_action = QtWidgets.QAction('yz padding -> 0', self) # zero_yz_pad_action.triggered.connect(self.zero_yz_pad) # self.toolbar.addAction(zero_yz_pad_action) # confusing, leave out # label = 'yz padding -> N(0, {:>4.2g})'.format(self.invertible_model.model.zeros_noise_scale) # noise_yz_pad_action = QtWidgets.QAction(label, self) # noise_yz_pad_action.triggered.connect(self.noise_yz_pad) # self.toolbar.addAction(noise_yz_pad_action) gauss_z_action = QtWidgets.QAction('z -> N(0, 1)', self) gauss_z_action.triggered.connect(self.gauss_z) self.toolbar.addAction(gauss_z_action) self.ssim_label = QtWidgets.QLabel( 'structural similarity(x, x_hat) = {:4.2g}'.format(0.9999), self) spacer = QtWidgets.QWidget() spacer.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding) self.toolbar.addWidget(spacer) self.toolbar.addWidget(self.ssim_label) # self.threshold_slider = QtWidgets.QSlider(Qt.Horizontal, self) # self.threshold_slider.setMinimum(0) # self.threshold_slider.setMaximum(500) # self.threshold_slider.setValue(50) # self.threshold_slider.valueChanged.connect(self.changeThreshold) # self.toolbar.addWidget(self.threshold_slider) # threshold_label = 'set all values < {:4.2g} to 0'.format( # self.threshold_slider.value() / 100. # ) # self.threshold_action = QtWidgets.QAction(threshold_label, self) # self.threshold_action.triggered.connect(self.threshold) # self.toolbar.addAction(self.threshold_action) # hide_editors_action = QtWidgets.QAction('Hide Editors', self) # hide_editors_action.triggered.connect(self.hide_editors) # self.toolbar.addAction(hide_editors_action) self.upper = QtWidgets.QFrame(self._main) self.lower_single = SingleEditorWidget(self._main) self.lower_single.setFixedHeight(170) self.lower_double = DoubleEditorWidget(self._main) self.lower_double.setFixedHeight(210) self.vertical_layout.addWidget(self.upper) self.vertical_layout.addWidget(self.lower_single) self.vertical_layout.addWidget(self.lower_double) upper_layout = QtWidgets.QHBoxLayout(self.upper) ##################################################### # these calls need to stay in this order! otherwise # the event handlers registered in the figure # will be overwritten! # create a mpl figure self.figure = create_figure() # create the figurecanvas object self.canvas = FigureCanvas(self.figure) # plot into the figure # self.combo_activated(combo.currentIndex()) filename, start = filenames_and_starts[combo.currentIndex()] x, x_frames, x_velocity = get_xy_from_file( filename + '.flac', filename + '.mid', self.invertible_model.audio_options) print('x.shape', x.shape) print('x_frames.shape', x_frames.shape) print('x_velocity.shape', x_velocity.shape) self.x_true = np.array(x[start:start + self.T]) self.z_pred, self.yz_pad_pred, self.y_pred = self.invertible_model.encode( self.x_true) self.x_inv, self.x_inv_padding = self.invertible_model.decode( self.z_pred, self.yz_pad_pred, self.y_pred) ################################################################# # test only # self.x_true = np.random.uniform(0, 1, (self.T, 256)) # self.y_pred = np.random.uniform(0, 1, (self.T, 185)) # self.z_pred = np.random.uniform(0, 1, (self.T, 9)) # self.yz_pad_pred = np.random.uniform(0, 1, (self.T, 62)) # self.x_inv = np.random.uniform(0, 1, (self.T, 256)) ################################################################# print('self.x_true.shape', self.x_true.shape) print('self.y_pred.shape', self.y_pred.shape) print('self.yz_pad_pred.shape', self.yz_pad_pred.shape) print('self.z_pred.shape', self.z_pred.shape) print('self.x_inv.shape', self.x_inv.shape) print('self.x_inv_padding.shape', self.x_inv_padding.shape) self.all_plots = AllPlots(fig=self.figure, x_true=self.x_true.view(), y_pred=self.y_pred.view(), z_pred=self.z_pred.view(), yz_pad_pred=self.yz_pad_pred.view(), x_inv=self.x_inv.view()) upper_layout.addWidget(self.canvas) # connect the signals to slots self.all_plots.ipo_y_instrument.do_select.connect(self.select) self.all_plots.ipo_y_phase.do_select.connect(self.select_pv) self.all_plots.ipo_y_velocity.do_select.connect(self.select_pv) self.all_plots.ipo_z.do_select.connect(self.select) self.all_plots.ipo_yz_pad_pred.do_select.connect(self.select) ###################################################### self.selected_y = 8 self.selected_ipo = self.all_plots.ipo_y_instrument self.select(self.selected_ipo, self.selected_y) self.lower_single.show() self.lower_double.hide() self.upper.setFocus()
self.editing = False self.lower_double.hide() self.lower_single.hide() self.all_plots.redraw() def update_selection(self): if self.selected_ipo == self.all_plots.ipo_y_phase: self.select_pv(self.selected_ipo, self.selected_y) else: self.select(self.selected_ipo, self.selected_y) def keyPressEvent(self, e): key = e.key() if key == Qt.Key_Escape: self.close() elif key == Qt.Key_F: self.selected_y += 1 self.update_selection() elif key == Qt.Key_S: self.selected_y -= 1 self.update_selection() if __name__ == "__main__": # if we don't pass the style, we'll get some warnings # https://github.com/therecipe/qt/issues/306 qapp = QtWidgets.QApplication(['main.py', '--style', 'Fusion']) app = ApplicationWindow() app.show() qapp.exec_()
def __init__(self, *args, **kwargs): super(UiSubplotTool, self).__init__(*args, **kwargs) self.setObjectName("SubplotTool") self._widgets = {} layout = QtWidgets.QHBoxLayout() self.setLayout(layout) left = QtWidgets.QVBoxLayout() layout.addLayout(left) right = QtWidgets.QVBoxLayout() layout.addLayout(right) box = QtWidgets.QGroupBox("Borders") left.addWidget(box) inner = QtWidgets.QFormLayout(box) for side in ["top", "bottom", "left", "right"]: self._widgets[side] = widget = QtWidgets.QDoubleSpinBox() widget.setMinimum(0) widget.setMaximum(1) widget.setDecimals(3) widget.setSingleStep(.005) widget.setKeyboardTracking(False) inner.addRow(side, widget) left.addStretch(1) box = QtWidgets.QGroupBox("Spacings") right.addWidget(box) inner = QtWidgets.QFormLayout(box) for side in ["hspace", "wspace"]: self._widgets[side] = widget = QtWidgets.QDoubleSpinBox() widget.setMinimum(0) widget.setMaximum(1) widget.setDecimals(3) widget.setSingleStep(.005) widget.setKeyboardTracking(False) inner.addRow(side, widget) right.addStretch(1) widget = QtWidgets.QPushButton("Export values") self._widgets["Export values"] = widget # Don't trigger on <enter>, which is used to input values. widget.setAutoDefault(False) left.addWidget(widget) for action in ["Tight layout", "Reset", "Close"]: self._widgets[action] = widget = QtWidgets.QPushButton(action) widget.setAutoDefault(False) right.addWidget(widget) self._widgets["Close"].setFocus()
def block(self, blocking_event): """ The default setting for the RunEngine's during_task parameter. This makes it possible for plots that use matplotlib's Qt backend to update live during data acquisition. It solves the problem that Qt must be run from the main thread. If matplotlib and a known Qt binding are already imported, run the matplotlib qApp until the task completes. If not, there is no need to handle qApp: just wait on the task. """ global _qapp if 'matplotlib' not in sys.modules: # We are not using matplotlib + Qt. Just wait on the Event. blocking_event.wait() # Figure out if we are using matplotlib with which backend # without importing anything that is not already imported. else: import matplotlib backend = matplotlib.get_backend().lower() # if with a Qt backend, do the scary thing if 'qt' in backend: from matplotlib.backends.qt_compat import QtCore, QtWidgets app = QtWidgets.QApplication.instance() if app is None: _qapp = app = QtWidgets.QApplication([b'bluesky']) assert app is not None event_loop = QtCore.QEventLoop() def start_killer_thread(): def exit_loop(): blocking_event.wait() # If the above wait ends quickly, we need to avoid the race # condition where this thread might try to exit the qApp # before it even starts. Therefore, we use QTimer, below, # which will not start running until the qApp event loop is # running. event_loop.exit() threading.Thread(target=exit_loop).start() # https://www.riverbankcomputing.com/pipermail/pyqt/2015-March/035674.html # adapted from code at # https://bitbucket.org/tortoisehg/thg/commits/550e1df5fbad if os.name == 'posix' and hasattr(signal, 'set_wakeup_fd'): # Wake up Python interpreter via pipe so that SIGINT # can be handled immediately. # (http://qt-project.org/doc/qt-4.8/unix-signals.html) # Updated docs: # https://doc.qt.io/qt-5/unix-signals.html import fcntl rfd, wfd = os.pipe() for fd in (rfd, wfd): flags = fcntl.fcntl(fd, fcntl.F_GETFL) fcntl.fcntl(fd, fcntl.F_SETFL, flags | os.O_NONBLOCK) wakeupsn = QtCore.QSocketNotifier( rfd, QtCore.QSocketNotifier.Read) origwakeupfd = signal.set_wakeup_fd(wfd) def cleanup(): wakeupsn.setEnabled(False) rfd = wakeupsn.socket() wfd = signal.set_wakeup_fd(origwakeupfd) os.close(int(rfd)) os.close(wfd) def handleWakeup(inp): # here Python signal handler will be invoked # this book-keeping is to drain the pipe wakeupsn.setEnabled(False) rfd = wakeupsn.socket() try: os.read(int(rfd), 4096) except OSError as inst: print('failed to read wakeup fd: %s\n' % inst) wakeupsn.setEnabled(True) wakeupsn.activated.connect(handleWakeup) else: # On Windows, non-blocking anonymous pipe or socket is # not available. def null(): ... # we need to 'kick' the python interpreter so it sees # system signals # https://stackoverflow.com/a/4939113/380231 kick_timer = QtCore.QTimer() kick_timer.timeout.connect(null) kick_timer.start(50) cleanup = kick_timer.stop # we also need to make sure that the qApp never sees # exceptions raised by python inside of a c++ callback (as # it will segfault itself because due to the way the # code is called there is no clear way to propagate that # back to the python code. vals = (None, None, None) old_sys_handler = sys.excepthook def my_exception_hook(exctype, value, traceback): nonlocal vals vals = (exctype, value, traceback) event_loop.exit() old_sys_handler(exctype, value, traceback) # this kill the Qt event loop when the plan is finished killer_timer = QtCore.QTimer() killer_timer.setSingleShot(True) killer_timer.timeout.connect(start_killer_thread) killer_timer.start(0) try: sys.excepthook = my_exception_hook event_loop.exec_() # make sure any pending signals are processed event_loop.processEvents() if vals[1] is not None: raise vals[1] finally: try: cleanup() finally: sys.excepthook = old_sys_handler elif 'ipympl' in backend or 'nbagg' in backend: Gcf = matplotlib._pylab_helpers.Gcf while True: done = blocking_event.wait(.1) for f_mgr in Gcf.get_all_fig_managers(): if f_mgr.canvas.figure.stale: f_mgr.canvas.draw() if done: return else: # We are not using matplotlib + Qt. Just wait on the Event. blocking_event.wait()
def __init__(self): super().__init__() self._main = QtWidgets.QWidget() self.setCentralWidget(self._main) self.vLayout = QtWidgets.QVBoxLayout(self._main) #------------------- WINDOW SETTINGS -------------------# #self.setGeometry(300,300,1000,600) self.setWindowTitle("Deep Features GUI") #self.setWindowIcon(QtGui.QIcon("")) self.setStyleSheet("background-color:") self.show() #------------------- WINDOW SETTINGS -------------------# self.fs=100 self.num=2000 #------------------- DEFINE FEATURE SPACE -------------------# self.boxValues, self.weightNames = list(), list() hLayout = QtWidgets.QHBoxLayout() self.loadPath = QtWidgets.QTextEdit(maximumHeight=30) hLayout.addWidget(self.loadPath) self.loadFile = QtWidgets.QPushButton('Load File', self) self.loadFile.clicked.connect(self.LoadFile) hLayout.addWidget(self.loadFile) self.vLayout.addLayout(hLayout) hLayout = QtWidgets.QHBoxLayout() numClasses = QtWidgets.QLabel('Number of Classes:') hLayout.addWidget(numClasses) self.classes = QtWidgets.QSpinBox(minimum=2,maximum=10, value=3) hLayout.addWidget(self.classes) self.vLayout.addLayout(hLayout) hLayout = QtWidgets.QHBoxLayout() numDimensions = QtWidgets.QLabel('Number of Dimensions:') hLayout.addWidget(numDimensions) self.dimensions = QtWidgets.QSpinBox(minimum=2,maximum=128, value=5) hLayout.addWidget(self.dimensions) self.vLayout.addLayout(hLayout) hLayout = QtWidgets.QHBoxLayout() self.space = QtWidgets.QPushButton('Create Space') hLayout.addWidget(self.space) self.space.clicked.connect(self.CreateSpace) self.normAll = QtWidgets.QPushButton('Normalize') hLayout.addWidget(self.normAll) self.normAll.clicked.connect(self.Normalize) self.calcul = QtWidgets.QPushButton('Calculate') hLayout.addWidget(self.calcul) self.calcul.clicked.connect(self.Calculate) self.progress = QtWidgets.QProgressBar(self, maximumWidth=200) hLayout.addWidget(self.progress) self.vLayout.addLayout(hLayout) self.static_canvas = FigureCanvas(Figure(figsize=(5,3))) self.toolbar = NavigationToolbar(self.static_canvas, self) self.toPlot = { '00': [np.arange(20), np.zeros((1,20)),'Norm' ], '01': [np.arange(20), np.zeros((1,20)),'Angle'], '10': [np.arange(20), np.zeros((1,20)),'Norm Derivative' ], '11': [np.arange(20), np.zeros((1,20)),'Angle Derivative'] } self.Plot() self.CreateSpace()
def __init__(self, parent, idx): super().__init__('FEMB%i' % idx, parent) self.idx = idx self.setAutoFillBackground(True) p = self.palette() p.setColor(self.backgroundRole(), QtGui.QColor(*colors[0])) self.setPalette(p) self.setStyleSheet('QGroupBox { font-weight: bold; color: #cb4b16; } ') self.tpower_sensor = VTSensor(self, 'Power Temp', lambda s: s.ltc2499_15_temps[self.idx]) self.iv_sensors = [] self.iv_sensors.append( IVSensor( self, 'LDO A0', lambda s: s.femb_ldo_a0_ltc2991_voltages[self.idx * 2: (self.idx + 1) * 2], sense_ohms=0.01, disabled=True)) self.iv_sensors.append( IVSensor( self, 'LDO A1', lambda s: s.femb_ldo_a1_ltc2991_voltages[self.idx * 2: (self.idx + 1) * 2], sense_ohms=0.01, disabled=True)) self.iv_sensors.append( IVSensor( self, '5V Bias', lambda s: s.femb_bias_ltc2991_voltages[self.idx * 2: (self.idx + 1) * 2], sense_ohms=0.1)) self.iv_sensors.append( IVSensor(self, 'DC/DC V1', lambda s: dc2dc(s, self.idx)[0:2], sense_ohms=0.1)) self.iv_sensors.append( IVSensor(self, 'DC/DC V2', lambda s: dc2dc(s, self.idx)[2:4], sense_ohms=0.1)) self.iv_sensors.append( IVSensor(self, 'DC/DC V3', lambda s: dc2dc(s, self.idx)[4:6], sense_ohms=0.01)) self.iv_sensors.append( IVSensor(self, 'DC/DC V4', lambda s: dc2dc(s, self.idx)[6:8], sense_ohms=0.1)) layout = QtWidgets.QGridLayout(self) layout.addWidget(self.tpower_sensor, 0, 0) for i, t in enumerate(self.iv_sensors): layout.addWidget(t, (i + 1) // 4, (i + 1) % 4)
def Init_StatusBox(self): sbox = QtWidgets.QGroupBox(self.main) self.gridlayout.addWidget(sbox, 0, 1, 10, 1) sbox.gridlayout = QtWidgets.QGridLayout() title = QtWidgets.QLabel(sbox) title.setText('Status box') sbox.gridlayout.addWidget(title, 0, 0, 1, 1, QtCore.Qt.AlignLeft) ### General status and kob box statbox = QtWidgets.QGroupBox(sbox) sbox.gridlayout.addWidget(statbox, 1, 0, 1, 1) statbox.gridlayout = QtWidgets.QGridLayout() ### Conditions OK? statlabel = QtWidgets.QLabel(statbox) statlabel.setText('Conditions') statbox.gridlayout.addWidget(statlabel, 0, 0, 1, 2, QtCore.Qt.AlignLeft) self.conds = QtWidgets.QLabel(statbox) statbox.gridlayout.addWidget(self.conds, 0, 1, 1, 1, QtCore.Qt.AlignLeft) statbox.setLayout(statbox.gridlayout) ### Which state is the software in? modlabel = QtWidgets.QLabel(statbox) modlabel.setText('Software Mode') statbox.gridlayout.addWidget(modlabel, 1, 0, 1, 1, QtCore.Qt.AlignLeft) self.auto_modus = QtWidgets.QLabel(statbox) statbox.gridlayout.addWidget(self.auto_modus, 1, 1, 1, 1, QtCore.Qt.AlignLeft) modlabel = QtWidgets.QLabel(statbox) modlabel.setText('Sequence running?') statbox.gridlayout.addWidget(modlabel, 2, 0, 1, 1, QtCore.Qt.AlignLeft) self.seq_modus = QtWidgets.QLabel(statbox) statbox.gridlayout.addWidget(self.seq_modus, 2, 1, 1, 1, QtCore.Qt.AlignLeft) statbox.setLayout(statbox.gridlayout) ### SR 80 monitor box tempbox = QtWidgets.QGroupBox(sbox) sbox.gridlayout.addWidget(tempbox, 2, 0, 1, 1) tempbox.gridlayout = QtWidgets.QGridLayout() templabel = QtWidgets.QLabel(tempbox) templabel.setText('SR80 Temperature') tempbox.gridlayout.addWidget(templabel, 1, 0, 1, 2, QtCore.Qt.AlignLeft) # self.sr80_temp = QtWidgets.QLabel(sbox) # sbox.gridlayout.addWidget(self.sr80_temp,1,1,1,1,QtCore.Qt.AlignLeft) sr80_l1 = QtWidgets.QLabel(tempbox) sr80_l1.setText('Target') tempbox.gridlayout.addWidget(sr80_l1, 2, 0, 1, 1, QtCore.Qt.AlignLeft) self.sr80_target = QtWidgets.QLabel(tempbox) tempbox.gridlayout.addWidget(self.sr80_target, 2, 1, 1, 1, QtCore.Qt.AlignLeft) sr80_l1 = QtWidgets.QLabel(tempbox) sr80_l1.setText('Reached') tempbox.gridlayout.addWidget(sr80_l1, 3, 0, 1, 1, QtCore.Qt.AlignLeft) self.sr80_reached = QtWidgets.QLabel(tempbox) tempbox.gridlayout.addWidget(self.sr80_reached, 3, 1, 1, 1, QtCore.Qt.AlignLeft) sr80_l1 = QtWidgets.QLabel(tempbox) sr80_l1.setText('Stable') tempbox.gridlayout.addWidget(sr80_l1, 4, 0, 1, 1, QtCore.Qt.AlignLeft) self.sr80_status = QtWidgets.QLabel(tempbox) tempbox.gridlayout.addWidget(self.sr80_status, 4, 1, 1, 1, QtCore.Qt.AlignLeft) tempbox.setLayout(tempbox.gridlayout) #### VR80 Monitor box v80box = QtWidgets.QGroupBox(sbox) sbox.gridlayout.addWidget(v80box, 3, 0, 1, 1) v80box.gridlayout = QtWidgets.QGridLayout() v80_label = QtWidgets.QLabel(v80box) v80_label.setText('Vertex 80') v80box.gridlayout.addWidget(v80_label, 0, 0, 1, 2, QtCore.Qt.AlignLeft) v80_l1 = QtWidgets.QLabel(v80box) v80_l1.setText('Status') v80box.gridlayout.addWidget(v80_l1, 1, 0, 1, 1, QtCore.Qt.AlignLeft) self.v80_status = QtWidgets.QLabel(v80box) v80box.gridlayout.addWidget(self.v80_status, 1, 1, 1, 1, QtCore.Qt.AlignLeft) v80_l4 = QtWidgets.QLabel(v80box) v80_l4.setText('Scans') v80box.gridlayout.addWidget(v80_l4, 2, 0, 1, 1, QtCore.Qt.AlignLeft) self.v80_scans = QtWidgets.QLabel(v80box) v80box.gridlayout.addWidget(self.v80_scans, 2, 1, 1, 1, QtCore.Qt.AlignLeft) v80_l2 = QtWidgets.QLabel(v80box) v80_l2.setText('Detector') v80box.gridlayout.addWidget(v80_l2, 3, 0, 1, 1, QtCore.Qt.AlignLeft) self.v80_detector = QtWidgets.QLabel(v80box) v80box.gridlayout.addWidget(self.v80_detector, 3, 1, 1, 1, QtCore.Qt.AlignLeft) v80_l3 = QtWidgets.QLabel(v80box) v80_l3.setText('Datafile') v80box.gridlayout.addWidget(v80_l3, 4, 0, 1, 1, QtCore.Qt.AlignLeft) self.v80_datafile = QtWidgets.QLabel(v80box) v80box.gridlayout.addWidget(self.v80_datafile, 4, 1, 1, 1, QtCore.Qt.AlignLeft) v80_pka = QtWidgets.QLabel(v80box) v80_pka.setText('Amplitude') v80box.gridlayout.addWidget(v80_pka, 5, 0, 1, 1, QtCore.Qt.AlignLeft) self.v80_pka = QtWidgets.QLabel(v80box) v80box.gridlayout.addWidget(self.v80_pka, 5, 1, 1, 1, QtCore.Qt.AlignLeft) v80box.setLayout(v80box.gridlayout) ### Hutch status hutchbox = QtWidgets.QGroupBox(sbox) sbox.gridlayout.addWidget(hutchbox, 4, 0, 1, 1) hutchbox.gridlayout = QtWidgets.QGridLayout() hutch_label = QtWidgets.QLabel(hutchbox) hutch_label.setText('Hutch') hutchbox.gridlayout.addWidget(hutch_label, 0, 0, 1, 2, QtCore.Qt.AlignLeft) hutchbox.setLayout(hutchbox.gridlayout) hutch_l1 = QtWidgets.QLabel(v80box) hutch_l1.setText('Status') hutchbox.gridlayout.addWidget(hutch_l1, 1, 0, 1, 1, QtCore.Qt.AlignLeft) self.hutch_status = QtWidgets.QLabel(hutchbox) hutchbox.gridlayout.addWidget(self.hutch_status, 1, 1, 1, 1, QtCore.Qt.AlignLeft) self.hutch_remote = QtWidgets.QLabel(hutchbox) hutchbox.gridlayout.addWidget(self.hutch_remote, 2, 1, 1, 1, QtCore.Qt.AlignLeft) sbox.setLayout(sbox.gridlayout)
def __init__(self, parent): super().__init__('WIB', parent) self.setAutoFillBackground(True) p = self.palette() p.setColor(self.backgroundRole(), QtGui.QColor(*colors[0])) self.setPalette(p) self.setStyleSheet('QGroupBox { font-weight: bold; color: #cb4b16; } ') self.t_sensors = [] self.t_sensors.append( TSensor(self, 'Board Temp 1', lambda s: s.ad7414_49_temp)) self.t_sensors.append( TSensor(self, 'Board Temp 2', lambda s: s.ad7414_4d_temp)) self.t_sensors.append( TSensor(self, 'Board Temp 3', lambda s: s.ad7414_4a_temp)) self.t_sensors.append(TSensor(self, 'DDR Temp', lambda s: nan)) #FIXME self.t_sensors.append( VTSensor(self, 'Power Temp 1', lambda s: s.ltc2499_15_temps[4])) self.t_sensors.append( VTSensor(self, 'Power Temp 2', lambda s: s.ltc2499_15_temps[5])) self.t_sensors.append( VTSensor(self, 'Power Temp 3', lambda s: s.ltc2499_15_temps[6])) self.iv_sensors = [] self.iv_sensors.append( IVSensor(self, 'WIB 5 V', lambda s: s.ltc2990_4e_voltages[0:2], sense_ohms=0.001)) self.iv_sensors.append( IVSensor(self, 'WIB 1.2 V', lambda s: s.ltc2990_4c_voltages[0:2], sense_ohms=0.001)) self.iv_sensors.append( IVSensor(self, 'WIB 3.3 V', lambda s: s.ltc2990_4c_voltages[2:4], sense_ohms=0.001)) self.iv_sensors.append( IVSensor(self, 'WIB 0.85 V', lambda s: s.ltc2991_48_voltages[0:2], sense_ohms=0.001)) self.iv_sensors.append( IVSensor(self, 'WIB 0.9 V', lambda s: s.ltc2991_48_voltages[2:4], sense_ohms=0.001)) self.iv_sensors.append( IVSensor(self, 'WIB 2.5 V', lambda s: s.ltc2991_48_voltages[4:6], sense_ohms=0.001)) self.iv_sensors.append( IVSensor(self, 'WIB 1.8 V', lambda s: s.ltc2991_48_voltages[6:8], sense_ohms=0.001)) layout = QtWidgets.QGridLayout(self) for i, t in enumerate(self.t_sensors): layout.addWidget(t, 0, i) for i, t in enumerate(self.iv_sensors): layout.addWidget(t, 1, i)
def _build_slider(num_frames): slider = QtWidgets.QSlider(QtCore.Qt.Horizontal) slider.setMinimum(0) slider.setMaximum(num_frames - 1) slider.setValue(0) return slider
def getPopfile(self): dlg = QtWidgets.QFileDialog(self, "Open File") dlg.setFileMode(QtWidgets.QFileDialog.AnyFile) fname, _ = dlg.getOpenFileName() self.popLine.setText(fname)
# non-ipython envs with suppress(ImportError): from IPython import get_ipython with suppress(AttributeError, NameError): # List available APIs get_ipython().run_line_magic("matplotlib", "-l") get_ipython().run_line_magic("matplotlib", "qt5") print(plt.get_backend()) #%% Matplotlib adjustments # Adjust matplotlib qt5 backend for high DPI monitors if plt.get_backend() == "Qt5Agg": from matplotlib.backends.qt_compat import QtWidgets # pylint: disable=C0412 from sys import argv qApp = QtWidgets.QApplication(argv) plt.matplotlib.rcParams["figure.dpi"] = qApp.desktop().physicalDpiX() # Set LaTeX compatibility settings # matplotlib.use("pgf") matplotlib.rcParams.update( { "pgf.texsystem": "pdflatex", "font.family": "sans-serif", "text.usetex": True, "pgf.rcfonts": True, } ) # plt.rcParams["figure.autolayout"] = True
def __init__(self, parent=None): super(StartP, self).__init__(parent) integerValidator = QtGui.QIntValidator(0, 10, self) dataLabel = QtWidgets.QLabel('Data Directory:') self.dataLine = QtWidgets.QLineEdit() dataBtn = QtWidgets.QPushButton('File', self) dataBtn.clicked.connect(self.getDir) self.registerField('dataDir*', self.dataLine) allelesLabel = QtWidgets.QLabel('Number of alleles:') self.allelesLine = QtWidgets.QLineEdit() self.allelesLine.setValidator(integerValidator) self.registerField('alleleCount*', self.allelesLine) groupsLabel = QtWidgets.QLabel('Number of Groups:') self.groupsLine = QtWidgets.QLineEdit() self.groupsLine.setValidator(integerValidator) self.registerField('groupCount*', self.groupsLine) self.b1 = QtWidgets.QCheckBox("Females") self.b1.setChecked(False) self.registerField('females', self.b1) comboLabel = QtWidgets.QLabel('Graphic Type:') self.combo = QtWidgets.QComboBox(self) self.combo.addItem('Allele Counts') self.combo.addItem('Allele Heatmap') self.combo.addItem('Allele Stack') self.combo.addItem('Allele Geo-Map') self.registerField('graphic', self.combo) grid = QtWidgets.QGridLayout() grid.setSpacing(10) grid.addWidget(dataLabel, 1, 0) grid.addWidget(self.dataLine, 1, 1) grid.addWidget(dataBtn, 1, 2) grid.addWidget(allelesLabel, 2, 0) grid.addWidget(self.allelesLine, 2, 1) grid.addWidget(groupsLabel, 3, 0) grid.addWidget(self.groupsLine, 3, 1) grid.addWidget(self.b1, 5, 1) grid.addWidget(comboLabel, 4, 0) grid.addWidget(self.combo, 4, 1) self.setLayout(grid)
def main(): app = QtWidgets.QApplication(sys.argv) application = ApplicationWindow() application.show() app.exec_()
def getDir(self): dlg = QtWidgets.QFileDialog(self, "Browse Directory") dlg.setFileMode(dlg.Directory) dlg.setOption(dlg.ShowDirsOnly) fname = str(dlg.getExistingDirectory()) self.dataLine.setText(fname)
def __init__(self): self.widget = QtWidgets.QWidget()
def __init__(self, parent=None): super(Page1, self).__init__(parent) self.setTitle('Group-Alelle weights') vbox = QtWidgets.QVBoxLayout() self.setLayout(vbox)
def setup(self): for label, value in self.data: if label is None and value is None: # Separator: (None, None) self.formlayout.addRow(QtWidgets.QLabel(" "), QtWidgets.QLabel(" ")) self.widgets.append(None) continue elif label is None: # Comment self.formlayout.addRow(QtWidgets.QLabel(value)) self.widgets.append(None) continue elif tuple_to_qfont(value) is not None: field = FontLayout(value, self) elif (label.lower() not in BLACKLIST and mcolors.is_color_like(value)): field = ColorLayout(to_qcolor(value), self) elif isinstance(value, str): field = QtWidgets.QLineEdit(value, self) elif isinstance(value, (list, tuple)): field = QtWidgets.QComboBox(self) selindex, *value = value if isinstance(value[0], (list, tuple)): keys = [key for key, _val in value] value = [val for _key, val in value] else: keys = value field.addItems(value) if selindex in value: selindex = value.index(selindex) elif selindex in keys: selindex = keys.index(selindex) elif not isinstance(selindex, Integral): warnings.warn( "index '%s' is invalid (label: %s, value: %s)" % (selindex, label, value), stacklevel=2) selindex = 0 field.setCurrentIndex(selindex) elif isinstance(value, bool): field = QtWidgets.QCheckBox(self) if value: field.setCheckState(QtCore.Qt.Checked) else: field.setCheckState(QtCore.Qt.Unchecked) elif isinstance(value, Integral): field = QtWidgets.QSpinBox(self) field.setRange(-1e9, 1e9) field.setValue(value) elif isinstance(value, Real): field = QtWidgets.QLineEdit(repr(value), self) field.setCursorPosition(0) field.setValidator(QtGui.QDoubleValidator(field)) field.validator().setLocale(QtCore.QLocale("C")) dialog = self.get_dialog() dialog.register_float_field(field) field.textChanged.connect(lambda text: dialog.update_buttons()) elif isinstance(value, datetime.datetime): field = QtWidgets.QDateTimeEdit(self) field.setDateTime(value) elif isinstance(value, datetime.date): field = QtWidgets.QDateEdit(self) field.setDate(value) else: field = QtWidgets.QLineEdit(repr(value), self) self.formlayout.addRow(label, field) self.widgets.append(field)
def create_status_bar(self): self.status_text = QtWidgets.QLabel("Please load a data file") self.statusBar().addWidget(self.status_text, 1)