def __init__(self, parent, new_size, old_size, text="", keep_original_size=False): QDialog.__init__(self, parent) intfunc = lambda tup: [int(val) for val in tup] if intfunc(new_size) == intfunc(old_size): self.keep_original_size = True else: self.keep_original_size = keep_original_size self.width, self.height = new_size self.old_width, self.old_height = old_size self.ratio = self.width / self.height layout = QVBoxLayout() self.setLayout(layout) formlayout = QFormLayout() layout.addLayout(formlayout) if text: label = QLabel(text) label.setAlignment(Qt.AlignHCenter) formlayout.addRow(label) self.w_edit = w_edit = QLineEdit(self) w_valid = QIntValidator(w_edit) w_valid.setBottom(1) w_edit.setValidator(w_valid) self.h_edit = h_edit = QLineEdit(self) h_valid = QIntValidator(h_edit) h_valid.setBottom(1) h_edit.setValidator(h_valid) zbox = QCheckBox(_("Original size"), self) formlayout.addRow(_("Width (pixels)"), w_edit) formlayout.addRow(_("Height (pixels)"), h_edit) formlayout.addRow("", zbox) formlayout.addRow(_("Original size:"), QLabel("%d x %d" % old_size)) self.z_label = QLabel() formlayout.addRow(_("Zoom factor:"), self.z_label) # Button box self.bbox = bbox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) bbox.accepted.connect(self.accept) bbox.rejected.connect(self.reject) layout.addWidget(bbox) self.w_edit.setText(str(self.width)) self.h_edit.setText(str(self.height)) self.update_widgets() self.setWindowTitle(_("Resize")) w_edit.textChanged.connect(self.width_changed) h_edit.textChanged.connect(self.height_changed) zbox.toggled.connect(self.toggled_no_zoom) zbox.setChecked(self.keep_original_size)
def __init__(self, item, parent_layout): super(CheckBoxWidget, self).__init__(item, parent_layout) self.checkbox = QCheckBox(self.item.get_prop_value("display", "text")) self.checkbox.setToolTip(item.get_help()) self.group = self.checkbox self.store = self.item.get_prop("display", "store", None) if self.store: self.checkbox.stateChanged.connect(self.do_store)
def add_buttons_to_layout(self, layout): """Add tool buttons to layout""" # Show crop rectangle checkbox show_crop = QCheckBox(_("Show cropping rectangle"), self) show_crop.setChecked(True) show_crop.toggled.connect(self.show_crop_rect) layout.addWidget(show_crop) layout.addSpacing(15) base.BaseTransformMixin.add_buttons_to_layout(self, layout)
def __init__(self, parent): super(FileUi, self).__init__(Qt.Vertical, parent) layoutWidget = QWidget() layout = QVBoxLayout() layoutWidget.setLayout(layout) self.comment = QPlainTextEdit() self.fileName = None self.saveTxtCheck = QCheckBox('Save Txt') self.saveHdfCheck = QCheckBox('Save HDF5') self.saveTxtBtn = QPushButton('Save Txt') self.saveHdfBtn = QPushButton('Save HDF5') ############# # stream group streamGroup = QGroupBox('Stream data to file:') streamGroup.setFlat(True) streamGroupLayout = QHBoxLayout() streamGroupLayout.addWidget(self.saveTxtCheck) streamGroupLayout.addWidget(self.saveHdfCheck) streamGroup.setLayout(streamGroupLayout) ############## # save static file saveGroup = QGroupBox('Save now to file:') saveGroup.setFlat(True) saveGroupLayout = QHBoxLayout() saveGroupLayout.addWidget(self.saveTxtBtn) saveGroupLayout.addWidget(self.saveHdfBtn) saveGroup.setLayout(saveGroupLayout) ############## # put layout together layout.addWidget(QLabel('Comment:')) layout.addWidget(self.comment) layout.addWidget(streamGroup) layout.addWidget(saveGroup) self.addWidget(layoutWidget) ############## # connnect stuff for functionality self.saveTxtCheck.stateChanged.connect(self.__makeFileName) self.saveHdfCheck.stateChanged.connect(self.__makeFileName) ############## # thread for streaming data to file #self.updateCurrPos.connect(self.__updateCurrPos) self.stream_thread = QThread() # create the QThread self.stream_thread.start() self.stream_worker = GenericWorker(self.__streamFile) self.stream_worker.moveToThread(self.stream_thread)
class CheckBoxWidget(AbstractDataSetWidget): """ BoolItem widget """ def __init__(self, item, parent_layout): super(CheckBoxWidget, self).__init__(item, parent_layout) self.checkbox = QCheckBox(self.item.get_prop_value("display", "text")) self.checkbox.setToolTip(item.get_help()) self.group = self.checkbox self.store = self.item.get_prop("display", "store", None) if self.store: self.checkbox.stateChanged.connect(self.do_store) def get(self): """Override AbstractDataSetWidget method""" value = self.item.get() if value: self.checkbox.setChecked(True) def set(self): """Override AbstractDataSetWidget method""" self.item.set(self.value()) def value(self): return self.checkbox.isChecked() def place_on_grid(self, layout, row, label_column, widget_column, row_span=1, column_span=1): """Override AbstractDataSetWidget method""" if not self.item.get_prop_value("display", "label"): widget_column = label_column column_span += 1 else: self.place_label(layout, row, label_column) layout.addWidget(self.group, row, widget_column, row_span, column_span) def do_store(self, state): self.store.set(self.item.instance, self.item.item, state) self.parent_layout.refresh_widgets()
def __init__(self, parent): super(controlWidget, self).__init__() self.widgetTimer = QTimer() self.widgetTimer.start(100) self.widgetTimer.timeout.connect(self.createNewDspWidgets) self.value =0 self.flag = True self.mainApp = parent self.inactivityTimeout = True self.setWindowTitle('Live Telemetry Visualizer') self.qbtn = QPushButton('Quit', self) self.qbtn.clicked.connect(self.mainApp.quit) self.qbtn.resize(self.qbtn.sizeHint()) self.qbtn.hide() qbtn1 = QPushButton('Check Performance status') qbtn1.clicked.connect(self.ButtonPressed) qbtn1.resize(qbtn1.sizeHint()) self.performance_status = QLabel("If Performance Curve at Monitor Mic is On turn it Off") self.performance_status.hide() icheck = QCheckBox('Inactivity Timeout') icheck.stateChanged.connect(self.toggleInactivity) icheck.setChecked(self.inactivityTimeout) layout = QVBoxLayout() self.setLayout(layout) layout.addWidget(self.qbtn) layout.addWidget(self.performance_status) layout.addWidget(qbtn1) layout.addWidget(icheck) layout.addWidget(QWidget()) self.resize(180, 100) self.show()
class CheckBoxWidget(AbstractDataSetWidget): """ BoolItem widget """ def __init__(self, item, parent_layout): super(CheckBoxWidget, self).__init__(item, parent_layout) self.checkbox = QCheckBox(self.item.get_prop_value("display", "text")) self.checkbox.setToolTip(item.get_help()) self.group = self.checkbox self.store = self.item.get_prop("display", "store", None) if self.store: self.checkbox.stateChanged.connect(self.do_store) def get(self): """Override AbstractDataSetWidget method""" value = self.item.get() if value is not None: self.checkbox.setChecked(value) def set(self): """Override AbstractDataSetWidget method""" self.item.set(self.value()) def value(self): return self.checkbox.isChecked() def place_on_grid(self, layout, row, label_column, widget_column, row_span=1, column_span=1): """Override AbstractDataSetWidget method""" if not self.item.get_prop_value("display", "label"): widget_column = label_column column_span += 1 else: self.place_label(layout, row, label_column) layout.addWidget(self.group, row, widget_column, row_span, column_span) def do_store(self, state): self.store.set(self.item.instance, self.item.item, state) self.parent_layout.refresh_widgets()
def __init__(self, item, parent_layout): super(MultipleChoiceWidget, self).__init__(item, parent_layout) self.groupbox = self.group = QGroupBox(item.get_prop_value("display", "label")) layout = QGridLayout() self.boxes = [] nx, ny = item.get_prop_value("display", "shape") cx, cy = 0, 0 _choices = item.get_prop_value("data", "choices") for _, choice, _img in _choices: checkbox = QCheckBox(choice) layout.addWidget(checkbox, cx, cy) if nx < 0: cy += 1 if cy >= ny: cy = 0 cx += 1 else: cx += 1 if cx >= nx: cx = 0 cy += 1 self.boxes.append(checkbox) self.groupbox.setLayout(layout)
class FileUi(QSplitter): def __init__(self, parent): super(FileUi, self).__init__(Qt.Vertical, parent) layoutWidget = QWidget() layout = QVBoxLayout() layoutWidget.setLayout(layout) self.comment = QPlainTextEdit() self.fileName = None self.saveTxtCheck = QCheckBox('Save Txt') self.saveHdfCheck = QCheckBox('Save HDF5') self.saveTxtBtn = QPushButton('Save Txt') self.saveHdfBtn = QPushButton('Save HDF5') ############# # stream group streamGroup = QGroupBox('Stream data to file:') streamGroup.setFlat(True) streamGroupLayout = QHBoxLayout() streamGroupLayout.addWidget(self.saveTxtCheck) streamGroupLayout.addWidget(self.saveHdfCheck) streamGroup.setLayout(streamGroupLayout) ############## # save static file saveGroup = QGroupBox('Save now to file:') saveGroup.setFlat(True) saveGroupLayout = QHBoxLayout() saveGroupLayout.addWidget(self.saveTxtBtn) saveGroupLayout.addWidget(self.saveHdfBtn) saveGroup.setLayout(saveGroupLayout) ############## # put layout together layout.addWidget(QLabel('Comment:')) layout.addWidget(self.comment) layout.addWidget(streamGroup) layout.addWidget(saveGroup) self.addWidget(layoutWidget) ############## # connnect stuff for functionality self.saveTxtCheck.stateChanged.connect(self.__makeFileName) self.saveHdfCheck.stateChanged.connect(self.__makeFileName) ############## # thread for streaming data to file #self.updateCurrPos.connect(self.__updateCurrPos) self.stream_thread = QThread() # create the QThread self.stream_thread.start() self.stream_worker = GenericWorker(self.__streamFile) self.stream_worker.moveToThread(self.stream_thread) def __makeFileName(self, state): if state == 2: self.fileName = datetime.now().strftime('%Y%m%d-%H%M%S') self.stream_worker.start.emit() else: self.fileName = None def __streamFile(self): while self.saveHdfCheck.isChecked(): self.saveHdfBtn.released.emit() time.sleep(10)
def __init__(self, parent): super().__init__(parent) self.camera = None self.cameraSettings = None self.aquireData = False self.directory = 'N:/4all/mpsd_drive/xtsfasta/Data' layoutWidget = QWidget() layout = QGridLayout() layoutWidget.setLayout(layout) ############### # GUI elements self.openCamBtn = QPushButton('Connect camera') self.startAquBtn = QPushButton('Start aquisiton') self.readoutSpeedCombo = QComboBox() # this really should not be hard coded but received from dll self.readoutSpeedCombo.addItems(["1 MHz", "1.8 MHz", "2.3 MHz", "2.8 MHz", "250 kHz", "500 kHz"]) self.exposureTimeSpin = QSpinBox() self.exposureTimeSpin.setRange(1, 1e6) self.exposureTimeSpin.setValue(1e3) # default exposure 1s self.exposureTimeSpin.setSingleStep(100) self.exposureTimeSpin.setSuffix(' ms') #self.exposureTimeSpin.setValidator(QIntValidator(1, 2**31)) # ms self.binningXCombo = QComboBox() self.binningXCombo.addItems(["No binning", "Binning of 2 columns", "Binning of 4 columns", "Binning of 8 columns", "Binning of 16 columns", "Binning of 32 columns", "Binning of 64 columns", "Binning of 128 columns", "Full horizontal binning"]) self.binningYCombo = QComboBox() self.binningYCombo.addItems(["No binning", "Binning of 2 lines", "Binning of 4 lines", "Binning of 8 lines", "Binning of 16 lines", "Binning of 32 lines", "Binning of 64 lines", "Binning of 128 lines", "Binning of 256 lines"]) self.temperatureSpin = QSpinBox() self.temperatureSpin.setRange(-100, 20) self.temperatureSpin.setValue(-10) self.temperatureSpin.setSuffix('°C') self.updateInterSpin = QSpinBox() self.updateInterSpin.setRange(1, 3600) self.updateInterSpin.setValue(5) self.updateInterSpin.setSuffix(' s') #self.updateInterSpin.setText("2") #self.updateInterEdit.setValidator(QIntValidator(1, 3600)) self.loi = QSpinBox() self.loi.setRange(1, 511) # one pixel less as the camera has self.deltaPixels = QSpinBox() self.deltaPixels.setRange(0, 256) self.autoSave = QCheckBox("Auto save") self.getDirectory = QPushButton('Choose Dir') self.dirPath = QLineEdit(self.directory) self.comment = QPlainTextEdit() ############## # put elements in layout layout.addWidget(self.openCamBtn, 0, 0) layout.addWidget(self.startAquBtn, 0, 1) layout.addWidget(QLabel('readout speed'), 1, 0) layout.addWidget(self.readoutSpeedCombo, 1, 1) layout.addWidget(QLabel('exposure time'), 2, 0) layout.addWidget(self.exposureTimeSpin, 2, 1) layout.addWidget(QLabel('binning X'), 3, 0) layout.addWidget(self.binningXCombo, 3, 1) layout.addWidget(QLabel('binning Y'), 4, 0) layout.addWidget(self.binningYCombo, 4, 1) layout.addWidget(QLabel('temperature'), 5, 0) layout.addWidget(self.temperatureSpin, 5, 1) layout.addWidget(QLabel('update every n-seconds'), 6, 0) layout.addWidget(self.updateInterSpin, 6, 1) layout.addWidget(QLabel('Pixel of interest'), 7, 0) layout.addWidget(self.loi, 7, 1) layout.addWidget(QLabel('Δ pixels'), 8, 0) layout.addWidget(self.deltaPixels, 8, 1) layout.addWidget(self.autoSave, 9, 1) layout.addWidget(self.getDirectory, 10, 0) layout.addWidget(self.dirPath, 10, 1) layout.addWidget(QLabel('Comment:'), 11, 0) layout.addWidget(self.comment, 12, 0, 1, 2) layout.setRowStretch(13, 10) self.addWidget(layoutWidget) ################# # connect elements for functionality self.openCamBtn.released.connect(self.__openCam) self.getDirectory.released.connect(self.__chooseDir) self.temperatureSpin.valueChanged.connect(self.__setTemperature) self.exposureTimeSpin.valueChanged.connect(self.__setCamParameter) self.readoutSpeedCombo.currentIndexChanged.connect(self.__setCamParameter) self.startAquBtn.released.connect(self.__startCurrImageThr) ################ # thread for updating position self.currImage_thread = QThread() # create the QThread self.currImage_thread.start() # This causes my_worker.run() to eventually execute in my_thread: self.currImage_worker = GenericWorker(self.__getCurrImage) self.currImage_worker.moveToThread(self.currImage_thread) self.startAquBtn.setEnabled(False) self.readoutSpeedCombo.setEnabled(False) self.exposureTimeSpin.setEnabled(False) self.binningXCombo.setEnabled(False) self.binningYCombo.setEnabled(False) self.temperatureSpin.setEnabled(False) self.updateInterSpin.setEnabled(False)
def __init__(self, parent, new_size, old_size, text="", keep_original_size=False): QDialog.__init__(self, parent) intfunc = lambda tup: [int(val) for val in tup] if intfunc(new_size) == intfunc(old_size): self.keep_original_size = True else: self.keep_original_size = keep_original_size self.width, self.height = new_size self.old_width, self.old_height = old_size self.ratio = self.width/self.height layout = QVBoxLayout() self.setLayout(layout) formlayout = QFormLayout() layout.addLayout(formlayout) if text: label = QLabel(text) label.setAlignment(Qt.AlignHCenter) formlayout.addRow(label) self.w_edit = w_edit = QLineEdit(self) w_valid = QIntValidator(w_edit) w_valid.setBottom(1) w_edit.setValidator(w_valid) self.h_edit = h_edit = QLineEdit(self) h_valid = QIntValidator(h_edit) h_valid.setBottom(1) h_edit.setValidator(h_valid) zbox = QCheckBox(_("Original size"), self) formlayout.addRow(_("Width (pixels)"), w_edit) formlayout.addRow(_("Height (pixels)"), h_edit) formlayout.addRow('', zbox) formlayout.addRow(_("Original size:"), QLabel("%d x %d" % old_size)) self.z_label = QLabel() formlayout.addRow(_("Zoom factor:"), self.z_label) # Button box self.bbox = bbox = QDialogButtonBox(QDialogButtonBox.Ok| QDialogButtonBox.Cancel) bbox.accepted.connect(self.accept) bbox.rejected.connect(self.reject) layout.addWidget(bbox) self.w_edit.setText(str(self.width)) self.h_edit.setText(str(self.height)) self.update_widgets() self.setWindowTitle(_("Resize")) w_edit.textChanged.connect(self.width_changed) h_edit.textChanged.connect(self.height_changed) zbox.toggled.connect(self.toggled_no_zoom) zbox.setChecked(self.keep_original_size)
def _set_widgets(self): """ Parse operation (function arguments) and create widgets according to the function annotations. Fill with default or current argument values and display the widgets. """ self._clear_widgets() # Retreive operation (function detail), instantiate neccesary widgets package, fun = self._op["module"].rsplit('.', 1) module = import_module(package) self._op["function"] = getattr(module, fun) argspec = inspect.getfullargspec(self._op["function"]) # Create widgets self._labels = [] self._widgets = [] self._none_checkbox_widgets = [] for par_name, annotation in sorted(argspec.annotations.items()): label = QLabel(par_name) font = qtgui.QFont() font.setPointSize(10) label.setFont(font) # find associated widget and functions mapping = {} if "widget" in annotation: mapping["widget"] = widget = getattr(qtgui, annotation["widget"]) mapping["display_func"] = annotation["display_func"] mapping["display_conversion"] = annotation["display_conversion"] mapping["get_func"] = annotation["get_func"] elif "type" in annotation: try: mapping = dict(GenericOperationWidget.type_mapping[annotation["type"]]) except KeyError: print("Can't find wiget for type: {type} for parameter " + "{par_name}".format(type=annotation["type"], par_name=par_name)) continue else: continue # instanciate widget and make display_function callable widget = mapping["widget"]() if not callable(mapping["display_func"]): mapping["display_func"] = widget.__getattribute__(mapping["display_func"]) # save mapping and parameter name for later use widget.mapping = mapping widget.par_name = par_name # create checkbox to allow not to set this parameter checkbox = QCheckBox() checkbox.setChecked(True) checkbox.setToolTip("Set the \"%s\" parameter. If unchecked, the default value is used." % par_name) checkbox.par_name = widget.par_name # Set value of widget according to parameters of the operation try: if "display_conversion" in mapping: display_value = mapping["display_conversion"](self._op["kwargs"][par_name]) else: display_value = self._op["kwargs"][par_name] mapping["display_func"](display_value) except KeyError: checkbox.setChecked(False) self._labels.append(label) self._widgets.append(widget) self._none_checkbox_widgets.append(checkbox) # Add widgets to layout if not self._widgets: self.widget_layout.addWidget(QLabel("No operation parameters")) for i, widget in enumerate(self._widgets): self.widget_layout.addWidget(self._labels[i]) self.widget_layout.addWidget(self._widgets[i]) self.widget_layout.addWidget(self._none_checkbox_widgets[i])