def _setupConfigurationWidget(self): statebutton_Test = PyDMStateButton( self, self.dcct_prefix.substitute(propty='Test-Sel')) statebutton_Test.shape = 1 statebutton_Test.setStyleSheet('min-width:6em; max-width:6em;') label_Test = PyDMLabel(self, self.dcct_prefix.substitute(propty='Test-Sts')) hlay_test = QHBoxLayout() hlay_test.addWidget(statebutton_Test) hlay_test.addWidget(label_Test) self.bt_dl = PyDMPushButton( parent=self, pressValue=1, icon=qta.icon('fa5s.sync'), init_channel=self.dcct_prefix.substitute(propty='Download-Cmd')) self.bt_dl.setObjectName('bt_dl') self.bt_dl.setStyleSheet( '#bt_dl{min-width:25px; max-width:25px; icon-size:20px;}') gbox_test = QGroupBox('Configurations') lay = QFormLayout(gbox_test) lay.setLabelAlignment(Qt.AlignRight) lay.setFormAlignment(Qt.AlignCenter) lay.addRow('Enable test current: ', hlay_test) lay.addRow('Download Configurations: ', self.bt_dl) return gbox_test
def __init__(self, parent=None): QWidget.__init__(self) self.tfPlot = TransferFunctionPlot() self.modelCombo = QComboBox() self.modelCombo.addItems(AvailableModels) self.quantityCombo = QComboBox() self.quantityCombo.addItems(['Impedance', 'Admittance']) self.fMinSb = QDoubleSpinBox() self.fMinSb.setRange(0.1, 1E6) self.fMaxSb = QDoubleSpinBox() self.fMaxSb.setRange(10, 1E6) self.fMinSb.setKeyboardTracking(False) self.fMaxSb.setKeyboardTracking(False) self.fMinSb.valueChanged.connect(self.fMinSb.setMinimum) self.fMaxSb.valueChanged.connect(self.fMaxSb.setMaximum) self.fMinSb.setValue(1) self.fMaxSb.setValue(250E3) self.shuntSb = QDoubleSpinBox() self.shuntSb.setDecimals(4) self.shuntSb.setKeyboardTracking(False) self.shuntSb.setRange(0.010, 10) self.shuntSb.setSuffix(u' m\u03A9') self.shuntSb.setValue(0.257) l = QFormLayout() l.addRow('Model', self.modelCombo) l.addRow('Quantity', self.quantityCombo) l.addRow('f (min)', self.fMinSb) l.addRow('f (max)', self.fMaxSb) l.addRow('Shunt resistance', self.shuntSb) self.setLayout(l)
class AttributesWidget(QWidget): """Shows info about device.""" def __init__(self, bot, parent): super(AttributesWidget, self).__init__(parent) self.bot = bot self.widgets = [] self.widget_layout = QHBoxLayout(self) self.setLayout(self.widget_layout) # widget with labels self.info_widget = QWidget(self) self.info_widget_layout = QFormLayout(self.info_widget) self.info_widget.setLayout(self.info_widget_layout) self.widget_layout.addWidget(self.info_widget) # widget with actions - remote shell, powershell, remote screen... self.actions_widget = QWidget(self) self.actions_widget_layout = QFormLayout(self.actions_widget) self.actions_widget.setLayout(self.actions_widget_layout) @Slot(Bot) def update_attributes(self, bot): # update labels with info about bot self.widgets.clear() for var, val in vars(bot).items(): label = QLabel(self.info_widget) label.setText(" ".join(var.split("_")).capitalize()) field = QLabel(self.info_widget) field.setText(str(val)) self.widgets.append({"label": label, "field": field}) self.info_widget_layout.addRow(label, field)
def setupUi(self, lista, query): formLayout = QFormLayout() groupBox = QGroupBox(f"Resultado de la búsqueda: {query}") labelLis = [] comboList = [] for i in range(len(lista)): f = open(lista[i]['name'], 'r', encoding='utf-8') jsonData = json.loads(f.read()) f.close() labelLis.append( QLabel( f'{jsonData["title"]} --- {round(float(lista[i]["distance"])*100, 2)}% --- {jsonData["categoria"]}' )) buttonOpen = QPushButton("Abrir noticia") buttonOpen.clicked.connect(self.make_openFile(lista[i]["name"])) comboList.append(buttonOpen) formLayout.addRow(labelLis[i], comboList[i]) groupBox.setLayout(formLayout) scroll = QScrollArea(self) scroll.setWidget(groupBox) scroll.setWidgetResizable(True) scroll.setMinimumHeight(600) scroll.setMinimumWidth(1200) layout = QVBoxLayout(self) layout.addWidget(scroll) self.setWindowTitle("Noticias") self.resize(1200, 600) self.show() self.exec_()
def __init__(self, parent=None): super().__init__(parent=parent) self.animation = self.parentWidget().animation self._layout = QFormLayout(parent=self) self._init_steps() self._init_ease() self._add_callbacks()
def _specViewLayout(self): dev = self.device.substitute(dev='TuneProc') # Mode lbl_mode = QLabel('Mode', self) self.cb_mode = PyDMEnumComboBox(self, dev.substitute(propty='SpecMode-Sel')) self.lb_mode = PyDMLabel(self, dev.substitute(propty='SpecMode-Sts')) hbox_mode = QHBoxLayout() hbox_mode.addWidget(self.cb_mode) hbox_mode.addWidget(self.lb_mode) # Time window lbl_timewdw = QLabel('Time Window [ms]', self) self.le_timewdw = PyDMLineEdit(self, dev.substitute(propty='SpecTime-SP')) self.le_timewdw.precisionFromPV = True self.lb_timewdw = PyDMLabel(self, dev.substitute(propty='SpecTime-RB')) hbox_timewdw = QHBoxLayout() hbox_timewdw.addWidget(self.le_timewdw) hbox_timewdw.addWidget(self.lb_timewdw) lay = QFormLayout() lay.setLabelAlignment(Qt.AlignRight) lay.setFormAlignment(Qt.AlignCenter) lay.addRow(lbl_mode, hbox_mode) lay.addRow(lbl_timewdw, hbox_timewdw) return lay
def create_controls(self): self.setWindowTitle(tr(self.plugin.name)) vbox = QVBoxLayout() form = QFormLayout() for Name, (enabled, url) in self.packages.items(): name = Name.lower() cbo = QComboBox() if enabled: branches = get_branches(name, url) for n, b in branches.items(): cbo.addItem(n, b) if not check_git_repo(name): cbo.insertItem(0, "<Select to change>", None) cbo.setCurrentIndex(0) self._prev_indices[cbo] = 0 cbo.currentIndexChanged.connect( partial(self._cbo_changed, cbo)) else: cbo.setEditText("<git repository>") cbo.setToolTip(tr( "This is installed in a git repository but we're set to " "not use git.")) cbo.setEnabled(enabled) form.addRow(Name + ':', cbo) vbox.addLayout(form) vbox.addWidget(QLabel(tr( "You should restart the application if you make any changes!"))) btns = QDialogButtonBox(QDialogButtonBox.Ok, Qt.Horizontal, self) btns.accepted.connect(self.accept) vbox.addWidget(btns) self.setLayout(vbox)
def __init__(self): QDialog.__init__(self) # setup UI self.form = QFormLayout(self) self.editPosition = QLineEdit('') self.form.addRow(QLabel('Position'), self.editPosition) self.editVelocity = QLineEdit('') self.form.addRow(QLabel('Velocity'), self.editVelocity) # configure network (take first available servo) self._net, self._servo = il.lucky(il.NET_PROT.EUSB) # create data model model = QStandardItemModel() pos = QStandardItem() vel = QStandardItem() model.appendRow([pos, vel]) # configure and start watcher self._watcher = RegisterWatcher(self._servo) self._watcher.add(POS_ACT, 500, pos) self._watcher.add(VEL_ACT, 100, vel) self._watcher.start(100) # map model fields to widgets self._mapper = QDataWidgetMapper() self._mapper.setModel(model) self._mapper.addMapping(self.editPosition, 0) self._mapper.addMapping(self.editVelocity, 1) self._mapper.toFirst()
def __init__(self): SimulationConfigPanel.__init__(self, EnsembleExperiment) layout = QFormLayout() self._case_selector = CaseSelector() layout.addRow("Current case:", self._case_selector) run_path_label = QLabel("<b>%s</b>" % getRunPath()) addHelpToWidget(run_path_label, "config/simulation/runpath") layout.addRow("Runpath:", run_path_label) number_of_realizations_label = QLabel("<b>%d</b>" % getRealizationCount()) addHelpToWidget(number_of_realizations_label, "config/ensemble/num_realizations") layout.addRow(QLabel("Number of realizations:"), number_of_realizations_label) self._active_realizations_field = StringBox( ActiveRealizationsModel(), "config/simulation/active_realizations", ) self._active_realizations_field.setValidator( RangeStringArgument(getRealizationCount()), ) layout.addRow("Active realizations", self._active_realizations_field) self.setLayout(layout) self._active_realizations_field.getValidationSupport( ).validationChanged.connect(self.simulationConfigurationChanged) self._case_selector.currentIndexChanged.connect( self._realizations_from_fs) self._realizations_from_fs() # update with the current case
def __init__(self, parent=None): super(UiUnitChangeDialog, self).__init__(parent) # Dialog settings self.setWindowTitle("Change Plot Units") self.layout_vertical = QVBoxLayout(self) self.form_layout = QFormLayout() self.layout_vertical.addLayout(self.form_layout) # Flux unit self.label_flux_unit = QLabel(self) self.line_edit_flux_unit = QLineEdit(self) self.label_flux_unit.setText("Flux Unit") self.form_layout.addRow(self.label_flux_unit, self.line_edit_flux_unit) # Dispersion unit self.label_disp_unit = QLabel(self) self.line_edit_disp_unit = QLineEdit(self) self.label_disp_unit.setText("Dispersion Unit") self.form_layout.addRow(self.label_disp_unit, self.line_edit_disp_unit) self.button_box = QDialogButtonBox(self) self.button_box.setOrientation(Qt.Horizontal) self.button_box.setStandardButtons(QDialogButtonBox.Cancel | QDialogButtonBox.Ok) self.layout_vertical.addWidget(self.button_box) self.button_box.accepted.connect(self.accept) self.button_box.rejected.connect(self.reject)
def __init__(self, main_display, parent=None): super(AxisSettingsDisplay, self).__init__(parent=parent) self.main_layout = QFormLayout() self.main_display = main_display self.chart = self.main_display.chart self.app = self.main_display.app self.x_axis_lbl = QLabel("x-axis Label") self.x_axis_label_line_edt = QLineEdit() current_x_label = self.chart.labels["bottom"] if current_x_label: current_x_label = current_x_label[current_x_label. find(X_AXIS_LABEL_SEPARATOR) + len(X_AXIS_LABEL_SEPARATOR):] self.x_axis_label_line_edt.setText(current_x_label) self.x_axis_label_line_edt.textChanged.connect( partial(self.handle_axis_label_change, "bottom")) self.x_axis_unit_lbl = QLabel("x-axis Unit") self.x_axis_unit_edt = QLineEdit() self.x_axis_unit_edt.setText(self.chart.units["bottom"]) self.x_axis_unit_edt.textChanged.connect( partial(self.handle_axis_label_change, "bottom", is_unit=True)) self.y_axis_lbl = QLabel("y-axis Label") self.y_axis_label_line_edt = QLineEdit() self.y_axis_label_line_edt.setText(self.chart.labels["left"]) self.y_axis_label_line_edt.textChanged.connect( partial(self.handle_axis_label_change, "left")) self.y_axis_unit_lbl = QLabel("y-axis Unit") self.y_axis_unit_edt = QLineEdit() self.y_axis_unit_edt.setText(self.chart.units["left"]) self.y_axis_unit_edt.textChanged.connect( partial(self.handle_axis_label_change, "left", is_unit=True)) self.right_y_axis_label_line_edt = QLineEdit() self.right_y_axis_lbl = QLabel("Right y-axis Label") self.display_right_y_axis_chk = QCheckBox("Display the right y-axis") self.display_right_y_axis_chk.setChecked(self.chart.getShowRightAxis()) self.display_right_y_axis_chk.clicked.connect( self.handle_right_y_axis_checkbox_changed) self.display_right_y_axis_chk.setChecked(self.chart.getShowRightAxis()) self.right_y_axis_lbl = None self.right_y_axis_unit_edt = None self.right_y_axis_unit_lbl = None self.right_y_axis_unit_edt = None self.close_dialog_btn = QPushButton("Close") self.close_dialog_btn.clicked.connect(self.handle_close_button_clicked) self.setWindowTitle("Axis Settings") self.setFixedSize(QSize(300, 250)) self.setWindowModality(Qt.ApplicationModal) self.setup_ui()
def __init__(self, parent): super(GUIConfigFrame, self).__init__(parent) self.widget_layout = QVBoxLayout(self) self.setLayout(self.widget_layout) self.gui_conf_label = QLabel(self) self.gui_conf_label.setText("GUI server configuration") self.widget_layout.addWidget(self.gui_conf_label) self.desc_label = QLabel(self) self.desc_label.setWordWrap(True) self.desc_label.setText( "QtPyBotnet GUI if fully remote. This means that you can connect to C2 server and " "manage bots wherever you are. To authenticate when connecting to GUI server use the " "key below.") self.widget_layout.addWidget(self.desc_label) self.gui_config = QWidget(self) self.gui_config_layout = QFormLayout(self.gui_config) self.widget_layout.addWidget(self.gui_config) self.gui_ip_label = QLabel(self.gui_config) self.gui_ip_label.setObjectName("gui_ip_label") self.gui_ip_label.setText("GUI IP Address") self.gui_ip_combo = QComboBox(self.gui_config) self.gui_config_layout.addRow(self.gui_ip_label, self.gui_ip_combo) self.gui_port_label = QLabel(self.gui_config) self.gui_port_label.setObjectName("gui_port_label") self.gui_port_label.setText("GUI Port") self.gui_port_edit = QSpinBox(self.gui_config) self.gui_port_edit.setObjectName("gui_port_spin") self.gui_port_edit.setRange(1024, 65535) self.gui_port_edit.setValue(15692) self.gui_config_layout.addRow(self.gui_port_label, self.gui_port_edit) self.gui_key_label = QLabel(self.gui_config) self.gui_key_label.setObjectName("gui_key_label") self.gui_key_label.setText("GUI encryption key") self.gui_key_edit = QLineEdit(self.gui_config) self.gui_key_edit.setObjectName("gui_key_edit") self.gui_key_edit.setReadOnly(True) self.gui_config_layout.addRow(self.gui_key_label, self.gui_key_edit) self.gmaps_key_label = QLabel(self.gui_config) self.gmaps_key_label.setObjectName("gmaps_key_label") self.gmaps_key_label.setText("Google Maps API key") self.gmap_key_edit = QLineEdit(self.gui_config) self.gmap_key_edit.setObjectName("gmap_key_edit") self.gui_config_layout.addRow(self.gmaps_key_label, self.gmap_key_edit) spacerItem = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding) self.widget_layout.addItem(spacerItem)
def create_controls(self): """ Create UI controls. """ vbox = QVBoxLayout() form = QFormLayout() self.num_angle = QDoubleSpinBox() self.num_angle.setValue(0.0) self.num_angle.setMinimum(-360) self.num_angle.setMaximum(360) form.addRow(tr("Angle:"), self.num_angle) vbox.addLayout(form) self.gbo_preview = QGroupBox(tr("Preview")) self.gbo_preview.setCheckable(True) self.gbo_preview.setChecked(False) gbo_vbox = QVBoxLayout() self.chk_grid = QCheckBox(tr("Grid")) self.chk_grid.setChecked(False) self.num_grid = QSpinBox() self.num_grid.setValue(4) self.num_grid.setMinimum(1) self.num_grid.setEnabled(False) self.chk_grid.toggled[bool].connect(self.num_grid.setEnabled) gbo_vbox.addWidget(self.chk_grid) gbo_vbox.addWidget(self.num_grid) self.gbo_preview.setLayout(gbo_vbox) vbox.addWidget(self.gbo_preview) self.gbo_preview.toggled[bool].connect(self.set_preview) self.gbo_output = QGroupBox(tr("Output")) self.opt_new = QRadioButton(tr("New signal")) self.opt_replace = QRadioButton(tr("In place")) self.opt_new.setChecked(True) gbo_vbox2 = QVBoxLayout() gbo_vbox2.addWidget(self.opt_new) gbo_vbox2.addWidget(self.opt_replace) self.gbo_output.setLayout(gbo_vbox2) vbox.addWidget(self.gbo_output) self.chk_reshape = QCheckBox(tr("Resize to fit")) self.chk_reshape.setChecked(False) vbox.addWidget(self.chk_reshape) self.btn_ok = QPushButton(tr("&OK")) self.btn_ok.setDefault(True) self.btn_ok.clicked.connect(self.accept) self.btn_cancel = QPushButton(tr("&Cancel")) self.btn_cancel.clicked.connect(self.reject) hbox = QHBoxLayout() hbox.addWidget(self.btn_ok) hbox.addWidget(self.btn_cancel) vbox.addLayout(hbox) vbox.addStretch(1) self.setLayout(vbox)
def setupUi(self): self.resize(350, 280) self.gridLayout = QGridLayout(self) self.levelNameLabel = QLabel("Level name", self) self.gridLayout.addWidget(self.levelNameLabel, 0, 0) self.levelNameLine = QLineEdit(self) self.gridLayout.addWidget(self.levelNameLine, 1, 0, 1, 0) self.groupBox = QGroupBox("Light mode", self) self.gridLayout.addWidget(self.groupBox, 2, 0) self.groupBoxDark = QGroupBox("Dark mode", self) self.gridLayout.addWidget(self.groupBoxDark, 2, 1) self.formLayout = QFormLayout(self.groupBox) self.groupBox.setLayout(self.formLayout) self.fgColorPreview = QLineEdit(self) self.formLayout.addRow("Foreground", self.fgColorPreview) self.bgColorPreview = QLineEdit(self) self.formLayout.addRow("Background", self.bgColorPreview) self.boldCheckBox = QCheckBox(self.groupBox) self.formLayout.addRow("Bold", self.boldCheckBox) self.italicCheckBox = QCheckBox(self.groupBox) self.formLayout.addRow("Italic", self.italicCheckBox) self.underlineCheckBox = QCheckBox(self.groupBox) self.formLayout.addRow("Underline", self.underlineCheckBox) self.formLayoutDark = QFormLayout(self.groupBoxDark) self.groupBoxDark.setLayout(self.formLayoutDark) self.fgColorPreviewDark = QLineEdit(self) self.formLayoutDark.addRow("Foreground", self.fgColorPreviewDark) self.bgColorPreviewDark = QLineEdit(self) self.formLayoutDark.addRow("Background", self.bgColorPreviewDark) self.boldCheckBoxDark = QCheckBox(self.groupBoxDark) self.formLayoutDark.addRow("Bold", self.boldCheckBoxDark) self.italicCheckBoxDark = QCheckBox(self.groupBox) self.formLayoutDark.addRow("Italic", self.italicCheckBoxDark) self.underlineCheckBoxDark = QCheckBox(self.groupBox) self.formLayoutDark.addRow("Underline", self.underlineCheckBoxDark) self.spacer = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding) self.gridLayout.addItem(self.spacer, 3, 0, 1, 2) self.previewLabel = QLabel("Preview", self) self.gridLayout.addWidget(self.previewLabel, 4, 0, 1, 2) self.previewLine = QLineEdit(self) self.gridLayout.addWidget(self.previewLine, 5, 0) self.previewLineDark = QLineEdit(self) self.gridLayout.addWidget(self.previewLineDark, 5, 1) buttons = QDialogButtonBox.Reset | QDialogButtonBox.Save | QDialogButtonBox.Cancel self.buttonBox = QDialogButtonBox(buttons, self) self.resetButton = self.buttonBox.button(QDialogButtonBox.Reset) self.gridLayout.addWidget(self.buttonBox, 6, 0, 1, 2) self.setup_widget_attributes() self.setup_widget_connections()
def __init__( self, title="Title", description="Description", unique_names=None, choose_from_list=False, ): QDialog.__init__(self) self.setModal(True) self.setWindowTitle(title) # self.setMinimumWidth(250) # self.setMinimumHeight(150) if unique_names is None: unique_names = [] self.unique_names = unique_names self.choose_from_list = choose_from_list self.layout = QFormLayout() self.layout.setSizeConstraint(QLayout.SetFixedSize) label = QLabel(description) label.setAlignment(Qt.AlignHCenter) self.layout.addRow(self.createSpace(5)) self.layout.addRow(label) self.layout.addRow(self.createSpace(10)) buttons = QDialogButtonBox( QDialogButtonBox.Ok | QDialogButtonBox.Cancel, Qt.Horizontal, self) self.ok_button = buttons.button(QDialogButtonBox.Ok) self.ok_button.setEnabled(False) if choose_from_list: self.param_name_combo = QComboBox() self.param_name.currentIndexChanged.connect(self.validateChoice) for item in unique_names: self.param_name_combo.addItem(item) self.layout.addRow("Job:", self.param_name_combo) else: self.param_name = QLineEdit(self) self.param_name.setFocus() self.param_name.textChanged.connect(self.validateName) self.validColor = self.param_name.palette().color( self.param_name.backgroundRole()) self.layout.addRow("Name:", self.param_name) self.layout.addRow(self.createSpace(10)) self.layout.addRow(buttons) buttons.accepted.connect(self.accept) buttons.rejected.connect(self.reject) self.setLayout(self.layout)
def featuresWidget(self): features = QWidget() featuresLayout = QFormLayout() featuresLayout.setSpacing(5) featuresLayout.addRow(self.bookLabel, self.bookFeatures()) featuresLayout.addRow(self.chapterLabel, self.chapterFeatures()) featuresLayout.addRow(self.verseLabel, self.verseFeatures()) features.setLayout(featuresLayout) return features
def __init__(self, parent): super(TaskKwargsGroupBox, self).__init__(parent) self.widgets = [] self.current_task = None self.widget_layout = QFormLayout(self) self.setLayout(self.widget_layout) self.setTitle("Options")
class FrameWidget(QWidget): """Widget for interatviely making animations using the napari viewer.""" def __init__(self, parent=None): super().__init__(parent=parent) self.animation = self.parentWidget().animation self._layout = QFormLayout(parent=self) self._init_steps() self._init_ease() self._add_callbacks() def _init_steps(self): self.stepsSpinBox = QSpinBox() self.stepsSpinBox.setRange(1, 100000) self.stepsSpinBox.setValue(15) self._layout.addRow("Steps", self.stepsSpinBox) def _init_ease(self): self.easeComboBox = QComboBox() self.easeComboBox.addItems([e.name.lower() for e in Easing]) index = self.easeComboBox.findText("linear", Qt.MatchFixedString) self.easeComboBox.setCurrentIndex(index) self._layout.addRow("Ease", self.easeComboBox) def get_easing_func(self): easing_name = str(self.easeComboBox.currentText()) return Easing[easing_name.upper()] def update_from_animation(self): """update state of self to reflect animation state at current key frame""" self._update_steps_spin_box() self._update_ease_combo_box() def _update_steps_spin_box(self): """update state of steps spin box to reflect animation state at current key frame""" self.stepsSpinBox.setValue(self.animation.current_key_frame.steps) def _update_animation_steps(self, event): """update state of 'steps' at current key-frame to reflect GUI state""" self.animation.current_key_frame.steps = self.stepsSpinBox.value() def _update_ease_combo_box(self): """update state of ease combo box to reflect animation state at current key frame""" ease = self.animation.current_key_frame.ease name = _easing_func_to_name(ease) index = self.easeComboBox.findText(name, Qt.MatchFixedString) self.easeComboBox.setCurrentIndex(index) def _update_animation_ease(self, event): """update state of 'ease' at current key-frame to reflect GUI state""" self.animation.current_key_frame.ease = self.get_easing_func() def _add_callbacks(self): """add callbacks to steps and ease widgets""" self.stepsSpinBox.valueChanged.connect(self._update_animation_steps) self.easeComboBox.currentIndexChanged.connect( self._update_animation_ease)
def _create_settings_widgets(self, settings): """ Create a widget for a settings instance, containing label/editor pairs for each setting in the current level of the passed QSettings instance. The key of the setting is used as the label, but it's capitalized and underscores are replaced by spaces. """ wrap = QWidget(self) form = QFormLayout() hint_lookup = Settings() for k in settings.allKeys(): if k.startswith("_"): continue # Ignore hidden keys v = settings.value(k) # Read value label = k.capitalize().replace('_', ' ') abs_key = settings.group() + '/' + k self._initial_values[abs_key] = v # Store initial value hints = hint_lookup.get_enum_hint(abs_key) # Check for enum hints # Create a fitting editor widget based on value type: if hints is not None: w = QComboBox() w.addItems(hints) w.setEditable(True) w.setEditText(v) w.editTextChanged.connect(partial(self._on_setting_changed, abs_key, w)) elif isinstance(v, str): if v.lower() in ('true', 'false'): w = QCheckBox() w.setChecked(v.lower() == 'true') w.toggled.connect(partial(self._on_setting_changed, abs_key, w)) else: w = QLineEdit(v) w.textChanged.connect(partial(self._on_setting_changed, abs_key, w)) elif isinstance(v, int): w = QSpinBox() w.setRange(np.iinfo(np.int32).min, np.iinfo(np.int32).max) w.setValue(v) w.valueChanged.connect(partial(self._on_setting_changed, abs_key, w)) elif isinstance(v, float): w = QDoubleSpinBox() w.setRange(np.finfo(np.float32).min, np.finfo(np.float32).max) w.setValue(v) w.valueChanged.connect(partial(self._on_setting_changed, abs_key, w)) else: w = QLineEdit(str(v)) w.textChanged.connect(partial(self._on_setting_changed, abs_key, w)) self._lut[abs_key] = w form.addRow(label, w) wrap.setLayout(form) return wrap
def _create_settings_widgets(self, settings): """ Create a widget for a settings instance, containing label/editor pairs for each setting in the current level of the passed QSettings instance. The key of the setting is used as the label, but it's capitalized and underscores are replaced by spaces. """ wrap = QWidget(self) form = QFormLayout() hint_lookup = Settings() for k in settings.allKeys(): if k.startswith("_"): continue # Ignore hidden keys v = settings.value(k) # Read value label = k.capitalize().replace('_', ' ') abs_key = settings.group() + '/' + k self._initial_values[abs_key] = v # Store initial value hints = hint_lookup.get_enum_hint(abs_key) # Check for enum hints # Create a fitting editor widget based on value type: if hints is not None: w = QComboBox() w.addItems(hints) w.setEditable(True) w.setEditText(v) w.editTextChanged.connect( partial(self._on_setting_changed, abs_key, w)) elif isinstance(v, str): if v.lower() in ('true', 'false'): w = QCheckBox() w.setChecked(v.lower() == 'true') w.toggled.connect( partial(self._on_setting_changed, abs_key, w)) else: w = QLineEdit(v) w.textChanged.connect( partial(self._on_setting_changed, abs_key, w)) elif isinstance(v, int): w = QSpinBox() w.setRange(np.iinfo(np.int32).min, np.iinfo(np.int32).max) w.setValue(v) w.valueChanged.connect( partial(self._on_setting_changed, abs_key, w)) elif isinstance(v, float): w = QDoubleSpinBox() w.setRange(np.finfo(np.float32).min, np.finfo(np.float32).max) w.setValue(v) w.valueChanged.connect( partial(self._on_setting_changed, abs_key, w)) else: w = QLineEdit(str(v)) w.textChanged.connect( partial(self._on_setting_changed, abs_key, w)) self._lut[abs_key] = w form.addRow(label, w) wrap.setLayout(form) return wrap
def __init__(self, parent): super(ModuleDetailsWindow, self).__init__(parent) self.content_widget = QWidget(self) self.widget_layout = QFormLayout(self.content_widget) self.content_widget.setLayout(self.widget_layout) self.addContentWidget(self.content_widget) self.module_code = QTextEdit(self.content_widget) self.module_code.setReadOnly(True) self.widget_layout.addWidget(self.module_code)
def __init__(self, properties: BaseSerializableClass, parent=None): super().__init__(parent) self.properties = properties self.widget_list = [] layout = QFormLayout() for key, val in properties.__annotations__.items(): name = key.replace("_", " ").capitalize() widget = self.get_widget(val) layout.addRow(name, widget) self.widget_list.append((key, widget)) self.setLayout(layout)
def __init__(self, parent): super(C2ConfigFrame, self).__init__(parent) self.widget_layout = QVBoxLayout(self) self.setLayout(self.widget_layout) self.c2_conf_label = QLabel(self) self.c2_conf_label.setText("C2 server configuration") self.widget_layout.addWidget(self.c2_conf_label) self.desc_label = QLabel(self) self.desc_label.setWordWrap(True) self.desc_label.setText( "Make sure that port you use is opened and IP address is " "valid. To balance server load, select amount of threads to use. Set 0 to use all " "available system cores.") self.widget_layout.addWidget(self.desc_label) self.ip_config = QWidget(self) self.ip_config_layout = QFormLayout(self.ip_config) self.widget_layout.addWidget(self.ip_config) self.c2_ip_label = QLabel(self.ip_config) self.c2_ip_label.setText("C2 IP Address") self.c2_ip_combo = QComboBox(self.ip_config) self.ip_config_layout.addRow(self.c2_ip_label, self.c2_ip_combo) self.port_label = QLabel(self.ip_config) self.port_label.setText("C2 Port") self.port_edit = QSpinBox(self.ip_config) self.port_edit.setRange(1024, 65535) self.port_edit.setValue(8192) self.ip_config_layout.addRow(self.port_label, self.port_edit) self.threads_label = QLabel(self.ip_config) self.threads_label.setText("C2 handler threads") self.threads_edit = QSpinBox(self.ip_config) self.threads_edit.setRange(0, 256) self.ip_config_layout.addRow(self.threads_label, self.threads_edit) self.c2_key_label = QLabel(self.ip_config) self.c2_key_label.setText("C2 encryption key") self.c2_key_edit = QLineEdit(self.ip_config) self.c2_key_edit.setReadOnly(True) self.c2_key_edit.setText(generate_key().decode()) self.ip_config_layout.addRow(self.c2_key_label, self.c2_key_edit) spacerItem = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding) self.widget_layout.addItem(spacerItem)
def setupui(self): self.fl = QFormLayout(self) self.fl.setLabelAlignment(Qt.AlignVCenter) self._add_row('FFTData-RB.SPAN', 'Number of points') self._add_row('FFTData-RB.INDX', 'Start Index') self._add_row('FFTData-RB.MXIX', 'Maximum Index') self._add_row('FFTData-RB.WIND', 'Window type', enum=True) self._add_row('FFTData-RB.CDIR', 'Direction', enum=True) self._add_row('FFTData-RB.ASUB', 'Subtract Avg', enum=True) pb = PyDMPushButton(self, label='Calculate', pressValue=1) self._make_connections(pb, 'FFTData-RB.PROC') self.fl.addRow(pb)
def __init__(self, server_info, parent=None): """ Construct a RecoveryDialog. Parameters ---------- servers : list of ServerProcess Information to be displayed. This parameter is read only. parent : QWidget, optional Parent of the dialog window. The default is None. """ super().__init__(parent) self.servers = server_info self.setWindowTitle(_('Notebook server info')) self.layout = QVBoxLayout(self) self.formlayout = QFormLayout() self.layout.addLayout(self.formlayout) self.process_combo = QComboBox(self) self.process_combo.currentIndexChanged.connect(self.select_process) self.formlayout.addRow(_('Process ID:'), self.process_combo) self.dir_lineedit = QLineEdit(self) self.dir_lineedit.setReadOnly(True) self.formlayout.addRow(_('Notebook dir:'), self.dir_lineedit) self.interpreter_lineedit = QLineEdit(self) self.interpreter_lineedit.setReadOnly(True) self.formlayout.addRow(_('Python interpreter:'), self.interpreter_lineedit) self.state_lineedit = QLineEdit(self) self.state_lineedit.setReadOnly(True) self.formlayout.addRow(_('State:'), self.state_lineedit) self.log_textedit = QTextEdit(self) self.log_textedit.setReadOnly(True) self.layout.addWidget(self.log_textedit) self.buttonbox = QDialogButtonBox(QDialogButtonBox.Ok, self) self.buttonbox.accepted.connect(self.accept) self.refresh_button = QPushButton(_('Refresh'), self) self.refresh_button.clicked.connect(self.refresh_data) self.buttonbox.addButton(self.refresh_button, QDialogButtonBox.ActionRole) self.layout.addWidget(self.buttonbox) self.refresh_data()
def __init__(self, main_display, pv_name, parent=None): """ Create all the widgets for the curve appearance settings. Parameters ---------- main_display : TimeChartDisplay The main display window pv_name: str The name of the PV the current curve is being plotted for parent : QWidget The parent widget, if applicable """ super(CurveSettingsDisplay, self).__init__(parent=parent) self.main_layout = QFormLayout() self.main_display = main_display self.chart = self.main_display.chart self.pv_name = pv_name self.channel_map = self.main_display.channel_map self.app = self.main_display.app self.curve_original_color = None self.curve_color_lbl = QLabel("Curve Color ") self.curve_color_btn = QPushButton() self.curve_color_btn.setMaximumWidth(20) self.curve_color_btn.clicked.connect( self.handle_curve_color_button_clicked) self.symbol_lbl = QLabel("Symbol") self.symbol_cmb = QComboBox() self.symbol_size_lbl = QLabel("Symbol Size") self.symbol_size_spin = QSpinBox() self.line_style_lbl = QLabel("Line Style") self.line_style_cmb = QComboBox() self.line_width_lbl = QLabel("Line Width") self.line_width_spin = QSpinBox() self.set_defaults_btn = QPushButton("Reset") self.set_defaults_btn.clicked.connect(self.handle_reset_button_clicked) self.close_dialog_btn = QPushButton("Close") self.close_dialog_btn.clicked.connect(self.handle_close_button_clicked) self.setWindowTitle(self.pv_name.split("://")[1]) self.setFixedSize(QSize(300, 200)) self.setWindowModality(Qt.ApplicationModal) self.setup_ui()
def _setup_status_wid(self): status_layout = QFormLayout(self.status_wid) status_layout.setHorizontalSpacing(20) status_layout.setVerticalSpacing(20) for bit, label in enumerate(_cstime.Const.HLTrigStatusLabels): led = SiriusLedAlert(self, self.get_pvname('Status-Mon'), bit) lab = QLabel(label, self) status_layout.addRow(led, lab)
def creategroupbox(self): wid = QGroupBox('Detailed Status', self) fbl = QFormLayout(wid) if self.is_orb: items = self._csorb.StsLblsOrb._fields name = 'Orb' else: items = self._csorb.StsLblsCorr._fields name = 'Corr' channel = self.devpref.substitute(propty=name + 'Status-Mon') for bit, label in enumerate(items): led = SiriusLedAlert(self, channel, bit) lab = QLabel(label, self) fbl.addRow(led, lab) return wid
def __init__(self, data, comment="", parent=None): QWidget.__init__(self, parent) from copy import deepcopy self.data = deepcopy(data) self.widgets = [] self.formlayout = QFormLayout(self) if comment: self.formlayout.addRow(QLabel(comment)) self.formlayout.addRow(QLabel(" ")) if DEBUG_FORMLAYOUT: print("\n" + ("*" * 80)) # trex: test-skip print("DATA:", self.data) # trex: test-skip print("*" * 80) # trex: test-skip print("COMMENT:", comment) # trex: test-skip print("*" * 80) # trex: test-skip
def __init__( self, title="Title", description="Description", unique_names=None, ): QDialog.__init__(self) self.setModal(True) self.setWindowTitle(title) if unique_names is None: unique_names = [] self.unique_names = unique_names self.layout = QFormLayout() self.layout.setSizeConstraint(QLayout.SetFixedSize) label = QLabel(description) label.setAlignment(Qt.AlignHCenter) self.layout.addRow(self.createSpace(5)) self.layout.addRow(label) self.layout.addRow(self.createSpace(10)) buttons = QDialogButtonBox( QDialogButtonBox.Ok | QDialogButtonBox.Cancel, Qt.Horizontal, self ) self.ok_button = buttons.button(QDialogButtonBox.Ok) self.ok_button.setEnabled(False) self.param_name = QLineEdit(self) self.param_name.setFocus() self.param_name.textChanged.connect(self.validateName) self.validColor = self.param_name.palette().color( self.param_name.backgroundRole() ) self.layout.addRow("Name:", self.param_name) self.layout.addRow(self.createSpace(10)) self.layout.addRow(buttons) buttons.accepted.connect(self.accept) buttons.rejected.connect(self.reject) self.setLayout(self.layout)
def __init__(self, parent=None): super().__init__(parent=parent) self.animation: Animation = self.parentWidget().animation self.animation.key_frames.selection.events.active.connect( self._on_active_keyframe_changed) # init steps self.stepsSpinBox = QSpinBox() self.stepsSpinBox.setRange(1, 100000) self.stepsSpinBox.setValue(15) # init ease self.easeComboBox = QComboBox() self.easeComboBox.addItems([e.name.lower() for e in Easing]) self.easeComboBox.setCurrentText("linear") # add callbacks self.stepsSpinBox.valueChanged.connect(self._update_animation_steps) self.easeComboBox.currentIndexChanged.connect( self._update_animation_ease) # layout self.setLayout(QFormLayout()) self.layout().addRow("Steps", self.stepsSpinBox) self.layout().addRow("Ease", self.easeComboBox)
class StringDictWidget(QWidget): """Show dict in key-value form.""" def __init__(self, parent): super(StringDictWidget, self).__init__(parent) self.setContentsMargins(11, 11, 11, 11) self.widget_layout = QFormLayout(self) self.widget_layout.setContentsMargins(0, 0, 0, 0) self.setLayout(self.widget_layout) def addEntry(self, key, value): key_label = QLabel(self) key_label.setText(str(key)) value_label = QLabel(self) value_label.setText(str(value)) self.widget_layout.addRow(key_label, value_label)
def __init__(self, data, comment="", parent=None): QWidget.__init__(self, parent) from copy import deepcopy self.data = deepcopy(data) self.widgets = [] self.formlayout = QFormLayout(self) if comment: self.formlayout.addRow(QLabel(comment)) self.formlayout.addRow(QLabel(" ")) if DEBUG_FORMLAYOUT: print("\n"+("*"*80)) print("DATA:", self.data) print("*"*80) print("COMMENT:", comment) print("*"*80)
def create_controls(self): self.txt_name = QLineEdit() self.chk_menu = QCheckBox(tr("Menu entry")) self.chk_menu.setChecked(True) self.chk_toolbar = QCheckBox(tr("Toolbar button")) self.chk_toolbar.setChecked(True) self.txt_category = QLineEdit() self.chk_icon = QCheckBox() self.chk_toolbar.setChecked(False) self.txt_iconpath = QLineEdit() self.btn_browse_icon = QPushButton("...") self.txt_iconpath.setEnabled(False) self.btn_browse_icon.setEnabled(False) btns = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel, QtCore.Qt.Horizontal) self.chk_menu.toggled.connect(self.checks_changed) self.chk_toolbar.toggled.connect(self.checks_changed) self.chk_icon.toggled.connect(self.checks_changed) self.btn_browse_icon.clicked.connect(self.browse_icon) btns.accepted.connect(self.accept) btns.rejected.connect(self.reject) hbox = QHBoxLayout() for w in [self.chk_icon, self.txt_iconpath, self.btn_browse_icon]: hbox.addWidget(w) form = QFormLayout() form.addRow(tr("Name"), self.txt_name) form.addRow(self.chk_menu, self.chk_toolbar) form.addRow(tr("Category"), self.txt_category) form.addRow(tr("Icon"), hbox) vbox = QVBoxLayout(self) vbox.addLayout(form) vbox.addWidget(btns) self.setLayout(vbox)
def __init__(self, parent, username, password, token, remember=False, remember_token=False): QDialog.__init__(self, parent) title = _("Sign in to Github") self.resize(415, 375) self.setWindowTitle(title) self.setWindowFlags( self.windowFlags() & ~Qt.WindowContextHelpButtonHint) # Header html = ('<html><head/><body><p align="center">' '{title}</p></body></html>') lbl_html = QLabel(html.format(title=title)) lbl_html.setStyleSheet('font-size: 16px;') # Tabs self.tabs = QTabWidget() # Basic form layout basic_form_layout = QFormLayout() basic_form_layout.setContentsMargins(-1, 0, -1, -1) basic_lbl_msg = QLabel(_("For regular users, i.e. users <b>without</b>" " two-factor authentication enabled")) basic_lbl_msg.setWordWrap(True) basic_lbl_msg.setAlignment(Qt.AlignJustify) lbl_user = QLabel(_("Username:"******"", QWidget()) lbl_password = QLabel(_("Password: "******"Remember me")) self.cb_remember.setToolTip(_("Spyder will save your credentials " "safely")) self.cb_remember.setChecked(remember) basic_form_layout.setWidget(4, QFormLayout.FieldRole, self.cb_remember) # Basic auth tab basic_auth = QWidget() basic_layout = QVBoxLayout() basic_layout.addSpacerItem(QSpacerItem(QSpacerItem(0, 8))) basic_layout.addWidget(basic_lbl_msg) basic_layout.addSpacerItem( QSpacerItem(QSpacerItem(0, 50, vPolicy=QSizePolicy.Expanding))) basic_layout.addLayout(basic_form_layout) basic_layout.addSpacerItem( QSpacerItem(QSpacerItem(0, 50, vPolicy=QSizePolicy.Expanding))) basic_auth.setLayout(basic_layout) self.tabs.addTab(basic_auth, _("Password Only")) # Token form layout token_form_layout = QFormLayout() token_form_layout.setContentsMargins(-1, 0, -1, -1) token_lbl_msg = QLabel(_("For users <b>with</b> two-factor " "authentication enabled, or who prefer a " "per-app token authentication.<br><br>" "You can go <b><a href=\"{}\">here</a></b> " "and click \"Generate token\" at the bottom " "to create a new token to use for this, with " "the appropriate permissions.").format( TOKEN_URL)) token_lbl_msg.setOpenExternalLinks(True) token_lbl_msg.setWordWrap(True) token_lbl_msg.setAlignment(Qt.AlignJustify) lbl_token = QLabel("Token: ") token_form_layout.setWidget(1, QFormLayout.LabelRole, lbl_token) self.le_token = QLineEdit() self.le_token.setEchoMode(QLineEdit.Password) self.le_token.textChanged.connect(self.update_btn_state) token_form_layout.setWidget(1, QFormLayout.FieldRole, self.le_token) self.cb_remember_token = None # Same validation as with cb_remember if self.is_keyring_available() and valid_py_os: self.cb_remember_token = QCheckBox(_("Remember token")) self.cb_remember_token.setToolTip(_("Spyder will save your " "token safely")) self.cb_remember_token.setChecked(remember_token) token_form_layout.setWidget(3, QFormLayout.FieldRole, self.cb_remember_token) # Token auth tab token_auth = QWidget() token_layout = QVBoxLayout() token_layout.addSpacerItem(QSpacerItem(QSpacerItem(0, 8))) token_layout.addWidget(token_lbl_msg) token_layout.addSpacerItem( QSpacerItem(QSpacerItem(0, 50, vPolicy=QSizePolicy.Expanding))) token_layout.addLayout(token_form_layout) token_layout.addSpacerItem( QSpacerItem(QSpacerItem(0, 50, vPolicy=QSizePolicy.Expanding))) token_auth.setLayout(token_layout) self.tabs.addTab(token_auth, _("Access Token")) # Sign in button self.bt_sign_in = QPushButton(_("Sign in")) self.bt_sign_in.clicked.connect(self.accept) self.bt_sign_in.setDisabled(True) # Main layout layout = QVBoxLayout() layout.addWidget(lbl_html) layout.addWidget(self.tabs) layout.addWidget(self.bt_sign_in) self.setLayout(layout) # Final adjustments if username and password: self.le_user.setText(username) self.le_password.setText(password) self.bt_sign_in.setFocus() elif username: self.le_user.setText(username) self.le_password.setFocus() elif token: self.le_token.setText(token) else: self.le_user.setFocus() self.setFixedSize(self.width(), self.height()) self.le_password.installEventFilter(self) self.le_user.installEventFilter(self) self.tabs.currentChanged.connect(self.update_btn_state)
def __init__(self, parent=None, is_report=False): QDialog.__init__(self, parent) self.is_report = is_report self.setWindowTitle(_("Issue reporter")) self.setModal(True) # To save the traceback sent to the internal console self.error_traceback = "" # Dialog main label if self.is_report: title = _("Please fill the following information") else: title = _("Spyder has encountered an internal problem!") main_label = QLabel( _("<h3>{title}</h3>" "Before reporting this problem, <i>please</i> consult our " "comprehensive " "<b><a href=\"{trouble_url}\">Troubleshooting Guide</a></b> " "which should help solve most issues, and search for " "<b><a href=\"{project_url}\">known bugs</a></b> " "matching your error message or problem description for a " "quicker solution." ).format(title=title, trouble_url=__trouble_url__, project_url=__project_url__)) main_label.setOpenExternalLinks(True) main_label.setWordWrap(True) main_label.setAlignment(Qt.AlignJustify) main_label.setStyleSheet('font-size: 12px;') # Issue title self.title = QLineEdit() self.title.textChanged.connect(self._contents_changed) self.title_chars_label = QLabel(_("{} more characters " "to go...").format(TITLE_MIN_CHARS)) form_layout = QFormLayout() form_layout.setFieldGrowthPolicy(QFormLayout.ExpandingFieldsGrow) red_asterisk = '<font color="Red">*</font>' title_label = QLabel(_("<b>Title</b>: {}").format(red_asterisk)) form_layout.setWidget(0, QFormLayout.LabelRole, title_label) form_layout.setWidget(0, QFormLayout.FieldRole, self.title) # Description steps_header = QLabel( _("<b>Steps to reproduce:</b> {}").format(red_asterisk)) steps_text = QLabel(_("Please enter a detailed step-by-step " "description (in English) of what led up to " "the problem below. Issue reports without a " "clear way to reproduce them will be closed.")) steps_text.setWordWrap(True) steps_text.setAlignment(Qt.AlignJustify) steps_text.setStyleSheet('font-size: 12px;') # Field to input the description of the problem self.input_description = DescriptionWidget(self) # Only allow to submit to Github if we have a long enough description self.input_description.textChanged.connect(self._contents_changed) # Widget to show errors self.details = ShowErrorWidget(self) self.details.set_pythonshell_font(get_font()) self.details.hide() # Label to show missing chars self.initial_chars = len(self.input_description.toPlainText()) self.desc_chars_label = QLabel(_("{} more characters " "to go...").format(DESC_MIN_CHARS)) # Checkbox to dismiss future errors self.dismiss_box = QCheckBox(_("Hide all future errors during this " "session")) if self.is_report: self.dismiss_box.hide() # Dialog buttons gh_icon = ima.icon('github') self.submit_btn = QPushButton(gh_icon, _('Submit to Github')) self.submit_btn.setEnabled(False) self.submit_btn.clicked.connect(self._submit_to_github) self.details_btn = QPushButton(_('Show details')) self.details_btn.clicked.connect(self._show_details) if self.is_report: self.details_btn.hide() self.close_btn = QPushButton(_('Close')) if self.is_report: self.close_btn.clicked.connect(self.reject) # Buttons layout buttons_layout = QHBoxLayout() buttons_layout.addWidget(self.submit_btn) buttons_layout.addWidget(self.details_btn) buttons_layout.addWidget(self.close_btn) # Main layout layout = QVBoxLayout() layout.addWidget(main_label) layout.addSpacing(20) layout.addLayout(form_layout) layout.addWidget(self.title_chars_label) layout.addSpacing(12) layout.addWidget(steps_header) layout.addSpacing(-1) layout.addWidget(steps_text) layout.addSpacing(1) layout.addWidget(self.input_description) layout.addWidget(self.details) layout.addWidget(self.desc_chars_label) layout.addSpacing(15) layout.addWidget(self.dismiss_box) layout.addSpacing(15) layout.addLayout(buttons_layout) layout.setContentsMargins(25, 20, 25, 10) self.setLayout(layout) self.resize(570, 600) self.title.setFocus() # Set Tab key focus order self.setTabOrder(self.title, self.input_description)
def _init_ui(self): layout = QFormLayout() layout.setFieldGrowthPolicy(QFormLayout.ExpandingFieldsGrow) # Fix for Mac OS return layout
class MyPowerSupply(Instrument): voltage = ManualFacet(type=float, units='volts') current = ManualFacet(type=float, units='amps') if __name__ == '__main__': ps = MyPowerSupply() ps.observe('voltage', print) app = QApplication(sys.argv) win = QMainWindow() w = QWidget(win) win.setCentralWidget(w) fbox = QFormLayout() box1 = ps.facets.voltage.create_widget() fbox.addRow('Voltage', box1) box2 = ps.facets.current.create_widget() fbox.addRow('Current', box2) def set_box(event): box1.setUValue(event.new) ps.observe('voltage', set_box) def f(): ps.voltage = '12 V' #box2.uValueChanged.connect(f) w.setLayout(fbox)
def __init__(self, *args, **kwargs): super(MainWidget, self).__init__(*args, **kwargs) #Widgets self.label_Title1 = QLabel() self.label_Title1.setText("INGRESE LOS DATOS") self.label_Title2 = QLabel() self.label_Title2.setText("DATOS BOMBILLOS ESTANDAR") self.label_Title3 = QLabel() self.label_Title3.setText("DATOS BOMBILLOS LED") self.label_Data1 = QLabel() self.label_Data1.setText("Costo de la electricidad (kW/hora)") self.label_Data2 = QLabel() self.label_Data2.setText("Numero de bombillos a reemplazar") self.label_Data3 = QLabel() self.label_Data3.setText("Vatios del bombillo existente") self.label_Data4 = QLabel() self.label_Data4.setText("Numero de Horas por Dia encendido") self.label_Data5 = QLabel() self.label_Data5.setText("Vida util bombillo actual") self.label_Data6 = QLabel() self.label_Data6.setText("Costo Bombillo actual") self.label_Data7 = QLabel() self.label_Data7.setText("Costo estimado mantenimiento por bombillo") self.label_Data8 = QLabel() self.label_Data8.setText("Vatios del bombillo LED") self.label_Data9 = QLabel() self.label_Data9.setText("Vida util estimada del bombillo") self.label_Data10 = QLabel() self.label_Data10.setText("Costo del bombillo led") #Widgets Titulos del Form self.label_Titlef1 = QLabel() self.label_Titlef1.setText("INFORMACION DE COSTOS CALCULADOS") self.label_Titlef2 = QLabel() self.label_Titlef2.setText("INFORMACION DE AHORROS CALCULADOS") self.line_Data1 = QLineEdit() #self.line_Data1.setValidator() self.line_Data2 = QLineEdit() self.line_Data2.setValidator(QIntValidator()) self.line_Data3 = QLineEdit() self.line_Data3.setValidator(QIntValidator()) self.line_Data4 = QLineEdit() self.line_Data4.setValidator(QIntValidator()) self.line_Data5 = QLineEdit() self.line_Data5.setValidator(QIntValidator()) self.line_Data6 = QLineEdit() #self.line_Data6.setValidator() self.line_Data7 = QLineEdit() #self.line_Data7.setValidator() self.line_Data8 = QLineEdit() #self.line_Data8.setValidator() self.line_Data9 = QLineEdit() #self.line_Data9.setValidator() self.line_Data10 = QLineEdit() #self.line_Data10.setValidator() #Widget Informacion Calculada Form1 Costos self.line_Inf1 = QLineEdit() self.line_Inf1.setValidator(QIntValidator()) self.line_Inf2 = QLineEdit() self.line_Inf2.setValidator(QIntValidator()) self.line_Inf3 = QLineEdit() self.line_Inf3.setValidator(QIntValidator()) self.line_Inf4 = QLineEdit() self.line_Inf4.setValidator(QIntValidator()) self.line_Inf5 = QLineEdit() self.line_Inf5.setValidator(QIntValidator()) self.line_Inf6 = QLineEdit() self.line_Inf6.setValidator(QIntValidator()) self.line_Inf7 = QLineEdit() self.line_Inf7.setValidator(QIntValidator()) self.line_Inf8 = QLineEdit() self.line_Inf8.setValidator(QIntValidator()) self.line_Inf9 = QLineEdit() self.line_Inf9.setValidator(QIntValidator()) #Widget Informacion Calculada Form2 Ahorros self.line_Sav1 = QLineEdit() self.line_Sav1.setValidator(QIntValidator()) self.line_Sav2 = QLineEdit() self.line_Sav2.setValidator(QIntValidator()) self.line_Sav3 = QLineEdit() self.line_Sav3.setValidator(QIntValidator()) self.line_Sav4 = QLineEdit() self.line_Sav4.setValidator(QIntValidator()) self.line_Sav5 = QLineEdit() self.line_Sav5.setValidator(QIntValidator()) self.line_Sav6 = QLineEdit() self.line_Sav6.setValidator(QIntValidator()) self.button_Calc = QPushButton('Calcular Ahorro', parent=self) self.button_Impr = QPushButton('Imprimir', parent=self) #Layouts layout = QGridLayout() layout.addWidget(self.label_Title1,0,0) layout.addWidget(self.label_Data1,1,0) layout.addWidget(self.line_Data1,1,1) layout.addWidget(self.label_Title2,2,0) layout.addWidget(self.label_Data2,3,0) layout.addWidget(self.line_Data2,3,1) layout.addWidget(self.label_Data5,3,2) layout.addWidget(self.line_Data5,3,3) layout.addWidget(self.label_Data3,4,0) layout.addWidget(self.line_Data3,4,1) layout.addWidget(self.label_Data6,4,2) layout.addWidget(self.line_Data6,4,3) layout.addWidget(self.label_Data4,5,0) layout.addWidget(self.line_Data4,5,1) layout.addWidget(self.label_Data7,5,2) layout.addWidget(self.line_Data7,5,3) layout.addWidget(self.label_Title3,6,0) layout.addWidget(self.label_Data8,7,0) layout.addWidget(self.line_Data8,7,1) layout.addWidget(self.label_Data10,7,2) layout.addWidget(self.line_Data10,7,3) layout.addWidget(self.label_Data9,8,0) layout.addWidget(self.line_Data9,8,1) layout.addWidget(self.button_Calc,8,3) layout1 = QFormLayout() layout1.addRow("Horas por año",self.line_Inf1) layout1.addRow("Costo de Energia por Dia",self.line_Inf2) layout1.addRow("Costo de Energia por Año",self.line_Inf3) layout1.addRow("Costo total de la Compra",self.line_Inf4) layout1.addRow("Costo Total de la compra con mantenimiento",self.line_Inf5) layout1.addRow("Costo Reemplazo Actuales Año",self.line_Inf6) layout1.addRow("Costo Energia por Dia LED",self.line_Inf7) layout1.addRow("Costo de Energia por Año LED",self.line_Inf8) layout1.addRow("Costo Total de la Compra LED",self.line_Inf9) layout2 = QFormLayout() layout2.addRow("Ahorro Energia Anual",self.line_Sav1) layout2.addRow("Ahorro Energia Mensual",self.line_Sav2) layout2.addRow("Periodo Retorno Inversion en Años",self.line_Sav3) layout2.addRow("Periodo Retorno Inversion en Meses",self.line_Sav4) layout2.addWidget(self.button_Impr) #Layout Horizontal Titulos del Form self.LayoutTitle = QHBoxLayout() self.LayoutTitle.addWidget(self.label_Titlef1) self.LayoutTitle.addWidget(self.label_Titlef2) ### Layout HOrizontal que une los dos Form self.LayoutForm = QHBoxLayout() self.LayoutForm.addLayout(layout1) self.LayoutForm.addLayout(layout2) ## LAyout Vertical Final self.myLayout = QVBoxLayout() self.myLayout.setMargin(20) self.myLayout.addLayout(layout) self.myLayout.addLayout(self.LayoutTitle) self.myLayout.addLayout(self.LayoutForm) self.setLayout(self.myLayout) # Signals self.button_Calc.clicked.connect(self.result_method)
def __init__(self, presenter, parent = None, name = '', isMD=False, noExp = 0): super(SampleLogsView, self).__init__(parent) self.presenter = presenter self.setWindowTitle("{} sample logs".format(name)) self.setWindowFlags(Qt.Window) # Create sample log table self.table = QTableView() self.table.setSelectionBehavior(QAbstractItemView.SelectRows) self.table.clicked.connect(self.presenter.clicked) self.table.doubleClicked.connect(self.presenter.doubleClicked) self.table.contextMenuEvent = self.tableMenu self.addWidget(self.table) frame_right = QFrame() layout_right = QVBoxLayout() #Add full_time and experimentinfo options layout_options = QHBoxLayout() if isMD: layout_options.addWidget(QLabel("Experiment Info #")) self.experimentInfo = QSpinBox() self.experimentInfo.setMaximum(noExp-1) self.experimentInfo.valueChanged.connect(self.presenter.changeExpInfo) layout_options.addWidget(self.experimentInfo) self.full_time = QCheckBox("Relative Time") self.full_time.setChecked(True) self.full_time.stateChanged.connect(self.presenter.plot_logs) layout_options.addWidget(self.full_time) layout_right.addLayout(layout_options) # Sample log plot self.fig = Figure() self.canvas = FigureCanvas(self.fig) self.canvas.setSizePolicy(QSizePolicy.Expanding,QSizePolicy.Expanding) self.canvas.mpl_connect('button_press_event', self.presenter.plot_clicked) self.ax = self.fig.add_subplot(111, projection='mantid') layout_right.addWidget(self.canvas) # Sample stats self.create_stats_widgets() layout_stats = QFormLayout() layout_stats.addRow('', QLabel("Log Statistics")) layout_stats.addRow('Min:', self.stats_widgets["minimum"]) layout_stats.addRow('Max:', self.stats_widgets["maximum"]) layout_stats.addRow('Mean:', self.stats_widgets["mean"]) layout_stats.addRow('Median:', self.stats_widgets["median"]) layout_stats.addRow('Std Dev:', self.stats_widgets["standard_deviation"]) layout_stats.addRow('Time Avg:', self.stats_widgets["time_mean"]) layout_stats.addRow('Time Std Dev:', self.stats_widgets["time_standard_deviation"]) layout_stats.addRow('Duration:', self.stats_widgets["duration"]) layout_right.addLayout(layout_stats) frame_right.setLayout(layout_right) self.addWidget(frame_right) self.setStretchFactor(0,1) self.resize(1200,800) self.show()
class FormWidget(QWidget): update_buttons = Signal() def __init__(self, data, comment="", parent=None): QWidget.__init__(self, parent) from copy import deepcopy self.data = deepcopy(data) self.widgets = [] self.formlayout = QFormLayout(self) if comment: self.formlayout.addRow(QLabel(comment)) self.formlayout.addRow(QLabel(" ")) if DEBUG_FORMLAYOUT: print("\n"+("*"*80)) print("DATA:", self.data) print("*"*80) print("COMMENT:", comment) print("*"*80) def get_dialog(self): """Return FormDialog instance""" dialog = self.parent() while not isinstance(dialog, QDialog): dialog = dialog.parent() return dialog def setup(self): for label, value in self.data: if DEBUG_FORMLAYOUT: print("value:", value) if label is None and value is None: # Separator: (None, None) self.formlayout.addRow(QLabel(" "), QLabel(" ")) self.widgets.append(None) continue elif label is None: # Comment self.formlayout.addRow(QLabel(value)) self.widgets.append(None) continue elif tuple_to_qfont(value) is not None: field = FontLayout(value, self) elif text_to_qcolor(value).isValid(): field = ColorLayout(QColor(value), self) elif is_text_string(value): if '\n' in value: for linesep in (os.linesep, '\n'): if linesep in value: value = value.replace(linesep, u"\u2029") field = QTextEdit(value, self) else: field = QLineEdit(value, self) elif isinstance(value, (list, tuple)): value = list(value) # in case this is a tuple selindex = value.pop(0) field = QComboBox(self) if isinstance(value[0], (list, tuple)): keys = [ key for key, _val in value ] value = [ val for _key, val in value ] else: keys = value field.addItems(value) if selindex in value: selindex = value.index(selindex) elif selindex in keys: selindex = keys.index(selindex) elif not isinstance(selindex, int): print("Warning: '%s' index is invalid (label: "\ "%s, value: %s)" % (selindex, label, value), file=STDERR) selindex = 0 field.setCurrentIndex(selindex) elif isinstance(value, bool): field = QCheckBox(self) field.setCheckState(Qt.Checked if value else Qt.Unchecked) elif isinstance(value, float): field = QLineEdit(repr(value), self) field.setValidator(QDoubleValidator(field)) dialog = self.get_dialog() dialog.register_float_field(field) field.textChanged.connect(lambda text: dialog.update_buttons()) elif isinstance(value, int): field = QSpinBox(self) field.setRange(-1e9, 1e9) field.setValue(value) elif isinstance(value, datetime.datetime): field = QDateTimeEdit(self) field.setDateTime(value) elif isinstance(value, datetime.date): field = QDateEdit(self) field.setDate(value) else: field = QLineEdit(repr(value), self) self.formlayout.addRow(label, field) self.widgets.append(field) def get(self): valuelist = [] for index, (label, value) in enumerate(self.data): field = self.widgets[index] if label is None: # Separator / Comment continue elif tuple_to_qfont(value) is not None: value = field.get_font() elif is_text_string(value): if isinstance(field, QTextEdit): value = to_text_string(field.toPlainText() ).replace(u"\u2029", os.linesep) else: value = to_text_string(field.text()) elif isinstance(value, (list, tuple)): index = int(field.currentIndex()) if isinstance(value[0], int): # Return an int index, if initialization was an int value = index else: value = value[index+1] if isinstance(value, (list, tuple)): value = value[0] elif isinstance(value, bool): value = field.checkState() == Qt.Checked elif isinstance(value, float): value = float(field.text()) elif isinstance(value, int): value = int(field.value()) elif isinstance(value, datetime.datetime): value = field.dateTime() try: value = value.toPyDateTime() # PyQt except AttributeError: value = value.toPython() # PySide elif isinstance(value, datetime.date): value = field.date() try: value = value.toPyDate() # PyQt except AttributeError: value = value.toPython() # PySide else: value = eval(str(field.text())) valuelist.append(value) return valuelist
def setup_grain_design(): # grain table view master = QHBoxLayout(self) master.addWidget(QTableView()) # grain design controls controls = QVBoxLayout(self) # add a push button self.btn_new_grain = QPushButton(self.tr("New Grain")) self.btn_new_grain.setMinimumHeight(50) controls.addWidget(self.btn_new_grain) # add a dividing line line = QFrame() line.setFrameShape(QFrame.HLine) line.setFrameShadow(QFrame.Sunken) controls.addSpacing(5) controls.addWidget(line) # rest of the controls buttons self.btn_edit_grain = QPushButton(self.tr("Edit")) self.btn_edit_grain.setMinimumHeight(30) controls.addWidget(self.btn_edit_grain) self.btn_delete_Grain = QPushButton(self.tr("Delete")) self.btn_delete_Grain.setMinimumHeight(30) controls.addWidget(self.btn_delete_Grain) # move grain up and down moveup = QHBoxLayout() self.btn_move_up = QToolButton() self.btn_move_up.setArrowType(Qt.UpArrow) moveup.addWidget(self.btn_move_up) moveup.addWidget(QLabel(self.tr("Move Up"))) controls.addLayout(moveup) movedown = QHBoxLayout() self.btn_move_down = QToolButton() self.btn_move_down.setArrowType(Qt.DownArrow) movedown.addWidget(self.btn_move_down) movedown.addWidget(QLabel(self.tr("Move Down"))) controls.addLayout(movedown) controls.addStretch() # add info for motor design fl_propellant_info = QFormLayout() gb_motor_info = QGroupBox(self.tr("Propellant Info")) gb_motor_info.setLayout(fl_propellant_info) self.lbl_num_grains = QLabel() fl_propellant_info.addRow(QLabel(self.tr("Number of Segments:")), self.lbl_num_grains) self.lbl_motor_dia = QLabel() fl_propellant_info.addRow(QLabel(self.tr("Motor Diameter:")), self.lbl_motor_dia) self.lbl_motor_len = QLabel() fl_propellant_info.addRow(QLabel(self.tr("Propellant Length:")), self.lbl_motor_len) self.lbl_prop_mass = QLabel() fl_propellant_info.addRow(QLabel(self.tr("Propellant Mass:")), self.lbl_prop_mass) self.lbl_volume_loading = QLabel() fl_propellant_info.addRow(QLabel(self.tr("Volume Loading:")), self.lbl_volume_loading) # set group box's layout controls.addWidget(gb_motor_info) # setup master layout master.addLayout(controls) self.gb_design = QGroupBox(self.tr("Grain Design")) self.gb_design.setLayout(master)
def setup_chamber_design(): # master layout master = QVBoxLayout() # master group box self.gb_chamber = QGroupBox(self.tr("Chamber Design")) # nozzle settings button self.btn_nozzle_settings = QPushButton(self.tr("Edit Nozzle")) self.btn_nozzle_settings.setMinimumHeight(50) master.addWidget(self.btn_nozzle_settings) # nozzle info pane fl_nozzle_info = QFormLayout() gb_nozzle = QGroupBox(self.tr("Nozzle Info")) gb_nozzle.setLayout(fl_nozzle_info) self.lbl_nozzle_throat = QLabel() fl_nozzle_info.addRow(QLabel(self.tr("Throat Diameter:")), self.lbl_nozzle_throat) self.lbl_nozzle_exit = QLabel() fl_nozzle_info.addRow(QLabel(self.tr("Exit Diameter:")), self.lbl_nozzle_exit) self.lbl_nozzle_expansion_ratio = QLabel() fl_nozzle_info.addRow(QLabel(self.tr("Expansion Ratio:")), self.lbl_nozzle_expansion_ratio) # add group box to master master.addWidget(gb_nozzle) master.addStretch() # overall motor info pane fl_motor_info = QFormLayout() gb_motor = QGroupBox(self.tr("Motor Info")) gb_motor.setLayout(fl_motor_info) self.lbl_kn = QLabel() fl_motor_info.addRow(QLabel(self.tr("Kn:")), self.lbl_kn) self.lbl_port_throat = QLabel() fl_motor_info.addRow(QLabel(self.tr("Port/Throat Ratio:")), self.lbl_port_throat) master.addWidget(gb_motor) self.gb_chamber.setLayout(master)