def generate_numeric_input(self, maximum, minimum, increment, current): sb = QDoubleSpinBox(self) sb.setMaximum(maximum) sb.setMinimum(minimum) sb.setSingleStep(increment) sb.setValue(current) return sb
class Slider(): def update_offset(self, pos): offset = round(pos, 2) return offset def __init__(self, tool, text, tooltip, precision, minimal, maximal, interval): self.tool = tool self.scale = precision self.name_label = QLabel(text) self.name_label.setAlignment(Qt.AlignLeft) if not tooltip == None: self.name_label.setToolTip(tooltip) self.offset_edit = QDoubleSpinBox() self.offset_edit.setRange(minimal, maximal) self.offset_edit.setSingleStep(precision) self.offset_edit.setDecimals(2) self.offset_edit.setAlignment(Qt.AlignRight) self.offset_edit.valueChanged.connect( lambda pos: self.slider.setSliderPosition( self.update_offset(pos) / self.scale)) self.slider = QSlider(Qt.Horizontal) self.slider.setRange(minimal / self.scale, maximal) self.slider.setTickInterval(interval / self.scale) self.slider.setTickPosition(QSlider.TicksAbove) self.slider.valueChanged.connect(lambda pos: self.offset_edit.setValue( self.update_offset(pos * self.scale))) self.update_offset(0)
def __init__(self, parent, patient): QDialog.__init__(self) self.patient = patient self.parent = parent self.save_button = QPushButton("Zapisz") self.save_button.clicked.connect(self.saveForm) self.spin_boxes = [] self.form_layout = QFormLayout() treatment_layout = QHBoxLayout() self.date_field = QDateEdit() spin_box = QDoubleSpinBox() spin_box.setRange(0.0, 1.0) spin_box.setSingleStep(0.1) self.treatment_field = spin_box treatment_layout.addWidget(self.date_field) treatment_layout.addWidget(self.treatment_field) self.form_layout.addRow(treatment_layout) buttons_layout = QHBoxLayout() buttons_layout.addWidget(self.save_button) self.layout = QVBoxLayout(self) self.layout.addLayout(self.form_layout) self.layout.addLayout(buttons_layout)
class Config(SignalNode.Config): """Config widget displayed for LSLInput.""" def __init__(self, parent=None): super().__init__(parent=parent) self.smoothing_factor = QDoubleSpinBox() self.smoothing_factor.setMinimum(0) self.smoothing_factor.setMaximum(1) self.smoothing_factor.setSingleStep(0.1) self.smoothing_factor.setPrefix("x") self.smoothing_factor.valueChanged.connect(self.updateModel) self.method = QComboBox() self.method.addItem("Rectification") self.method.addItem("Fourier Transform") self.method.addItem("Hilbert Transform") self.method.addItem("cFIR") self.method.currentTextChanged.connect(self.updateModel) self.smoother_type = QComboBox() for name in EnvelopeDetector.smoother_name_to_type: self.smoother_type.addItem(name) self.smoother_type.currentTextChanged.connect(self.updateModel) layout = QFormLayout() self.setLayout(layout) layout.addRow("Smoothing factor", self.smoothing_factor) layout.addRow("Method", self.method) layout.addRow("Smoother type", self.smoother_type) def updateModel(self): n = self.node() if n is None: return smoothing_factor = self.smoothing_factor.value() method = self.method.currentText() smoother_type = n.smoother_name_to_type[self.smoother_type.currentText()] n.setSmoothingFactor(smoothing_factor) n.setMethod(method) n.setSmootherType(smoother_type) def updateView(self): n = self.node() if n is None: return self.smoothing_factor.blockSignals(True) self.method.blockSignals(True) self.smoother_type.blockSignals(True) self.smoothing_factor.setValue(n.smoothingFactor()) self.method.setCurrentText(n.method()) self.smoother_type.setCurrentText(n.smoother_type_to_name[n.smootherType()]) self.smoothing_factor.blockSignals(False) self.method.blockSignals(False) self.smoother_type.blockSignals(False)
def _make_double_spinbox(default, min_value, max_value, single_step): spinbox = QDoubleSpinBox() spinbox.setSingleStep(single_step) spinbox.setMaximum(max_value) spinbox.setMinimum(min_value) spinbox.setValue(default) return spinbox
class MainWindow(QMainWindow): def __init__(self): super().__init__() form = QFormLayout() self.track_id = QSpinBox() self.track_id.setRange(0, 2147483647) self.track_id.setDisabled(True) self.name = QLineEdit() self.album = QComboBox() self.media_type = QComboBox() self.genre = QComboBox() self.composer = QLineEdit() self.milliseconds = QSpinBox() self.milliseconds.setRange(0, 2147483647) # <1> self.milliseconds.setSingleStep(1) self.bytes = QSpinBox() self.bytes.setRange(0, 2147483647) self.bytes.setSingleStep(1) self.unit_price = QDoubleSpinBox() self.unit_price.setRange(0, 999) self.unit_price.setSingleStep(0.01) self.unit_price.setPrefix("$") form.addRow(QLabel("Track ID"), self.track_id) form.addRow(QLabel("Track name"), self.name) form.addRow(QLabel("Composer"), self.composer) form.addRow(QLabel("Milliseconds"), self.milliseconds) form.addRow(QLabel("Bytes"), self.bytes) form.addRow(QLabel("Unit Price"), self.unit_price) self.model = QSqlTableModel(db=db) self.mapper = QDataWidgetMapper() # <2> self.mapper.setModel(self.model) self.mapper.addMapping(self.track_id, 0) # <3> self.mapper.addMapping(self.name, 1) self.mapper.addMapping(self.composer, 5) self.mapper.addMapping(self.milliseconds, 6) self.mapper.addMapping(self.bytes, 7) self.mapper.addMapping(self.unit_price, 8) self.model.setTable("Track") self.model.select() # <4> self.mapper.toFirst() # <5> self.setMinimumSize(QSize(400, 400)) widget = QWidget() widget.setLayout(form) self.setCentralWidget(widget)
def change_n_components(self, n_components: int): for widget in self.control_widgets: self.control_layout.removeWidget(widget) widget.hide() self.control_widgets.clear() self.input_widgets.clear() widgets = [] slider_range = (0, 1000) input_widgets = [] mean_range = (-5, 15) std_range = (0.0, 10) weight_range = (0, 10) names = [self.tr("Mean"), self.tr("STD"), self.tr("Weight")] ranges = [mean_range, std_range, weight_range] slider_values = [500, 100, 100] input_values = [0.0, 1.0, 1.0] for i in range(n_components): group = QGroupBox(f"C{i+1}") group.setMinimumWidth(200) group_layout = QGridLayout(group) inputs = [] for j, (name, range_, slider_value, input_value) in enumerate( zip(names, ranges, slider_values, input_values)): label = QLabel(name) slider = QSlider() slider.setRange(*slider_range) slider.setValue(slider_value) slider.setOrientation(Qt.Horizontal) input_ = QDoubleSpinBox() input_.setRange(*range_) input_.setDecimals(3) input_.setSingleStep(0.01) input_.setValue(input_value) slider.valueChanged.connect(self.on_value_changed) input_.valueChanged.connect(self.on_value_changed) slider.valueChanged.connect( lambda x, input_=input_, range_=range_: input_.setValue( x / 1000 * (range_[-1] - range_[0]) + range_[0])) input_.valueChanged.connect( lambda x, slider=slider, range_=range_: slider.setValue( (x - range_[0]) / (range_[-1] - range_[0]) * 1000)) group_layout.addWidget(label, j, 0) group_layout.addWidget(slider, j, 1) group_layout.addWidget(input_, j, 2) inputs.append(input_) self.control_layout.addWidget(group, i + 5, 0, 1, 4) widgets.append(group) input_widgets.append(inputs) self.control_widgets = widgets self.input_widgets = input_widgets
def get_settings_window(self, parent=None): gcodesender_settings = QGroupBox("GCodeSender Settings:", parent) buildplate_label = QLabel("Buildplate Motor:", gcodesender_settings) nodes = [str(item) for item in self.__g_code_sender.get_motor_nodes_id_list()] self.buildplate_combo_box = MyQComboBox(gcodesender_settings) self.buildplate_combo_box.addItems(nodes) self.buildplate_combo_box.setCurrentIndex(self.__g_code_sender.get_buildplate_node()) self.buildplate_combo_box.combo_box_clicked.connect(self.__update_nodes_list) self.buildplate_combo_box.currentIndexChanged.connect(self.__set_buildplate_node) wiper_label = QLabel("Wiper Motor:", gcodesender_settings) self.wiper_combo_box = MyQComboBox(gcodesender_settings) self.wiper_combo_box.addItems(nodes) self.wiper_combo_box.setCurrentIndex(self.__g_code_sender.get_wiper_node()) self.wiper_combo_box.combo_box_clicked.connect(self.__update_nodes_list) self.wiper_combo_box.currentIndexChanged.connect(self.__set_wiper_node) buildplate_recoat_offset_label = QLabel("Buildplate recoating offset (mm):", gcodesender_settings) buildplate_recoat_offset_spin = QDoubleSpinBox(gcodesender_settings) buildplate_recoat_offset_spin.setRange(0, 99999) buildplate_recoat_offset_spin.setDecimals(3) buildplate_recoat_offset_spin.setSingleStep(0.001) buildplate_recoat_offset_spin.setValue(self.__g_code_sender.get_building_plate_recoating_offset()) buildplate_recoat_offset_spin.valueChanged.connect(self.__g_code_sender.set_building_plate_recoat_offset) buildplate_recoat_feedrate_label = QLabel("Buildplate recoating feedrate (mm/min):", gcodesender_settings) buildplate_recoat_feedrate_spin = QDoubleSpinBox(gcodesender_settings) buildplate_recoat_feedrate_spin.setRange(0, 99999) buildplate_recoat_feedrate_spin.setDecimals(3) buildplate_recoat_feedrate_spin.setSingleStep(0.001) buildplate_recoat_feedrate_spin.setValue(self.__g_code_sender.get_building_plate_recoating_feedrate()) buildplate_recoat_feedrate_spin.valueChanged.connect(self.__g_code_sender.set_building_plate_recoat_feedrate) wiper_recoat_offset_label = QLabel("Wiper recoating offset: (mm)", gcodesender_settings) wiper_recoat_offset_spin = QDoubleSpinBox(gcodesender_settings) wiper_recoat_offset_spin.setRange(0, 99999) wiper_recoat_offset_spin.setDecimals(3) wiper_recoat_offset_spin.setSingleStep(0.001) wiper_recoat_offset_spin.setValue(self.__g_code_sender.get_wiper_recoating_offset()) wiper_recoat_offset_spin.valueChanged.connect(self.__g_code_sender.set_wiper_recoat_offset) wiper_recoat_feedrate_label = QLabel("Wiper recoating feedrate (mm/min):", gcodesender_settings) wiper_recoat_feedrate_spin = QDoubleSpinBox(gcodesender_settings) wiper_recoat_feedrate_spin.setRange(0, 99999) wiper_recoat_feedrate_spin.setDecimals(3) wiper_recoat_feedrate_spin.setSingleStep(0.001) wiper_recoat_feedrate_spin.setValue(self.__g_code_sender.get_wiper_recoating_feedrate()) wiper_recoat_feedrate_spin.valueChanged.connect(self.__g_code_sender.set_wiper_recoat_feedrate) motor_layout = QGridLayout(gcodesender_settings) motor_layout.addWidget(buildplate_label, 0, 0) motor_layout.addWidget(self.buildplate_combo_box, 0, 1) motor_layout.addWidget(buildplate_recoat_offset_label, 1, 0) motor_layout.addWidget(buildplate_recoat_offset_spin, 1, 1) motor_layout.addWidget(buildplate_recoat_feedrate_label, 2, 0) motor_layout.addWidget(buildplate_recoat_feedrate_spin, 2, 1) motor_layout.addWidget(wiper_label, 3, 0) motor_layout.addWidget(self.wiper_combo_box, 3, 1) motor_layout.addWidget(wiper_recoat_offset_label, 4, 0) motor_layout.addWidget(wiper_recoat_offset_spin, 4, 1) motor_layout.addWidget(wiper_recoat_feedrate_label, 5, 0) motor_layout.addWidget(wiper_recoat_feedrate_spin, 5, 1) return gcodesender_settings
class FloatField(Field): def __init__(self, property): super(FloatField, self).__init__(property) self._widget = QDoubleSpinBox() self._widget.valueChanged.connect(self.emitChanged) self._widget.setMinimum(property.min()) self._widget.setMaximum(property.max()) self._widget.setSingleStep(property.step()) def value(self): return self._widget.value() def setValue(self, value): self._widget.setValue(value) def setReadOnly(self, value): self._widget.setReadOnly(value) valueProperty = Property( float, value, Field.setValueBlocked) # C++: should be in parent class
def __init__(self, parent, patient): QDialog.__init__(self) self.parent = parent self.patient = patient self.resize(480, 100) self.setWindowTitle("Stwórz predykcję") self.choose_method = QComboBox() self.choose_method.setItemDelegate(QStyledItemDelegate()) self.choose_method.addItem(self.base_esn_method) self.choose_method.addItem(self.deep_esn_method) self.choose_method.addItem(self.sub_reservoir_method) self.choose_method.addItem(self.abc_smc_method) spin_box = QDoubleSpinBox() spin_box.setRange(0.0, 1000.0) spin_box.setSingleStep(0.1) self.choose_prediction_length = spin_box self.predict_button = QPushButton("Stwórz predykcję") self.predict_button.clicked.connect(self.generatePrediction) self.add_future_treatment_button = QPushButton( "Dodaj podanie lekarstwa") self.add_future_treatment_button.clicked.connect( self.addFutureTreatment) self.form_layout = QFormLayout() self.form_layout.addRow("Wybierz metodę", self.choose_method) self.form_layout.addRow("Długość predykcji (dni)", self.choose_prediction_length) self.treatments = [] buttons_layout = QHBoxLayout() buttons_layout.addWidget(self.add_future_treatment_button) buttons_layout.addWidget(self.predict_button) layout = QVBoxLayout(self) layout.addLayout(self.form_layout) layout.addLayout(buttons_layout)
def __init__(self, parent, patient): QDialog.__init__(self) self.patient = patient self.parent = parent self.setWindowTitle("Dodaj pomiar") self.save_button = QPushButton("Zapisz") self.save_button.clicked.connect(self.saveForm) self.exit_button = QPushButton("Wyjdź") self.exit_button.clicked.connect(self.accept) self.spin_boxes = [] self.form_layout = QFormLayout() measurement_layout = QHBoxLayout() self.date_field = QDateEdit() spin_box = QDoubleSpinBox() spin_box.setRange(0.0, 10000.0) spin_box.setSingleStep(0.1) self.measurement_field = spin_box measurement_layout.addWidget(self.date_field) measurement_layout.addWidget(self.measurement_field) self.form_layout.addRow(measurement_layout) buttons_layout = QHBoxLayout() buttons_layout.addWidget(self.exit_button) buttons_layout.addWidget(self.save_button) self.layout = QVBoxLayout(self) self.layout.addLayout(self.form_layout) self.layout.addLayout(buttons_layout)
def createPointWidget(self, x, y, z): layout = QHBoxLayout() x_label = QLabel("x:") x_label.setFixedWidth(10) x_val = QDoubleSpinBox() x_val.setSingleStep(0.01) x_val.setMinimum(-100) x_val.setMaximum(100) x_val.setDecimals(5) x_val.setValue(x) x_val.valueChanged.connect(self.onCoordsChanged) y_label = QLabel("y:") y_label.setFixedWidth(10) y_val = QDoubleSpinBox() y_val.setMinimum(-100) y_val.setMaximum(100) y_val.setDecimals(5) y_val.setSingleStep(0.01) y_val.setValue(y) y_val.valueChanged.connect(self.onCoordsChanged) z_label = QLabel("z:") z_label.setFixedWidth(10) z_val = QDoubleSpinBox() z_val.setMinimum(-100) z_val.setMaximum(100) z_val.setDecimals(5) z_val.setSingleStep(0.01) z_val.setValue(z) z_val.valueChanged.connect(self.onCoordsChanged) layout.addWidget(x_label) layout.addWidget(x_val) layout.addWidget(y_label) layout.addWidget(y_val) layout.addWidget(z_label) layout.addWidget(z_val) self.widgets.append([x_val, y_val, z_val]) return layout
class ColorDialog(QDialog): def __init__(self, model, font_metric, parent=None): super().__init__(parent) self.setWindowTitle('Color Options') self.model = model self.font_metric = font_metric self.main_window = parent self.createDialogLayout() def createDialogLayout(self): self.createGeneralTab() self.cellTable = self.createDomainTable(self.main_window.cellsModel) self.matTable = self.createDomainTable(self.main_window.materialsModel) self.tabs = { 'cell': self.createDomainTab(self.cellTable), 'material': self.createDomainTab(self.matTable), 'temperature': self.createPropertyTab('temperature'), 'density': self.createPropertyTab('density') } self.tab_bar = QTabWidget() self.tab_bar.setMaximumHeight(800) self.tab_bar.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self.tab_bar.addTab(self.generalTab, 'General') self.tab_bar.addTab(self.tabs['cell'], 'Cells') self.tab_bar.addTab(self.tabs['material'], 'Materials') self.tab_bar.addTab(self.tabs['temperature'], 'Temperature') self.tab_bar.addTab(self.tabs['density'], 'Density') self.createButtonBox() self.colorDialogLayout = QVBoxLayout() self.colorDialogLayout.addWidget(self.tab_bar) self.colorDialogLayout.addWidget(self.buttonBox) self.setLayout(self.colorDialogLayout) def createGeneralTab(self): main_window = self.main_window # Masking options self.maskingCheck = QCheckBox('') self.maskingCheck.stateChanged.connect(main_window.toggleMasking) button_width = self.font_metric.boundingRect("XXXXXXXXXX").width() self.maskColorButton = QPushButton() self.maskColorButton.setCursor(QtCore.Qt.PointingHandCursor) self.maskColorButton.setFixedWidth(button_width) self.maskColorButton.setFixedHeight(self.font_metric.height() * 1.5) self.maskColorButton.clicked.connect(main_window.editMaskingColor) # Highlighting options self.hlCheck = QCheckBox('') self.hlCheck.stateChanged.connect(main_window.toggleHighlighting) self.hlColorButton = QPushButton() self.hlColorButton.setCursor(QtCore.Qt.PointingHandCursor) self.hlColorButton.setFixedWidth(button_width) self.hlColorButton.setFixedHeight(self.font_metric.height() * 1.5) self.hlColorButton.clicked.connect(main_window.editHighlightColor) self.alphaBox = QDoubleSpinBox() self.alphaBox.setRange(0, 1) self.alphaBox.setSingleStep(.05) self.alphaBox.valueChanged.connect(main_window.editAlpha) self.seedBox = QSpinBox() self.seedBox.setRange(1, 999) self.seedBox.valueChanged.connect(main_window.editSeed) # General options self.bgButton = QPushButton() self.bgButton.setCursor(QtCore.Qt.PointingHandCursor) self.bgButton.setFixedWidth(button_width) self.bgButton.setFixedHeight(self.font_metric.height() * 1.5) self.bgButton.clicked.connect(main_window.editBackgroundColor) self.colorbyBox = QComboBox(self) self.colorbyBox.addItem("material") self.colorbyBox.addItem("cell") self.colorbyBox.addItem("temperature") self.colorbyBox.addItem("density") self.colorbyBox.currentTextChanged[str].connect( main_window.editColorBy) self.universeLevelBox = QComboBox(self) self.universeLevelBox.addItem('all') for i in range(self.model.max_universe_levels): self.universeLevelBox.addItem(str(i)) self.universeLevelBox.currentTextChanged[str].connect( main_window.editUniverseLevel) # Overlap plotting self.overlapCheck = QCheckBox('', self) overlap_connector = partial(main_window.toggleOverlaps) self.overlapCheck.stateChanged.connect(overlap_connector) self.overlapColorButton = QPushButton() self.overlapColorButton.setCursor(QtCore.Qt.PointingHandCursor) self.overlapColorButton.setFixedWidth(button_width) self.overlapColorButton.setFixedHeight(self.font_metric.height() * 1.5) self.overlapColorButton.clicked.connect(main_window.editOverlapColor) self.colorResetButton = QPushButton("&Reset Colors") self.colorResetButton.setCursor(QtCore.Qt.PointingHandCursor) self.colorResetButton.clicked.connect(main_window.resetColors) formLayout = QFormLayout() formLayout.setAlignment(QtCore.Qt.AlignHCenter) formLayout.setFormAlignment(QtCore.Qt.AlignHCenter) formLayout.setLabelAlignment(QtCore.Qt.AlignLeft) formLayout.addRow('Masking:', self.maskingCheck) formLayout.addRow('Mask Color:', self.maskColorButton) formLayout.addRow(HorizontalLine()) formLayout.addRow('Highlighting:', self.hlCheck) formLayout.addRow('Highlight Color:', self.hlColorButton) formLayout.addRow('Highlight Alpha:', self.alphaBox) formLayout.addRow('Highlight Seed:', self.seedBox) formLayout.addRow(HorizontalLine()) formLayout.addRow('Background Color: ', self.bgButton) formLayout.addRow(HorizontalLine()) formLayout.addRow('Show Overlaps:', self.overlapCheck) formLayout.addRow('Overlap Color:', self.overlapColorButton) formLayout.addRow(HorizontalLine()) formLayout.addRow('Color Plot By:', self.colorbyBox) formLayout.addRow('Universe Level:', self.universeLevelBox) formLayout.addRow(self.colorResetButton, None) generalLayout = QHBoxLayout() innerWidget = QWidget() generalLayout.setAlignment(QtCore.Qt.AlignVCenter) innerWidget.setLayout(formLayout) generalLayout.addStretch(1) generalLayout.addWidget(innerWidget) generalLayout.addStretch(1) self.generalTab = QWidget() self.generalTab.setLayout(generalLayout) def createDomainTable(self, domainmodel): domainTable = QTableView() domainTable.setModel(domainmodel) domainTable.setItemDelegate(DomainDelegate(domainTable)) domainTable.verticalHeader().setVisible(False) domainTable.resizeColumnsToContents() domainTable.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) domainTable.horizontalHeader().setSectionResizeMode( 1, QHeaderView.Stretch) return domainTable def createDomainTab(self, domaintable): domainTab = QWidget() domainTab.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) domainLayout = QVBoxLayout() domainLayout.addWidget(domaintable) domainTab.setLayout(domainLayout) return domainTab def createPropertyTab(self, property_kind): propertyTab = QWidget() propertyTab.property_kind = property_kind propertyTab.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) propertyLayout = QVBoxLayout() propertyTab.minMaxCheckBox = QCheckBox() propertyTab.minMaxCheckBox.setCheckable(True) connector1 = partial(self.main_window.toggleUserMinMax, property=property_kind) propertyTab.minMaxCheckBox.stateChanged.connect(connector1) propertyTab.minBox = ScientificDoubleSpinBox(self) propertyTab.minBox.setMaximum(1E9) propertyTab.minBox.setMinimum(0) propertyTab.maxBox = ScientificDoubleSpinBox(self) propertyTab.maxBox.setMaximum(1E9) propertyTab.maxBox.setMinimum(0) connector2 = partial(self.main_window.editColorbarMin, property_type=property_kind) propertyTab.minBox.valueChanged.connect(connector2) connector3 = partial(self.main_window.editColorbarMax, property_type=property_kind) propertyTab.maxBox.valueChanged.connect(connector3) propertyTab.colormapBox = QComboBox(self) cmaps = sorted(m for m in mcolormaps.datad if not m.endswith("_r")) for cmap in cmaps: propertyTab.colormapBox.addItem(cmap) connector = partial(self.main_window.editColorMap, property_type=property_kind) propertyTab.colormapBox.currentTextChanged[str].connect(connector) propertyTab.dataIndicatorCheckBox = QCheckBox() propertyTab.dataIndicatorCheckBox.setCheckable(True) connector4 = partial(self.main_window.toggleDataIndicatorCheckBox, property=property_kind) propertyTab.dataIndicatorCheckBox.stateChanged.connect(connector4) propertyTab.colorBarScaleCheckBox = QCheckBox() propertyTab.colorBarScaleCheckBox.setCheckable(True) connector5 = partial(self.main_window.toggleColorbarScale, property=property_kind) propertyTab.colorBarScaleCheckBox.stateChanged.connect(connector5) formLayout = QFormLayout() formLayout.setAlignment(QtCore.Qt.AlignHCenter) formLayout.setFormAlignment(QtCore.Qt.AlignHCenter) formLayout.setLabelAlignment(QtCore.Qt.AlignLeft) formLayout.addRow('Colormap:', propertyTab.colormapBox) formLayout.addRow('Custom Min/Max', propertyTab.minMaxCheckBox) formLayout.addRow('Data Indicator', propertyTab.dataIndicatorCheckBox) formLayout.addRow('Log Scale', propertyTab.colorBarScaleCheckBox) formLayout.addRow(HorizontalLine()) formLayout.addRow('Max: ', propertyTab.maxBox) formLayout.addRow('Min: ', propertyTab.minBox) propertyTab.setLayout(formLayout) return propertyTab def updateDataIndicatorVisibility(self): av = self.model.activeView for key, val in av.data_indicator_enabled.items(): self.tabs[key].dataIndicatorCheckBox.setChecked(val) def updateColorMaps(self): cmaps = self.model.activeView.colormaps for key, val in cmaps.items(): idx = self.tabs[key].colormapBox.findText( val, QtCore.Qt.MatchFixedString) if idx >= 0: self.tabs[key].colormapBox.setCurrentIndex(idx) def updateColorMinMax(self): minmax = self.model.activeView.user_minmax for key, val in minmax.items(): self.tabs[key].minBox.setValue(val[0]) self.tabs[key].maxBox.setValue(val[1]) custom_minmax = self.model.activeView.use_custom_minmax for key, val, in custom_minmax.items(): self.tabs[key].minMaxCheckBox.setChecked(val) self.tabs[key].minBox.setEnabled(val) self.tabs[key].maxBox.setEnabled(val) def updateColorbarScale(self): av = self.model.activeView for key, val in av.color_scale_log.items(): self.tabs[key].colorBarScaleCheckBox.setChecked(val) def createButtonBox(self): applyButton = QPushButton("Apply Changes") applyButton.clicked.connect(self.main_window.applyChanges) closeButton = QPushButton("Close") closeButton.clicked.connect(self.hide) buttonLayout = QHBoxLayout() buttonLayout.addStretch(1) buttonLayout.addWidget(applyButton) buttonLayout.addWidget(closeButton) self.buttonBox = QWidget() self.buttonBox.setLayout(buttonLayout) def updateDialogValues(self): self.updateMasking() self.updateMaskingColor() self.updateColorMaps() self.updateColorMinMax() self.updateColorbarScale() self.updateDataIndicatorVisibility() self.updateHighlighting() self.updateHighlightColor() self.updateAlpha() self.updateSeed() self.updateBackgroundColor() self.updateColorBy() self.updateUniverseLevel() self.updateDomainTabs() self.updateOverlap() self.updateOverlapColor() def updateMasking(self): masking = self.model.activeView.masking self.maskingCheck.setChecked(masking) self.maskColorButton.setDisabled(not masking) if masking: self.cellTable.showColumn(4) self.matTable.showColumn(4) else: self.cellTable.hideColumn(4) self.matTable.hideColumn(4) def updateMaskingColor(self): color = self.model.activeView.maskBackground style_values = "border-radius: 8px; background-color: rgb{}" self.maskColorButton.setStyleSheet(style_values.format(str(color))) def updateHighlighting(self): highlighting = self.model.activeView.highlighting self.hlCheck.setChecked(highlighting) self.hlColorButton.setDisabled(not highlighting) self.alphaBox.setDisabled(not highlighting) self.seedBox.setDisabled(not highlighting) if highlighting: self.cellTable.showColumn(5) self.cellTable.hideColumn(2) self.cellTable.hideColumn(3) self.matTable.showColumn(5) self.matTable.hideColumn(2) self.matTable.hideColumn(3) else: self.cellTable.hideColumn(5) self.cellTable.showColumn(2) self.cellTable.showColumn(3) self.matTable.hideColumn(5) self.matTable.showColumn(2) self.matTable.showColumn(3) def updateHighlightColor(self): color = self.model.activeView.highlightBackground style_values = "border-radius: 8px; background-color: rgb{}" self.hlColorButton.setStyleSheet(style_values.format(str(color))) def updateAlpha(self): self.alphaBox.setValue(self.model.activeView.highlightAlpha) def updateSeed(self): self.seedBox.setValue(self.model.activeView.highlightSeed) def updateBackgroundColor(self): color = self.model.activeView.domainBackground self.bgButton.setStyleSheet("border-radius: 8px;" "background-color: rgb%s" % (str(color))) def updateOverlapColor(self): color = self.model.activeView.overlap_color self.overlapColorButton.setStyleSheet("border-radius: 8px;" "background-color: rgb%s" % (str(color))) def updateOverlap(self): colorby = self.model.activeView.colorby overlap_val = self.model.activeView.color_overlaps if colorby in ('cell', 'material'): self.overlapCheck.setChecked(overlap_val) def updateColorBy(self): colorby = self.model.activeView.colorby self.colorbyBox.setCurrentText(colorby) self.overlapCheck.setEnabled(colorby in ("cell", "material")) self.universeLevelBox.setEnabled(colorby == 'cell') def updateUniverseLevel(self): level = self.model.activeView.level if level == -1: self.universeLevelBox.setCurrentText('all') else: self.universeLevelBox.setCurrentText(str(level)) def updateDomainTabs(self): self.cellTable.setModel(self.main_window.cellsModel) self.matTable.setModel(self.main_window.materialsModel)
class MainWindow(QMainWindow): def __init__(self): super().__init__() layout = QVBoxLayout() form = QFormLayout() self.track_id = QSpinBox() self.track_id.setDisabled(True) self.name = QLineEdit() self.album = QComboBox() self.media_type = QComboBox() self.genre = QComboBox() self.composer = QLineEdit() self.milliseconds = QSpinBox() self.milliseconds.setRange(0, 2147483647) self.milliseconds.setSingleStep(1) self.bytes = QSpinBox() self.bytes.setRange(0, 2147483647) self.bytes.setSingleStep(1) self.unit_price = QDoubleSpinBox() self.unit_price.setRange(0, 999) self.unit_price.setSingleStep(0.01) self.unit_price.setPrefix("$") form.addRow(QLabel("Track ID"), self.track_id) form.addRow(QLabel("Track name"), self.name) form.addRow(QLabel("Composer"), self.composer) form.addRow(QLabel("Milliseconds"), self.milliseconds) form.addRow(QLabel("Bytes"), self.bytes) form.addRow(QLabel("Unit Price"), self.unit_price) self.model = QSqlTableModel(db=db) self.mapper = QDataWidgetMapper() self.mapper.setModel(self.model) self.mapper.addMapping(self.track_id, 0) self.mapper.addMapping(self.name, 1) self.mapper.addMapping(self.composer, 5) self.mapper.addMapping(self.milliseconds, 6) self.mapper.addMapping(self.bytes, 7) self.mapper.addMapping(self.unit_price, 8) self.model.setTable("Track") self.model.select() self.mapper.toFirst() self.setMinimumSize(QSize(400, 400)) controls = QHBoxLayout() # tag::controls[] prev_rec = QPushButton("Previous") prev_rec.clicked.connect(self.mapper.toPrevious) next_rec = QPushButton("Next") next_rec.clicked.connect(self.mapper.toNext) save_rec = QPushButton("Save Changes") save_rec.clicked.connect(self.mapper.submit) # end::controls[] controls.addWidget(prev_rec) controls.addWidget(next_rec) controls.addWidget(save_rec) layout.addLayout(form) layout.addLayout(controls) widget = QWidget() widget.setLayout(layout) self.setCentralWidget(widget)
def __init__(self, prefs, icon=None): super().__init__() self.prefs = prefs self.hotkey_format_regex = r'^\<ctrl\>\+\<alt\>(\+\<shift\>)?\+[a-zA-Z0-9]$' if icon: self.setWindowIcon(icon) # checkbox: Include Minimized include_minimized = QCheckBox() include_minimized.setFixedWidth(35) include_minimized.setChecked(self.prefs["include_minimized"]["value"]) include_minimized.stateChanged.connect( lambda: self.include_minimized(include_minimized.isChecked())) include_minimized_descr = QLabel( self.prefs["include_minimized"]["description"]) include_minimized_descr.setWordWrap(True) include_minimized_layout = QHBoxLayout() include_minimized_layout.addWidget(include_minimized) include_minimized_layout.addWidget(include_minimized_descr) include_minimized_groupbox = QGroupBox("Include Minimized") include_minimized_groupbox.setLayout(include_minimized_layout) # checkbox: snap to grid snap_to_grid = QCheckBox() snap_to_grid.setFixedWidth(35) snap_to_grid.setChecked(self.prefs["snap_to_grid"]["value"]) snap_to_grid.stateChanged.connect( lambda: self.snap_to_grid(snap_to_grid.isChecked())) snap_to_grid_descr = QLabel(self.prefs["snap_to_grid"]["description"]) snap_to_grid_descr.setWordWrap(True) snap_to_grid_layout = QHBoxLayout() snap_to_grid_layout.addWidget(snap_to_grid) snap_to_grid_layout.addWidget(snap_to_grid_descr) snap_to_grid_groupbox = QGroupBox("Snap To Grid") snap_to_grid_groupbox.setLayout(snap_to_grid_layout) # checkbox: fit into screen fit_into_screen = QCheckBox() fit_into_screen.setFixedWidth(35) fit_into_screen.setChecked(self.prefs["fit_into_screen"]["value"]) fit_into_screen.stateChanged.connect( lambda: self.fit_into_screen(fit_into_screen.isChecked())) fit_into_screen_descr = QLabel( self.prefs["fit_into_screen"]["description"]) fit_into_screen_descr.setWordWrap(True) fit_into_screen_layout = QHBoxLayout() fit_into_screen_layout.addWidget(fit_into_screen) fit_into_screen_layout.addWidget(fit_into_screen_descr) fit_into_screen_groupbox = QGroupBox("Fit Into Screen") fit_into_screen_groupbox.setLayout(fit_into_screen_layout) # doublespinBox: match cutoff match_cutoff = QDoubleSpinBox() match_cutoff.setFixedWidth(35) match_cutoff.setValue(self.prefs["match_cutoff"]["value"]) match_cutoff.setRange(0.1, 1.0) match_cutoff.setSingleStep(0.1) match_cutoff.setDecimals(1) match_cutoff.valueChanged.connect( lambda: self.match_cutoff(match_cutoff.value())) match_cutoff_descr = QLabel(self.prefs["match_cutoff"]["description"]) match_cutoff_descr.setWordWrap(True) match_cutoff_layout = QHBoxLayout() match_cutoff_layout.addWidget(match_cutoff) match_cutoff_layout.addWidget(match_cutoff_descr) match_cutoff_groupbox = QGroupBox("Match Cutoff") match_cutoff_groupbox.setLayout(match_cutoff_layout) # checkbox: enable hotkeys enable_hotkeys = QCheckBox() enable_hotkeys.setFixedWidth(35) enable_hotkeys.setChecked(self.prefs["enable_hotkeys"]["value"]) enable_hotkeys.stateChanged.connect( lambda: self.enable_hotkeys(enable_hotkeys.isChecked())) enable_hotkeys_descr = QLabel( self.prefs["enable_hotkeys"]["description"]) enable_hotkeys_descr.setWordWrap(True) enable_hotkeys_layout = QHBoxLayout() enable_hotkeys_layout.addWidget(enable_hotkeys) enable_hotkeys_layout.addWidget(enable_hotkeys_descr) # lineedit: hotkeys shortcuts hotkey_freeze_new_name = QLabel("Freeze New:") hotkey_freeze_new_name.setFixedWidth(75) self.hotkey_freeze_new_status = QLabel() self.hotkey_freeze_new = QLineEdit( self.prefs["hotkeys"]["value"]["freeze_new"]) self.hotkey_freeze_new.setFixedWidth(140) self.hotkey_freeze_new.editingFinished.connect( lambda: self.hotkey_freeze_new_update(self.hotkey_freeze_new.text( ))) self.hotkey_freeze_new.cursorPositionChanged.connect( self.hotkey_freeze_new_status.clear) hotkey_freeze_new_layout = QHBoxLayout() hotkey_freeze_new_layout.addWidget(hotkey_freeze_new_name) hotkey_freeze_new_layout.addWidget(self.hotkey_freeze_new) hotkey_freeze_new_layout.addWidget(self.hotkey_freeze_new_status) hotkey_freeze_all_name = QLabel("Freeze All:") hotkey_freeze_all_name.setFixedWidth(75) self.hotkey_freeze_all_status = QLabel() self.hotkey_freeze_all = QLineEdit( self.prefs["hotkeys"]["value"]["freeze_all"]) self.hotkey_freeze_all.setFixedWidth(140) self.hotkey_freeze_all.editingFinished.connect( lambda: self.hotkey_freeze_all_update(self.hotkey_freeze_all.text( ))) self.hotkey_freeze_all.cursorPositionChanged.connect( self.hotkey_freeze_all_status.clear) hotkey_freeze_all_layout = QHBoxLayout() hotkey_freeze_all_layout.addWidget(hotkey_freeze_all_name) hotkey_freeze_all_layout.addWidget(self.hotkey_freeze_all) hotkey_freeze_all_layout.addWidget(self.hotkey_freeze_all_status) hotkey_restore_name = QLabel("Restore:") hotkey_restore_name.setFixedWidth(75) self.hotkey_restore_status = QLabel() self.hotkey_restore = QLineEdit( self.prefs["hotkeys"]["value"]["restore"]) self.hotkey_restore.setFixedWidth(140) self.hotkey_restore.editingFinished.connect( lambda: self.hotkey_restore_update(self.hotkey_restore.text())) self.hotkey_restore.cursorPositionChanged.connect( self.hotkey_restore_status.clear) hotkey_restore_layout = QHBoxLayout() hotkey_restore_layout.addWidget(hotkey_restore_name) hotkey_restore_layout.addWidget(self.hotkey_restore) hotkey_restore_layout.addWidget(self.hotkey_restore_status) self.hotkeys_statusbar = QLabel() self.hotkeys_statusbar.setWordWrap(True) self.hotkeys_statusbar.setText(hotkeys_statusbar_map[ self.prefs['enable_hotkeys']['value']]['text']) self.hotkeys_statusbar.setStyleSheet(hotkeys_statusbar_map[ self.prefs['enable_hotkeys']['value']]['style']) close_button = QPushButton("Close") close_button.setMaximumWidth(75) close_button.clicked.connect(self.close) hotkeys_statusbar_layout = QHBoxLayout() hotkeys_statusbar_layout.addWidget(self.hotkeys_statusbar) hotkeys_statusbar_layout.addWidget(close_button) hotkeys_layout = QVBoxLayout() hotkeys_layout.addLayout(hotkey_freeze_new_layout) hotkeys_layout.addLayout(hotkey_freeze_all_layout) hotkeys_layout.addLayout(hotkey_restore_layout) self.hotkeys_groupbox = QGroupBox() self.hotkeys_groupbox.setFlat(True) self.hotkeys_groupbox.setDisabled( not self.prefs["enable_hotkeys"]["value"]) self.hotkeys_groupbox.setLayout(hotkeys_layout) enable_hotkeys_outer_layout = QVBoxLayout() enable_hotkeys_outer_layout.addLayout(enable_hotkeys_layout) enable_hotkeys_outer_layout.addWidget(self.hotkeys_groupbox) enable_hotkeys_groupbox = QGroupBox("Enable Hotkeys") enable_hotkeys_groupbox.setLayout(enable_hotkeys_outer_layout) # Create main layout and add widgets main_layout = QVBoxLayout() main_layout.addWidget(include_minimized_groupbox) main_layout.addWidget(snap_to_grid_groupbox) main_layout.addWidget(fit_into_screen_groupbox) main_layout.addWidget(match_cutoff_groupbox) main_layout.addWidget(enable_hotkeys_groupbox) main_layout.addWidget(self.hotkeys_groupbox) #main_layout.addWidget(hotkeys_statusbar_groupbox) main_layout.addLayout(hotkeys_statusbar_layout) self.setLayout(main_layout)
def __init_advanced_features_widget__(self, parent=None): self.__advanced_widget = QGroupBox("Advanced Features Options", parent) fixed_layer_check = QCheckBox("Fixed Layer", self.__advanced_widget) fixed_layer_check.setChecked(self.dlp_controller.fixed_layer) fixed_layer_check.toggled.connect(self.dlp_controller.set_fixed_layer) incremental_amplitude_check = QCheckBox("Incremental Amplitude", self.__advanced_widget) incremental_amplitude_check.setChecked( self.dlp_controller.incremental_amplitude) incremental_amplitude_check.toggled.connect( self.dlp_controller.set_incremental_amplitude) starting_amplitude_label = QLabel("Starting Amplitude", self.__advanced_widget) starting_amplitude_edit = QSpinBox(self.__advanced_widget) starting_amplitude_edit.setMaximum(1000) starting_amplitude_edit.setMinimum(0) starting_amplitude_edit.setSingleStep(1) starting_amplitude_edit.setValue( self.dlp_controller.starting_incremental_amplitude) starting_amplitude_edit.valueChanged.connect( self.dlp_controller.set_starting_incremental_amplitude) amplitude_step_label = QLabel("Step Size", self.__advanced_widget) amplitude_step_edit = QSpinBox(self.__advanced_widget) amplitude_step_edit.setMaximum(1000) amplitude_step_edit.setMinimum(0) amplitude_step_edit.setSingleStep(1) amplitude_step_edit.setValue( self.dlp_controller.incremental_step_amplitude) amplitude_step_edit.valueChanged.connect( self.dlp_controller.set_incremental_step_amplitude) incremental_exposure_check = QCheckBox("Incremental Exposure", self.__advanced_widget) incremental_exposure_check.setChecked( self.dlp_controller.incremental_exposure) incremental_exposure_check.toggled.connect( self.dlp_controller.set_incremental_exposure) starting_exposure_label = QLabel("Starting Exposure", self.__advanced_widget) starting_exposure_edit = QDoubleSpinBox(self.__advanced_widget) starting_exposure_edit.setSuffix(str('ms')) starting_exposure_edit.setMaximum(100000) starting_exposure_edit.setMinimum(0) starting_exposure_edit.setDecimals(1) starting_exposure_edit.setSingleStep(0.1) starting_exposure_edit.valueChanged.connect( self.dlp_controller.set_starting_incremental_exposure) starting_exposure_edit.setValue( self.dlp_controller.starting_incremental_exposure) exposure_step_label = QLabel("Step Size", self.__advanced_widget) exposure_step_edit = QDoubleSpinBox(self.__advanced_widget) exposure_step_edit.setSuffix(str('ms')) exposure_step_edit.setMaximum(100000) exposure_step_edit.setMinimum(0) exposure_step_edit.setDecimals(1) exposure_step_edit.setSingleStep(0.1) exposure_step_edit.valueChanged.connect( self.dlp_controller.set_incremental_step_exposure) exposure_step_edit.setValue( self.dlp_controller.incremental_step_exposure) incremental_thickness_check = QCheckBox("Incremental Thickness", self.__advanced_widget) incremental_thickness_check.setChecked( self.dlp_controller.incremental_thickness) incremental_thickness_check.toggled.connect( self.dlp_controller.set_incremental_thickness) thickness_label = QLabel("Starting Thickness", self.__features_widget) self.starting_thickness_edit = MyDiscreteStepsSpinBox( self.dlp_controller.get_step_length_microns(), self.__features_widget) self.starting_thickness_edit.setSuffix(str('\u03BCm')) self.starting_thickness_edit.setMaximum(1000000) self.starting_thickness_edit.setMinimum(0) self.starting_thickness_edit.setDecimals(3) self.starting_thickness_edit.my_value_changed_signal.connect( self.dlp_controller.set_starting_incremental_thickness) self.starting_thickness_edit.setValue( self.dlp_controller.starting_incremental_thickness * 1000) thickness_step_label = QLabel("Step Size", self.__features_widget) self.thickness_step_edit = MyDiscreteStepsSpinBox( self.dlp_controller.get_step_length_microns(), self.__features_widget) self.thickness_step_edit.setSuffix(str('\u03BCm')) self.thickness_step_edit.setMaximum(1000000) self.thickness_step_edit.setMinimum(0) self.thickness_step_edit.setDecimals(3) self.thickness_step_edit.my_value_changed_signal.connect( self.dlp_controller.set_incremental_step_thickness) self.thickness_step_edit.setValue( self.dlp_controller.incremental_step_thickness * 1000) apply_grayscale_correction_check = QCheckBox("Grayscale Correction", self.__advanced_widget) apply_grayscale_correction_check.setChecked( self.dlp_controller.grayscale_correction) apply_grayscale_correction_check.toggled.connect( self.dlp_controller.set_grayscale_correction) grayscale_parameters_widget = QWidget(self.__features_widget) a_parameter_label = QLabel("\u03B1", grayscale_parameters_widget) alpha_parameter_edit = QDoubleSpinBox(grayscale_parameters_widget) alpha_parameter_edit.setMaximum(1000) alpha_parameter_edit.setMinimum(0) alpha_parameter_edit.setDecimals(3) alpha_parameter_edit.setSingleStep(0.001) alpha_parameter_edit.valueChanged.connect( self.dlp_controller.set_grayscale_alpha) alpha_parameter_edit.setValue(self.dlp_controller.grayscale_alpha) beta_parameter_label = QLabel("\u03B2", grayscale_parameters_widget) beta_parameter_edit = QDoubleSpinBox(grayscale_parameters_widget) beta_parameter_edit.setMaximum(1000) beta_parameter_edit.setMinimum(0) beta_parameter_edit.setDecimals(3) beta_parameter_edit.setSingleStep(0.001) beta_parameter_edit.valueChanged.connect( self.dlp_controller.set_grayscale_beta) beta_parameter_edit.setValue(self.dlp_controller.grayscale_beta) gamma_parameter_label = QLabel("\u03B3", grayscale_parameters_widget) gamma_parameter_edit = QDoubleSpinBox(grayscale_parameters_widget) gamma_parameter_edit.setMaximum(1000) gamma_parameter_edit.setMinimum(0) gamma_parameter_edit.setDecimals(3) gamma_parameter_edit.setSingleStep(0.001) gamma_parameter_edit.valueChanged.connect( self.dlp_controller.set_grayscale_gamma) gamma_parameter_edit.setValue(self.dlp_controller.grayscale_gamma) grayscale_parameters_layout = QHBoxLayout(grayscale_parameters_widget) grayscale_parameters_layout.addWidget(a_parameter_label) grayscale_parameters_layout.addWidget(alpha_parameter_edit) grayscale_parameters_layout.addWidget(beta_parameter_label) grayscale_parameters_layout.addWidget(beta_parameter_edit) grayscale_parameters_layout.addWidget(gamma_parameter_label) grayscale_parameters_layout.addWidget(gamma_parameter_edit) grayscale_parameters_widget.setLayout(grayscale_parameters_layout) advanced_features_layout = QGridLayout(self.__advanced_widget) advanced_features_layout.addWidget(incremental_amplitude_check, 1, 0, 1, 2) advanced_features_layout.addWidget(fixed_layer_check, 1, 3) advanced_features_layout.addWidget(starting_amplitude_label, 2, 0) advanced_features_layout.addWidget(starting_amplitude_edit, 2, 1) advanced_features_layout.addWidget(amplitude_step_label, 2, 2) advanced_features_layout.addWidget(amplitude_step_edit, 2, 3) advanced_features_layout.addWidget(incremental_exposure_check, 3, 0, 1, 2) advanced_features_layout.addWidget(starting_exposure_label, 4, 0) advanced_features_layout.addWidget(starting_exposure_edit, 4, 1) advanced_features_layout.addWidget(exposure_step_label, 4, 2) advanced_features_layout.addWidget(exposure_step_edit, 4, 3) advanced_features_layout.addWidget(incremental_thickness_check, 5, 0, 1, 2) advanced_features_layout.addWidget(thickness_label, 6, 0) advanced_features_layout.addWidget(self.starting_thickness_edit, 6, 1) advanced_features_layout.addWidget(thickness_step_label, 6, 2) advanced_features_layout.addWidget(self.thickness_step_edit, 6, 3) advanced_features_layout.addWidget(apply_grayscale_correction_check, 7, 0, 1, 2) advanced_features_layout.addWidget(grayscale_parameters_widget, 8, 0, 1, 4) self.__advanced_widget.setLayout(advanced_features_layout)
class InputsLayout(QFormLayout): # this signal is connected to print_output from output_layout class. Connection is done in center_layout ga_result = Signal( str ) # a signal that is emitted so it can transfer resulting string to the output_layout class def __init__(self): super(InputsLayout, self).__init__() self.big_font = QFont() self.medium_font = QFont() self.header = QLabel() self.header_general = QLabel() self.header_fitness_remapping = QLabel() self.header_stop = QLabel() self.header_selection = QLabel() self.header_pairing = QLabel() self.header_crossover = QLabel() self.header_mutation = QLabel() self.inp_functions_combo = QComboBox() self.inp_num_variables = QSpinBox() self.inp_extrema_min = QRadioButton("Minimum") self.inp_extrema_max = QRadioButton("Maximum") self.inp_pop_size = QSpinBox() self.inp_lower_bound = QDoubleSpinBox() self.inp_upper_bound = QDoubleSpinBox() # Stopping self.inp_max_iter = QSpinBox() self.inp_similarity_cb = QCheckBox() self.inp_similarity = QSpinBox() self.inp_best_result_cb = QCheckBox() self.inp_best_result = QDoubleSpinBox() self.inp_average_result_cb = QCheckBox() self.inp_average_result = QDoubleSpinBox() # Fitness remapping self.inp_fitness_remapping = QComboBox() # Selection self.inp_selection_method = QComboBox() self.inp_elitism = QDoubleSpinBox() # Pairing self.inp_pairing_method = QComboBox() # Crossover self.inp_crossover_method = QComboBox() self.inp_crossover_fraction = QDoubleSpinBox() self.intermediate_offset = QDoubleSpinBox() # Mutation self.inp_mutation_method = QComboBox() self.inp_mutation_intensity = QDoubleSpinBox() self.inp_mutation_intensity_final = QDoubleSpinBox() self.init_fonts() self.init_header() self.init_row_functions() self.init_row_general() self.init_row_fitness_remapping() self.init_row_stop() self.init_row_selection() self.init_row_pairing() self.init_row_crossover() self.init_row_mutation() def init_fonts(self): self.big_font.setPointSizeF(14) self.medium_font.setPointSizeF(12) def init_header(self): self.header.setFont(self.big_font) self.header.setAlignment(Qt.AlignCenter) self.header.setText("Genetic Algorithm Continuous Optimization") self.addRow(self.header) self.addRow(QHLine()) def init_row_functions(self): self.inp_functions_combo.addItem("Ackley", ackley) self.inp_functions_combo.addItem("Griewank", griewank) self.inp_functions_combo.addItem("Michalewicz", michalewicz) self.inp_extrema_min.setChecked(True) radio_box = QHBoxLayout() radio_box.addWidget(self.inp_extrema_min) radio_box.addWidget(self.inp_extrema_max) self.addRow("Function:", self.inp_functions_combo) self.inp_num_variables.setMaximum(10000) self.inp_num_variables.setValue(10) self.addRow("Number of variables:", self.inp_num_variables) self.addRow("Find:", radio_box) self.addRow(QHLine()) def init_row_general(self): self.header_general.setFont(self.medium_font) self.header_general.setText("General") self.inp_pop_size.setMaximum(10000) self.inp_pop_size.setValue(300) self.inp_lower_bound.setMaximum(1000000) self.inp_lower_bound.setMinimum(-1000000.0) self.inp_lower_bound.setValue(-10) self.inp_upper_bound.setMaximum(1000000) self.inp_upper_bound.setMinimum(-1000000.0) self.inp_upper_bound.setValue(10) self.addRow(self.header_general) self.addRow("Population size", self.inp_pop_size) self.addRow("Lower Bound", self.inp_lower_bound) self.addRow("Upper Bound", self.inp_upper_bound) self.addRow(QHLine()) def init_row_fitness_remapping(self): self.header_fitness_remapping.setFont(self.medium_font) self.header_fitness_remapping.setText("Fitness Remapping") self.inp_fitness_remapping.addItem("Rank Scaling", "Rank Scaling") self.inp_fitness_remapping.addItem("Fitness Scaling", "Fitness Scaling") self.addRow(self.header_fitness_remapping) self.addRow("Fitness remapping", self.inp_fitness_remapping) self.addRow(QHLine()) def init_row_stop(self): self.header_stop.setFont(self.medium_font) self.header_stop.setText("Stopping Criteria") self.inp_max_iter.setMaximum(100000) self.inp_similarity.setMaximum(100000) self.inp_best_result.setMinimum(-100000) self.inp_best_result.setMaximum(100000) self.inp_average_result.setMinimum(-100000) self.inp_average_result.setMaximum(100000) self.inp_max_iter.setValue(500) self.inp_similarity.setValue(80) self.inp_best_result.setValue(-10) self.inp_average_result.setValue(-10000) self.inp_similarity_cb.setText("Similar Results") self.inp_best_result_cb.setText("Best Result") self.inp_average_result_cb.setText("Average Result") self.inp_similarity_cb.stateChanged.connect(self.cb_similarity_signal) self.inp_best_result_cb.stateChanged.connect( self.cb_best_result_signal) self.inp_average_result_cb.stateChanged.connect( self.cb_average_result_signal) self.inp_similarity_cb.setChecked(False) self.inp_best_result_cb.setChecked(False) self.inp_average_result_cb.setChecked(False) self.inp_similarity.setEnabled(True) self.inp_best_result.setEnabled(False) self.inp_best_result.setStyleSheet("background:#555") self.inp_average_result.setEnabled(False) self.inp_average_result.setStyleSheet("background:#555") self.addRow(self.header_stop) self.addRow("Max iter", self.inp_max_iter) self.addRow(self.inp_similarity_cb, self.inp_similarity) self.addRow(self.inp_best_result_cb, self.inp_best_result) self.addRow(self.inp_average_result_cb, self.inp_average_result) self.addRow(QHLine()) def init_row_selection(self): self.header_selection.setFont(self.medium_font) self.header_selection.setText("Selection") self.inp_selection_method.addItem("Fittest Half", "Fittest Half") self.inp_selection_method.addItem("Roulette Wheel", "Roulette Wheel") self.inp_selection_method.addItem("Random", "Random") self.inp_selection_method.addItem("Whole Population", "Whole Population") self.inp_elitism.setMaximum(1) self.inp_elitism.setValue(0.01) self.inp_elitism.setSingleStep(0.01) self.addRow(self.header_selection) self.addRow("Selection Method", self.inp_selection_method) self.addRow("Elitism Percentage", self.inp_elitism) self.addRow(QHLine()) def init_row_pairing(self): self.header_pairing.setFont(self.medium_font) self.header_pairing.setText("Pairing") self.inp_pairing_method.addItem("Random", "Random") self.inp_pairing_method.addItem("Roulette Wheel", "Roulette Wheel") self.inp_pairing_method.addItem("Fittest", "Fittest") self.addRow(self.header_pairing) self.addRow("Pairing Method", self.inp_pairing_method) self.addRow(QHLine()) def init_row_crossover(self): self.header_crossover.setFont(self.medium_font) self.header_crossover.setText("Crossover") self.inp_crossover_method.addItem("Intermediate", "Intermediate") self.inp_crossover_method.addItem("Line Intermediate", "Line Intermediate") self.inp_crossover_method.addItem("Heuristic", "Heuristic") self.inp_crossover_method.addItem("One point", "One point") self.inp_crossover_method.addItem("Two point", "Two point") self.inp_crossover_method.addItem("Random", "Random") self.inp_mutation_method.setCurrentIndex(2) self.inp_crossover_fraction.setMaximum(1) self.inp_crossover_fraction.setValue(0.7) self.inp_crossover_fraction.setSingleStep(0.05) self.intermediate_offset.setMaximum(20) self.intermediate_offset.setValue(1.55) self.intermediate_offset.setSingleStep(0.05) self.addRow(self.header_crossover) self.addRow("Crossover Method", self.inp_crossover_method) self.addRow("Crossover Fraction", self.inp_crossover_fraction) self.addRow("Intermediate Offset", self.intermediate_offset) self.addRow(QHLine()) def init_row_mutation(self): self.header_mutation.setFont(self.medium_font) self.header_mutation.setText("Mutation") self.inp_mutation_method.addItem("Gauss", "Gauss") self.inp_mutation_method.addItem("Random", "Random") self.inp_mutation_intensity.setMaximum(200) self.inp_mutation_intensity.setValue(2) self.inp_mutation_intensity.setDecimals(4) self.inp_mutation_intensity.setSingleStep(0.01) self.inp_mutation_intensity_final.setMaximum(200) self.inp_mutation_intensity_final.setDecimals(4) self.inp_mutation_intensity_final.setValue(0.001) self.inp_mutation_intensity_final.setSingleStep(0.5) self.addRow(self.header_mutation) self.addRow("Mutation Method", self.inp_mutation_method) self.addRow("Mutation Intensity", self.inp_mutation_intensity) self.addRow("Final Mutation Intensity", self.inp_mutation_intensity_final) self.addRow(QHLine()) def get_options(self): function = self.inp_functions_combo.currentData() num_var = self.inp_num_variables.text() if self.inp_extrema_min.isChecked(): extrem = 0 else: extrem = 1 pop_size = self.inp_pop_size.text() low_bound = self.inp_lower_bound.text() upp_bound = self.inp_upper_bound.text() max_iter = self.inp_max_iter.text() sim_results = self.inp_similarity.text() best_res = self.inp_best_result.text() average_res = self.inp_average_result.text() select_method = self.inp_selection_method.currentText() elite_percent = self.inp_elitism.text() pairing = self.inp_pairing_method.currentText() crossover_method = self.inp_crossover_method.currentText() crossover_fraction = self.inp_crossover_fraction.text() intermediate_offset = self.intermediate_offset.text() mutation_method = self.inp_mutation_method.currentText() mutation_intensity = self.inp_mutation_intensity.text() mutation_intensity_final = self.inp_mutation_intensity_final.text() fitness_remapping = self.inp_fitness_remapping.currentText() options = { "function": function, "num_var": num_var, "pop_size": int(pop_size), "max_iter": int(max_iter), "lower_bound": float(low_bound.replace(",", ".")), "upper_bound": float(upp_bound.replace(",", ".")), "find_max": extrem, "prints": 0, "average_result": float(average_res.replace(",", ".")), "best_result": float(best_res.replace(",", ".")), "similarity": float(sim_results.replace(",", ".")), "selection": select_method, "pairing": pairing, "crossover": crossover_method, "crossover_fraction": float(crossover_fraction.replace(",", ".")), "intermediate_offset": float(intermediate_offset.replace(",", ".")), # 0 mean child will be between parents, 1 mean offset is same as two parent distance "mutation": mutation_method, "mutation_intensity": float(mutation_intensity.replace(",", ".")), "mutation_intensity_final": float(mutation_intensity_final.replace(",", ".")), "elitism": float(elite_percent.replace(",", ".")), "fitness_remapping": fitness_remapping } if not self.inp_similarity_cb.isChecked(): options["similarity"] = None if not self.inp_best_result_cb.isChecked(): options["best_result"] = None if not self.inp_average_result_cb.isChecked(): options["average_result"] = None return options def cb_similarity_signal(self): if self.inp_similarity_cb.isChecked(): self.inp_similarity.setEnabled(True) self.inp_similarity.setStyleSheet("") else: self.inp_similarity.setEnabled(False) self.inp_similarity.setStyleSheet("background:#555") def cb_best_result_signal(self): if self.inp_best_result_cb.isChecked(): self.inp_best_result.setEnabled(True) self.inp_best_result.setStyleSheet("") else: self.inp_best_result.setEnabled(False) self.inp_best_result.setStyleSheet("background:#555") def cb_average_result_signal(self): if self.inp_average_result_cb.isChecked(): self.inp_average_result.setEnabled(True) self.inp_average_result.setStyleSheet("") else: self.inp_average_result.setEnabled(False) self.inp_average_result.setStyleSheet("background:#555")
def __init_projector_widget__(self, parent=None): self.__projector_widget = QGroupBox("Projector Options", parent) # self.__projector_widget.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum) mirror_x = QCheckBox("Mirror X") mirror_x.setChecked(self.dlp_controller.is_horizontal_mirrored()) mirror_x.toggled.connect(self.dlp_controller.set_horizontal_mirroring) mirror_y = QCheckBox("Mirror Y") mirror_y.setChecked(self.dlp_controller.is_vertical_mirrored()) mirror_y.toggled.connect(self.dlp_controller.set_vertical_mirroring) start_projector_button = QPushButton("Start Projector", self.__projector_widget) start_projector_button.clicked.connect( self.dlp_controller.start_projector) project_pattern_button = QPushButton("Project Pattern", self.__projector_widget) project_pattern_button.clicked.connect( self.dlp_controller.project_calibration_pattern) print_position_button = QPushButton("Print Position", self.__projector_widget) print_position_button.clicked.connect( self.dlp_controller.print_motor_position) home_projector_button = QPushButton("Home Projector", self.__projector_widget) home_projector_button.clicked.connect( self.dlp_controller.home_projector) move_projector_button = QPushButton("Move Projector", self.__projector_widget) move_projector_button.clicked.connect( self.dlp_controller.move_projector) move_projector_edit = QDoubleSpinBox(self.__projector_widget) move_projector_edit.setSuffix("mm") move_projector_edit.setMaximum(10000) move_projector_edit.setMinimum(-10000) move_projector_edit.setDecimals(3) move_projector_edit.setSingleStep(0.001) move_projector_edit.valueChanged.connect( self.dlp_controller.update_projector_distance) set_amplitude_button = QPushButton("Set Projector Amplitude", self.__projector_widget) set_amplitude_button.clicked.connect( self.dlp_controller.set_projector_amplitude) set_amplitude_edit = QSpinBox(self.__projector_widget) set_amplitude_edit.setMaximum(1000) set_amplitude_edit.setMinimum(0) set_amplitude_edit.setValue(self.dlp_controller.projector_amplitude) set_amplitude_edit.valueChanged.connect( self.dlp_controller.update_projector_amplitude) lock_unlock_projector_button = QPushButton("Lock/Unlock Projector", self.__projector_widget) lock_unlock_projector_button.clicked.connect( self.dlp_controller.lock_unlock_projector) projector_layout = QGridLayout(self.__projector_widget) # projector_layout.addWidget(projector_label, 0, 0) projector_layout.addWidget(mirror_x, 0, 1) projector_layout.addWidget(mirror_y, 0, 2) projector_layout.addWidget(start_projector_button, 1, 0, 1, 1) projector_layout.addWidget(project_pattern_button, 1, 1, 1, 1) projector_layout.addWidget(print_position_button, 1, 2, 1, 1) projector_layout.addWidget(home_projector_button, 2, 0, 1, 1) projector_layout.addWidget(move_projector_button, 2, 1, 1, 1) projector_layout.addWidget(move_projector_edit, 2, 2) projector_layout.addWidget(set_amplitude_button, 3, 0, 1, 1) projector_layout.addWidget(set_amplitude_edit, 3, 1) projector_layout.addWidget(lock_unlock_projector_button, 3, 2, 1, 1) self.__projector_widget.setLayout(projector_layout)
def __init_features_widget__(self, parent=None): self.__features_widget = QGroupBox("Features Layers Parameters", parent) # self.__features_widget.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum) thickness_label = QLabel("Layer Thickness", self.__features_widget) self.features_thickness_edit = MyDiscreteStepsSpinBox( self.dlp_controller.get_step_length_microns(), self.__features_widget) self.features_thickness_edit.setSuffix(str('\u03BCm')) self.features_thickness_edit.setMaximum(1000000) self.features_thickness_edit.setMinimum(0) self.features_thickness_edit.setDecimals(3) self.features_thickness_edit.my_value_changed_signal.connect( self.dlp_controller.set_features_thickness) self.features_thickness_edit.setValue( self.dlp_controller.features_thickness * 1000) exposure_label = QLabel("Exposure Time", self.__features_widget) exposure_edit = QDoubleSpinBox(self.__features_widget) exposure_edit.setSuffix(str('ms')) exposure_edit.setMaximum(10000000) exposure_edit.setMinimum(0) exposure_edit.setDecimals(1) exposure_edit.setSingleStep(0.1) exposure_edit.setValue(self.dlp_controller.features_exposure) exposure_edit.valueChanged.connect( self.dlp_controller.set_features_exposure_time) amplitude_label = QLabel("Light Amplitude", self.__features_widget) amplitude_edit = QSpinBox(self.__features_widget) amplitude_edit.setMaximum(1600) amplitude_edit.setMinimum(0) amplitude_edit.setSingleStep(1) amplitude_edit.setValue(self.dlp_controller.features_amplitude) amplitude_edit.valueChanged.connect( self.dlp_controller.set_features_amplitude) burn_layers_label = QLabel("Burn Layers", self.__features_widget) burn_layers_edit = QSpinBox(self.__features_widget) burn_layers_edit.setMaximum(1000) burn_layers_edit.setMinimum(0) burn_layers_edit.setSingleStep(1) burn_layers_edit.setValue(self.dlp_controller.features_burn_layers) burn_layers_edit.valueChanged.connect( self.dlp_controller.set_features_burning_layers) burn_exposure_label = QLabel("Burn Exposure", self.__features_widget) burn_exposure_edit = QDoubleSpinBox(self.__features_widget) burn_exposure_edit.setSuffix(str('ms')) burn_exposure_edit.setMaximum(100000) burn_exposure_edit.setMinimum(0) burn_exposure_edit.setDecimals(1) burn_exposure_edit.setSingleStep(0.1) burn_exposure_edit.setValue(self.dlp_controller.features_burn_exposure) burn_exposure_edit.valueChanged.connect( self.dlp_controller.set_features_burning_exposure_time) burn_amplitude_label = QLabel("Burn Amplitude", self.__features_widget) burn_amplitude_edit = QSpinBox(self.__features_widget) burn_amplitude_edit.setMaximum(1600) burn_amplitude_edit.setMinimum(0) burn_amplitude_edit.setSingleStep(1) burn_amplitude_edit.setValue( self.dlp_controller.features_burn_amplitude) burn_amplitude_edit.valueChanged.connect( self.dlp_controller.set_features_burning_amplitude) select_layers_button = QPushButton("Select Features Images") select_layers_button.clicked.connect(self.load_features_images) features_layout = QGridLayout(self.__features_widget) features_layout.addWidget(thickness_label, 1, 0) features_layout.addWidget(self.features_thickness_edit, 1, 1) features_layout.addWidget(exposure_label, 2, 0) features_layout.addWidget(exposure_edit, 2, 1) features_layout.addWidget(amplitude_label, 3, 0) features_layout.addWidget(amplitude_edit, 3, 1) features_layout.addWidget(burn_layers_label, 4, 0) features_layout.addWidget(burn_layers_edit, 4, 1) features_layout.addWidget(burn_exposure_label, 5, 0) features_layout.addWidget(burn_exposure_edit, 5, 1) features_layout.addWidget(burn_amplitude_label, 6, 0) features_layout.addWidget(burn_amplitude_edit, 6, 1) features_layout.addWidget(select_layers_button, 7, 0, 1, 2) self.__features_widget.setLayout(features_layout)
class DLPSlicerGUI(QWidget): def __init__(self, dlp_controller=None, parent=None): QWidget.__init__(self, parent) if dlp_controller: self.dlp_controller = dlp_controller self.main_layout = QVBoxLayout() self.__init_slicer_widget__() self.__init_options_widget__() self.__options_widget.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Maximum) self.main_layout.addWidget(self.__slicer_widget) self.main_layout.addWidget(self.__options_widget) self.setLayout(self.main_layout) def __init_slicer_widget__(self): self.__slicer_widget = DLPSlicer(parent=self, dlp_controller=self.dlp_controller) self.__slicer_widget.update_physical_size.connect( self.update_size_label) self.__slicer_widget.update_fps.connect(self.update_fps_label) self.__slicer_widget.update_slice_counts.connect( self.update_slices_label) def __init_options_widget__(self): self.__options_widget = QWidget(self) self.__init_info_widget__() self.__init_geometry_widget__() self.__init_slicer_options_widget__() self.__options_layout = QGridLayout() self.__options_layout.addWidget(self.__info_widget, 0, 0, 1, 3) self.__options_layout.addWidget(self.__geometry_widget, 1, 0, 1, 2) self.__options_layout.addWidget(self.__slicer_options_widget, 1, 2) self.__options_widget.setLayout(self.__options_layout) def __init_info_widget__(self): self.__info_widget = QWidget(self) current_geometry_label = QLabel("Selected Geometry:", self.__info_widget) self.current_geometry_index = -1 self.geometry_list = MyQComboBox(self.__info_widget) self.geometry_list.currentIndexChanged.connect( self.update_geometry_transformations) self.fps_label = QLabel(f'fps: {0:.2f}', self.__info_widget) self.physical_size_label = QLabel( f'Width: {0:.2f} \u03BCm, Depth: {0:.2f} \u03BCm, Height: {0:.2f} \u03BCm', self.__info_widget) info_layout = QHBoxLayout() info_layout.addWidget(current_geometry_label) info_layout.addWidget(self.geometry_list) info_layout.addWidget(self.physical_size_label) info_layout.addWidget(self.fps_label) self.__info_widget.setLayout(info_layout) self.__info_widget.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Maximum) def __init_geometry_widget__(self): self.__geometry_widget = QGroupBox("Geometry", self) load_geometry_button = QPushButton("Load Geometry") load_geometry_button.clicked.connect(self.load_geometry) remove_geometry_button = QPushButton("Remove Geometry") remove_geometry_button.clicked.connect(self.remove_geometry) rotate_x_label = QLabel("Rotate X:", self.__geometry_widget) self.rotate_x_slider = QSlider(orientation=Qt.Horizontal, parent=self.__geometry_widget) self.rotate_x_slider.setTickPosition(QSlider.TicksBothSides) self.rotate_x_slider.setTickInterval(45) self.rotate_x_slider.setRange(-180, 180) self.rotate_x_slider.setValue(0) self.rotate_x_spin = QSpinBox(self.__geometry_widget) self.rotate_x_spin.setMinimum(-180) self.rotate_x_spin.setMaximum(180) self.rotate_x_spin.setValue(0) self.rotate_x_slider.valueChanged.connect(self.rotate_x_spin.setValue) self.rotate_x_slider.valueChanged.connect( self.__slicer_widget.set_x_rotation) self.rotate_x_spin.valueChanged.connect(self.rotate_x_slider.setValue) self.rotate_x_spin.valueChanged.connect( self.__slicer_widget.set_x_rotation) rotate_y_label = QLabel("Rotate Y:", self.__geometry_widget) self.rotate_y_slider = QSlider(orientation=Qt.Horizontal, parent=self.__geometry_widget) self.rotate_y_slider.setTickPosition(QSlider.TicksBothSides) self.rotate_y_slider.setTickInterval(45) self.rotate_y_slider.setRange(-180, 180) self.rotate_y_slider.setValue(0) self.rotate_y_spin = QSpinBox(self.__geometry_widget) self.rotate_y_spin.setMinimum(-180) self.rotate_y_spin.setMaximum(180) self.rotate_y_spin.setValue(0) self.rotate_y_slider.valueChanged.connect(self.rotate_y_spin.setValue) self.rotate_y_slider.valueChanged.connect( self.__slicer_widget.set_y_rotation) self.rotate_y_spin.valueChanged.connect(self.rotate_y_slider.setValue) self.rotate_y_spin.valueChanged.connect( self.__slicer_widget.set_y_rotation) rotate_z_label = QLabel("Rotate Z:", self.__geometry_widget) self.rotate_z_slider = QSlider(orientation=Qt.Horizontal, parent=self.__geometry_widget) self.rotate_z_slider.setTickPosition(QSlider.TicksBothSides) self.rotate_z_slider.setTickInterval(45) self.rotate_z_slider.setRange(-180, 180) self.rotate_z_slider.setValue(0) self.rotate_z_spin = QSpinBox(self.__geometry_widget) self.rotate_z_spin.setMinimum(-180) self.rotate_z_spin.setMaximum(180) self.rotate_z_spin.setValue(0) self.rotate_z_slider.valueChanged.connect(self.rotate_z_spin.setValue) self.rotate_z_slider.valueChanged.connect( self.__slicer_widget.set_z_rotation) self.rotate_z_spin.valueChanged.connect(self.rotate_z_slider.setValue) self.rotate_z_spin.valueChanged.connect( self.__slicer_widget.set_z_rotation) translate_x_label = QLabel("Translate X:", self.__geometry_widget) self.translate_x_slider = QSlider(orientation=Qt.Horizontal, parent=self.__geometry_widget) self.translate_x_slider.setTickPosition(QSlider.TicksBothSides) self.translate_x_slider.setTickInterval( self.dlp_controller.projector_pixel_size) self.translate_x_slider.setRange( -self.dlp_controller.projector_width * self.dlp_controller.projector_pixel_size * 0.5, self.dlp_controller.projector_width * self.dlp_controller.projector_pixel_size * 0.5) self.translate_x_slider.setValue(0) self.translate_x_spin = QDoubleSpinBox(self.__geometry_widget) self.translate_x_spin.setMinimum( -self.dlp_controller.projector_width * self.dlp_controller.projector_pixel_size * 0.5) self.translate_x_spin.setMaximum( self.dlp_controller.projector_width * self.dlp_controller.projector_pixel_size * 0.5) self.translate_x_spin.setSingleStep( self.dlp_controller.projector_pixel_size) self.translate_x_spin.setValue(0) self.translate_x_slider.valueChanged.connect( self.translate_x_spin.setValue) self.translate_x_slider.valueChanged.connect( self.__slicer_widget.set_x_pos) self.translate_x_spin.valueChanged.connect( self.translate_x_slider.setValue) self.translate_x_spin.valueChanged.connect( self.__slicer_widget.set_x_pos) translate_z_label = QLabel("Translate Z:", self.__geometry_widget) self.translate_z_slider = QSlider(orientation=Qt.Horizontal, parent=self.__geometry_widget) self.translate_z_slider.setTickPosition(QSlider.TicksBothSides) self.translate_z_slider.setTickInterval( self.dlp_controller.projector_pixel_size) self.translate_z_slider.setRange( -self.dlp_controller.projector_height * self.dlp_controller.projector_pixel_size * 0.5, self.dlp_controller.projector_height * self.dlp_controller.projector_pixel_size * 0.5) self.translate_z_slider.setValue(0) self.translate_z_spin = QDoubleSpinBox(self.__geometry_widget) self.translate_z_spin.setMinimum( -self.dlp_controller.projector_height * self.dlp_controller.projector_pixel_size * 0.5) self.translate_z_spin.setMaximum( self.dlp_controller.projector_height * self.dlp_controller.projector_pixel_size * 0.5) self.translate_z_spin.setSingleStep( self.dlp_controller.projector_pixel_size) self.translate_z_spin.setValue(0) self.translate_z_slider.valueChanged.connect( self.translate_z_spin.setValue) self.translate_z_slider.valueChanged.connect( self.__slicer_widget.set_z_pos) self.translate_z_spin.valueChanged.connect( self.translate_z_slider.setValue) self.translate_z_spin.valueChanged.connect( self.__slicer_widget.set_z_pos) scale_x_label = QLabel("Scale X:", self.__geometry_widget) self.scale_x_spin = QDoubleSpinBox(self.__geometry_widget) self.scale_x_spin.setMinimum(-1000) self.scale_x_spin.setMaximum(1000) self.scale_x_spin.setDecimals(2) self.scale_x_spin.setValue(1) self.scale_x_spin.setSingleStep(0.01) self.scale_x_spin.setObjectName("scale_x_spin") self.scale_x_spin.valueChanged.connect(self.set_scaling) scale_y_label = QLabel("Scale Y:", self.__geometry_widget) self.scale_y_spin = QDoubleSpinBox(self.__geometry_widget) self.scale_y_spin.setMinimum(-1000) self.scale_y_spin.setMaximum(1000) self.scale_y_spin.setDecimals(2) self.scale_y_spin.setValue(1) self.scale_y_spin.setSingleStep(0.01) self.scale_y_spin.setObjectName("scale_y_spin") self.scale_y_spin.valueChanged.connect(self.set_scaling) scale_z_label = QLabel("Scale Z:", self.__geometry_widget) self.scale_z_spin = QDoubleSpinBox(self.__geometry_widget) self.scale_z_spin.setMinimum(-1000) self.scale_z_spin.setMaximum(1000) self.scale_z_spin.setDecimals(2) self.scale_z_spin.setValue(1) self.scale_z_spin.setSingleStep(0.01) self.scale_z_spin.setObjectName("scale_z_spin") self.scale_z_spin.valueChanged.connect(self.set_scaling) self.uniform_scaling = QCheckBox("Uniform Scaling", self.__geometry_widget) self.uniform_scaling.setChecked(True) # self.uniform_scaling.setLayoutDirection(Qt.RightToLeft) list_of_measures = ('\u03BCm', 'mm', 'cm', 'dm', 'm') self.list_of_measures_coefficients = [0.001, 1, 10, 100, 1000] unit_of_measure_label = QLabel("Unit of Measure", self.__geometry_widget) self.unit_of_measure_combo = QComboBox(self.__geometry_widget) for measure in list_of_measures: self.unit_of_measure_combo.addItem(measure) self.unit_of_measure_combo.setCurrentIndex(1) self.unit_of_measure_combo.currentIndexChanged.connect( self.update_unit_of_measure) rotate_x_row = 0 rotate_y_row = rotate_x_row + 1 rotate_z_row = rotate_y_row + 1 translate_x_row = rotate_z_row + 1 translate_z_row = translate_x_row + 1 scale_x_row = translate_z_row + 1 scale_y_row = scale_x_row + 1 scale_z_row = scale_y_row + 1 uniform_scaling_row = scale_x_row unit_of_measure_row = scale_y_row load_geometry_row = scale_z_row + 1 remove_geometry_row = load_geometry_row geometry_layout = QGridLayout(self.__geometry_widget) geometry_layout.addWidget(load_geometry_button, load_geometry_row, 1, 1, 2) geometry_layout.addWidget(remove_geometry_button, remove_geometry_row, 3, 1, 2) geometry_layout.addWidget(rotate_x_label, rotate_x_row, 0) geometry_layout.addWidget(self.rotate_x_slider, rotate_x_row, 1, 1, 4) geometry_layout.addWidget(self.rotate_x_spin, rotate_x_row, 5) geometry_layout.addWidget(rotate_y_label, rotate_y_row, 0) geometry_layout.addWidget(self.rotate_y_slider, rotate_y_row, 1, 1, 4) geometry_layout.addWidget(self.rotate_y_spin, rotate_y_row, 5) geometry_layout.addWidget(rotate_z_label, rotate_z_row, 0) geometry_layout.addWidget(self.rotate_z_slider, rotate_z_row, 1, 1, 4) geometry_layout.addWidget(self.rotate_z_spin, rotate_z_row, 5) geometry_layout.addWidget(translate_x_label, translate_x_row, 0) geometry_layout.addWidget(self.translate_x_slider, translate_x_row, 1, 1, 4) geometry_layout.addWidget(self.translate_x_spin, translate_x_row, 5) geometry_layout.addWidget(translate_z_label, translate_z_row, 0) geometry_layout.addWidget(self.translate_z_slider, translate_z_row, 1, 1, 4) geometry_layout.addWidget(self.translate_z_spin, translate_z_row, 5) geometry_layout.addWidget(scale_x_label, scale_x_row, 0) geometry_layout.addWidget(self.scale_x_spin, scale_x_row, 1) geometry_layout.addWidget(scale_y_label, scale_y_row, 0) geometry_layout.addWidget(self.scale_y_spin, scale_y_row, 1) geometry_layout.addWidget(scale_z_label, scale_z_row, 0) geometry_layout.addWidget(self.scale_z_spin, scale_z_row, 1) geometry_layout.addWidget(self.uniform_scaling, uniform_scaling_row, 3, 1, 2) geometry_layout.addWidget(unit_of_measure_label, unit_of_measure_row, 4) geometry_layout.addWidget(self.unit_of_measure_combo, unit_of_measure_row, 3) self.__geometry_widget.setLayout(geometry_layout) def __init_slicer_options_widget__(self): self.__slicer_options_widget = QGroupBox("Slicer Options", self) thickness_label = QLabel("Layer Thickness", self.__slicer_options_widget) thickness_edit = QDoubleSpinBox(self.__slicer_options_widget) thickness_edit.setSuffix(str('\u03BCm')) thickness_edit.setMaximum(1000000) thickness_edit.setMinimum(0) thickness_edit.setDecimals(3) thickness_edit.setSingleStep(0.001) thickness_edit.setValue(self.dlp_controller.support_thickness * 1000) # self.__opengl_widget.set_slice_thickness(self.dlp_controller.support_thickness) thickness_edit.valueChanged.connect( self.__slicer_widget.set_slice_thickness) pixel_size_label = QLabel("Projector Pixel Size", self.__slicer_options_widget) pixel_size_edit = QDoubleSpinBox(self.__slicer_options_widget) pixel_size_edit.setSuffix(str('\u03BCm')) pixel_size_edit.setMaximum(1000000) pixel_size_edit.setMinimum(0) pixel_size_edit.setDecimals(2) pixel_size_edit.setSingleStep(0.01) pixel_size_edit.setValue(self.dlp_controller.projector_pixel_size * 1000) pixel_size_edit.valueChanged.connect( self.__slicer_widget.set_pixel_size) projector_resolution_label = QLabel("Projector Resolution", self.__slicer_options_widget) projector_resolution_edit_x = QSpinBox(self.__slicer_options_widget) projector_resolution_edit_x.setSuffix(str('W')) projector_resolution_edit_x.setMaximum(1000000) projector_resolution_edit_x.setMinimum(0) projector_resolution_edit_x.setValue( self.dlp_controller.projector_width) projector_resolution_edit_x.valueChanged.connect( self.__slicer_widget.set_projector_width) projector_resolution_edit_y = QSpinBox(self.__slicer_options_widget) projector_resolution_edit_y.setSuffix(str('H')) projector_resolution_edit_y.setMaximum(1000000) projector_resolution_edit_y.setMinimum(0) projector_resolution_edit_y.setValue( self.dlp_controller.projector_height) projector_resolution_edit_y.valueChanged.connect( self.__slicer_widget.set_projector_height) samples_per_pixel_label = QLabel("Samples per Pixel", self.__slicer_options_widget) samples_per_pixel_edit = QSpinBox(self.__slicer_options_widget) samples_per_pixel_edit.setMaximum(1000000) samples_per_pixel_edit.setMinimum(1) samples_per_pixel_edit.setValue(self.dlp_controller.samples_per_pixel) samples_per_pixel_edit.valueChanged.connect( self.__slicer_widget.set_samples_per_pixel) slice_geometry_button = QPushButton("Slice Geometry") slice_geometry_button.clicked.connect(self.start_slicing_process) slice_interrupt_button = QPushButton("Stop Slicing") slice_interrupt_button.clicked.connect( self.__slicer_widget.interrupt_slicing) self.slices_label = QLabel(f'Slicing progress: {0:.0f}/{0:.0f}', self.__info_widget) thickness_label_row = 0 pixel_size_row = 1 projector_resolution_row = 2 samples_per_pixel_row = 3 slice_button_row = 4 slices_label_row = 5 # slice_interrupt_row = slice_button_row slice_layout = QGridLayout(self.__slicer_options_widget) slice_layout.addWidget(thickness_label, thickness_label_row, 0) slice_layout.addWidget(thickness_edit, thickness_label_row, 1) slice_layout.addWidget(pixel_size_label, pixel_size_row, 0) slice_layout.addWidget(pixel_size_edit, pixel_size_row, 1) slice_layout.addWidget(projector_resolution_label, projector_resolution_row, 0) slice_layout.addWidget(projector_resolution_edit_x, projector_resolution_row, 1) slice_layout.addWidget(projector_resolution_edit_y, projector_resolution_row, 2) slice_layout.addWidget(self.slices_label, slice_button_row, 0) slice_layout.addWidget(slice_geometry_button, slice_button_row, 1) slice_layout.addWidget(slice_interrupt_button, slice_button_row, 2) slice_layout.addWidget(samples_per_pixel_label, samples_per_pixel_row, 0) slice_layout.addWidget(samples_per_pixel_edit, samples_per_pixel_row, 1) self.__slicer_options_widget.setLayout(slice_layout) @Slot(float) def set_scaling(self, value): if self.uniform_scaling.isChecked(): self.__slicer_widget.set_x_scale(value) self.__slicer_widget.set_y_scale(value) self.__slicer_widget.set_z_scale(value) self.scale_x_spin.setValue(value) self.scale_y_spin.setValue(value) self.scale_z_spin.setValue(value) else: self.__slicer_widget.set_x_scale(self.scale_x_spin.value()) self.__slicer_widget.set_y_scale(self.scale_y_spin.value()) self.__slicer_widget.set_z_scale(self.scale_z_spin.value()) @Slot() def load_geometry(self): file_names = QFileDialog.getOpenFileNames(caption='Select Geometry', dir='../', filter="Files (*.obj *.stl)", parent=self) loading_dialog = QMessageBox() loading_dialog.setText("Loading Geometry...") loading_dialog.setWindowTitle("AMLab Software") loading_dialog.setStandardButtons(QMessageBox.NoButton) loading_dialog.open() QGuiApplication.processEvents() swapyz = True for file_name in file_names[0]: if self.__slicer_widget.load_geometry(file_name, swapyz): self.geometry_list.addItem( self.__slicer_widget.geometry_name_list[ self.__slicer_widget.geometries_loaded - 1]) self.geometry_list.setCurrentIndex(self.geometry_list.count() - 1) QGuiApplication.processEvents() @Slot() def remove_geometry(self): self.__slicer_widget.remove_geometry() self.geometry_list.removeItem(self.geometry_list.currentIndex()) @Slot() def start_slicing_process(self): directory_name = QFileDialog.getExistingDirectory( caption='Select Directory', dir='../', parent=self) if len(directory_name) > 0: self.__slicer_widget.prepare_for_slicing(directory=directory_name) @Slot(float, float, float) def update_size_label(self, width, depth, height): self.physical_size_label.setText( f'Width: {width:.3f} mm, Depth: {depth:.3f} mm, Height: {height:.3f} mm' ) @Slot(float) def update_fps_label(self, fps): self.fps_label.setText(f'fps: {fps:.2f}') @Slot(float, float) def update_slices_label(self, slice, total_slices): self.slices_label.setText( f'Slicing progress: {slice:.0f}/{total_slices:.0f}') @Slot(int) def update_unit_of_measure(self, index): self.__slicer_widget.set_unit_of_measurement( self.list_of_measures_coefficients[index]) @Slot(int) def update_geometry_transformations(self, index): if index >= 0: self.__slicer_widget.current_geometry_idx = index x_rot = self.__slicer_widget.get_x_rot() y_rot = self.__slicer_widget.get_y_rot() z_rot = self.__slicer_widget.get_z_rot() x_scale = self.__slicer_widget.get_x_scale() y_scale = self.__slicer_widget.get_y_scale() z_scale = self.__slicer_widget.get_z_scale() x_pos = self.__slicer_widget.get_x_pos() z_pos = self.__slicer_widget.get_z_pos() unit_measurement = self.__slicer_widget.get_unit_of_measurement() self.__geometry_widget.blockSignals(True) self.rotate_x_slider.setValue(x_rot) self.rotate_x_spin.setValue(x_rot) self.rotate_y_slider.setValue(y_rot) self.rotate_y_spin.setValue(y_rot) self.rotate_z_slider.setValue(z_rot) self.rotate_z_spin.setValue(z_rot) self.translate_x_slider.setValue(x_pos) self.translate_x_spin.setValue(x_pos) self.translate_z_slider.setValue(z_pos) self.translate_z_spin.setValue(z_pos) self.scale_x_spin.setValue(x_scale) self.scale_y_spin.setValue(y_scale) self.scale_z_spin.setValue(z_scale) self.unit_of_measure_combo.setCurrentIndex( self.list_of_measures_coefficients.index(unit_measurement)) self.__geometry_widget.blockSignals(False)
class CleanSkinUI(QWidget): def __init__(self): QWidget.__init__(self) self.setParent(uiUtils.getTopLevelWidget(), 1) self.setAttribute(Qt.WA_DeleteOnClose) self.setWindowTitle("Clean Skin") self.setWindowIcon(QIcon(uiUtils.getIconFolder()+"arikara_CleanSkin.png")) lLayout = QFormLayout() # Max Weight self.dsb_maxWeight = QDoubleSpinBox() self.dsb_maxWeight.setRange(0.0, 1.0) self.dsb_maxWeight.setDecimals(4) self.dsb_maxWeight.setSingleStep(0.001) weight = 0.001 if cmds.optionVar(exists="ariCleanSkin_MW"): weight = cmds.optionVar(q="ariCleanSkin_MW") else: cmds.optionVar(fv=("ariCleanSkin_MW", weight)) self.dsb_maxWeight.setValue(weight) self.dsb_maxWeight.editingFinished.connect(self.dsb_maxWeightEdited) # Max Influence self.sb_maxInfluence = QSpinBox() self.sb_maxInfluence.setRange(1, 12) infl = 4 if cmds.optionVar(exists="ariCleanSkin_MI"): infl = cmds.optionVar(q="ariCleanSkin_MI") else: cmds.optionVar(iv=("ariCleanSkin_MI", infl)) self.sb_maxInfluence.setValue(infl) self.sb_maxInfluence.editingFinished.connect(self.sb_maxInfluenceEdited) self.pb_cleanSkin = QPushButton("Clean Skin") self.pb_cleanSkin.clicked.connect(self.cleanSkinCallback) lLayout.addRow("Max Weight:", self.dsb_maxWeight) lLayout.addRow("Max Influence:", self.sb_maxInfluence) lLayout.addRow(self.pb_cleanSkin) self.setLayout(lLayout) if cmds.optionVar(exists="ariCleanSkin_Geo"): geo = cmds.optionVar(q="ariCleanSkin_Geo") self.setGeometry(*geo) def cleanSkinCallback(self): cmds.undoInfo(openChunk=True, chunkName="Arikara Clean Skin") selection = cmds.ls(selection=True) maxWeight = self.dsb_maxWeight.value() maxInfluence = self.sb_maxInfluence.value() for obj in selection: try: cmds.arikaraInfluence(obj, maxInfluence=maxInfluence) except Exception as e: print e try: cmds.arikaraInfluence(obj, ru=maxWeight) except Exception as e: print e cmds.undoInfo(closeChunk=True) def updateGeometry(self): geo = self.geometry() cmds.optionVar(iv=("ariCleanSkin_Geo", geo.x())) cmds.optionVar(iva=("ariCleanSkin_Geo", geo.y())) cmds.optionVar(iva=("ariCleanSkin_Geo", geo.width())) cmds.optionVar(iva=("ariCleanSkin_Geo", geo.height())) def moveEvent(self, event): self.updateGeometry() def resizeEvent(self, event): self.updateGeometry() def dsb_maxWeightEdited(self): val = self.dsb_maxWeight.value() cmds.optionVar(fv=("ariCleanSkin_MW", val)) def sb_maxInfluenceEdited(self): val = self.sb_maxInfluence.value() cmds.optionVar(iv=("ariCleanSkin_MI", val))
class SCOUTS(QMainWindow): """Main Window Widget for SCOUTS.""" style = { 'title': 'QLabel {font-size: 18pt; font-weight: 600}', 'header': 'QLabel {font-size: 12pt; font-weight: 520}', 'label': 'QLabel {font-size: 10pt}', 'button': 'QPushButton {font-size: 10pt}', 'md button': 'QPushButton {font-size: 12pt}', 'run button': 'QPushButton {font-size: 18pt; font-weight: 600}', 'line edit': 'QLineEdit {font-size: 10pt}', 'checkbox': 'QCheckBox {font-size: 10pt}', 'radio button': 'QRadioButton {font-size: 10pt}' } def __init__(self) -> None: """SCOUTS Constructor. Defines all aspects of the GUI.""" # ### # ### Main Window setup # ### # Inherits from QMainWindow super().__init__() self.rootdir = get_project_root() self.threadpool = QThreadPool() # Sets values for QMainWindow self.setWindowTitle("SCOUTS") self.setWindowIcon( QIcon( os.path.abspath(os.path.join(self.rootdir, 'src', 'scouts.ico')))) # Creates StackedWidget as QMainWindow's central widget self.stacked_pages = QStackedWidget(self) self.setCentralWidget(self.stacked_pages) # Creates Widgets for individual "pages" and adds them to the StackedWidget self.main_page = QWidget() self.samples_page = QWidget() self.gating_page = QWidget() self.pages = (self.main_page, self.samples_page, self.gating_page) for page in self.pages: self.stacked_pages.addWidget(page) # ## Sets widget at program startup self.stacked_pages.setCurrentWidget(self.main_page) # ### # ### MAIN PAGE # ### # Main page layout self.main_layout = QVBoxLayout(self.main_page) # Title section # Title self.title = QLabel(self.main_page) self.title.setText('SCOUTS - Single Cell Outlier Selector') self.title.setStyleSheet(self.style['title']) self.title.adjustSize() self.main_layout.addWidget(self.title) # ## Input section # Input header self.input_header = QLabel(self.main_page) self.input_header.setText('Input settings') self.input_header.setStyleSheet(self.style['header']) self.main_layout.addChildWidget(self.input_header) self.input_header.adjustSize() self.main_layout.addWidget(self.input_header) # Input frame self.input_frame = QFrame(self.main_page) self.input_frame.setFrameShape(QFrame.StyledPanel) self.input_frame.setLayout(QFormLayout()) self.main_layout.addWidget(self.input_frame) # Input button self.input_button = QPushButton(self.main_page) self.input_button.setStyleSheet(self.style['button']) self.set_icon(self.input_button, 'x-office-spreadsheet') self.input_button.setObjectName('input') self.input_button.setText(' Select input file (.xlsx or .csv)') self.input_button.clicked.connect(self.get_path) # Input path box self.input_path = QLineEdit(self.main_page) self.input_path.setObjectName('input_path') self.input_path.setStyleSheet(self.style['line edit']) # Go to sample naming page self.samples_button = QPushButton(self.main_page) self.samples_button.setStyleSheet(self.style['button']) self.set_icon(self.samples_button, 'preferences-other') self.samples_button.setText(' Name samples...') self.samples_button.clicked.connect(self.goto_samples_page) # Go to gating page self.gates_button = QPushButton(self.main_page) self.gates_button.setStyleSheet(self.style['button']) self.set_icon(self.gates_button, 'preferences-other') self.gates_button.setText(' Gating && outlier options...') self.gates_button.clicked.connect(self.goto_gates_page) # Add widgets above to input frame Layout self.input_frame.layout().addRow(self.input_button, self.input_path) self.input_frame.layout().addRow(self.samples_button) self.input_frame.layout().addRow(self.gates_button) # ## Analysis section # Analysis header self.analysis_header = QLabel(self.main_page) self.analysis_header.setText('Analysis settings') self.analysis_header.setStyleSheet(self.style['header']) self.analysis_header.adjustSize() self.main_layout.addWidget(self.analysis_header) # Analysis frame self.analysis_frame = QFrame(self.main_page) self.analysis_frame.setFrameShape(QFrame.StyledPanel) self.analysis_frame.setLayout(QVBoxLayout()) self.main_layout.addWidget(self.analysis_frame) # Cutoff text self.cutoff_text = QLabel(self.main_page) self.cutoff_text.setText('Type of outlier to select:') self.cutoff_text.setToolTip( 'Choose whether to select outliers using the cutoff value from a reference\n' 'sample (OutR) or by using the cutoff value calculated for each sample\n' 'individually (OutS)') self.cutoff_text.setStyleSheet(self.style['label']) # Cutoff button group self.cutoff_group = QButtonGroup(self) # Cutoff by sample self.cutoff_sample = QRadioButton(self.main_page) self.cutoff_sample.setText('OutS') self.cutoff_sample.setObjectName('sample') self.cutoff_sample.setStyleSheet(self.style['radio button']) self.cutoff_sample.setChecked(True) self.cutoff_group.addButton(self.cutoff_sample) # Cutoff by reference self.cutoff_reference = QRadioButton(self.main_page) self.cutoff_reference.setText('OutR') self.cutoff_reference.setObjectName('ref') self.cutoff_reference.setStyleSheet(self.style['radio button']) self.cutoff_group.addButton(self.cutoff_reference) # Both cutoffs self.cutoff_both = QRadioButton(self.main_page) self.cutoff_both.setText('both') self.cutoff_both.setObjectName('sample ref') self.cutoff_both.setStyleSheet(self.style['radio button']) self.cutoff_group.addButton(self.cutoff_both) # Markers text self.markers_text = QLabel(self.main_page) self.markers_text.setStyleSheet(self.style['label']) self.markers_text.setText('Show results for:') self.markers_text.setToolTip( 'Individual markers: for each marker, select outliers\n' 'Any marker: select cells that are outliers for AT LEAST one marker' ) # Markers button group self.markers_group = QButtonGroup(self) # Single marker self.single_marker = QRadioButton(self.main_page) self.single_marker.setText('individual markers') self.single_marker.setObjectName('single') self.single_marker.setStyleSheet(self.style['radio button']) self.single_marker.setChecked(True) self.markers_group.addButton(self.single_marker) # Any marker self.any_marker = QRadioButton(self.main_page) self.any_marker.setText('any marker') self.any_marker.setObjectName('any') self.any_marker.setStyleSheet(self.style['radio button']) self.markers_group.addButton(self.any_marker) # Both methods self.both_methods = QRadioButton(self.main_page) self.both_methods.setText('both') self.both_methods.setObjectName('single any') self.both_methods.setStyleSheet(self.style['radio button']) self.markers_group.addButton(self.both_methods) # Tukey text self.tukey_text = QLabel(self.main_page) self.tukey_text.setStyleSheet(self.style['label']) # Tukey button group self.tukey_text.setText('Tukey factor:') self.tukey_group = QButtonGroup(self) # Low Tukey value self.tukey_low = QRadioButton(self.main_page) self.tukey_low.setText('1.5') self.tukey_low.setStyleSheet(self.style['radio button']) self.tukey_low.setChecked(True) self.tukey_group.addButton(self.tukey_low) # High Tukey value self.tukey_high = QRadioButton(self.main_page) self.tukey_high.setText('3.0') self.tukey_high.setStyleSheet(self.style['radio button']) self.tukey_group.addButton(self.tukey_high) # Add widgets above to analysis frame layout self.analysis_frame.layout().addWidget(self.cutoff_text) self.cutoff_buttons = QHBoxLayout() for button in self.cutoff_group.buttons(): self.cutoff_buttons.addWidget(button) self.analysis_frame.layout().addLayout(self.cutoff_buttons) self.analysis_frame.layout().addWidget(self.markers_text) self.markers_buttons = QHBoxLayout() for button in self.markers_group.buttons(): self.markers_buttons.addWidget(button) self.analysis_frame.layout().addLayout(self.markers_buttons) self.analysis_frame.layout().addWidget(self.tukey_text) self.tukey_buttons = QHBoxLayout() for button in self.tukey_group.buttons(): self.tukey_buttons.addWidget(button) self.tukey_buttons.addWidget(QLabel()) # aligns row with 2 buttons self.analysis_frame.layout().addLayout(self.tukey_buttons) # ## Output section # Output header self.output_header = QLabel(self.main_page) self.output_header.setText('Output settings') self.output_header.setStyleSheet(self.style['header']) self.output_header.adjustSize() self.main_layout.addWidget(self.output_header) # Output frame self.output_frame = QFrame(self.main_page) self.output_frame.setFrameShape(QFrame.StyledPanel) self.output_frame.setLayout(QFormLayout()) self.main_layout.addWidget(self.output_frame) # Output button self.output_button = QPushButton(self.main_page) self.output_button.setStyleSheet(self.style['button']) self.set_icon(self.output_button, 'folder') self.output_button.setObjectName('output') self.output_button.setText(' Select output folder') self.output_button.clicked.connect(self.get_path) # Output path box self.output_path = QLineEdit(self.main_page) self.output_path.setStyleSheet(self.style['line edit']) # Generate CSV checkbox self.output_csv = QCheckBox(self.main_page) self.output_csv.setText('Export multiple text files (.csv)') self.output_csv.setStyleSheet(self.style['checkbox']) self.output_csv.setChecked(True) # Generate XLSX checkbox self.output_excel = QCheckBox(self.main_page) self.output_excel.setText('Export multiple Excel spreadsheets (.xlsx)') self.output_excel.setStyleSheet(self.style['checkbox']) self.output_excel.clicked.connect(self.enable_single_excel) # Generate single, large XLSX checkbox self.single_excel = QCheckBox(self.main_page) self.single_excel.setText( 'Also save one multi-sheet Excel spreadsheet') self.single_excel.setToolTip( 'After generating all Excel spreadsheets, SCOUTS combines them into ' 'a single\nExcel spreadsheet where each sheet corresponds to an output' 'file from SCOUTS') self.single_excel.setStyleSheet(self.style['checkbox']) self.single_excel.setEnabled(False) self.single_excel.clicked.connect(self.memory_warning) # Add widgets above to output frame layout self.output_frame.layout().addRow(self.output_button, self.output_path) self.output_frame.layout().addRow(self.output_csv) self.output_frame.layout().addRow(self.output_excel) self.output_frame.layout().addRow(self.single_excel) # ## Run & help-quit section # Run button (stand-alone) self.run_button = QPushButton(self.main_page) self.set_icon(self.run_button, 'system-run') self.run_button.setText(' Run!') self.run_button.setStyleSheet(self.style['run button']) self.main_layout.addWidget(self.run_button) self.run_button.clicked.connect(self.run) # Help-quit frame (invisible) self.helpquit_frame = QFrame(self.main_page) self.helpquit_frame.setLayout(QHBoxLayout()) self.helpquit_frame.layout().setMargin(0) self.main_layout.addWidget(self.helpquit_frame) # Help button self.help_button = QPushButton(self.main_page) self.set_icon(self.help_button, 'help-about') self.help_button.setText(' Help') self.help_button.setStyleSheet(self.style['md button']) self.help_button.clicked.connect(self.get_help) # Quit button self.quit_button = QPushButton(self.main_page) self.set_icon(self.quit_button, 'process-stop') self.quit_button.setText(' Quit') self.quit_button.setStyleSheet(self.style['md button']) self.quit_button.clicked.connect(self.close) # Add widgets above to help-quit layout self.helpquit_frame.layout().addWidget(self.help_button) self.helpquit_frame.layout().addWidget(self.quit_button) # ### # ### SAMPLES PAGE # ### # Samples page layout self.samples_layout = QVBoxLayout(self.samples_page) # ## Title section # Title self.samples_title = QLabel(self.samples_page) self.samples_title.setText('Name your samples') self.samples_title.setStyleSheet(self.style['title']) self.samples_title.adjustSize() self.samples_layout.addWidget(self.samples_title) # Subtitle self.samples_subtitle = QLabel(self.samples_page) string = ( 'Please name the samples to be analysed by SCOUTS.\n\nSCOUTS searches the first ' 'column of your data\nand locates the exact string as part of the sample name.' ) self.samples_subtitle.setText(string) self.samples_subtitle.setStyleSheet(self.style['label']) self.samples_subtitle.adjustSize() self.samples_layout.addWidget(self.samples_subtitle) # ## Sample addition section # Sample addition frame self.samples_frame = QFrame(self.samples_page) self.samples_frame.setFrameShape(QFrame.StyledPanel) self.samples_frame.setLayout(QGridLayout()) self.samples_layout.addWidget(self.samples_frame) # Sample name box self.sample_name = QLineEdit(self.samples_page) self.sample_name.setStyleSheet(self.style['line edit']) self.sample_name.setPlaceholderText('Sample name ...') # Reference check self.is_reference = QCheckBox(self.samples_page) self.is_reference.setText('Reference?') self.is_reference.setStyleSheet(self.style['checkbox']) # Add sample to table self.add_sample_button = QPushButton(self.samples_page) QShortcut(QKeySequence("Return"), self.add_sample_button, self.write_to_sample_table) self.set_icon(self.add_sample_button, 'list-add') self.add_sample_button.setText(' Add sample (Enter)') self.add_sample_button.setStyleSheet(self.style['button']) self.add_sample_button.clicked.connect(self.write_to_sample_table) # Remove sample from table self.remove_sample_button = QPushButton(self.samples_page) QShortcut(QKeySequence("Delete"), self.remove_sample_button, self.remove_from_sample_table) self.set_icon(self.remove_sample_button, 'list-remove') self.remove_sample_button.setText(' Remove sample (Del)') self.remove_sample_button.setStyleSheet(self.style['button']) self.remove_sample_button.clicked.connect( self.remove_from_sample_table) # Add widgets above to sample addition layout self.samples_frame.layout().addWidget(self.sample_name, 0, 0) self.samples_frame.layout().addWidget(self.is_reference, 1, 0) self.samples_frame.layout().addWidget(self.add_sample_button, 0, 1) self.samples_frame.layout().addWidget(self.remove_sample_button, 1, 1) # ## Sample table self.sample_table = QTableWidget(self.samples_page) self.sample_table.setColumnCount(2) self.sample_table.setHorizontalHeaderItem(0, QTableWidgetItem('Sample')) self.sample_table.setHorizontalHeaderItem( 1, QTableWidgetItem('Reference?')) self.sample_table.horizontalHeader().setSectionResizeMode( 0, QHeaderView.Stretch) self.sample_table.horizontalHeader().setSectionResizeMode( 1, QHeaderView.ResizeToContents) self.samples_layout.addWidget(self.sample_table) # ## Save & clear buttons # Save & clear frame (invisible) self.saveclear_frame = QFrame(self.samples_page) self.saveclear_frame.setLayout(QHBoxLayout()) self.saveclear_frame.layout().setMargin(0) self.samples_layout.addWidget(self.saveclear_frame) # Clear samples button self.clear_samples = QPushButton(self.samples_page) self.set_icon(self.clear_samples, 'edit-delete') self.clear_samples.setText(' Clear table') self.clear_samples.setStyleSheet(self.style['md button']) self.clear_samples.clicked.connect(self.prompt_clear_data) # Save samples button self.save_samples = QPushButton(self.samples_page) self.set_icon(self.save_samples, 'document-save') self.save_samples.setText(' Save samples') self.save_samples.setStyleSheet(self.style['md button']) self.save_samples.clicked.connect(self.goto_main_page) # Add widgets above to save & clear layout self.saveclear_frame.layout().addWidget(self.clear_samples) self.saveclear_frame.layout().addWidget(self.save_samples) # ### # ### GATING PAGE # ### # Gating page layout self.gating_layout = QVBoxLayout(self.gating_page) # ## Title section # Title self.gates_title = QLabel(self.gating_page) self.gates_title.setText('Gating & outlier options') self.gates_title.setStyleSheet(self.style['title']) self.gates_title.adjustSize() self.gating_layout.addWidget(self.gates_title) # ## Gating options section # Gating header self.gate_header = QLabel(self.gating_page) self.gate_header.setText('Gating') self.gate_header.setStyleSheet(self.style['header']) self.gate_header.adjustSize() self.gating_layout.addWidget(self.gate_header) # Gating frame self.gate_frame = QFrame(self.gating_page) self.gate_frame.setFrameShape(QFrame.StyledPanel) self.gate_frame.setLayout(QFormLayout()) self.gating_layout.addWidget(self.gate_frame) # Gating button group self.gating_group = QButtonGroup(self) # Do not gate samples self.no_gates = QRadioButton(self.gating_page) self.no_gates.setObjectName('no_gate') self.no_gates.setText("Don't gate samples") self.no_gates.setStyleSheet(self.style['radio button']) self.no_gates.setChecked(True) self.gating_group.addButton(self.no_gates) self.no_gates.clicked.connect(self.activate_gate) # CyToF gating self.cytof_gates = QRadioButton(self.gating_page) self.cytof_gates.setObjectName('cytof') self.cytof_gates.setText('Mass Cytometry gating') self.cytof_gates.setStyleSheet(self.style['radio button']) self.cytof_gates.setToolTip( 'Exclude cells for which the average expression of all\n' 'markers is below the selected value') self.gating_group.addButton(self.cytof_gates) self.cytof_gates.clicked.connect(self.activate_gate) # CyToF gating spinbox self.cytof_gates_value = QDoubleSpinBox(self.gating_page) self.cytof_gates_value.setMinimum(0) self.cytof_gates_value.setMaximum(1) self.cytof_gates_value.setValue(0.1) self.cytof_gates_value.setSingleStep(0.05) self.cytof_gates_value.setEnabled(False) # scRNA-Seq gating self.rnaseq_gates = QRadioButton(self.gating_page) self.rnaseq_gates.setText('scRNA-Seq gating') self.rnaseq_gates.setStyleSheet(self.style['radio button']) self.rnaseq_gates.setToolTip( 'When calculating cutoff, ignore reads below the selected value') self.rnaseq_gates.setObjectName('rnaseq') self.gating_group.addButton(self.rnaseq_gates) self.rnaseq_gates.clicked.connect(self.activate_gate) # scRNA-Seq gating spinbox self.rnaseq_gates_value = QDoubleSpinBox(self.gating_page) self.rnaseq_gates_value.setMinimum(0) self.rnaseq_gates_value.setMaximum(10) self.rnaseq_gates_value.setValue(0) self.rnaseq_gates_value.setSingleStep(1) self.rnaseq_gates_value.setEnabled(False) # export gated population checkbox self.export_gated = QCheckBox(self.gating_page) self.export_gated.setText('Export gated cells as an output file') self.export_gated.setStyleSheet(self.style['checkbox']) self.export_gated.setEnabled(False) # Add widgets above to Gate frame layout self.gate_frame.layout().addRow(self.no_gates, QLabel()) self.gate_frame.layout().addRow(self.cytof_gates, self.cytof_gates_value) self.gate_frame.layout().addRow(self.rnaseq_gates, self.rnaseq_gates_value) self.gate_frame.layout().addRow(self.export_gated, QLabel()) # ## Outlier options section # Outlier header self.outlier_header = QLabel(self.gating_page) self.outlier_header.setText('Outliers') self.outlier_header.setStyleSheet(self.style['header']) self.outlier_header.adjustSize() self.gating_layout.addWidget(self.outlier_header) # Outlier frame self.outlier_frame = QFrame(self.gating_page) self.outlier_frame.setFrameShape(QFrame.StyledPanel) self.outlier_frame.setLayout(QVBoxLayout()) self.gating_layout.addWidget(self.outlier_frame) # Top outliers information self.top_outliers = QLabel(self.gating_page) self.top_outliers.setStyleSheet(self.style['label']) self.top_outliers.setText( 'By default, SCOUTS selects the top outliers from the population') self.top_outliers.setStyleSheet(self.style['label']) # Bottom outliers data self.bottom_outliers = QCheckBox(self.gating_page) self.bottom_outliers.setText('Include results for low outliers') self.bottom_outliers.setStyleSheet(self.style['checkbox']) # Non-outliers data self.not_outliers = QCheckBox(self.gating_page) self.not_outliers.setText('Include results for non-outliers') self.not_outliers.setStyleSheet(self.style['checkbox']) # Add widgets above to Gate frame layout self.outlier_frame.layout().addWidget(self.top_outliers) self.outlier_frame.layout().addWidget(self.bottom_outliers) self.outlier_frame.layout().addWidget(self.not_outliers) # ## Save/back button self.save_gates = QPushButton(self.gating_page) self.set_icon(self.save_gates, 'go-next') self.save_gates.setText(' Back to main menu') self.save_gates.setStyleSheet(self.style['md button']) self.gating_layout.addWidget(self.save_gates) self.save_gates.clicked.connect(self.goto_main_page) # ## Add empty label to take vertical space self.empty_label = QLabel(self.gating_page) self.empty_label.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self.gating_layout.addWidget(self.empty_label) # ### # ### ICON SETTING # ### def set_icon(self, widget: QWidget, icon: str) -> None: """Associates an icon to a widget.""" i = QIcon() i.addPixmap( QPixmap( os.path.abspath( os.path.join(self.rootdir, 'src', 'default_icons', f'{icon}.svg')))) widget.setIcon(QIcon.fromTheme(icon, i)) # ### # ### STACKED WIDGET PAGE SWITCHING # ### def goto_main_page(self) -> None: """Switches stacked widget pages to the main page.""" self.stacked_pages.setCurrentWidget(self.main_page) def goto_samples_page(self) -> None: """Switches stacked widget pages to the samples table page.""" self.stacked_pages.setCurrentWidget(self.samples_page) def goto_gates_page(self) -> None: """Switches stacked widget pages to the gating & other options page.""" self.stacked_pages.setCurrentWidget(self.gating_page) # ### # ### MAIN PAGE GUI LOGIC # ### def get_path(self) -> None: """Opens a dialog box and sets the chosen file/folder path, depending on the caller widget.""" options = QFileDialog.Options() options |= QFileDialog.DontUseNativeDialog sender_name = self.sender().objectName() if sender_name == 'input': query, _ = QFileDialog.getOpenFileName(self, "Select file", "", "All Files (*)", options=options) elif sender_name == 'output': query = QFileDialog.getExistingDirectory(self, "Select Directory", options=options) else: return if query: getattr(self, f'{sender_name}_path').setText(query) def enable_single_excel(self) -> None: """Enables checkbox for generating a single Excel output.""" if self.output_excel.isChecked(): self.single_excel.setEnabled(True) else: self.single_excel.setEnabled(False) self.single_excel.setChecked(False) # ### # ### SAMPLE NAME/SAMPLE TABLE GUI LOGIC # ### def write_to_sample_table(self) -> None: """Writes data to sample table.""" table = self.sample_table ref = 'no' sample = self.sample_name.text() if sample: for cell in range(table.rowCount()): item = table.item(cell, 0) if item.text() == sample: self.same_sample() return if self.is_reference.isChecked(): for cell in range(table.rowCount()): item = table.item(cell, 1) if item.text() == 'yes': self.more_than_one_reference() return ref = 'yes' sample = QTableWidgetItem(sample) is_reference = QTableWidgetItem(ref) is_reference.setFlags(Qt.ItemIsEnabled) row_position = table.rowCount() table.insertRow(row_position) table.setItem(row_position, 0, sample) table.setItem(row_position, 1, is_reference) self.is_reference.setChecked(False) self.sample_name.setText('') def remove_from_sample_table(self) -> None: """Removes data from sample table.""" table = self.sample_table rows = set(index.row() for index in table.selectedIndexes()) for index in sorted(rows, reverse=True): self.sample_table.removeRow(index) def prompt_clear_data(self) -> None: """Prompts option to clear all data in the sample table.""" if self.confirm_clear_data(): table = self.sample_table while table.rowCount(): self.sample_table.removeRow(0) # ### # ### GATING GUI LOGIC # ### def activate_gate(self) -> None: """Activates/deactivates buttons related to gating.""" if self.sender().objectName() == 'no_gate': self.cytof_gates_value.setEnabled(False) self.rnaseq_gates_value.setEnabled(False) self.export_gated.setEnabled(False) self.export_gated.setChecked(False) elif self.sender().objectName() == 'cytof': self.cytof_gates_value.setEnabled(True) self.rnaseq_gates_value.setEnabled(False) self.export_gated.setEnabled(True) elif self.sender().objectName() == 'rnaseq': self.cytof_gates_value.setEnabled(False) self.rnaseq_gates_value.setEnabled(True) self.export_gated.setEnabled(True) # ### # ### CONNECT SCOUTS TO ANALYTICAL MODULES # ### def run(self) -> None: """Runs SCOUTS as a Worker, based on user input in the GUI.""" try: data = self.parse_input() except Exception as error: trace = traceback.format_exc() self.propagate_error((error, trace)) else: data['widget'] = self worker = Worker(func=start_scouts, **data) worker.signals.started.connect(self.analysis_has_started) worker.signals.finished.connect(self.analysis_has_finished) worker.signals.success.connect(self.success_message) worker.signals.error.connect(self.propagate_error) self.threadpool.start(worker) def parse_input(self) -> Dict: """Returns user input on the GUI as a dictionary.""" # Input and output input_dict = { 'input_file': str(self.input_path.text()), 'output_folder': str(self.output_path.text()) } if not input_dict['input_file'] or not input_dict['output_folder']: raise NoIOPathError # Set cutoff by reference or by sample rule input_dict['cutoff_rule'] = self.cutoff_group.checkedButton( ).objectName() # 'sample', 'ref', 'sample ref' # Outliers for each individual marker or any marker in row input_dict['marker_rule'] = self.markers_group.checkedButton( ).objectName() # 'single', 'any', 'single any' # Tukey factor used for calculating cutoff input_dict['tukey_factor'] = float( self.tukey_group.checkedButton().text()) # '1.5', '3.0' # Output settings input_dict['export_csv'] = True if self.output_csv.isChecked( ) else False input_dict['export_excel'] = True if self.output_excel.isChecked( ) else False input_dict['single_excel'] = True if self.single_excel.isChecked( ) else False # Retrieve samples from sample table input_dict['sample_list'] = [] for tuples in self.yield_samples_from_table(): input_dict['sample_list'].append(tuples) if not input_dict['sample_list']: raise NoSampleError # Set gate cutoff (if any) input_dict['gating'] = self.gating_group.checkedButton().objectName( ) # 'no_gate', 'cytof', 'rnaseq' input_dict['gate_cutoff_value'] = None if input_dict['gating'] != 'no_gate': input_dict['gate_cutoff_value'] = getattr( self, f'{input_dict["gating"]}_gates_value').value() input_dict['export_gated'] = True if self.export_gated.isChecked( ) else False # Generate results for non-outliers input_dict['non_outliers'] = False if self.not_outliers.isChecked(): input_dict['non_outliers'] = True # Generate results for bottom outliers input_dict['bottom_outliers'] = False if self.bottom_outliers.isChecked(): input_dict['bottom_outliers'] = True # return dictionary with all gathered inputs return input_dict def yield_samples_from_table( self) -> Generator[Tuple[str, str], None, None]: """Yields sample names from the sample table.""" table = self.sample_table for cell in range(table.rowCount()): sample_name = table.item(cell, 0).text() sample_type = table.item(cell, 1).text() yield sample_name, sample_type # ### # ### MESSAGE BOXES # ### def analysis_has_started(self) -> None: """Disables run button while SCOUTS analysis is underway.""" self.run_button.setText(' Working...') self.run_button.setEnabled(False) def analysis_has_finished(self) -> None: """Enables run button after SCOUTS analysis has finished.""" self.run_button.setEnabled(True) self.run_button.setText(' Run!') def success_message(self) -> None: """Info message box used when SCOUTS finished without errors.""" title = "Analysis finished!" mes = "Your analysis has finished. No errors were reported." if self.stacked_pages.isEnabled() is True: QMessageBox.information(self, title, mes) def memory_warning(self) -> None: """Warning message box used when user wants to generate a single excel file.""" if self.sender().isChecked(): title = 'Memory warning!' mes = ( "Depending on your dataset, this option can consume a LOT of memory and take" " a long time to process. Please make sure that your computer can handle it!" ) QMessageBox.information(self, title, mes) def same_sample(self) -> None: """Error message box used when the user tries to input the same sample twice in the sample table.""" title = 'Error: sample name already in table' mes = ( "Sorry, you can't do this because this sample name is already in the table. " "Please select a different name.") QMessageBox.critical(self, title, mes) def more_than_one_reference(self) -> None: """Error message box used when the user tries to input two reference samples in the sample table.""" title = "Error: more than one reference selected" mes = ( "Sorry, you can't do this because there is already a reference column in the table. " "Please remove it before adding a reference.") QMessageBox.critical(self, title, mes) def confirm_clear_data(self) -> bool: """Question message box used to confirm user action of clearing sample table.""" title = 'Confirm Action' mes = "Table will be cleared. Are you sure?" reply = QMessageBox.question(self, title, mes, QMessageBox.Yes | QMessageBox.No, QMessageBox.No) if reply == QMessageBox.Yes: return True return False # ### # ### EXCEPTIONS & ERRORS # ### def propagate_error(self, error: Tuple[Exception, str]) -> None: """Calls the appropriate error message box based on type of Exception raised.""" if isinstance(error[0], NoIOPathError): self.no_io_path_error_message() elif isinstance(error[0], NoReferenceError): self.no_reference_error_message() elif isinstance(error[0], NoSampleError): self.no_sample_error_message() elif isinstance(error[0], PandasInputError): self.pandas_input_error_message() elif isinstance(error[0], SampleNamingError): self.sample_naming_error_message() else: self.generic_error_message(error) def no_io_path_error_message(self) -> None: """Message displayed when the user did not include an input file path, or an output folder path.""" title = 'Error: no file/folder' message = ("Sorry, no input file and/or output folder was provided. " "Please add the path to the necessary file/folder.") QMessageBox.critical(self, title, message) def no_reference_error_message(self) -> None: """Message displayed when the user wants to analyse cutoff based on a reference, but did not specify what sample corresponds to the reference.""" title = "Error: No reference selected" message = ( "Sorry, no reference sample was found on the sample list, but analysis was set to " "reference. Please add a reference sample, or change the rule for cutoff calculation." ) QMessageBox.critical(self, title, message) def no_sample_error_message(self) -> None: """Message displayed when the user did not add any samples to the sample table.""" title = "Error: No samples selected" message = ( "Sorry, the analysis cannot be performed because no sample names were input. " "Please add your sample names.") QMessageBox.critical(self, title, message) def pandas_input_error_message(self) -> None: """Message displayed when the input file cannot be read (likely because it is not a Excel or csv file).""" title = 'Error: unexpected input file' message = ( "Sorry, the input file could not be read. Please make sure that " "the data is save in a valid format (supported formats are: " ".csv, .xlsx).") QMessageBox.critical(self, title, message) def sample_naming_error_message(self) -> None: """Message displayed when none of the sample names passed by the user are found in the input DataFrame.""" title = 'Error: sample names not in input file' message = ( "Sorry, your sample names were not found in the input file. Please " "make sure that the names were typed correctly (case-sensitive).") QMessageBox.critical(self, title, message) def generic_error_message(self, error: Tuple[Exception, str]) -> None: """Error message box used to display any error message (including traceback) for any uncaught errors.""" title = 'An error occurred!' name, trace = error QMessageBox.critical(self, title, f"{str(name)}\n\nfull traceback:\n{trace}") def not_implemented_error_message(self) -> None: """Error message box used when the user accesses a functionality that hasn't been implemented yet.""" title = "Not yet implemented" mes = "Sorry, this functionality has not been implemented yet." QMessageBox.critical(self, title, mes) # ### # ### HELP & QUIT # ### @staticmethod def get_help() -> None: """Opens SCOUTS documentation on the browser. Called when the user clicks the "help" button""" webbrowser.open('https://scouts.readthedocs.io/en/master/') def closeEvent(self, event: QEvent) -> None: """Defines the message box for when the user wants to quit SCOUTS.""" title = 'Quit SCOUTS' mes = "Are you sure you want to quit?" reply = QMessageBox.question(self, title, mes, QMessageBox.Yes | QMessageBox.No, QMessageBox.No) if reply == QMessageBox.Yes: self.stacked_pages.setEnabled(False) message = self.quit_message() waiter = Waiter(waiter_func=self.threadpool.activeThreadCount) waiter.signals.started.connect(message.show) waiter.signals.finished.connect(message.destroy) waiter.signals.finished.connect(sys.exit) self.threadpool.start(waiter) event.ignore() def quit_message(self) -> QDialog: """Displays a window while SCOUTS is exiting""" message = QDialog(self) message.setWindowTitle('Exiting SCOUTS') message.resize(300, 50) label = QLabel('SCOUTS is exiting, please wait...', message) label.setStyleSheet(self.style['label']) label.adjustSize() label.setAlignment(Qt.AlignCenter) label.move(int((message.width() - label.width()) / 2), int((message.height() - label.height()) / 2)) return message
class NGL_HKLViewer(QWidget): def __init__(self, parent=None): super(NGL_HKLViewer, self).__init__(parent) self.verbose = 0 self.UseOSbrowser = False self.jscriptfname = "" self.devmode = False for e in sys.argv: if "verbose" in e: self.verbose = e.split("verbose=")[1] if "UseOSbrowser" in e: self.UseOSbrowser = e.split("UseOSbrowser=")[1] if "jscriptfname" in e: self.jscriptfname = e.split("jscriptfname=")[1] if "devmode" in e: self.devmode = True self.zmq_context = None self.bufsize = 20000 self.originalPalette = QApplication.palette() self.openFileNameButton = QPushButton("Load reflection file") self.openFileNameButton.setDefault(True) self.openFileNameButton.clicked.connect(self.OpenReflectionsFile) self.debugbutton = QPushButton("Debug") self.debugbutton.clicked.connect(self.DebugInteractively) self.settingsbtn = QPushButton("Settings") self.settingsbtn.clicked.connect(self.SettingsDialog) self.mousemoveslider = QSlider(Qt.Horizontal) self.mousemoveslider.setMinimum(0) self.mousemoveslider.setMaximum(300) self.mousemoveslider.setValue(0) self.mousemoveslider.sliderReleased.connect( self.onFinalMouseSensitivity) self.mousemoveslider.valueChanged.connect(self.onMouseSensitivity) self.mousesensitxtbox = QLineEdit('') self.mousesensitxtbox.setReadOnly(True) self.fontspinBox = QDoubleSpinBox() self.fontspinBox.setSingleStep(1) self.fontspinBox.setRange(4, 50) self.font = QFont() self.font.setFamily(self.font.defaultFamily()) self.fontspinBox.setValue(self.font.pointSize()) #self.fontspinBox.setValue(self.font.pixelSize()) self.fontspinBox.valueChanged.connect(self.onFontsizeChanged) self.Fontsize_labeltxt = QLabel() self.Fontsize_labeltxt.setText("Font size:") self.cameraPerspectCheckBox = QCheckBox() self.cameraPerspectCheckBox.setText("Perspective camera") self.cameraPerspectCheckBox.clicked.connect(self.onCameraPerspect) self.cameraPerspectCheckBox.setCheckState(Qt.Unchecked) self.settingsform = SettingsForm(self) self.MillerComboBox = QComboBox() self.MillerComboBox.activated.connect(self.onMillerComboSelchange) #self.MillerComboBox.setSizeAdjustPolicy(QComboBox.AdjustToContents) self.MillerLabel = QLabel() self.MillerLabel.setText("Selected HKL Scene") self.HKLnameedit = QLineEdit('') self.HKLnameedit.setReadOnly(True) self.textInfo = QTextEdit() self.textInfo.setLineWrapMode(QTextEdit.NoWrap) self.textInfo.setReadOnly(True) labels = [ "Label", "Type", "no. of HKLs", "Span of HKLs", "Min Max data", "Min Max sigmas", "d_min, d_max", "Symmetry unique", "Anomalous" ] self.millertable = QTableWidget(0, len(labels)) self.millertable.setHorizontalHeaderLabels(labels) self.millertable.horizontalHeader().setDefaultAlignment(Qt.AlignLeft) # don't allow editing this table self.millertable.setEditTriggers(QTableWidget.NoEditTriggers) self.createExpansionBox() self.createFileInfoBox() self.CreateSliceTabs() self.createRadiiScaleGroupBox() self.createBinsBox() self.CreateFunctionTabs() mainLayout = QGridLayout() mainLayout.addWidget(self.FileInfoBox, 0, 0) mainLayout.addWidget(self.MillerLabel, 1, 0) mainLayout.addWidget(self.MillerComboBox, 2, 0) mainLayout.addWidget(self.functionTabWidget, 3, 0) mainLayout.addWidget(self.settingsbtn, 4, 0, 1, 1) #import code, traceback; code.interact(local=locals(), banner="".join( traceback.format_stack(limit=10) ) ) if self.UseOSbrowser == False: self.BrowserBox = QWebEngineView() mainLayout.addWidget(self.BrowserBox, 0, 1, 5, 3) self.BrowserBox.setUrl("https://cctbx.github.io/") #self.BrowserBox.setUrl("https://webglreport.com/") #self.BrowserBox.loadFinished.connect(self.onLoadFinished) mainLayout.setColumnStretch(2, 1) mainLayout.setRowStretch(0, 1) mainLayout.setRowStretch(1, 0) mainLayout.setRowStretch(2, 1) mainLayout.setRowStretch(3, 1) mainLayout.setColumnStretch(4, 0) self.setLayout(mainLayout) self.setWindowTitle("HKL-Viewer") self.cctbxproc = None self.LaunchCCTBXPython() self.out = None self.err = None self.comboviewwidth = 0 self.hklscenes_arrays = [] self.array_infotpls = [] self.matching_arrays = [] self.bin_infotpls = None self.bin_opacities = None self.html_url = "" self.spacegroups = [] self.info = [] self.infostr = "" self.fileisvalid = False self.NewFileLoaded = False self.NewHKLscenes = False self.updatingNbins = False self.binstableitemchanges = False self.show() def SettingsDialog(self): self.settingsform.show() def update(self): if self.cctbxproc: if self.cctbxproc.stdout: print(self.cctbxproc.stdout.read().decode("utf-8")) if self.cctbxproc.stderr: print(self.cctbxproc.stderr.read().decode("utf-8")) if self.out: print(self.out.decode("utf-8")) if self.err: print(self.err.decode("utf-8")) if self.zmq_context: try: msg = self.socket.recv( flags=zmq.NOBLOCK ) #To empty the socket from previous messages msgstr = msg.decode() self.infodict = eval(msgstr) #print("received from cctbx: " + str(self.infodict)) if self.infodict: if self.infodict.get("hklscenes_arrays"): self.hklscenes_arrays = self.infodict.get( "hklscenes_arrays", []) if self.infodict.get("array_infotpls"): self.array_infotpls = self.infodict.get( "array_infotpls", []) if self.infodict.get("bin_data_label"): self.BinDataComboBox.setCurrentText( self.infodict["bin_data_label"]) if self.infodict.get("bin_infotpls"): self.bin_infotpls = self.infodict["bin_infotpls"] self.nbins = len(self.bin_infotpls) self.updatingNbins = True self.Nbins_spinBox.setValue(self.nbins) self.updatingNbins = False self.binstable.clearContents() self.binstable.setRowCount(self.nbins) for row, bin_infotpl in enumerate(self.bin_infotpls): for col, elm in enumerate(bin_infotpl): # only allow changing the last column with opacity values if col != 3: item = QTableWidgetItem(str(elm)) else: item = QTableWidgetItem() item.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled) item.setCheckState(Qt.Checked) item.setFlags(item.flags() ^ Qt.ItemIsEditable) self.binstable.setItem(row, col, item) if self.bin_opacities: self.update_table_opacities() if self.infodict.get("bin_opacities"): self.bin_opacities = self.infodict["bin_opacities"] if self.binstable.rowCount() > 0: self.update_table_opacities() if self.infodict.get("html_url"): self.html_url = self.infodict["html_url"] if self.UseOSbrowser == False: self.BrowserBox.setUrl(self.html_url) # workaround for background colour bug in chromium # https://bugreports.qt.io/browse/QTBUG-41960 self.BrowserBox.page().setBackgroundColor( QColor(100, 100, 100, 1.0)) if self.infodict.get("spacegroups"): self.spacegroups = self.infodict.get("spacegroups", []) self.SpaceGroupComboBox.clear() self.SpaceGroupComboBox.addItems(self.spacegroups) if self.infodict.get("merge_data"): self.mergedata = self.infodict["merge_data"] currentinfostr = "" if self.infodict.get("info"): currentinfostr = self.infodict.get("info", []) if self.infodict.get("NewFileLoaded"): self.NewFileLoaded = self.infodict.get( "NewFileLoaded", False) if self.infodict.get("NewHKLscenes"): self.NewHKLscenes = self.infodict.get( "NewHKLscenes", False) self.fileisvalid = True #print("ngl_hkl_infodict: " + str(ngl_hkl_infodict)) if currentinfostr: #print(currentinfostr) self.infostr += currentinfostr + "\n" # display no more than self.bufsize bytes of text self.infostr = self.infostr[-self.bufsize:] self.textInfo.setPlainText(self.infostr) self.textInfo.verticalScrollBar().setValue( self.textInfo.verticalScrollBar().maximum()) if self.NewFileLoaded and self.NewHKLscenes: #if self.mergedata == True : val = Qt.CheckState.Checked #if self.mergedata == None : val = Qt.CheckState.PartiallyChecked #if self.mergedata == False : val = Qt.CheckState.Unchecked #self.mergecheckbox.setCheckState(val ) #print("got hklscenes: " + str(self.hklscenes_arrays)) self.MillerComboBox.clear() self.MillerComboBox.addItems( [e[3] for e in self.hklscenes_arrays]) self.MillerComboBox.setCurrentIndex( -1) # unselect the first item in the list self.comboviewwidth = 0 for e in self.hklscenes_arrays: self.comboviewwidth = max( self.comboviewwidth, self.MillerComboBox.fontMetrics().width(e[3])) self.MillerComboBox.view().setMinimumWidth( self.comboviewwidth) self.millertable.clearContents() self.millertable.setRowCount(len( self.hklscenes_arrays)) for n, millarr in enumerate(self.array_infotpls): for m, elm in enumerate(millarr): self.millertable.setItem( n, m, QTableWidgetItem(str(elm))) self.functionTabWidget.setDisabled(True) self.NewFileLoaded = False if self.NewHKLscenes: self.BinDataComboBox.clear() self.BinDataComboBox.addItems( ["Resolution"] + [e[3] for e in self.hklscenes_arrays]) self.BinDataComboBox.view().setMinimumWidth( self.comboviewwidth) #self.BinDataComboBox.setCurrentIndex(-1) # unselect the first item in the list self.NewHKLscenes = False except Exception as e: errmsg = str(e) if "Resource temporarily unavailable" not in errmsg: print(errmsg + traceback.format_exc(limit=10)) pass def onFinalMouseSensitivity(self): val = self.mousemoveslider.value() / 100.0 self.NGL_HKL_command( 'NGL_HKLviewer.viewer.NGL.mouse_sensitivity = %f' % val) def onMouseSensitivity(self): val = self.mousemoveslider.value() / 100.0 self.mousesensitxtbox.setText("%2.2f" % val) def onFontsizeChanged(self, val): font = app.font() font.setPointSize(val) app.setFont(font) self.settingsform.setFixedSize(self.settingsform.sizeHint()) def onCameraPerspect(self, val): if self.cameraPerspectCheckBox.isChecked(): self.NGL_HKL_command("NGL_HKLviewer.camera_type = perspective") else: self.NGL_HKL_command("NGL_HKLviewer.camera_type = orthographic") def MergeData(self): if self.mergecheckbox.checkState() == Qt.CheckState.Checked: self.NGL_HKL_command('NGL_HKLviewer.mergedata = True') if self.mergecheckbox.checkState() == Qt.CheckState.PartiallyChecked: self.NGL_HKL_command('NGL_HKLviewer.mergedata = None') if self.mergecheckbox.checkState() == Qt.CheckState.Unchecked: self.NGL_HKL_command('NGL_HKLviewer.mergedata = False') def ExpandToP1(self): if self.expandP1checkbox.isChecked(): self.NGL_HKL_command('NGL_HKLviewer.viewer.expand_to_p1 = True') else: self.NGL_HKL_command('NGL_HKLviewer.viewer.expand_to_p1 = False') def ExpandAnomalous(self): if self.expandAnomalouscheckbox.isChecked(): self.NGL_HKL_command( 'NGL_HKLviewer.viewer.expand_anomalous = True') else: self.NGL_HKL_command( 'NGL_HKLviewer.viewer.expand_anomalous = False') def showSysAbsent(self): if self.sysabsentcheckbox.isChecked(): self.NGL_HKL_command( 'NGL_HKLviewer.viewer.show_systematic_absences = True') else: self.NGL_HKL_command( 'NGL_HKLviewer.viewer.show_systematic_absences = False') def showMissing(self): if self.missingcheckbox.isChecked(): self.NGL_HKL_command('NGL_HKLviewer.viewer.show_missing = True') else: self.NGL_HKL_command('NGL_HKLviewer.viewer.show_missing = False') def showOnlyMissing(self): if self.onlymissingcheckbox.isChecked(): self.NGL_HKL_command( 'NGL_HKLviewer.viewer.show_only_missing = True') else: self.NGL_HKL_command( 'NGL_HKLviewer.viewer.show_only_missing = False') def showSlice(self): if self.showslicecheckbox.isChecked(): self.NGL_HKL_command('NGL_HKLviewer.viewer.slice_mode = True') if self.expandP1checkbox.isChecked(): self.NGL_HKL_command("""NGL_HKLviewer.viewer { expand_to_p1 = True inbrowser = False } """) if self.expandAnomalouscheckbox.isChecked(): self.NGL_HKL_command("""NGL_HKLviewer.viewer { expand_anomalous = True inbrowser = False } """) else: self.NGL_HKL_command("""NGL_HKLviewer.viewer { slice_mode = False inbrowser = True } """) def onSliceComboSelchange(self, i): rmin = self.array_infotpls[self.MillerComboBox.currentIndex()][3][0][i] rmax = self.array_infotpls[self.MillerComboBox.currentIndex()][3][1][i] self.sliceindexspinBox.setRange(rmin, rmax) self.NGL_HKL_command("NGL_HKLviewer.viewer.slice_axis = %s" % self.sliceaxis[i]) def onSliceIndexChanged(self, val): self.sliceindex = val self.NGL_HKL_command("NGL_HKLviewer.viewer.slice_index = %d" % self.sliceindex) def onBindataComboSelchange(self, i): if self.BinDataComboBox.currentText(): if self.BinDataComboBox.currentIndex() > 0: bin_scene_label = str(self.BinDataComboBox.currentIndex() - 1) else: bin_scene_label = "Resolution" self.NGL_HKL_command("NGL_HKLviewer.bin_scene_label = %s" % bin_scene_label) def update_table_opacities(self, allalpha=None): bin_opacitieslst = eval(self.bin_opacities) self.binstable_isready = False for binopacity in bin_opacitieslst: if not allalpha: alpha = float(binopacity.split(",")[0]) else: alpha = allalpha bin = int(binopacity.split(",")[1]) item = QTableWidgetItem() item.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled) if alpha < 0.5: item.setCheckState(Qt.Unchecked) else: item.setCheckState(Qt.Checked) item.setFlags(item.flags() ^ Qt.ItemIsEditable) self.binstable.setItem(bin, 3, item) self.binstable_isready = True def SetOpaqueAll(self): if self.binstableitemchanges: return bin_opacitieslst = eval(self.bin_opacities) nbins = len(bin_opacitieslst) sum = 0 for binopacity in bin_opacitieslst: sum += float(binopacity.split(",")[0]) if sum >= nbins: self.OpaqueAllCheckbox.setCheckState(Qt.Checked) if sum == 0: self.OpaqueAllCheckbox.setCheckState(Qt.Unchecked) if sum > 0.0 and sum < nbins: self.OpaqueAllCheckbox.setCheckState(Qt.PartiallyChecked) def onBinsTableItemChanged(self, item): row = item.row() column = item.column() try: if item.checkState() == Qt.Unchecked: newval = 0 else: newval = 1.0 if column == 3 and self.binstable_isready: # changing opacity assert (newval <= 1.0 and newval >= 0.0) bin_opacitieslst = eval(self.bin_opacities) bin_opacitieslst[row] = str(newval) + ', ' + str(row) self.bin_opacities = str(bin_opacitieslst) self.SetOpaqueAll() self.NGL_HKL_command( 'NGL_HKLviewer.viewer.NGL.bin_opacities = "%s"' % self.bin_opacities) except Exception as e: print(str(e)) #self.binstable.currentItem().setText( self.currentSelectedBinsTableVal) def onBinsTableItemSelectionChanged(self): row = self.binstable.currentItem().row() column = self.binstable.currentItem().column() self.currentSelectedBinsTableVal = self.binstable.currentItem().text() #print( "in itemSelectionChanged " + self.currentSelectedBinsTableVal) def onOpaqueAll(self): self.binstableitemchanges = True bin_opacitieslst = eval(self.bin_opacities) nbins = len(bin_opacitieslst) bin_opacitieslst = [] self.binstable_isready = False if self.OpaqueAllCheckbox.isChecked(): for i in range(nbins): bin_opacitieslst.append("1.0, %d" % i) else: for i in range(nbins): bin_opacitieslst.append("0.0, %d" % i) self.bin_opacities = str(bin_opacitieslst) self.NGL_HKL_command('NGL_HKLviewer.viewer.NGL.bin_opacities = "%s"' % self.bin_opacities) self.binstableitemchanges = False self.binstable_isready = True """ def onLoadFinished(self, val): pass #print("web page finished loading now") def onBinsTableitemActivated(self, item): row = item.row() column = item.column() currentval = item.text() #print( "in itemActivated " + currentval) def onBinsTableCellentered(self, row, col): pass #print( "in Cellentered " + self.binstable.currentItem().text() ) def onBinsTableCellPressed(self, row, col): pass #print( "in CellPressed " + self.binstable.currentItem().text() ) """ def onNbinsChanged(self, val): self.nbins = val if not self.updatingNbins: # avoid possible endless loop to cctbx self.NGL_HKL_command("NGL_HKLviewer.nbins = %d" % self.nbins) def onRadiiScaleChanged(self, val): self.radii_scale = val self.NGL_HKL_command(""" NGL_HKLviewer.viewer { nth_power_scale_radii = %f scale = %f } """ % (self.nth_power_scale, self.radii_scale)) def onPowerScaleChanged(self, val): self.nth_power_scale = val self.NGL_HKL_command(""" NGL_HKLviewer.viewer { nth_power_scale_radii = %f scale = %f } """ % (self.nth_power_scale, self.radii_scale)) def onManualPowerScale(self): if self.ManualPowerScalecheckbox.isChecked(): self.NGL_HKL_command( 'NGL_HKLviewer.viewer.nth_power_scale_radii = %f' % self.nth_power_scale) self.power_scale_spinBox.setEnabled(True) else: self.NGL_HKL_command( 'NGL_HKLviewer.viewer.nth_power_scale_radii = -1.0') self.power_scale_spinBox.setEnabled(False) self.nth_power_scale = -1.0 def OpenReflectionsFile(self): options = QFileDialog.Options() fileName, filtr = QFileDialog.getOpenFileName( self, "Load reflections file", "", "All Files (*);;MTZ Files (*.mtz);;CIF (*.cif)", "", options) if fileName: self.HKLnameedit.setText(fileName) #self.infostr = "" self.textInfo.setPlainText("") self.fileisvalid = False self.NGL_HKL_command('NGL_HKLviewer.filename = "%s"' % fileName) self.MillerComboBox.clear() self.BinDataComboBox.clear() def createExpansionBox(self): self.SpaceGroupComboBox = QComboBox() self.SpaceGroupComboBox.activated.connect(self.SpacegroupSelchange) self.SpacegroupLabel = QLabel() self.SpacegroupLabel.setText("Space Subgroups") self.mergecheckbox = QCheckBox() self.mergecheckbox.setText("Merge data") #self.mergecheckbox.setTristate (True) self.mergecheckbox.clicked.connect(self.MergeData) self.expandP1checkbox = QCheckBox() self.expandP1checkbox.setText("Expand to P1") self.expandP1checkbox.clicked.connect(self.ExpandToP1) self.expandAnomalouscheckbox = QCheckBox() self.expandAnomalouscheckbox.setText("Show Friedel pairs") self.expandAnomalouscheckbox.clicked.connect(self.ExpandAnomalous) self.sysabsentcheckbox = QCheckBox() self.sysabsentcheckbox.setText("Show Systematic Absences") self.sysabsentcheckbox.clicked.connect(self.showSysAbsent) self.missingcheckbox = QCheckBox() self.missingcheckbox.setText("Show Missing") self.missingcheckbox.clicked.connect(self.showMissing) self.onlymissingcheckbox = QCheckBox() self.onlymissingcheckbox.setText("Only Show Missing") self.onlymissingcheckbox.clicked.connect(self.showOnlyMissing) self.ExpansionBox = QGroupBox("Expansions") layout = QGridLayout() layout.addWidget(self.SpacegroupLabel, 0, 0) layout.addWidget(self.SpaceGroupComboBox, 0, 1) #layout.addWidget(self.mergecheckbox, 1, 0) layout.addWidget(self.expandP1checkbox, 1, 0) layout.addWidget(self.expandAnomalouscheckbox, 1, 1) layout.addWidget(self.sysabsentcheckbox, 2, 0) layout.addWidget(self.missingcheckbox, 3, 0) layout.addWidget(self.onlymissingcheckbox, 3, 1) layout.setRowStretch(0, 0) layout.setRowStretch(1, 0) layout.setRowStretch(2, 0) layout.setRowStretch(3, 1) self.ExpansionBox.setLayout(layout) def CreateSliceTabs(self): self.showslicecheckbox = QCheckBox() self.showslicecheckbox.setText("Show Slice") self.showslicecheckbox.clicked.connect(self.showSlice) self.sliceindexspinBox = QDoubleSpinBox() self.sliceindex = 0 self.sliceindexspinBox.setValue(self.sliceindex) self.sliceindexspinBox.setDecimals(0) self.sliceindexspinBox.setSingleStep(1) self.sliceindexspinBox.setRange(0, 20) self.sliceindexspinBox.valueChanged.connect(self.onSliceIndexChanged) self.SliceLabelComboBox = QComboBox() self.SliceLabelComboBox.activated.connect(self.onSliceComboSelchange) self.sliceaxis = ["h", "k", "l"] self.SliceLabelComboBox.addItems(self.sliceaxis) self.sliceTabWidget = QTabWidget() tab1 = QWidget() layout1 = QGridLayout() layout1.addWidget(self.showslicecheckbox, 0, 0, 1, 1) layout1.addWidget(self.SliceLabelComboBox, 0, 1, 1, 1) layout1.addWidget(self.sliceindexspinBox, 0, 2, 1, 1) tab1.setLayout(layout1) tab2 = QWidget() layout2 = QGridLayout() self.hvec_spinBox = QDoubleSpinBox(self.sliceTabWidget) self.hvecval = 2.0 self.hvec_spinBox.setValue(self.hvecval) self.hvec_spinBox.setDecimals(2) self.hvec_spinBox.setSingleStep(0.5) self.hvec_spinBox.setRange(-100.0, 10.0) self.hvec_spinBox.valueChanged.connect(self.onHvecChanged) self.hvec_Label = QLabel() self.hvec_Label.setText("H") layout2.addWidget(self.hvec_Label, 0, 0, 1, 1) layout2.addWidget(self.hvec_spinBox, 0, 1, 1, 1) self.kvec_spinBox = QDoubleSpinBox(self.sliceTabWidget) self.kvecval = 0.0 self.kvec_spinBox.setValue(self.kvecval) self.kvec_spinBox.setDecimals(2) self.kvec_spinBox.setSingleStep(0.5) self.kvec_spinBox.setRange(-100.0, 100.0) self.kvec_spinBox.valueChanged.connect(self.onKvecChanged) self.kvec_Label = QLabel() self.kvec_Label.setText("K") layout2.addWidget(self.kvec_Label, 1, 0, 1, 1) layout2.addWidget(self.kvec_spinBox, 1, 1, 1, 1) self.lvec_spinBox = QDoubleSpinBox(self.sliceTabWidget) self.lvecval = 0.0 self.lvec_spinBox.setValue(self.lvecval) self.lvec_spinBox.setDecimals(2) self.lvec_spinBox.setSingleStep(0.5) self.lvec_spinBox.setRange(-100.0, 100.0) self.lvec_spinBox.valueChanged.connect(self.onLvecChanged) self.lvec_Label = QLabel() self.lvec_Label.setText("L") layout2.addWidget(self.lvec_Label, 2, 0, 1, 1) layout2.addWidget(self.lvec_spinBox, 2, 1, 1, 1) self.hkldist_spinBox = QDoubleSpinBox(self.sliceTabWidget) self.hkldistval = 0.0 self.hkldist_spinBox.setValue(self.hkldistval) self.hkldist_spinBox.setDecimals(2) self.hkldist_spinBox.setSingleStep(0.5) self.hkldist_spinBox.setRange(-100.0, 100.0) self.hkldist_spinBox.valueChanged.connect(self.onHKLdistChanged) self.hkldist_Label = QLabel() self.hkldist_Label.setText("Distance from Origin") layout2.addWidget(self.hkldist_Label, 3, 0, 1, 1) layout2.addWidget(self.hkldist_spinBox, 3, 1, 1, 1) self.clipwidth_spinBox = QDoubleSpinBox(self.sliceTabWidget) self.clipwidthval = 0.5 self.clipwidth_spinBox.setValue(self.clipwidthval) self.clipwidth_spinBox.setDecimals(2) self.clipwidth_spinBox.setSingleStep(0.05) self.clipwidth_spinBox.setRange(0.0, 100.0) self.clipwidth_spinBox.valueChanged.connect(self.onClipwidthChanged) self.clipwidth_Label = QLabel() self.clipwidth_Label.setText("Clip Plane Width") layout2.addWidget(self.clipwidth_Label, 4, 0, 1, 1) layout2.addWidget(self.clipwidth_spinBox, 4, 1, 1, 1) self.ClipBox = QGroupBox("Normal Vector to Clip Plane") self.ClipBox.setLayout(layout2) layout3 = QGridLayout() self.ClipPlaneChkBox = QCheckBox(self.sliceTabWidget) self.ClipPlaneChkBox.setText( "Use clip plane normal to HKL vector pointing out") self.ClipPlaneChkBox.clicked.connect(self.onClipPlaneChkBox) layout3.addWidget(self.ClipPlaneChkBox, 0, 0) layout3.addWidget(self.ClipBox, 1, 0) tab2.setLayout(layout3) self.sliceTabWidget.addTab(tab1, "Explicit Slicing") self.sliceTabWidget.addTab(tab2, "Clip Plane Slicing") self.ClipBox.setDisabled(True) def onClipPlaneChkBox(self): if self.ClipPlaneChkBox.isChecked(): self.ClipBox.setDisabled(False) philstr = """NGL_HKLviewer.normal_clip_plane { h = %s k = %s l = %s hkldist = %s clipwidth = %s } NGL_HKLviewer.viewer.NGL.fixorientation = %s """ %(self.hvecval, self.kvecval, self.lvecval, self.hkldistval, self.clipwidthval, \ str(self.fixedorientcheckbox.isChecked()) ) self.NGL_HKL_command(philstr) else: self.ClipBox.setDisabled(True) self.NGL_HKL_command( "NGL_HKLviewer.normal_clip_plane.clipwidth = None") def onClipwidthChanged(self, val): self.clipwidthval = val self.NGL_HKL_command("NGL_HKLviewer.normal_clip_plane.clipwidth = %f" % self.clipwidthval) def onHKLdistChanged(self, val): self.hkldistval = val self.NGL_HKL_command("NGL_HKLviewer.normal_clip_plane.hkldist = %f" % self.hkldistval) def onHvecChanged(self, val): self.hvecval = val self.NGL_HKL_command("NGL_HKLviewer.normal_clip_plane.h = %f" % self.hvecval) def onKvecChanged(self, val): self.kvecval = val self.NGL_HKL_command("NGL_HKLviewer.normal_clip_plane.k = %f" % self.kvecval) def onLvecChanged(self, val): self.lvecval = val self.NGL_HKL_command("NGL_HKLviewer.normal_clip_plane.l = %f" % self.lvecval) def onFixedorient(self): self.NGL_HKL_command('NGL_HKLviewer.viewer.NGL.fixorientation = %s' \ %str(self.fixedorientcheckbox.isChecked())) def onMillerComboSelchange(self, i): self.NGL_HKL_command("NGL_HKLviewer.scene_id = %d" % i) #self.MillerComboBox.setCurrentIndex(i) if self.MillerComboBox.currentText(): self.functionTabWidget.setEnabled(True) self.expandAnomalouscheckbox.setEnabled(True) # don' allow anomalous expansion for data that's already anomalous for arrayinfo in self.array_infotpls: isanomalous = arrayinfo[-1] label = arrayinfo[0] if isanomalous and label == self.MillerComboBox.currentText( )[:len(label)]: self.expandAnomalouscheckbox.setDisabled(True) else: self.functionTabWidget.setDisabled(True) self.SpaceGroupComboBox.clear() self.SpaceGroupComboBox.addItems(self.spacegroups) # need to supply issymunique flag in infotuple #if self.hklscenes_arrays[ i ][6] == 0: # self.mergecheckbox.setEnabled(True) #else: # self.mergecheckbox.setEnabled(False) def createFileInfoBox(self): self.FileInfoBox = QGroupBox("Reflection File Information") layout = QGridLayout() layout.addWidget(self.openFileNameButton, 0, 0, 1, 2) if self.devmode: layout.addWidget(self.debugbutton, 0, 2, 1, 1) layout.addWidget(self.HKLnameedit, 1, 0, 1, 3) layout.addWidget(self.millertable, 2, 0, 1, 3) layout.addWidget(self.textInfo, 3, 0, 1, 3) #layout.setColumnStretch(1, 2) self.FileInfoBox.setLayout(layout) def createRadiiScaleGroupBox(self): self.RadiiScaleGroupBox = QGroupBox("Radii Size of HKL Spheres") self.ManualPowerScalecheckbox = QCheckBox() self.ManualPowerScalecheckbox.setText( "Manual Power Scaling of Sphere Radii") self.ManualPowerScalecheckbox.clicked.connect(self.onManualPowerScale) self.power_scale_spinBox = QDoubleSpinBox(self.RadiiScaleGroupBox) self.nth_power_scale = 0.5 self.power_scale_spinBox.setValue(self.nth_power_scale) self.power_scale_spinBox.setDecimals(2) self.power_scale_spinBox.setSingleStep(0.05) self.power_scale_spinBox.setRange(0.0, 1.0) self.power_scale_spinBox.valueChanged.connect(self.onPowerScaleChanged) self.power_scale_spinBox.setEnabled(False) self.powerscaleLabel = QLabel() self.powerscaleLabel.setText("Power scale Factor") self.radii_scale_spinBox = QDoubleSpinBox(self.RadiiScaleGroupBox) self.radii_scale = 1.0 self.radii_scale_spinBox.setValue(self.radii_scale) self.radii_scale_spinBox.setDecimals(1) self.radii_scale_spinBox.setSingleStep(0.1) self.radii_scale_spinBox.setRange(0.2, 2.0) self.radii_scale_spinBox.valueChanged.connect(self.onRadiiScaleChanged) self.radiiscaleLabel = QLabel() self.radiiscaleLabel.setText("Linear Scale Factor") layout = QGridLayout() layout.addWidget(self.ManualPowerScalecheckbox, 1, 0, 1, 2) layout.addWidget(self.powerscaleLabel, 2, 0, 1, 2) layout.addWidget(self.power_scale_spinBox, 2, 1, 1, 2) layout.addWidget(self.radiiscaleLabel, 3, 0, 1, 2) layout.addWidget(self.radii_scale_spinBox, 3, 1, 1, 2) layout.setColumnStretch(0, 1) layout.setColumnStretch(1, 0) self.RadiiScaleGroupBox.setLayout(layout) def createBinsBox(self): self.binstable = QTableWidget(0, 4) self.binstable_isready = False labels = [ "no. of HKLs", "lower bin value", "upper bin value", "opacity" ] self.binstable.setHorizontalHeaderLabels(labels) self.binstable.horizontalHeader().setDefaultAlignment(Qt.AlignLeft) self.bindata_labeltxt = QLabel() self.bindata_labeltxt.setText("Data binned:") self.Nbins_spinBox = QSpinBox() self.Nbins_spinBox.setSingleStep(1) self.Nbins_spinBox.setRange(1, 40) self.Nbins_spinBox.valueChanged.connect(self.onNbinsChanged) self.Nbins_labeltxt = QLabel() self.Nbins_labeltxt.setText("Number of bins:") self.OpaqueAllCheckbox = QCheckBox() #self.OpaqueAllCheckbox.setTristate() self.OpaqueAllCheckbox.setText("Show all data in bins") self.OpaqueAllCheckbox.clicked.connect(self.onOpaqueAll) self.binstable.itemChanged.connect(self.onBinsTableItemChanged) self.binstable.itemSelectionChanged.connect( self.onBinsTableItemSelectionChanged) self.BinDataComboBox = QComboBox() self.BinDataComboBox.activated.connect(self.onBindataComboSelchange) self.BinsGroupBox = QGroupBox("Bins") layout = QGridLayout() layout.addWidget(self.bindata_labeltxt, 0, 0) layout.addWidget(self.BinDataComboBox, 0, 1) layout.addWidget(self.Nbins_labeltxt, 0, 2) layout.addWidget(self.Nbins_spinBox, 0, 3) layout.addWidget(self.OpaqueAllCheckbox, 1, 2) layout.addWidget(self.binstable, 2, 0, 1, 4) layout.setColumnStretch(0, 0) layout.setColumnStretch(1, 2) layout.setColumnStretch(3, 1) self.BinsGroupBox.setLayout(layout) def DebugInteractively(self): import code, traceback code.interact(local=locals(), banner="".join(traceback.format_stack(limit=10))) def CreateFunctionTabs(self): self.functionTabWidget = QTabWidget() tab1 = QWidget() layout1 = QGridLayout() layout1.addWidget(self.ExpansionBox, 0, 0) layout1.setRowStretch(0, 0) tab1.setLayout(layout1) tab2 = QWidget() layout2 = QGridLayout() self.fixedorientcheckbox = QCheckBox(self.sliceTabWidget) self.fixedorientcheckbox.setText( "Fix orientation but allow zoom and translation") self.fixedorientcheckbox.clicked.connect(self.onFixedorient) layout2.addWidget(self.fixedorientcheckbox, 0, 0) layout2.addWidget(self.sliceTabWidget, 1, 0) tab2.setLayout(layout2) tab3 = QWidget() layout3 = QGridLayout() layout3.addWidget(self.RadiiScaleGroupBox, 0, 0) tab3.setLayout(layout3) tab4 = QWidget() layout4 = QGridLayout() layout4.addWidget(self.BinsGroupBox, 0, 0) tab4.setLayout(layout4) self.functionTabWidget.addTab(tab1, "Expand") self.functionTabWidget.addTab(tab2, "Slice") self.functionTabWidget.addTab(tab3, "Size") self.functionTabWidget.addTab(tab4, "Bins") self.functionTabWidget.setDisabled(True) def SpacegroupSelchange(self, i): self.NGL_HKL_command("NGL_HKLviewer.spacegroup_choice = %d" % i) def find_free_port(self): import socket s = socket.socket() s.bind(('', 0)) # Bind to a free port provided by the host. port = s.getsockname()[1] s.close() return port def LaunchCCTBXPython(self): self.sockport = self.find_free_port() self.zmq_context = zmq.Context() self.socket = self.zmq_context.socket(zmq.PAIR) self.socket.bind("tcp://127.0.0.1:%s" % self.sockport) try: msg = self.socket.recv( flags=zmq.NOBLOCK) #To empty the socket from previous messages except Exception as e: pass cmdargs = 'cctbx.python.bat -i -c "from crys3d.hklview import cmdlineframes;' \ + ' myHKLview = cmdlineframes.HKLViewFrame(useGuiSocket=%s, high_quality=True,' %self.sockport \ + ' jscriptfname = \'%s\', ' %self.jscriptfname \ + ' verbose=%s, UseOSBrowser= %s )"\n' %(self.verbose, str(self.UseOSbrowser)) self.cctbxproc = subprocess.Popen(cmdargs, shell=True, stdin=subprocess.PIPE, stdout=sys.stdout, stderr=sys.stderr) #time.sleep(1) def NGL_HKL_command(self, cmdstr): #print("sending:\n" + cmdstr) self.socket.send(bytes(cmdstr, "utf-8"))
def _gui(self): layout = QVBoxLayout() self.setLayout(layout) slider_layout = QHBoxLayout() layout.addLayout(slider_layout) slider = ClickSlider(self) slider.setOrientation(Qt.Horizontal) slider.valueChanged.connect(self._slider_changed) slider_layout.addWidget(slider) self.slider = slider max_time = QLabel(self) self.max_time = max_time max_time.setText('--:--') slider_layout.addWidget(max_time) form = QFormLayout() layout.addLayout(form) time = QTimeEdit(self) time.setDisplayFormat('mm:ss.zzz') time.setAlignment(Qt.AlignRight) time.timeChanged.connect(self._edit_time_changed) self.time = time form.addRow(QLabel('Time', self),time) speed = QDoubleSpinBox(self) speed.setMinimum(0.1) speed.setMaximum(2.0) speed.setSingleStep(0.1) speed.setValue(1) speed.setAlignment(Qt.AlignRight) self.speed = speed speed.valueChanged.connect(self._speed_changed) form.addRow(QLabel('Speed', self), speed) playback = QHBoxLayout() layout.addLayout(playback) back_fast = QToolButton(self) playback.addWidget(back_fast) abf = QAction('<<', back_fast) abf.setShortcut(QKeySequence(Qt.Key_F1)) abf.triggered.connect(self.back_fast) back_fast.setDefaultAction(abf) back = QToolButton(self) playback.addWidget(back) ab = QAction('<', back) ab.setShortcut(QKeySequence(Qt.Key_F2)) ab.triggered.connect(self.back) back.setDefaultAction(ab) play = QToolButton(self) playback.addWidget(play) self.play_button = play play.setCheckable(True) play.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred) ap = QAction('Play', play) ap.setShortcut(QKeySequence(Qt.Key_F5)) ap.triggered.connect(self.play) play.setDefaultAction(ap) forward = QToolButton(self) playback.addWidget(forward) af = QAction('>', forward) af.setShortcut(QKeySequence(Qt.Key_F3)) af.triggered.connect(self.forward) forward.setDefaultAction(af) forward_fast = QToolButton(self) playback.addWidget(forward_fast) aff = QAction('>>', forward_fast) aff.setShortcut(QKeySequence(Qt.Key_F4)) aff.triggered.connect(self.forward_fast) forward_fast.setDefaultAction(aff) speed_up = QAction('Speed up', forward_fast) speed_up.setShortcut(QKeySequence(Qt.Key_F7)) speed_up.triggered.connect(self.speed.stepUp) speed_down = QAction('Speed down', forward_fast) speed_down.setShortcut(QKeySequence(Qt.Key_F6)) speed_down.triggered.connect(self.speed.stepDown) self.utils = [ slider, back_fast, back, play, forward, forward_fast, time, speed ] self.playback_actions = [abf, ab, ap, af, aff, speed_down, speed_up] self.set_enabled_utils(False) self.prevent = False self.timer = QTimer(self) self.timer.timeout.connect(self._update) self.timer.start(1) self.player = None
class TrainingPanel(Panel): def __init__(self, datasets, testing_panel, threads): super().__init__() if isinstance(testing_panel, TestingPanel): self.testing_panel = testing_panel else: raise TypeError('"testing_panel" must be the instance of ' '"TestingPanel"') self.datasets = datasets self.threads = threads self.__set_execution_ui() self.__set_options_ui() self.__set_outputs_ui() self.__set_graphic_ui() def __set_execution_ui(self): group_box = QGroupBox('Training Execution') inner_layout = QHBoxLayout() group_box.setLayout(inner_layout) self.data_selector = QComboBox() self.data_selector.addItems(list(self.datasets.keys())) self.data_selector.setStatusTip('Select the training dataset.') self.start_btn = QPushButton('Train') self.start_btn.setStatusTip('Start training.') self.start_btn.clicked.connect(self.__run) self.stop_btn = QPushButton('Stop') self.stop_btn.setStatusTip('Force the training stop running.') self.stop_btn.setDisabled(True) self.multicore_cb = QCheckBox('Multicore') self.multicore_cb.setStatusTip('Use multiprocessing in calculating ' 'fitting for populations.') self.multicore_cb.setChecked(True) inner_layout.addWidget(self.data_selector, 1) inner_layout.addWidget(self.start_btn) inner_layout.addWidget(self.stop_btn) inner_layout.addWidget(self.multicore_cb) self._layout.addWidget(group_box) def __set_options_ui(self): group_box = QGroupBox('Training Options') inner_layout = QFormLayout() group_box.setLayout(inner_layout) self.iter_times = QSpinBox() self.iter_times.setRange(1, 1000000) self.iter_times.setValue(200) self.iter_times.setStatusTip('The total iterating times for training.') self.population_size = QSpinBox() self.population_size.setRange(1, 100000) self.population_size.setValue(100) self.population_size.setStatusTip('The population size for the PSO.') self.inertia_weight = QDoubleSpinBox() self.inertia_weight.setRange(0, 50) self.inertia_weight.setValue(1) self.inertia_weight.setSingleStep(0.1) self.inertia_weight.setStatusTip('The inertia weight of the velocity ' ' for each individual.') self.cognitive_const_rand_upper = QDoubleSpinBox() self.cognitive_const_rand_upper.setRange(0, 50) self.cognitive_const_rand_upper.setValue(2) self.cognitive_const_rand_upper.setSingleStep(0.1) self.cognitive_const_rand_upper.setStatusTip( 'The random upper bound for cognitive accelerate constant.') self.social_const_rand_upper = QDoubleSpinBox() self.social_const_rand_upper.setRange(0, 50) self.social_const_rand_upper.setValue(3) self.social_const_rand_upper.setSingleStep(0.1) self.social_const_rand_upper.setStatusTip( 'The random upper bound for social accelerate constant.') self.v_max = QDoubleSpinBox() self.v_max.setRange(0.5, 100) self.v_max.setValue(5) self.v_max.setSingleStep(1) self.v_max.setStatusTip('The maximum of velocity for each individual.') self.nneuron = QSpinBox() self.nneuron.setRange(1, 100) self.nneuron.setValue(6) self.nneuron.setStatusTip('The number of RBFN neuron.') self.sd_max = QDoubleSpinBox() self.sd_max.setRange(0.01, 20) self.sd_max.setValue(10) self.sd_max.setSingleStep(0.1) self.sd_max.setStatusTip('The random range maximum of standard ' 'deviation of each neuron in RBFN (only for ' 'initialization).') inner_layout.addRow('Iterating Times:', self.iter_times) inner_layout.addRow('Population Size:', self.population_size) inner_layout.addRow('Inertia Weight:', self.inertia_weight) inner_layout.addRow('Cognitive Const Upper:', self.cognitive_const_rand_upper) inner_layout.addRow('Social Const Upper:', self.social_const_rand_upper) inner_layout.addRow('Maximum of Velocity:', self.v_max) inner_layout.addRow('Number of Neuron:', self.nneuron) inner_layout.addRow('Maximum of SD:', self.sd_max) self._layout.addWidget(group_box) def __set_outputs_ui(self): group_box = QGroupBox('Training Details') inner_layout = QFormLayout() group_box.setLayout(inner_layout) self.current_iter_time = QLabel('--') self.current_error = QLabel('--') self.avg_error = QLabel('--') self.global_best_error = QLabel('--') self.total_best_error = QLabel('--') self.progressbar = QProgressBar() self.current_iter_time.setAlignment(Qt.AlignCenter) self.current_error.setAlignment(Qt.AlignCenter) self.avg_error.setAlignment(Qt.AlignCenter) self.global_best_error.setAlignment(Qt.AlignCenter) self.total_best_error.setAlignment(Qt.AlignCenter) self.current_iter_time.setStatusTip('The current iterating time of ' 'the PSO.') self.current_error.setStatusTip('The current error from the fitting ' 'function. ("( )": normalized error)') self.avg_error.setStatusTip('The average error from the fitting ' 'function in current iteration. ("( )": ' 'normalized error)') self.global_best_error.setStatusTip( 'The error of global best individual from the fitting function in ' 'current iteration. ("( )": normalized error)') self.total_best_error.setStatusTip( 'The error of total best individual from the fitting function in ' 'training. ("( )": normalized error)') inner_layout.addRow('Current Iterating Time:', self.current_iter_time) inner_layout.addRow('Current Error:', self.current_error) inner_layout.addRow('Average Error:', self.avg_error) inner_layout.addRow('Global Best Error:', self.global_best_error) inner_layout.addRow('Total Best Error:', self.total_best_error) inner_layout.addRow(self.progressbar) self._layout.addWidget(group_box) def __set_graphic_ui(self): group_box = QGroupBox('Error Line Charts:') inner_layout = QVBoxLayout() group_box.setLayout(inner_layout) self.err_chart = ErrorLineChart(1) self.err_chart.setStatusTip('The history of error from the fitting ' 'of the PSO for each data.') self.__err_x = 1 self.iter_err_chart = ErrorLineChart( 3, ('Avg', 'Global Best', 'Total Best')) self.iter_err_chart.setStatusTip('The history of average and least ' 'error from the fitting of the PSO ' 'for each iteration.') self.iter_err_chart.setMinimumHeight(150) inner_layout.addWidget(QLabel('Current Error')) inner_layout.addWidget(self.err_chart) inner_layout.addWidget(QLabel('Average Error')) inner_layout.addWidget(self.iter_err_chart) self._layout.addWidget(group_box) @Slot() def __init_widgets(self): self.start_btn.setDisabled(True) self.stop_btn.setEnabled(True) self.multicore_cb.setDisabled(True) self.data_selector.setDisabled(True) self.iter_times.setDisabled(True) self.population_size.setDisabled(True) self.inertia_weight.setDisabled(True) self.cognitive_const_rand_upper.setDisabled(True) self.social_const_rand_upper.setDisabled(True) self.v_max.setDisabled(True) self.nneuron.setDisabled(True) self.sd_max.setDisabled(True) self.err_chart.clear() self.iter_err_chart.clear() self.__err_x = 1 @Slot() def __reset_widgets(self): self.start_btn.setEnabled(True) self.stop_btn.setDisabled(True) self.multicore_cb.setEnabled(True) self.data_selector.setEnabled(True) self.iter_times.setEnabled(True) self.population_size.setEnabled(True) self.inertia_weight.setEnabled(True) self.cognitive_const_rand_upper.setEnabled(True) self.social_const_rand_upper.setEnabled(True) self.v_max.setEnabled(True) self.nneuron.setEnabled(True) self.sd_max.setEnabled(True) self.progressbar.setMinimum(0) self.progressbar.setMaximum(100) @Slot() def __indicate_busy(self): self.progressbar.setMinimum(0) self.progressbar.setMaximum(0) @Slot(int) def __show_current_iter_time(self, value): self.current_iter_time.setText(str(value + 1)) self.progressbar.setValue(value + 1) @Slot(float) def __show_current_error(self, value): self.current_error.setText('{:.5f} ({:.5f})'.format(value, value / 40)) self.err_chart.append_point(self.__err_x, value) self.__err_x += 1 @Slot(float, float, float) def __show_iter_error(self, avg, glob, total): self.avg_error.setText('{:.5f} ({:.5f})'.format(avg, avg / 40)) self.global_best_error.setText( '{:.5f} ({:.5f})'.format(glob, glob / 40)) self.total_best_error.setText( '{:.5f} ({:.5f})'.format(total, total / 40)) self.iter_err_chart.append_point( int(self.current_iter_time.text()), total, 2) self.iter_err_chart.append_point( int(self.current_iter_time.text()), glob, 1) self.iter_err_chart.append_point( int(self.current_iter_time.text()), avg, 0) def __run(self): self.progressbar.setMaximum(self.iter_times.value()) self.__current_dataset = self.datasets[ self.data_selector.currentText()] self.__pso = PSO(self.iter_times.value(), self.population_size.value(), self.inertia_weight.value(), self.cognitive_const_rand_upper.value(), self.social_const_rand_upper.value(), self.v_max.value(), self.nneuron.value(), self.__current_dataset, self.sd_max.value(), is_multicore=self.multicore_cb.isChecked()) self.threads.append(self.__pso) self.stop_btn.clicked.connect(self.__pso.stop) self.__pso.started.connect(self.__init_widgets) self.__pso.finished.connect(self.__reset_widgets) self.__pso.sig_current_iter_time.connect(self.__show_current_iter_time) self.__pso.sig_current_error.connect(self.__show_current_error) self.__pso.sig_iter_error.connect(self.__show_iter_error) self.__pso.sig_indicate_busy.connect(self.__indicate_busy) self.__pso.sig_console.connect(self.testing_panel.print_console) self.__pso.sig_rbfn.connect(self.testing_panel.load_rbfn) self.__pso.start()
class BlockView(QWidget): """Config widget for a single experiment block. In a model-view paradigm, this is a view, and block is a model. A new block can be set using setModel. """ statistics_type_to_name = { "max": "Min/Max", "meanstd": "Standardise" } statistics_name_to_type = {v: k for k, v in statistics_type_to_name.items()} def __init__(self, parent=None): super().__init__(parent) layout = QFormLayout() self.setLayout(layout) self._model = None # Block properties --------------------------------------------------------------------------------------------- self.duration = QWidget() self.duration.setContentsMargins(0, 0, 0, 0) ly = QHBoxLayout() ly.setContentsMargins(0, 0, 0, 0) self.duration.setLayout(ly) self.duration_base = QDoubleSpinBox() self.duration_base.setRange(0, 1000) self.duration_base.setValue(10) self.duration_deviation = QDoubleSpinBox() self.duration_deviation.setRange(0, 10) self.duration_deviation.setValue(0) self.duration_deviation.setSingleStep(0.1) self.duration_deviation.setSuffix(" s") self.duration_base.valueChanged.connect(self.duration_deviation.setMaximum) ly.addWidget(self.duration_base) ly.addWidget(QLabel("±")) ly.addWidget(self.duration_deviation) self.feedback_source = QLineEdit("All") self.feedback_type = QComboBox() self.feedback_type.addItem("Baseline") self.feedback_type.addItem("Feedback") self.mock_signal_path = QLineEdit() self.mock_signal_dataset = QLineEdit() self.mock_previous = QSpinBox() self.mock_previous_reverse = QCheckBox() self.mock_previous_random = QCheckBox() self.pause = QCheckBox() self.beep = QCheckBox() self.start_data_driven_filter_designer = QCheckBox() self.update_statistics = QCheckBox() self.update_statistics.stateChanged.connect(lambda state: self.statistics_type.setEnabled(bool(state))) self.statistics_type = QComboBox() self.statistics_type.setEnabled(False) for name in self.statistics_name_to_type: self.statistics_type.addItem(name) self.statistics_type.setCurrentText("Standardise") self.random_bound = QComboBox() self.random_bound.addItem("SimCircle") self.random_bound.addItem("RandomCircle") self.random_bound.addItem("Bar") self.video_path = QLineEdit() self.message = QLineEdit() self.feedback_type.currentTextChanged.connect(lambda ftype: self.message.setEnabled(ftype == "Baseline")) self.voiceover = QCheckBox() # Grouped properties ------------------------------------------------------------------------------------------- # Mock signal mock_signal_groupbox = QGroupBox("Mock signal") mock_signal_gblayout = QFormLayout() mock_signal_groupbox.setLayout(mock_signal_gblayout) mock_signal_gblayout.addRow("Mock signal file path", self.mock_signal_path) mock_signal_gblayout.addRow("Mock signal file dataset", self.mock_signal_dataset) mock_signal_gblayout.addRow("Mock previous", self.mock_previous) mock_signal_gblayout.addRow("Reverse mock previous", self.mock_previous_reverse) mock_signal_gblayout.addRow("Random mock previous", self.mock_previous_random) # After block actions after_block_groupbox = QGroupBox("After block actions") after_block_gblayout = QFormLayout() after_block_groupbox.setLayout(after_block_gblayout) after_block_gblayout.addRow("Start data driven filter designer", self.start_data_driven_filter_designer) after_block_gblayout.addRow("Pause", self.pause) after_block_gblayout.addRow("Beep", self.beep) after_block_gblayout.addRow("Update statistics", self.update_statistics) after_block_gblayout.addRow("Statistics type", self.statistics_type) # Adding properties to the widget ------------------------------------------------------------------------------ layout.addRow("Duration", self.duration) layout.addRow("Source", self.feedback_source) layout.addRow("FB Type", self.feedback_type) layout.addRow("Random bound", self.random_bound) layout.addRow("Video path", self.video_path) layout.addRow("Message for test subject", self.message) layout.addRow("Voiceover for message", self.voiceover) layout.addRow(mock_signal_groupbox) layout.addRow(after_block_groupbox) def model(self): return self._model def setModel(self, block, /): """Set the model block for this view. Data in the view will be updated to reflect the new block. """ self._model = block self.updateView() def updateModel(self): """Copy data from this view to the block model. A similarly named function in the block copies data the opposite way. Use one or the other depending on where data was changed. """ model = self.model() if model is None: return model.duration = self.duration_base.value() model.duration_deviation = self.duration_deviation.value() model.feedback_source = self.feedback_source.text() model.feedback_type = self.feedback_type.currentText() model.random_bound = self.random_bound.currentText() model.video_path = self.video_path.text() model.message = self.message.text() model.voiceover = self.voiceover.isChecked() model.mock_signal_path = self.mock_signal_path.text() model.mock_signal_dataset = self.mock_signal_dataset.text() model.mock_previous = self.mock_previous.value() model.mock_previous_reverse = self.mock_previous_reverse.isChecked() model.mock_previous_random = self.mock_previous_random.isChecked() model.start_data_driven_filter_designer = self.start_data_driven_filter_designer.isChecked() model.pause = self.pause.isChecked() model.beep = self.beep.isChecked() model.update_statistics = self.update_statistics.isChecked() model.statistics_type = self.statistics_name_to_type[self.statistics_type.currentText()] def updateView(self): model = self.model() if model is None: return self.duration_base.setValue(model.duration) self.duration_deviation.setValue(model.duration_deviation) self.feedback_source.setText(model.feedback_source) self.feedback_type.setCurrentText(model.feedback_type) self.mock_signal_path.setText(model.mock_signal_path) self.mock_signal_dataset.setText(model.mock_signal_dataset) self.mock_previous.setValue(model.mock_previous) self.mock_previous_reverse.setChecked(model.mock_previous_reverse) self.mock_previous_random.setChecked(model.mock_previous_random) self.pause.setChecked(model.pause) self.beep.setChecked(model.beep) self.start_data_driven_filter_designer.setChecked(model.start_data_driven_filter_designer) self.update_statistics.setChecked(model.update_statistics) self.statistics_type.setCurrentText(self.statistics_type_to_name[model.statistics_type]) self.random_bound.setCurrentText(model.random_bound) self.video_path.setText(model.video_path) self.message.setText(model.message) self.voiceover.setChecked(model.voiceover)
class WidgetConfig(QGroupBox): def __init__(self): super(WidgetConfig, self).__init__() HEIGHT = 40 grid = QGridLayout() # 使用默认摄像头复选框 self.check_camera = QCheckBox('Use default camera') self.check_camera.setChecked(False) self.check_camera.stateChanged.connect(self.slot_check_camera) grid.addWidget(self.check_camera, 0, 0, 1, 3) # 一行三列 # 选择视频文件 label_video = QLabel('Detect File') self.line_video = QLineEdit() if 'video' in GLOBAL.config: self.line_video.setText(GLOBAL.config['video']) self.line_video.setFixedHeight(HEIGHT) self.line_video.setEnabled(False) self.line_video.editingFinished.connect( lambda: GLOBAL.record_config({'video': self.line_video.text()})) self.btn_video = QPushButton('Choose') self.btn_video.setFixedHeight(HEIGHT) self.btn_video.setEnabled(False) self.btn_video.clicked.connect(self.choose_video_file) self.slot_check_camera() grid.addWidget(label_video, 1, 0) grid.addWidget(self.line_video, 1, 1) grid.addWidget(self.btn_video, 1, 2) # 选择权重文件 label_weights = QLabel('Weights File') self.line_weights = QLineEdit() if 'weights' in GLOBAL.config: self.line_weights.setText(GLOBAL.config['weights']) self.line_weights.setFixedHeight(HEIGHT) self.line_weights.editingFinished.connect(lambda: GLOBAL.record_config( {'weights': self.line_weights.text()})) self.btn_weights = QPushButton('Choose') self.btn_weights.setFixedHeight(HEIGHT) self.btn_weights.clicked.connect(self.choose_weights_file) grid.addWidget(label_weights, 2, 0) grid.addWidget(self.line_weights, 2, 1) grid.addWidget(self.btn_weights, 2, 2) # 是否使用GPU label_device = QLabel('CUDA device') self.line_device = QLineEdit('gpu') if 'device' in GLOBAL.config: self.line_device.setText(GLOBAL.config['device']) else: self.line_device.setText('cpu') self.line_device.setPlaceholderText('cpu or 0 or 0,1,2,3') self.line_device.setFixedHeight(HEIGHT) self.line_device.editingFinished.connect( lambda: GLOBAL.record_config({'device': self.line_device.text()})) grid.addWidget(label_device, 3, 0) grid.addWidget(self.line_device, 3, 1, 1, 2) # 设置图像大小 label_size = QLabel('Img Size') self.combo_size = QComboBox() self.combo_size.setFixedHeight(HEIGHT) self.combo_size.setStyleSheet( 'QAbstractItemView::item {height: 40px;}') self.combo_size.setView(QListView()) self.combo_size.addItem('320', 320) self.combo_size.addItem('416', 416) self.combo_size.addItem('480', 480) self.combo_size.addItem('544', 544) self.combo_size.addItem('640', 640) self.combo_size.setCurrentIndex(2) self.combo_size.currentIndexChanged.connect( lambda: GLOBAL.record_config( {'img_size': self.combo_size.currentData()})) grid.addWidget(label_size, 4, 0) grid.addWidget(self.combo_size, 4, 1, 1, 2) #choose net camera label_stream = QLabel('NetVedioStream') self.combo_stream = QComboBox() self.combo_stream.setFixedHeight(HEIGHT) self.combo_stream.setStyleSheet( 'QAbstractItemView::item {height: 40px;}') self.combo_stream.setView(QListView()) self.combo_stream.addItem('rtsp://*****:*****@192.168.0.65/', 'rtsp://*****:*****@192.168.0.65/') self.combo_stream.addItem('rtsp://*****:*****@192.168.0.66/', 'rtsp://*****:*****@192.168.0.66/') self.combo_stream.addItem('rtsp://*****:*****@192.168.0.67/', 'rtsp://*****:*****@192.168.0.67/') self.combo_stream.addItem('rtsp://*****:*****@192.168.0.68/', 'rtsp://*****:*****@192.168.0.68/') self.combo_stream.addItem('rtsp://*****:*****@192.168.0.65/', 'rtsp://*****:*****@192.168.0.65/') self.combo_stream.setCurrentIndex(0) self.combo_stream.currentIndexChanged.connect( lambda: GLOBAL.record_config( {'netstreamvedio': self.combo_stream.currentData()})) grid.addWidget(label_stream, 5, 0) grid.addWidget(self.combo_stream, 5, 1, 1, 2) # 设置置信度阈值 label_conf = QLabel('Confidence') self.spin_conf = QDoubleSpinBox() self.spin_conf.setFixedHeight(HEIGHT) self.spin_conf.setDecimals(1) self.spin_conf.setRange(0.1, 0.9) self.spin_conf.setSingleStep(0.1) if 'conf_thresh' in GLOBAL.config: self.spin_conf.setValue(GLOBAL.config['conf_thresh']) else: self.spin_conf.setValue(0.4) # 默认值 GLOBAL.record_config({'conf_thresh': 0.4}) self.spin_conf.valueChanged.connect(lambda: GLOBAL.record_config( {'conf_thresh': round(self.spin_conf.value(), 1)})) grid.addWidget(label_conf, 6, 0) grid.addWidget(self.spin_conf, 6, 1, 1, 2) # 设置IOU阈值 label_iou = QLabel('IOU') self.spin_iou = QDoubleSpinBox() self.spin_iou.setFixedHeight(HEIGHT) self.spin_iou.setDecimals(1) self.spin_iou.setRange(0.1, 0.9) self.spin_iou.setSingleStep(0.1) if 'iou_thresh' in GLOBAL.config: self.spin_iou.setValue(GLOBAL.config['iou_thresh']) else: self.spin_iou.setValue(0.5) # 默认值 GLOBAL.record_config({'iou_thresh': 0.5}) self.spin_iou.valueChanged.connect(lambda: GLOBAL.record_config( {'iou_thresh': round(self.spin_iou.value(), 1)})) grid.addWidget(label_iou, 7, 0) grid.addWidget(self.spin_iou, 7, 1, 1, 2) # class-agnostic NMS self.check_agnostic = QCheckBox('Agnostic') if 'agnostic' in GLOBAL.config: self.check_agnostic.setChecked(GLOBAL.config['agnostic']) else: self.check_agnostic.setChecked(True) self.check_agnostic.stateChanged.connect(lambda: GLOBAL.record_config( {'agnostic': self.check_agnostic.isChecked()})) grid.addWidget(self.check_agnostic, 8, 0, 1, 3) # 一行三列 # augmented inference self.check_augment = QCheckBox('Augment') if 'augment' in GLOBAL.config: self.check_augment.setChecked(GLOBAL.config['augment']) else: self.check_augment.setChecked(True) self.check_augment.stateChanged.connect(lambda: GLOBAL.record_config( {'augment': self.check_augment.isChecked()})) grid.addWidget(self.check_augment, 9, 0, 1, 3) # 一行三列 self.setLayout(grid) # 设置布局 def slot_check_camera(self): check = self.check_camera.isChecked() GLOBAL.record_config({'use_camera': check}) # 保存配置 if check: self.line_video.setEnabled(False) self.btn_video.setEnabled(False) else: self.line_video.setEnabled(True) self.btn_video.setEnabled(True) def choose_weights_file(self): """从系统中选择权重文件""" file = QFileDialog.getOpenFileName( self, "Pre-trained YOLOv5 Weights", "./", "Weights Files (*.pt);;All Files (*)") if file[0] != '': self.line_weights.setText(file[0]) GLOBAL.record_config({'weights': file[0]}) def choose_video_file(self): """从系统中选择视频文件""" file = QFileDialog.getOpenFileName(self, "Video Files", "./", "Video Files (*)") if file[0] != '': self.line_video.setText(file[0]) GLOBAL.record_config({'video': file[0]}) def save_config(self): """保存当前的配置到配置文件""" config = { 'use_camera': self.check_camera.isChecked(), 'video': self.line_video.text(), 'weights': self.line_weights.text(), 'device': self.line_device.text(), 'img_size': self.combo_size.currentData(), 'conf_thresh': round(self.spin_conf.value(), 1), 'iou_thresh': round(self.spin_iou.value(), 1), 'agnostic': self.check_agnostic.isChecked(), 'augment': self.check_augment.isChecked(), 'netstreamvedio': self.combo_stream.currentData() } GLOBAL.record_config(config)
class PlotsWidget(ToolWidget): def __init__(self, image, parent=None): super(PlotsWidget, self).__init__(parent) choices = ['Red', 'Green', 'Blue', 'Hue', 'Saturation', 'Value'] self.xaxis_combo = QComboBox() self.xaxis_combo.addItems(choices) self.xaxis_combo.setCurrentIndex(3) self.yaxis_combo = QComboBox() self.yaxis_combo.addItems(choices) self.yaxis_combo.setCurrentIndex(4) self.sampling_spin = QSpinBox() levels = int(np.log2(min(image.shape[:-1]))) self.sampling_spin.setRange(0, levels) self.sampling_spin.setSpecialValueText(self.tr('Off')) self.sampling_spin.setValue(1) self.sampling_spin.setSuffix(self.tr(' level(s)')) self.size_spin = QSpinBox() self.size_spin.setRange(1, 10) self.size_spin.setValue(2) self.size_spin.setSuffix(self.tr(' pt')) self.style_combo = QComboBox() self.markers = [ ',', '.', 'o', '8', 's', 'p', 'P', '*', 'h', 'H', 'X', 'D' ] self.style_combo.addItems([ 'pixel', 'point', 'circle', 'octa', 'square', 'penta', 'plus', 'star', 'hexa1', 'hexa2', 'cross', 'diamond' ]) self.alpha_spin = QDoubleSpinBox() self.alpha_spin.setRange(0, 1) self.alpha_spin.setDecimals(2) self.alpha_spin.setSingleStep(0.05) self.alpha_spin.setValue(1) self.colors_check = QCheckBox(self.tr('Show colors')) self.grid_check = QCheckBox(self.tr('Show grid')) self.norm_check = QCheckBox(self.tr('Normalized')) self.total_label = QLabel() img = np.copy(image) self.colors = [None] * (levels + 1) for scale in range(levels + 1): rgb = cv.cvtColor(img.astype(np.float32) / 255, cv.COLOR_BGR2RGB) hsv = cv.cvtColor(rgb, cv.COLOR_RGB2HSV) hsv[:, :, 0] /= 360 shape = (img.shape[0] * img.shape[1], img.shape[2]) self.colors[scale] = np.concatenate( (np.reshape(rgb, shape), np.reshape(hsv, shape)), axis=1) img = cv.pyrDown(img) figure = Figure() plot_canvas = FigureCanvas(figure) self.axes = plot_canvas.figure.subplots() self.redraw() figure.set_tight_layout(True) self.xaxis_combo.currentIndexChanged.connect(self.redraw) self.yaxis_combo.currentIndexChanged.connect(self.redraw) self.sampling_spin.valueChanged.connect(self.redraw) self.size_spin.valueChanged.connect(self.redraw) self.style_combo.currentIndexChanged.connect(self.redraw) self.alpha_spin.valueChanged.connect(self.redraw) self.colors_check.stateChanged.connect(self.redraw) self.grid_check.stateChanged.connect(self.redraw) self.norm_check.stateChanged.connect(self.redraw) bottom_layout = QGridLayout() bottom_layout.addWidget(NavigationToolbar(plot_canvas, self), 0, 0, 1, 5) bottom_layout.addWidget(QLabel(self.tr('X axis:')), 1, 0) bottom_layout.addWidget(self.xaxis_combo, 1, 1) bottom_layout.addWidget(QLabel(self.tr('Y Axis:')), 2, 0) bottom_layout.addWidget(self.yaxis_combo, 2, 1) bottom_layout.addWidget(QLabel(self.tr('Subsampling:')), 3, 0) bottom_layout.addWidget(self.sampling_spin, 3, 1) bottom_layout.addWidget(QLabel(self.tr('Point size:')), 1, 2) bottom_layout.addWidget(self.size_spin, 1, 3) bottom_layout.addWidget(QLabel(self.tr('Point style:')), 2, 2) bottom_layout.addWidget(self.style_combo, 2, 3) bottom_layout.addWidget(QLabel(self.tr('Point alpha:')), 3, 2) bottom_layout.addWidget(self.alpha_spin, 3, 3) bottom_layout.addWidget(self.colors_check, 1, 4) bottom_layout.addWidget(self.grid_check, 2, 4) bottom_layout.addWidget(self.total_label, 3, 4) main_layout = QVBoxLayout() main_layout.addWidget(plot_canvas) main_layout.addLayout(bottom_layout) self.setLayout(main_layout) def redraw(self): start = time() v = self.sampling_spin.value() x = self.colors[v][:, self.xaxis_combo.currentIndex()] y = self.colors[v][:, self.yaxis_combo.currentIndex()] xlim = self.axes.get_xlim() ylim = self.axes.get_ylim() s = self.size_spin.value()**2 c = None if not self.colors_check.isChecked( ) else self.colors[v][:, :3] a = self.alpha_spin.value() m = self.markers[self.style_combo.currentIndex()] self.axes.clear() self.axes.set_facecolor([0.5] * 3 if c is not None else [1.0] * 3) self.axes.scatter(x, y, s, c, m, alpha=a) self.axes.set_xlabel(self.xaxis_combo.currentText()) self.axes.set_ylabel(self.yaxis_combo.currentText()) self.axes.grid(self.grid_check.isChecked(), which='both') self.axes.set_xlim(xlim) self.axes.set_ylim(ylim) self.axes.figure.canvas.draw() self.total_label.setText(self.tr('[{} points]'.format(len(x)))) self.info_message.emit('Plot redraw = {}'.format(elapsed_time(start)))
class SubtitleInfoDialog(QDialog): def __init__(self, subtitle_name="Test", subtitle_delay=0.0, subtitle_language=Default_Subtitle_Language, subtitle_track_name="Test", subtitle_set_default=False, subtitle_set_forced=False, subtitle_default_value_delay=0.0, subtitle_default_value_language=Default_Subtitle_Language, subtitle_default_value_track_name="Test", subtitle_default_value_set_default=False, subtitle_default_value_set_forced=False, subtitle_set_default_disabled=False, subtitle_set_forced_disabled=False, disable_edit=False, parent=None): super().__init__(parent) self.window_title = "Subtitle Info" self.state = "no" self.messageIcon = QLabel() self.disable_edit = disable_edit self.current_subtitle_language = str(subtitle_language) self.current_subtitle_delay = str(subtitle_delay) self.current_subtitle_track_name = str(subtitle_track_name) self.current_subtitle_set_default = subtitle_set_default self.current_subtitle_set_forced = subtitle_set_forced self.default_subtitle_language = str(subtitle_default_value_language) self.default_subtitle_delay = str(subtitle_default_value_delay) self.default_subtitle_track_name = str( subtitle_default_value_track_name) self.default_subtitle_set_default = subtitle_default_value_set_default self.default_subtitle_set_forced = subtitle_default_value_set_forced self.subtitle_set_default_disabled = subtitle_set_default_disabled self.subtitle_set_forced_disabled = subtitle_set_forced_disabled self.subtitle_name_label = QLabel("Subtitle Name:") self.subtitle_name_value = QLabel(str(subtitle_name)) self.subtitle_delay_label = QLabel("Subtitle Delay:") self.subtitle_delay_spin = QDoubleSpinBox() self.setup_subtitle_delay_spin() self.subtitle_language_label = QLabel("Subtitle Language:") self.subtitle_language_comboBox = QComboBox() self.setup_subtitle_language_comboBox() self.subtitle_track_name_label = QLabel("Subtitle Track Name:") self.subtitle_track_name_lineEdit = QLineEdit() self.setup_subtitle_track_name_lineEdit() self.subtitle_set_forced_label = QLabel("Subtitle Forced State:") self.subtitle_set_forced_checkBox = QCheckBox() self.setup_subtitle_set_forced_checkBox() self.subtitle_set_default_label = QLabel("Subtitle Default State:") self.subtitle_set_default_checkBox = QCheckBox() self.setup_subtitle_set_default_checkBox() self.yes_button = QPushButton("OK") self.no_button = QPushButton("Cancel") self.reset_button = QPushButton("Reset To Default") self.buttons_layout = QHBoxLayout() self.subtitle_delay_layout = QHBoxLayout() self.subtitle_language_layout = QHBoxLayout() self.subtitle_track_name_layout = QHBoxLayout() self.subtitle_set_default_layout = QHBoxLayout() self.subtitle_set_forced_layout = QHBoxLayout() self.buttons_layout.addWidget(QLabel(""), stretch=3) self.buttons_layout.addWidget(self.reset_button, stretch=2) self.buttons_layout.addWidget(self.yes_button, stretch=2) self.buttons_layout.addWidget(self.no_button, stretch=2) self.buttons_layout.addWidget(QLabel(""), stretch=3) self.subtitle_setting_layout = QGridLayout() self.subtitle_changeble_setting_layout = QFormLayout() self.subtitle_changeble_setting_layout.addRow(self.subtitle_name_label, self.subtitle_name_value) self.subtitle_changeble_setting_layout.addRow( self.subtitle_track_name_label, self.subtitle_track_name_lineEdit) self.subtitle_changeble_setting_layout.addRow( self.subtitle_language_label, self.subtitle_language_comboBox) self.subtitle_changeble_setting_layout.addRow( self.subtitle_delay_label, self.subtitle_delay_spin) self.subtitle_changeble_setting_layout.addRow( self.subtitle_set_default_label, self.subtitle_set_default_checkBox) self.subtitle_changeble_setting_layout.addRow( self.subtitle_set_forced_label, self.subtitle_set_forced_checkBox) self.subtitle_setting_layout.addLayout( self.subtitle_changeble_setting_layout, 0, 0, 5, 2) self.subtitle_setting_layout.addWidget(self.messageIcon, 0, 3, 5, -1) self.main_layout = QGridLayout() self.main_layout.addLayout(self.subtitle_setting_layout, 0, 0, 2, 3) self.main_layout.addLayout(self.buttons_layout, 2, 0, 1, -1) self.main_layout.setContentsMargins(20, 20, 20, 20) self.setLayout(self.main_layout) self.setup_ui() self.signal_connect() def setup_ui(self): self.disable_question_mark_window() self.messageIcon.setPixmap( QtGui.QPixmap(GlobalFiles.SubtitleIconPath).scaledToHeight(100)) self.set_dialog_values() self.set_default_buttons() if self.subtitle_set_default_disabled: self.subtitle_set_default_disable() if self.subtitle_set_forced_disabled: self.subtitle_set_forced_disable() if self.disable_edit: self.subtitle_track_name_lineEdit.setEnabled(False) self.subtitle_language_comboBox.setEnabled(False) self.subtitle_delay_spin.setEnabled(False) self.subtitle_set_default_checkBox.setEnabled(False) self.subtitle_set_forced_checkBox.setEnabled(False) self.reset_button.setEnabled(False) self.setup_tool_tip_hint_subtitle_set_default() self.setup_tool_tip_hint_subtitle_set_forced() def signal_connect(self): self.subtitle_track_name_lineEdit.textEdited.connect( self.update_current_subtitle_track_name) self.subtitle_delay_spin.editingFinished.connect( self.update_current_subtitle_delay) self.subtitle_language_comboBox.currentTextChanged.connect( self.update_current_subtitle_language) self.subtitle_set_default_checkBox.stateChanged.connect( self.update_current_subtitle_set_default) self.subtitle_set_forced_checkBox.stateChanged.connect( self.update_current_subtitle_set_forced) self.yes_button.clicked.connect(self.click_yes) self.no_button.clicked.connect(self.click_no) self.reset_button.clicked.connect(self.reset_subtitle_setting) def click_yes(self): self.state = "yes" self.close() def click_no(self): self.close() def set_dialog_values(self): self.setWindowTitle(self.window_title) self.setWindowIcon(GlobalFiles.InfoSettingIcon) def disable_question_mark_window(self): self.setWindowFlag(Qt.WindowContextHelpButtonHint, on=False) def increase_message_font_size(self, value): message_font = self.message.font() message_font.setPointSize(self.message.fontInfo().pointSize() + value) self.message.setFont(message_font) def set_default_buttons(self): self.yes_button.setDefault(True) self.yes_button.setFocus() def showEvent(self, a0: QtGui.QShowEvent) -> None: super().showEvent(a0) self.setFixedSize(self.size()) def setup_subtitle_track_name_lineEdit(self): self.subtitle_track_name_lineEdit.setClearButtonEnabled(True) self.subtitle_track_name_lineEdit.setText( self.current_subtitle_track_name) def setup_subtitle_language_comboBox(self): self.subtitle_language_comboBox.addItems(AllSubtitlesLanguages) self.subtitle_language_comboBox.setCurrentIndex( AllSubtitlesLanguages.index(self.current_subtitle_language)) self.subtitle_language_comboBox.setMaxVisibleItems(8) self.subtitle_language_comboBox.setStyleSheet( "QComboBox { combobox-popup: 0; }") def setup_subtitle_delay_spin(self): # self.subtitle_delay_spin.setMaximumWidth(screen_size.width() // 16) self.subtitle_delay_spin.setDecimals(3) self.subtitle_delay_spin.setMinimum(-9999.0) self.subtitle_delay_spin.setMaximum(9999.0) self.subtitle_delay_spin.setSingleStep(0.5) self.subtitle_delay_spin.setValue(float(self.current_subtitle_delay)) def setup_subtitle_set_default_checkBox(self): self.subtitle_set_default_checkBox.setText("Set Default") self.subtitle_set_default_checkBox.setChecked( bool(self.current_subtitle_set_default)) def setup_subtitle_set_forced_checkBox(self): self.subtitle_set_forced_checkBox.setText("Set Forced") self.subtitle_set_forced_checkBox.setChecked( bool(self.current_subtitle_set_forced)) def update_current_subtitle_track_name(self): self.current_subtitle_track_name = str( self.subtitle_track_name_lineEdit.text()) def update_current_subtitle_delay(self): self.current_subtitle_delay = round(self.subtitle_delay_spin.value(), 5) def update_current_subtitle_language(self): self.current_subtitle_language = str( self.subtitle_language_comboBox.currentText()) def update_current_subtitle_set_default(self): self.current_subtitle_set_default = ( self.subtitle_set_default_checkBox.checkState() == Qt.Checked) def update_current_subtitle_set_forced(self): self.current_subtitle_set_forced = ( self.subtitle_set_forced_checkBox.checkState() == Qt.Checked) def reset_subtitle_setting(self): self.current_subtitle_language = self.default_subtitle_language self.current_subtitle_delay = self.default_subtitle_delay self.current_subtitle_track_name = self.default_subtitle_track_name self.current_subtitle_set_default = self.default_subtitle_set_default self.current_subtitle_set_forced = self.default_subtitle_set_forced self.subtitle_language_comboBox.setCurrentIndex( AllSubtitlesLanguages.index(self.current_subtitle_language)) self.subtitle_delay_spin.setValue(float(self.current_subtitle_delay)) self.subtitle_track_name_lineEdit.setText( self.current_subtitle_track_name) self.subtitle_set_default_checkBox.setChecked( bool(self.current_subtitle_set_default)) self.subtitle_set_forced_checkBox.setChecked( bool(self.current_subtitle_set_forced)) def subtitle_set_default_disable(self): self.subtitle_set_default_checkBox.setDisabled(True) def subtitle_set_forced_disable(self): self.subtitle_set_forced_checkBox.setDisabled(True) def setup_tool_tip_hint_subtitle_set_default(self): if self.subtitle_set_default_checkBox.isEnabled(): self.subtitle_set_default_checkBox.setToolTip( "<nobr>set this subtitle to be the default subtitle track " "when play") self.subtitle_set_default_checkBox.setToolTipDuration(12000) else: self.subtitle_set_default_checkBox.setToolTip( "<nobr>set this subtitle to be the default subtitle track when play<br><b>Disabled</b> because " "option " "<b>make this subtitle default</b> is enabled on mux setting tab " ) self.subtitle_set_default_checkBox.setToolTipDuration(12000) def setup_tool_tip_hint_subtitle_set_forced(self): if self.subtitle_set_forced_checkBox.isEnabled(): self.subtitle_set_forced_checkBox.setToolTip( "<nobr>set this subtitle to be the forced subtitle track when " "play") self.subtitle_set_forced_checkBox.setToolTipDuration(12000) else: self.subtitle_set_forced_checkBox.setToolTip( "<nobr>set this subtitle to be the forced subtitle track when play<br><b>Disabled</b> because " "option " "<b>make this subtitle default and forced</b> is enabled on mux setting tab " ) self.subtitle_set_forced_checkBox.setToolTipDuration(12000) def execute(self): self.exec_()
def __init_slicer_options_widget__(self): self.__slicer_options_widget = QGroupBox("Slicer Options", self) thickness_label = QLabel("Layer Thickness", self.__slicer_options_widget) thickness_edit = QDoubleSpinBox(self.__slicer_options_widget) thickness_edit.setSuffix(str('\u03BCm')) thickness_edit.setMaximum(1000000) thickness_edit.setMinimum(0) thickness_edit.setDecimals(3) thickness_edit.setSingleStep(0.001) thickness_edit.setValue(self.dlp_controller.support_thickness * 1000) # self.__opengl_widget.set_slice_thickness(self.dlp_controller.support_thickness) thickness_edit.valueChanged.connect( self.__slicer_widget.set_slice_thickness) pixel_size_label = QLabel("Projector Pixel Size", self.__slicer_options_widget) pixel_size_edit = QDoubleSpinBox(self.__slicer_options_widget) pixel_size_edit.setSuffix(str('\u03BCm')) pixel_size_edit.setMaximum(1000000) pixel_size_edit.setMinimum(0) pixel_size_edit.setDecimals(2) pixel_size_edit.setSingleStep(0.01) pixel_size_edit.setValue(self.dlp_controller.projector_pixel_size * 1000) pixel_size_edit.valueChanged.connect( self.__slicer_widget.set_pixel_size) projector_resolution_label = QLabel("Projector Resolution", self.__slicer_options_widget) projector_resolution_edit_x = QSpinBox(self.__slicer_options_widget) projector_resolution_edit_x.setSuffix(str('W')) projector_resolution_edit_x.setMaximum(1000000) projector_resolution_edit_x.setMinimum(0) projector_resolution_edit_x.setValue( self.dlp_controller.projector_width) projector_resolution_edit_x.valueChanged.connect( self.__slicer_widget.set_projector_width) projector_resolution_edit_y = QSpinBox(self.__slicer_options_widget) projector_resolution_edit_y.setSuffix(str('H')) projector_resolution_edit_y.setMaximum(1000000) projector_resolution_edit_y.setMinimum(0) projector_resolution_edit_y.setValue( self.dlp_controller.projector_height) projector_resolution_edit_y.valueChanged.connect( self.__slicer_widget.set_projector_height) samples_per_pixel_label = QLabel("Samples per Pixel", self.__slicer_options_widget) samples_per_pixel_edit = QSpinBox(self.__slicer_options_widget) samples_per_pixel_edit.setMaximum(1000000) samples_per_pixel_edit.setMinimum(1) samples_per_pixel_edit.setValue(self.dlp_controller.samples_per_pixel) samples_per_pixel_edit.valueChanged.connect( self.__slicer_widget.set_samples_per_pixel) slice_geometry_button = QPushButton("Slice Geometry") slice_geometry_button.clicked.connect(self.start_slicing_process) slice_interrupt_button = QPushButton("Stop Slicing") slice_interrupt_button.clicked.connect( self.__slicer_widget.interrupt_slicing) self.slices_label = QLabel(f'Slicing progress: {0:.0f}/{0:.0f}', self.__info_widget) thickness_label_row = 0 pixel_size_row = 1 projector_resolution_row = 2 samples_per_pixel_row = 3 slice_button_row = 4 slices_label_row = 5 # slice_interrupt_row = slice_button_row slice_layout = QGridLayout(self.__slicer_options_widget) slice_layout.addWidget(thickness_label, thickness_label_row, 0) slice_layout.addWidget(thickness_edit, thickness_label_row, 1) slice_layout.addWidget(pixel_size_label, pixel_size_row, 0) slice_layout.addWidget(pixel_size_edit, pixel_size_row, 1) slice_layout.addWidget(projector_resolution_label, projector_resolution_row, 0) slice_layout.addWidget(projector_resolution_edit_x, projector_resolution_row, 1) slice_layout.addWidget(projector_resolution_edit_y, projector_resolution_row, 2) slice_layout.addWidget(self.slices_label, slice_button_row, 0) slice_layout.addWidget(slice_geometry_button, slice_button_row, 1) slice_layout.addWidget(slice_interrupt_button, slice_button_row, 2) slice_layout.addWidget(samples_per_pixel_label, samples_per_pixel_row, 0) slice_layout.addWidget(samples_per_pixel_edit, samples_per_pixel_row, 1) self.__slicer_options_widget.setLayout(slice_layout)