def __init__(self, config: ConfigFactory, logger: LoggerFactory, title: str, surpacs: list): super(ChoiceSurpacDialog, self).__init__() self.config = config self.logger = logger self.setWindowTitle(title) self.setModal(True) self.setWindowFlag(Qt.WindowContextHelpButtonHint, False) self.surpacs = surpacs self.choice_surpac_button_group = QButtonGroup() self.choice_surpac_button_group.setExclusive(True) layout = QVBoxLayout() for surpac_id, choice in enumerate(surpacs): surpac_item = QRadioButton(choice) self.choice_surpac_button_group.addButton(surpac_item) self.choice_surpac_button_group.setId(surpac_item, surpac_id) if surpac_id == 0: surpac_item.setChecked(True) self.surpac_id = 0 layout.addWidget(surpac_item) self.choice_surpac_button_group.buttonClicked.connect( self.choice_surpac_change) self.buttons = QDialogButtonBox( QDialogButtonBox.Ok | QDialogButtonBox.Cancel, Qt.Horizontal, self) self.buttons.accepted.connect(self.accept) self.buttons.rejected.connect(self.reject) layout.addWidget(self.buttons) self.setLayout(layout)
class PrimaryMonitorSelect(QWidget): def __init__(self, parent): super(PrimaryMonitorSelect, self).__init__() self.parent = parent self.layout = QHBoxLayout() self.layout.setAlignment(Qt.AlignCenter) self.setLayout(self.layout) self.label = QLabel("Primary Monitor:") self.layout.addWidget(self.label) self.radio_buttons_setup() def radio_buttons_setup(self): self.leftRadioButton = QRadioButton("Left") self.leftRadioButton.toggled.connect(self.handle_toggled) self.rightRadioButton = QRadioButton("Right") self.rightRadioButton.toggled.connect(self.handle_toggled) if defaultSettings.list[2][1] == "True": self.leftRadioButton.setChecked(True) else: self.rightRadioButton.setChecked(True) self.layout.addWidget(self.leftRadioButton) self.layout.addWidget(self.rightRadioButton) def handle_toggled(self): defaultSettings.list[2][1] = str(self.leftRadioButton.isChecked()) defaultSettings.write()
def _create_switch(self, box, layout, col, labels): if labels is None: return None l = QLabel(labels[0], box) l.setMinimumHeight(20) l.setAlignment(Qt.AlignCenter | Qt.AlignBottom) font = l.font() font.setPointSize(7) font.setBold(True) l.setFont(font) layout.addWidget(l, 3, col, Qt.AlignBottom | Qt.AlignCenter) r1 = QRadioButton(box) r1.setStyleSheet( 'QRadioButton::indicator{subcontrol-position:center;}') layout.addWidget(r1, 4, col, Qt.AlignCenter) r2 = QRadioButton(box) r2.setStyleSheet( 'QRadioButton::indicator{subcontrol-position:center;}') layout.addWidget(r2, 5, col, Qt.AlignCenter) l = QLabel(labels[1], box) l.setAlignment(Qt.AlignCenter) l.setFont(font) layout.addWidget(l, 6, col, Qt.AlignTop | Qt.AlignCenter) g = QButtonGroup(box) g.addButton(r1) g.addButton(r2) r1.setChecked(True) return r2
def on_select_area(self): for node in self.radio_button_to_node.keys(): node.deleteLater() self.radio_button_to_node.clear() current_area = self.current_area if not current_area: self.new_node_button.setEnabled(False) self.delete_node_button.setEnabled(False) return is_first = True for node in sorted(current_area.nodes, key=lambda x: x.name): button = QRadioButton(self.points_of_interest_group) button.setText(node.name) self.radio_button_to_node[button] = node if is_first: self.selected_node_button = button button.setChecked(is_first) button.toggled.connect(self.on_select_node) is_first = False self.verticalLayout.addWidget(button) self.new_node_button.setEnabled(True) self.delete_node_button.setEnabled(len(current_area.nodes) > 1) self.update_selected_node()
def __init__(self, config: ConfigFactory, logger: LoggerFactory, title: str, languages: list): super(ChoiceLanguageDialog, self).__init__() self.config = config self.logger = logger self.setWindowTitle(title) self.setModal(True) self.setWindowFlag(Qt.WindowContextHelpButtonHint, False) self.languages = languages self.choice_language_button_group = QButtonGroup() self.choice_language_button_group.setExclusive(True) layout = QVBoxLayout() for language_id, language in enumerate(languages): # 显示语言提示 language_item = QRadioButton(language.split(':')[0]) self.choice_language_button_group.addButton(language_item) self.choice_language_button_group.setId(language_item, language_id) if language_id == 0: language_item.setChecked(True) self.language_id = 0 layout.addWidget(language_item) self.choice_language_button_group.buttonClicked.connect(self.language_change) self.buttons = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel, Qt.Horizontal, self) self.buttons.accepted.connect(self.accept) self.buttons.rejected.connect(self.reject) layout.addWidget(self.buttons) self.setLayout(layout)
def initUI(self): grid_layout = QGridLayout() grid_layout.setSpacing(10) self.setLayout(grid_layout) #Tutorial self.tutorialLabel = QLabel() self.tutorialLabel.setText("Welcome to DeepCreamPy!\nIf you're new to DCP, please read the manual.") self.tutorialLabel.setAlignment(Qt.AlignCenter) self.tutorialLabel.setFont(QFont('Sans Serif', 13)) #Censor type group self.censorTypeGroupBox = QGroupBox('Censor Type') barButton = QRadioButton('Bar censor') mosaicButton = QRadioButton('Mosaic censor') barButton.setChecked(True) censorLayout = QVBoxLayout() censorLayout.addWidget(barButton) censorLayout.addWidget(mosaicButton) # censorLayout.addStretch(1) self.censorTypeGroupBox.setLayout(censorLayout) #Variation count group self.variationsGroupBox = QGroupBox('Number of Decensor Variations') var1Button = QRadioButton('1') var2Button = QRadioButton('2') var3Button = QRadioButton('4') var1Button.setChecked(True) varLayout = QVBoxLayout() varLayout.addWidget(var1Button) varLayout.addWidget(var2Button) varLayout.addWidget(var3Button) # varLayout.addStretch(1) self.variationsGroupBox.setLayout(varLayout) #button decensorButton = QPushButton('Decensor Your Images') decensorButton.clicked.connect(self.decensorClicked) decensorButton.setSizePolicy( QSizePolicy.Preferred, QSizePolicy.Preferred) #put all groups into grid grid_layout.addWidget(self.tutorialLabel, 0, 0, 1, 2) grid_layout.addWidget(self.censorTypeGroupBox, 1, 0, 1, 1) grid_layout.addWidget(self.variationsGroupBox, 1, 1, 1, 1) grid_layout.addWidget(decensorButton, 2, 0, 1, 2) #window size settings self.resize(300, 300) self.center() self.setWindowTitle('DeepCreamPy v2.2.0') self.show()
class ReverseWidget(ToolWidget): def __init__(self, parent=None): super(ReverseWidget, self).__init__(parent) self.tineye_radio = QRadioButton(self.tr("TinEye")) self.tineye_radio.setIcon(QIcon("icons/tineye.png")) self.google_radio = QRadioButton(self.tr("Google")) self.google_radio.setIcon(QIcon("icons/google.svg")) self.bing_radio = QRadioButton(self.tr("Bing")) self.bing_radio.setIcon(QIcon("icons/bing.svg")) self.root_radio = QRadioButton(self.tr("RootAbout")) self.root_radio.setIcon(QIcon("icons/rootabout.png")) self.karma_radio = QRadioButton(self.tr("KarmaDecay")) self.karma_radio.setIcon(QIcon("icons/karmadecay.jpg")) self.tineye_radio.setChecked(True) self.last_radio = self.tineye_radio self.web_view = QWebEngineView() self.choose() self.tineye_radio.clicked.connect(self.choose) self.google_radio.clicked.connect(self.choose) self.bing_radio.clicked.connect(self.choose) self.root_radio.clicked.connect(self.choose) self.karma_radio.clicked.connect(self.choose) top_layout = QHBoxLayout() top_layout.addWidget(QLabel(self.tr("Search engine:"))) top_layout.addWidget(self.tineye_radio) top_layout.addWidget(self.google_radio) top_layout.addWidget(self.bing_radio) top_layout.addWidget(self.root_radio) top_layout.addWidget(self.karma_radio) top_layout.addStretch() main_layout = QVBoxLayout() main_layout.addLayout(top_layout) main_layout.addWidget(self.web_view) self.setLayout(main_layout) def choose(self): if self.tineye_radio.isChecked(): self.web_view.load(QUrl("https://tineye.com/")) self.last_radio = self.tineye_radio elif self.google_radio.isChecked(): self.web_view.load(QUrl("https://www.google.com/imghp")) self.last_radio = self.google_radio elif self.bing_radio.isChecked(): self.web_view.load( QUrl("https://www.bing.com/?scope=images&nr=1&FORM=NOFORM")) self.last_radio = self.bing_radio elif self.root_radio.isChecked(): self.web_view.load(QUrl("http://rootabout.com/")) self.last_radio = self.root_radio elif self.karma_radio.isChecked(): self.web_view.load(QUrl("http://karmadecay.com/")) self.last_radio = self.karma_radio else: self.last_radio.setChecked(True)
def __init__(self, buttons, index, parent=None): QVBoxLayout.__init__(self) self.setSpacing(0) self.group = QButtonGroup() for i, button in enumerate(buttons): btn = QRadioButton(button) if i == index: btn.setChecked(True) self.addWidget(btn) self.group.addButton(btn, i)
def __init__(self): QWidget.__init__(self) self.layout = QHBoxLayout() # start main panel self.list = QListWidget() self.table = QTableWidget() self.table.setColumnCount(3) self.table.setHorizontalHeaderLabels(["Track Name", "Artist", "Album"]) self.right = QVBoxLayout() self.right.setMargin(10) # self.right.addStretch() self.filter_group = QGroupBox("Filters") filter_artist = QRadioButton("By Artist") filter_genre = QRadioButton("By Genre") filter_track = QRadioButton("By Track") filter_artist.setChecked(True) vbox = QVBoxLayout() vbox.addWidget(filter_artist) vbox.addWidget(filter_genre) vbox.addWidget(filter_track) # vbox.addStretch(1) self.filter_group.setLayout(vbox) self.search_layout = QHBoxLayout() self.search_field = QLineEdit() self.search_layout.addWidget(QLabel("Search Term")) self.search_layout.addWidget(self.search_field) self.neg_search_button = QCheckBox("Enable Negative Search") create_box = QGroupBox("Create Playlist") vbox_create_playlist = QVBoxLayout() hbox_name = QHBoxLayout() self.create_name_field = QLineEdit() hbox_name.addWidget(QLabel("Name")) hbox_name.addWidget(self.create_name_field) self.desc_edit = QPlainTextEdit() self.create_button = QPushButton("Create Playlist") vbox_create_playlist.addLayout(hbox_name) vbox_create_playlist.addWidget(QLabel("Description")) vbox_create_playlist.addWidget(self.desc_edit) vbox_create_playlist.addWidget(self.create_button) create_box.setLayout(vbox_create_playlist) self.right.addWidget(self.filter_group) self.right.addLayout(self.search_layout) self.right.addWidget(self.neg_search_button) self.right.addWidget(create_box) self.layout.addWidget(self.list) self.layout.addWidget(self.table) self.layout.addLayout(self.right) self.setLayout(self.layout) # end main panel
def load_available(self): self.ava_table.setRowCount(0) self.ava_table.clearContents() for name, info in G.config.DB_INFO.items(): self.ava_table.insertRow(0) self.ava_table.setItem(0, 0, QTableWidgetItem(name)) radio = QRadioButton(self) self.btn_group.addButton(radio) radio.clicked.connect(self.radio_slot) if name == G.config.WHICH_DB: radio.setChecked(True) self.ava_table.setCellWidget(0, 1, radio)
def make_radio_box(self, chk_default): radio_layout = QVBoxLayout() for key in self.target_dict: button_key = QRadioButton(key, self) button_key.clicked.connect(self.radiobox_check) if key == chk_default: button_key.setChecked(True) self.result = self.target_dict[key] auto_atr = "radio_" + key setattr(self, auto_atr, button_key) radio_layout.addWidget(button_key) return radio_layout
def set_whittles(self, whittles: list): self.whittles = whittles for _id, whittle in enumerate(self.whittles): whittle_item = QRadioButton(whittle) self.start_whittle_button_group.addButton(whittle_item) self.start_whittle_button_group.setId(whittle_item, _id) if _id == 0: whittle_item.setChecked(True) self.whittle_id = 0 self.layout.addWidget(whittle_item) self.start_whittle_button_group.buttonClicked.connect(self.start_whittle_change) self.buttons.accepted.connect(self.accept) self.buttons.rejected.connect(self.reject) self.layout.addWidget(self.buttons)
def set_surpacs(self, surpacs: list): self.surpacs = surpacs for _id, surpac in enumerate(surpacs): surpac_item = QRadioButton(surpac) self.start_surpac_button_group.addButton(surpac_item) self.start_surpac_button_group.setId(surpac_item, _id) if _id == 0: surpac_item.setChecked(True) self.surpac_id = 0 self.layout.addWidget(surpac_item) self.start_surpac_button_group.buttonClicked.connect( self.start_surpac_change) self.buttons.accepted.connect(self.accept) self.buttons.rejected.connect(self.reject) self.layout.addWidget(self.buttons)
def configFilterTypeButtons(self, name=u"default", checked=False, xPos=0, yPos=0, idButton=0): button = QRadioButton(self) button.setObjectName(name) button.setEnabled(True) button.setGeometry(QRect(xPos, yPos, 82, 17)) button.setCursor(QCursor(Qt.PointingHandCursor)) button.setChecked(checked) lam = lambda id=idButton: self.buttonChecked(id) self.connect(button, SIGNAL("clicked()"), lam) self.filterTypeButtons.addButton(button, idButton)
def set_minescheds(self, minescheds: list): self.minescheds = minescheds for _id, minesched in enumerate(self.minescheds): minesched_item = QRadioButton(minesched) self.start_minesched_button_group.addButton(minesched_item) self.start_minesched_button_group.setId(minesched_item, _id) if _id == 0: minesched_item.setChecked(True) self.minesched_id = 0 self.layout.addWidget(minesched_item) self.start_minesched_button_group.buttonClicked.connect( self.start_minesched_change) self.buttons.accepted.connect(self.accept) self.buttons.rejected.connect(self.reject) self.layout.addWidget(self.buttons)
def initUI(self): grid_layout = QGridLayout() grid_layout.setSpacing(10) self.setLayout(grid_layout) #Censor type group self.censorTypeGroupBox = QGroupBox('Censor Type') barButton = QRadioButton('Bar censor') mosaicButton = QRadioButton('Mosaic censor') barButton.setChecked(True) censorLayout = QVBoxLayout() censorLayout.addWidget(barButton) censorLayout.addWidget(mosaicButton) censorLayout.addStretch(1) self.censorTypeGroupBox.setLayout(censorLayout) #Variation count group self.variationsGroupBox = QGroupBox('Number of Decensor Variations') var1Button = QRadioButton('1') var2Button = QRadioButton('2') var3Button = QRadioButton('4') var1Button.setChecked(True) varLayout = QVBoxLayout() varLayout.addWidget(var1Button) varLayout.addWidget(var2Button) varLayout.addWidget(var3Button) varLayout.addStretch(1) self.variationsGroupBox.setLayout(varLayout) #button decensorButton = QPushButton('Decensor Your Images') decensorButton.clicked.connect(self.decensorClicked) #put all groups into grid grid_layout.addWidget(self.censorTypeGroupBox, 0, 0, 1, 1) grid_layout.addWidget(self.variationsGroupBox, 0, 1, 1, 1) grid_layout.addWidget(decensorButton, 1, 0, 1, 2) #window size settings self.resize(300, 200) self.center() self.setWindowTitle('DeepCreamPy v2.2.0') self.show()
def __init__(self, numwin: int): super(QW_NumWin, self).__init__() r1 = QRadioButton("one window") r1.toggled.connect(self.checked) r2 = QRadioButton("two window") r2.toggled.connect(self.checked) button_group_numwin = QButtonGroup() button_group_numwin.addButton(r1) button_group_numwin.addButton(r2) if numwin == 1: r1.setChecked(True) else: r2.setChecked(True) self.layout_numwin = QHBoxLayout() self.layout_numwin.addWidget(r1, alignment=Qt.AlignLeft) self.layout_numwin.addWidget(r2, alignment=Qt.AlignLeft) self.setLayout(self.layout_numwin)
def createTopLeftGroupBox(self): self.topLeftGroupBox = QGroupBox("Group 1") radioButton1 = QRadioButton("Radio button 1") radioButton2 = QRadioButton("Radio button 2") radioButton3 = QRadioButton("Radio button 3") radioButton1.setChecked(True) checkBox = QCheckBox("Tri-state check box") checkBox.setTristate(True) checkBox.setCheckState(Qt.PartiallyChecked) layout = QVBoxLayout() layout.addWidget(radioButton1) layout.addWidget(radioButton2) layout.addWidget(radioButton3) layout.addWidget(checkBox) layout.addStretch(1) self.topLeftGroupBox.setLayout(layout)
def __init__(self, parent): super(WelcomePage, self).__init__(parent) self.parent_wizard = weakref.proxy(parent) self.setTitle('Welcome') basic_radio = QRadioButton('&Basic') basic_radio.setChecked(True) self.advanced_radio = QRadioButton('&Advanced') group = QButtonGroup(self) group.addButton(basic_radio) group.addButton(self.advanced_radio) grid = QGridLayout(self) grid.addWidget(basic_radio, 0, 0) grid.addWidget(self.advanced_radio, 1, 0) self.registerField('basic', basic_radio) self.setLayout(grid)
def __init__(self, parent): super().__init__(parent) self.parent_wizard = weakref.proxy(parent) self.setTitle('Continuous criteria') # Radio button, if yes then ask for inputs self.yes = QRadioButton( '&Yes, there are criteria that needs to be calculated') no = QRadioButton( 'N&o, I will manually give a rating for every choice and criteria') no.setChecked(True) self.registerField('yes', self.yes) self.yes.toggled.connect(self.toggled) group = QButtonGroup(self) group.addButton(self.yes) group.addButton(no) # Duplicated from AbstractMultiInputPage self.line_edit = QLineEdit() self.list_widget = QListWidget() self.add_button = QPushButton('&Add criterion') self.delete_button = QPushButton('&Delete') self.line_edit.setDisabled(True) self.list_widget.setDisabled(True) self.add_button.setDisabled(True) self.delete_button.setDisabled(True) self.line_edit.returnPressed.connect(self.add_item) self.add_button.clicked.connect(self.add_item) self.delete_button.clicked.connect(self.delete_item) grid = QGridLayout(self) grid.addWidget(self.yes, 0, 0) grid.addWidget(no, 1, 0) grid.addWidget(self.line_edit, 2, 0) grid.addWidget(self.add_button, 2, 1) grid.addWidget(self.list_widget, 3, 0) grid.addWidget(self.delete_button, 3, 1, Qt.AlignTop) self.setLayout(grid)
class MyForm(QWidget): def __init__(self, parent=None): QWidget.__init__(self, parent) self.setWindowTitle('Button Demo') self.button = QPushButton('&Ok', self) self.button.clicked.connect(self.okButtonClicked) self.checkBox = QCheckBox('&Case sensitivity', self) self.checkBox.toggled.connect(self.onCaseSensitivity) box = QGroupBox("Sex", self) self.button1 = QRadioButton("Male", box) self.button2 = QRadioButton("Female", box) self.button1.setChecked(True) groupBoxLayout = QVBoxLayout(box) groupBoxLayout.addWidget(self.button1) groupBoxLayout.addWidget(self.button2) self.button1.toggled.connect(self.onMale) mainlayout = QVBoxLayout() mainlayout.addWidget(self.button) mainlayout.addWidget(self.checkBox) mainlayout.addWidget(box) self.setLayout(mainlayout) def okButtonClicked(self): devices = asyncio.run(discover(timeout=2.0)) for d in devices: print(d) print('okButtonClicked') def onCaseSensitivity(self, toggle): print('okCaseSensitity', toggle) print(self.checkBox.isChecked()) def onMale(self, toggle): print('onMale', toggle)
def __init__(self, blacklisted_names=[], parent=None): super(CreateBufferDialog, self).__init__(parent) self.setWindowTitle('Create new buffer') self.blacklisted_names = blacklisted_names layout = QVBoxLayout() self.buff_name = QLineEdit("Buffer name") self.buff_width = QLineEdit("Buffer size (bytes)") layout.addWidget(self.buff_name) layout.addWidget(self.buff_width) self.constraints = dict() for cid in sorted(CreateBufferDialog.constraint_list.keys()): name = CreateBufferDialog.constraint_list[cid] item = QRadioButton(name) if cid == NO_CONSTRAINTS: item.setChecked(True) self.constraints[cid] = item layout.addWidget(item) self.checkbox_terminator = QCheckBox("Terminator") self.checkbox_terminator.setChecked(True) layout.addWidget(self.checkbox_terminator) self.ok = QPushButton("Ok") self.ok.clicked.connect(self.on_okClick) self.cancel = QPushButton("Cancel") self.cancel.clicked.connect(self.on_cancelClick) layout.addWidget(self.ok) layout.addWidget(self.cancel) self.setLayout(layout) self.res_name = None self.res_width = None self.res_constraints = None
def rebuild_class_selection(self, obj): # clear layout for i in range(self.class_selection_layout.count()): item = self.class_selection_layout.itemAt(0) widget = item.widget() widget.hide() self.class_selection_layout.removeItem(item) self.buttons_obj_dict = {} self.active_class_index = -1 if find_type_in_object(obj, NodeInstance): # NI class node_inst_class_RB = QRadioButton('NodeInstance') node_inst_class_RB.toggled.connect(self.class_RB_toggled) self.buttons_obj_dict[node_inst_class_RB] = obj self.class_selection_layout.addWidget(node_inst_class_RB, 0, 0) # main_widget class if obj.main_widget is not None: main_widget_class_RB = QRadioButton('MainWidget') main_widget_class_RB.toggled.connect(self.class_RB_toggled) self.buttons_obj_dict[main_widget_class_RB] = obj.main_widget self.class_selection_layout.addWidget(main_widget_class_RB, 1, 0) # data input widgets row_count = 0 for inp in obj.inputs: if inp.widget is not None: inp_widget_class_RB = QRadioButton( 'Input ' + str(obj.inputs.index(inp))) inp_widget_class_RB.toggled.connect(self.class_RB_toggled) self.buttons_obj_dict[inp_widget_class_RB] = inp.widget self.class_selection_layout.addWidget( inp_widget_class_RB, row_count, 1) row_count += 1 node_inst_class_RB.setChecked(True)
class Config(SignalNode.Config): """Config widget displayed for LSLInput.""" def __init__(self, parent=None): super().__init__(parent=parent) layout = QFormLayout() self.setLayout(layout) self.vector = QLineEdit() self.vector.setPlaceholderText("Fp1=1;Cz=-1;...") self.vector.editingFinished.connect(self.updateModel) self.vector_path = PathEdit() dialog = QFileDialog(self, "Open") dialog.setFileMode(dialog.AnyFile) self.vector_path.setDialog(dialog) self.vector_path.pathChanged.connect(self.updateModel) # Vector data can be contained in a file or inputted directly from a file self.vector_radio_button = QRadioButton("Filter vector") self.vector_radio_button.toggled.connect(self.vector.setEnabled) self.vector_radio_button.clicked.connect(self.updateModel) self.vector_path_radio_button = QRadioButton("Filter vector file") self.vector_path_radio_button.toggled.connect(self.vector_path.setEnabled) self.vector_path_radio_button.clicked.connect(self.updateModel) layout.addRow(self.vector_radio_button, self.vector) layout.addRow(self.vector_path_radio_button, self.vector_path) self.vector_radio_button.setChecked(True) self.vector_path.setEnabled(False) def updateModel(self): n = self.node() if n is None: return if self.vector.isEnabled(): n.setVector(self.vector.text()) else: n.setVectorPath(self.vector_path.text()) def updateView(self): n = self.node() if n is None: return self.vector.blockSignals(True) self.vector_path.blockSignals(True) if n.vector() is not None: self.vector.setText(n.vector()) self.vector_radio_button.setChecked(True) else: self.vector_path.setText(n.vectorPath()) self.vector_path_radio_button.setChecked(True) self.vector.blockSignals(False) self.vector_path.blockSignals(False)
def make_layout(self) -> QLayout: """Builds the layout of widgets for user-selected import parameters.""" param_list = self.import_type["params"] widget_layout = QVBoxLayout() widget_elements = dict() for param_item in param_list: name = param_item["name"] type = param_item["type"] options = param_item.get("options", None) if type == "radio": radio_group = QButtonGroup(parent=self) option_list = options.split(",") selected_option = option_list[0] for option in option_list: btn_widget = QRadioButton(option) if option == selected_option: btn_widget.setChecked(True) widget_layout.addWidget(btn_widget) radio_group.addButton(btn_widget) radio_group.buttonToggled.connect(lambda: self.changed.emit()) widget_elements[name] = radio_group elif type == "check": check_widget = QCheckBox(name) check_widget.stateChanged.connect(lambda: self.changed.emit()) widget_layout.addWidget(check_widget) widget_elements[name] = check_widget elif type == "function_menu": list_widget = QComboBox() # options has name of method which returns list of options option_list = getattr(self, options)() for option in option_list: list_widget.addItem(option) list_widget.currentIndexChanged.connect( lambda: self.changed.emit()) widget_layout.addWidget(list_widget) widget_elements[name] = list_widget self.widget_elements = widget_elements return widget_layout
def __init__(self, title: str, index_to_label: Dict[int, str], is_vertical=True, checked_index: Optional[int] = None, parent=None): super().__init__(parent) self.__mapping = {} self.__main_layout = QVBoxLayout() self.__group_box = QGroupBox(title) self.__button_group = QButtonGroup() if is_vertical: self.__group_box_layout = QVBoxLayout() else: self.__group_box_layout = QHBoxLayout() for index, label in index_to_label.items(): button = QRadioButton(label) self.__button_group.addButton(button, index) self.__group_box_layout.addWidget(button) if checked_index == index: button.setChecked(True) self.__group_box.setLayout(self.__group_box_layout) self.__button_group.idToggled.connect(self.__on_toggled) self.__main_layout.addWidget(self.__group_box) self.setLayout(self.__main_layout)
class WelcomePage(QWizardPage): def __init__(self, parent): super(WelcomePage, self).__init__(parent) self.parent_wizard = weakref.proxy(parent) self.setTitle('Welcome') basic_radio = QRadioButton('&Basic') basic_radio.setChecked(True) self.advanced_radio = QRadioButton('&Advanced') group = QButtonGroup(self) group.addButton(basic_radio) group.addButton(self.advanced_radio) grid = QGridLayout(self) grid.addWidget(basic_radio, 0, 0) grid.addWidget(self.advanced_radio, 1, 0) self.registerField('basic', basic_radio) self.setLayout(grid) def initializePage(self): if self.parent_wizard.main_parent.matrix.continuous_criteria: self.advanced_radio.setChecked(True)
def _setup_ui(self): layout = QVBoxLayout(self) self.setLayout(layout) layout.setMargin(1) layout.setSpacing(1) layout.addSpacing(50) l = QLabel('BANK S', self) l.setMinimumHeight(20) l.setAlignment(Qt.AlignCenter | Qt.AlignBottom) font = l.font() font.setPointSize(7) font.setBold(True) l.setFont(font) layout.addWidget(l, Qt.AlignCenter) bank_s = QRadioButton(self) bank_s.setStyleSheet( 'QRadioButton::indicator{subcontrol-position:center;}') layout.addWidget(bank_s, Qt.AlignTop | Qt.AlignCenter) s_only = QRadioButton(self) s_only.setStyleSheet( 'QRadioButton::indicator{subcontrol-position:center;}') s_only.toggled.connect( lambda s: self._usbif.send(um.WriteControlBankS(s))) layout.addWidget(s_only, Qt.AlignTop | Qt.AlignCenter) l = QLabel('S ONLY', self) l.setAlignment(Qt.AlignCenter | Qt.AlignTop) l.setFont(font) layout.addWidget(l, Qt.AlignTop | Qt.AlignCenter) bank_s.setChecked(True)
class LCAResultsTab(NewAnalysisTab): """Class for the 'LCA Results' sub-tab. This tab allows the user to get a basic overview of the results of the calculation setup. Shows: 'Overview' and 'by LCIA method' options for different plots/graphs Plots/graphs Export buttons """ def __init__(self, parent=None): super().__init__(parent) self.parent = parent self.lca_scores_widget = LCAScoresTab(parent) self.lca_overview_widget = LCIAResultsTab(parent) self.layout.setAlignment(QtCore.Qt.AlignTop) self.layout.addLayout(get_header_layout('LCA Results')) # buttons button_layout = QHBoxLayout() self.button_group = QButtonGroup() self.button_overview = QRadioButton("Overview") self.button_overview.setToolTip( "Show a matrix of all functional units and all impact categories") button_layout.addWidget(self.button_overview) self.button_by_method = QRadioButton("by LCIA method") self.button_by_method.setToolTip( "Show the impacts of each functional unit for the selected impact categories" ) self.button_by_method.setChecked(True) self.scenario_label = QLabel("Scenario:") self.button_group.addButton(self.button_overview, 0) self.button_group.addButton(self.button_by_method, 1) button_layout.addWidget(self.button_by_method) button_layout.addWidget(self.scenario_label) button_layout.addWidget(self.scenario_box) button_layout.addStretch(1) self.layout.addLayout(button_layout) self.layout.addWidget(self.lca_scores_widget) self.layout.addWidget(self.lca_overview_widget) self.button_clicked(False) self.connect_signals() def connect_signals(self): self.button_overview.toggled.connect(self.button_clicked) if self.using_presamples: self.scenario_box.currentIndexChanged.connect( self.parent.update_scenario_data) self.parent.update_scenario_box_index.connect( lambda index: self.set_combobox_index(self.scenario_box, index )) self.button_by_method.toggled.connect( lambda on_lcia: self.scenario_box.setHidden(on_lcia)) self.button_by_method.toggled.connect( lambda on_lcia: self.scenario_label.setHidden(on_lcia)) @QtCore.Slot(bool, name="overviewToggled") def button_clicked(self, is_overview: bool): self.lca_overview_widget.setVisible(is_overview) self.lca_scores_widget.setHidden(is_overview) def configure_scenario(self): """Allow scenarios options to be visible when used.""" super().configure_scenario() self.scenario_box.setHidden(self.button_by_method.isChecked()) self.scenario_label.setHidden(self.button_by_method.isChecked()) def update_tab(self): """Update the tab.""" self.lca_scores_widget.update_tab() self.lca_overview_widget.update_plot() self.lca_overview_widget.update_table()
class InventoryTab(NewAnalysisTab): """Class for the 'Inventory' sub-tab. This tab allows for investigation of the inventories of the calculation. Shows: Option to choose between 'Biosphere flows' and 'Technosphere flows' Inventory table for either 'Biosphere flows' or 'Technosphere flows' Export options """ def __init__(self, parent=None): super().__init__(parent) self.df_biosphere = None self.df_technosphere = None self.layout.addLayout(get_header_layout('Inventory')) # buttons button_layout = QHBoxLayout() self.radio_button_biosphere = QRadioButton("Biosphere flows") self.radio_button_biosphere.setChecked(True) button_layout.addWidget(self.radio_button_biosphere) self.radio_button_technosphere = QRadioButton("Technosphere flows") self.scenario_label = QLabel("Scenario:") button_layout.addWidget(self.radio_button_technosphere) button_layout.addWidget(self.scenario_label) button_layout.addWidget(self.scenario_box) button_layout.addStretch(1) self.layout.addLayout(button_layout) # table self.table = InventoryTable(self.parent) self.table.table_name = 'Inventory_' + self.parent.cs_name self.layout.addWidget(self.table) self.layout.addLayout(self.build_export(has_plot=False, has_table=True)) self.connect_signals() def connect_signals(self): self.radio_button_biosphere.toggled.connect(self.button_clicked) if self.using_presamples: self.scenario_box.currentIndexChanged.connect( self.parent.update_scenario_data) self.parent.update_scenario_box_index.connect( lambda index: self.set_combobox_index(self.scenario_box, index )) @QtCore.Slot(bool, name="isBiosphereToggled") def button_clicked(self, toggled: bool): """Update table according to radiobutton selected.""" if not toggled: self.update_table(inventory='technosphere') self.table.table_name = self.parent.cs_name + '_Inventory_technosphere' else: self.update_table(inventory='biosphere') self.table.table_name = self.parent.cs_name + '_Inventory' def configure_scenario(self): """Allow scenarios options to be visible when used.""" super().configure_scenario() self.scenario_label.setVisible(self.using_presamples) def update_tab(self): """Update the tab.""" self.clear_tables() super().update_tab() def update_table(self, inventory='biosphere'): """Update the table.""" if inventory == 'biosphere': if self.df_biosphere is None: self.df_biosphere = self.parent.contributions.inventory_df( inventory_type='biosphere') self.table.sync(self.df_biosphere) else: if self.df_technosphere is None: self.df_technosphere = self.parent.contributions.inventory_df( inventory_type='technosphere') self.table.sync(self.df_technosphere) def clear_tables(self) -> None: """Set the biosphere and technosphere to None.""" self.df_biosphere, self.df_technosphere = None, None