def setup_ui(self): self.l = l = QVBoxLayout(self) self.splitter = s = QSplitter(self) l.addWidget(s) self.ab = b = self.bb.addButton(_('Add new account'), QDialogButtonBox.ButtonRole.ActionRole) b.clicked.connect(self.add_account) l.addWidget(self.bb) self.accounts = a = QListWidget(self) a.setDragDropMode(QAbstractItemView.DragDropMode.InternalMove) self.edit_account = e = EditAccount(self) e.changed.connect(self.data_changed) e.delete_requested.connect(self.delete_requested) s.addWidget(a), s.addWidget(e) for n, account in enumerate(self.db[self.key]['accounts']): if n == 0: e.data = account i = QListWidgetItem(account['username'], a) i.setData(Qt.ItemDataRole.UserRole, account) if a.count() < 1: na = {'username': '', 'password': '', 'notes': ''} i = QListWidgetItem('', a) i.setData(Qt.ItemDataRole.UserRole, na) a.setCurrentRow(0) a.currentItemChanged.connect(self.current_item_changed)
def questionPlayPageUI(self): layout = QFormLayout() self.questionPlayPage.titleDisplay = QLabel() layout.addRow(self.questionPlayPage.titleDisplay) self.questionPlayPage.contentDisplay = QLabel() layout.addRow(self.questionPlayPage.contentDisplay) self.questionPlayPage.choiceList = QListWidget() self.questionPlayPage.playerScores = QLabel() layout.addRow(self.questionPlayPage.choiceList, self.questionPlayPage.playerScores) self.questionPlayPage.chooseButton = QPushButton("&Submit") self.questionPlayPage.chooseButton.clicked.connect( self.submitPlayQuestion) layout.addRow(self.questionPlayPage.chooseButton) self.questionPlayPage.collapseButton = QPushButton("Collapse!") self.questionPlayPage.collapseButton.clicked.connect( self.goTo_CollapsePage) self.questionPlayPage.abortButton = QPushButton("Abort") self.questionPlayPage.abortButton.clicked.connect( self.abortGameInProgress) layout.addRow(self.questionPlayPage.collapseButton, self.questionPlayPage.abortButton) self.questionPlayPage.setLayout(layout)
def playerAdmissionsPageUI(self): layout = QFormLayout() self.playerAdmissionsPage.createAnAccountButton = QPushButton( "&Create New Account!") self.playerAdmissionsPage.createAnAccountButton.clicked.connect( self.goTo_AccountCreationPage) layout.addRow(self.playerAdmissionsPage.createAnAccountButton) self.playerAdmissionsPage.proceedToLoginButton = QPushButton("&Login") self.playerAdmissionsPage.proceedToLoginButton.clicked.connect( self.goTo_LoginPage) layout.addRow(self.playerAdmissionsPage.proceedToLoginButton) self.playerAdmissionsPage.readyList = QListWidget() layout.addRow(self.playerAdmissionsPage.readyList) self.playerAdmissionsPage.removePlayerButton = QPushButton( "&Remove Selected Players") self.playerAdmissionsPage.removePlayerButton.clicked.connect( self.removePlayerFromPlayerAdmissionsPageList) layout.addRow(self.playerAdmissionsPage.removePlayerButton) self.playerAdmissionsPage.startGameButton = QPushButton("&Start Game!") self.playerAdmissionsPage.startGameButton.clicked.connect( self.startNewGame) layout.addRow(self.playerAdmissionsPage.startGameButton) self.playerAdmissionsPage.proceedToFacilAuthPageButton = QPushButton( "&Faciliator Page") self.playerAdmissionsPage.proceedToFacilAuthPageButton.clicked.connect( self.goTo_FacilAuthPage) layout.addRow(self.playerAdmissionsPage.proceedToFacilAuthPageButton) self.playerAdmissionsPage.setLayout(layout)
def setup_layout(self): lay = QtWidgets.QHBoxLayout(self) selectedLayout = QVBoxLayout() self.mInput = QListWidget() selectedLayout.addWidget(QLabel("Selected:")) selectedLayout.addWidget(self.mInput) availableLayout = QVBoxLayout() self.mOuput = QListWidget() availableLayout.addWidget(QLabel("Available")) availableLayout.addWidget(self.mOuput) self.mButtonToSelected = QtWidgets.QPushButton(">>") self.mBtnMoveToAvailable = QtWidgets.QPushButton(">") self.mBtnMoveToSelected = QtWidgets.QPushButton("<") self.mButtonToAvailable = QtWidgets.QPushButton("<<") vlay = QtWidgets.QVBoxLayout() vlay.addStretch() vlay.addWidget(self.mButtonToSelected) vlay.addWidget(self.mBtnMoveToAvailable) vlay.addWidget(self.mBtnMoveToSelected) vlay.addWidget(self.mButtonToAvailable) vlay.addStretch() self.mBtnUp = QtWidgets.QPushButton("Up") self.mBtnDown = QtWidgets.QPushButton("Down") vlay2 = QtWidgets.QVBoxLayout() vlay2.addStretch() vlay2.addWidget(self.mBtnUp) vlay2.addWidget(self.mBtnDown) vlay2.addStretch() lay.addLayout(selectedLayout) lay.addLayout(vlay) lay.addLayout(availableLayout) lay.addLayout(vlay2) self.update_buttons_status() self.connections()
def __init__(self, parent=None): super(MainWidget, self).__init__(parent) self.setWindowTitle("QThread Demo") self.thread = Worker() self.listFile = QListWidget() self.buttonStart = QPushButton("开始") layout = QGridLayout(self) layout.addWidget(self.listFile, 0, 0, 1, 2) layout.addWidget(self.buttonStart, 1, 1) self.buttonStart.clicked.connect(self.slotStart) self.thread.sinOut.connect(self.slodAdd)
def __init__( self, parent=None, ): super(AllKeysDialog, self).__init__(parent) layout = QVBoxLayout(self) label = QLabel("Below you can see a list with all the supported keys.") self.list = QListWidget() self.listAllKeys() layout.addWidget(label) layout.setAlignment(label, Qt.Alignment.AlignTop) layout.addWidget(self.list) self.setLayout(layout) self.window().setMaximumWidth(300)
def setupUi(self, TrainPanel): self.parent = TrainPanel self.mainLayout = QHBoxLayout(TrainPanel) self.bigFont = QLabel().font() self.bigFont.setPointSize(13) self.actionsLayout = QHBoxLayout(TrainPanel) # self.checkRecording = QCheckBox(TrainPanel) self.calibrateButton = QPushButton("Calibrate", parent=TrainPanel) self.calibrateButton.setFont(self.bigFont) self.calibrateButton.setStyleSheet(CustomQStyles.buttonStyle) self.calibrateButton.setMinimumHeight(50) self.calibrateButton.setMaximumWidth(170) self.calibrateButton.setMinimumWidth(120) self.sessionButton = QPushButton("Session", parent=TrainPanel) self.sessionButton.setFont(self.bigFont) self.sessionButton.setStyleSheet(CustomQStyles.outlineButtonStyle) self.sessionButton.setMinimumHeight(50) self.sessionButton.setMaximumWidth(170) self.sessionButton.setMinimumWidth(120) self.listFiles = QListWidget(TrainPanel) self.listFiles.setFont(self.bigFont) self.label = QLabel('or select', parent=TrainPanel) self.subjectLayout = QVBoxLayout(TrainPanel) print("init") self.box1 = QGroupBox(parent=TrainPanel) self.box2 = QGroupBox(parent=TrainPanel) self.wizard = CalibrateWizard(parent=TrainPanel) self.setPatientsBox(TrainPanel) # right panel self.setActionsBox(TrainPanel) # left panel self.mainLayout.addWidget(self.box1, stretch=2) self.mainLayout.addWidget(self.box2, stretch=3)
def __init__(self, parent=None): super(WinForm, self).__init__(parent) self.setWindowTitle("QTimer demo") self.listFile = QListWidget() self.label = QLabel("显示当前时间") self.startButton = QPushButton("开始") self.endButton = QPushButton("结束") layout = QGridLayout(self) # 初始化定时器 self.timer = QTimer(self) # 显示时间 self.timer.timeout.connect( self.showTime) # timeout 信号连接到特定的槽,当定时器超时,发出 timeout 信号 layout.addWidget(self.label, 0, 0, 1, 2) layout.addWidget(self.startButton, 1, 0) layout.addWidget(self.endButton, 1, 1) self.startButton.clicked.connect(self.start_timer) self.endButton.clicked.connect(self.end_timer) self.setLayout(layout)
def __init__(self): super().__init__() self.setFixedSize(800, 410) self.setWindowTitle("PyLX16A Servo Testing Software") self.port_selection_box = QComboBox(self) self.port_selection_box.setFixedSize(200, 27) self.port_selection_box.move(30, 65) port_selection_box_label = QLabel("Select Port:", self) port_selection_box_label.move(30, 35) self.port_selection_box_refresh_button = QPushButton("Refresh", self) self.port_selection_box_refresh_button.setFixedSize(60, 23) self.port_selection_box_refresh_button.move(170, 38) self.id_selection_box = QListWidget(self) self.id_selection_box.setFixedSize(200, 200) self.id_selection_box.move(30, 135) id_selection_box_label = QLabel("Connected Servos:", self) id_selection_box_label.setFixedWidth(200) id_selection_box_label.move(30, 105) self.id_selection_box_refresh_button = QPushButton("Refresh", self) self.id_selection_box_refresh_button.setFixedSize(60, 23) self.id_selection_box_refresh_button.move(170, 108) self.set_id_line_edit = QLineEdit(self) self.set_id_line_edit.setFixedSize(50, 27) self.set_id_line_edit.move(80, 355) set_id_line_edit_label = QLabel("Set ID:", self) set_id_line_edit_label.move(30, 355) set_id_line_edit_label.setFixedSize(50, 27) self.set_id_button = QPushButton("Change ID!", self) self.set_id_button.setFixedSize(85, 27) self.set_id_button.move(145, 355) self.position_slider = QSlider(Qt.Orientation.Horizontal, self) self.position_slider.setMinimum(0) self.position_slider.setMaximum(240) self.position_slider.setFixedWidth(200) self.position_slider.move(300, 55) self.position_slider_readout = QLabel("0.00°", self) self.position_slider_readout.setFixedWidth(50) self.position_slider_readout.move(450, 30) self.position_slider_readout.setAlignment( Qt.AlignmentFlag.AlignRight | Qt.AlignmentFlag.AlignVCenter) position_slider_label = QLabel("Angle (degrees):", self) position_slider_label.move(300, 30) self.position_offset_slider = QSlider(Qt.Orientation.Horizontal, self) self.position_offset_slider.setMinimum(-30) self.position_offset_slider.setMaximum(30) self.position_offset_slider.setFixedWidth(200) self.position_offset_slider.move(300, 125) self.position_offset_slider_readout = QLabel("0.00°", self) self.position_offset_slider_readout.setFixedWidth(50) self.position_offset_slider_readout.move(450, 100) self.position_offset_slider_readout.setAlignment( Qt.AlignmentFlag.AlignRight | Qt.AlignmentFlag.AlignVCenter) position_offset_slider_label = QLabel("Angle offset (degrees):", self) position_offset_slider_label.setFixedWidth(200) position_offset_slider_label.move(300, 100) self.angle_lower_limit_textentry = QLineEdit(self) self.angle_lower_limit_textentry.setFixedWidth(50) self.angle_lower_limit_textentry.move(450, 175) self.angle_lower_limit_textentry.setValidator( QIntValidator(0, 240, self)) self.angle_upper_limit_textentry = QLineEdit(self) self.angle_upper_limit_textentry.setFixedWidth(50) self.angle_upper_limit_textentry.move(450, 210) self.angle_upper_limit_textentry.setValidator( QIntValidator(0, 240, self)) self.angle_lower_limit_textentry_label = QLabel( "Lower Limit (degrees):", self) self.angle_lower_limit_textentry_label.move(300, 175) self.angle_lower_limit_textentry_label.setFixedWidth(150) self.angle_upper_limit_textentry_label = QLabel( "Upper Limit (degrees):", self) self.angle_upper_limit_textentry_label.move(300, 210) self.angle_upper_limit_textentry_label.setFixedWidth(150) self.vin_lower_limit_textentry = QLineEdit(self) self.vin_lower_limit_textentry.setFixedWidth(50) self.vin_lower_limit_textentry.move(450, 265) self.vin_lower_limit_textentry.setValidator( QIntValidator(4500, 12000, self)) self.vin_upper_limit_textentry = QLineEdit(self) self.vin_upper_limit_textentry.setFixedWidth(50) self.vin_upper_limit_textentry.move(450, 300) self.vin_upper_limit_textentry.setValidator( QIntValidator(4500, 12000, self)) self.vin_lower_limit_textentry_label = QLabel( "Voltage Lower Limit (mV):", self) self.vin_lower_limit_textentry_label.move(300, 265) self.vin_lower_limit_textentry_label.setFixedWidth(150) self.vin_upper_limit_textentry_label = QLabel( "Voltage Upper Limit (mV):", self) self.vin_upper_limit_textentry_label.move(300, 300) self.vin_upper_limit_textentry_label.setFixedWidth(150) self.temp_limit_textentry = QLineEdit(self) self.temp_limit_textentry.setFixedWidth(50) self.temp_limit_textentry.move(450, 355) self.temp_limit_textentry.setValidator(QIntValidator(50, 100, self)) self.temp_limit_textentry_label = QLabel("Temp Limit (°C):", self) self.temp_limit_textentry_label.move(300, 355) self.temp_limit_textentry_label.setFixedWidth(150) self.servo_mode_radio_button = QRadioButton("Servo Mode", self) self.servo_mode_radio_button.move(565, 50) self.motor_mode_radio_button = QRadioButton("Motor Mode", self) self.motor_mode_radio_button.move(565, 75) self.motor_speed_slider = QSlider(Qt.Orientation.Horizontal, self) self.motor_speed_slider.setMinimum(-1000) self.motor_speed_slider.setMaximum(1000) self.motor_speed_slider.setFixedWidth(200) self.motor_speed_slider.move(565, 125) motor_speed_slider_label = QLabel("Motor Speed:", self) motor_speed_slider_label.move(565, 100) self.torque_enabled_checkbox = QCheckBox("Torque Enabled", self) self.torque_enabled_checkbox.move(565, 175) self.torque_enabled_checkbox.setFixedWidth(200) self.led_enabled_checkbox = QCheckBox("LED Enabled", self) self.led_enabled_checkbox.move(565, 210) self.led_enabled_checkbox.setFixedWidth(200) self.led_over_temp_checkbox = QCheckBox("LED Over Temperature", self) self.led_over_temp_checkbox.move(565, 258) self.led_over_temp_checkbox.setFixedWidth(200) self.led_over_voltage_checkbox = QCheckBox("LED Over Voltage", self) self.led_over_voltage_checkbox.move(565, 283) self.led_over_voltage_checkbox.setFixedWidth(200) self.led_rotor_locked_checkbox = QCheckBox("LED Rotor Locked", self) self.led_rotor_locked_checkbox.move(565, 308) self.led_rotor_locked_checkbox.setFixedWidth(200) self.physical_position_readout = QLabel("--°", self) self.physical_position_readout.move(565, 367) self.physical_position_readout.setFixedWidth(200) self.physical_position_readout_label = QLabel("Position", self) self.physical_position_readout_label.move(565, 347) self.temperature_readout = QLabel("-- °C", self) self.temperature_readout.move(635, 367) self.temperature_readout.setFixedWidth(200) self.temperature_readout_label = QLabel("Temperature", self) self.temperature_readout_label.move(635, 347) self.voltage_readout = QLabel("-- V", self) self.voltage_readout.move(730, 367) self.voltage_readout.setFixedWidth(200) self.voltage_readout_label = QLabel("Voltage", self) self.voltage_readout_label.move(730, 347) self.readout_update_timer = QTimer(self) self.readout_update_timer.timeout.connect(self.update_readouts) self.readout_update_timer.start(250) self.active_servo: LX16A = None self.position_slider.setValue(0) self.position_offset_slider.setValue(0) self.motor_speed_slider.setValue(0) self.id_selection_box_refresh_button.setEnabled(False) self.disable_widgets() self.port_selection_box.currentTextChanged.connect( self.port_selection_box_changed) self.port_selection_box_refresh_button.clicked.connect( self.port_refresh_button_clicked) self.id_selection_box.currentTextChanged.connect( self.id_selection_box_changed) self.id_selection_box_refresh_button.clicked.connect( self.id_refresh_button_clicked) self.set_id_button.pressed.connect(self.id_updated) self.position_slider.sliderMoved.connect(self.position_slider_updated) self.position_offset_slider.sliderMoved.connect( self.position_offset_slider_updated) self.angle_lower_limit_textentry.textChanged.connect( self.angle_lower_limit_updated) self.angle_upper_limit_textentry.textChanged.connect( self.angle_upper_limit_updated) self.vin_lower_limit_textentry.textChanged.connect( self.vin_lower_limit_updated) self.vin_upper_limit_textentry.textChanged.connect( self.vin_upper_limit_updated) self.temp_limit_textentry.textChanged.connect(self.temp_limit_updated) self.servo_mode_radio_button.toggled.connect( self.servo_mode_radio_button_toggled) self.motor_mode_radio_button.toggled.connect( self.motor_mode_radio_button_toggled) self.motor_speed_slider.valueChanged.connect( self.motor_speed_slider_updated) self.torque_enabled_checkbox.stateChanged.connect( self.torque_enabled_checkbox_toggled) self.led_enabled_checkbox.stateChanged.connect( self.led_enabled_checkbox_toggled) self.led_over_temp_checkbox.stateChanged.connect( self.led_error_triggers_checkbox_toggled) self.led_over_voltage_checkbox.stateChanged.connect( self.led_error_triggers_checkbox_toggled) self.led_rotor_locked_checkbox.stateChanged.connect( self.led_error_triggers_checkbox_toggled) self.scan_for_ports()
def questionBankPageUI(self): layout = QFormLayout() subLayout = QHBoxLayout() self.questionBankPage.questionList = QListWidget() self.questionBankPage.questionList.currentRowChanged.connect( self.displayQuestionOnQuestionBankPage) self.questionBankPage.questionTextDisplay = QLabel() self.questionBankPage.questionTextDisplay.setFixedSize(500, 100) self.questionBankPage.questionAnswersList = QListWidget() self.questionBankPage.definedCorrectAnswerDisplay = QLabel() self.questionBankPage.definedCorrectAnswerDisplay.setFixedSize(50, 10) self.questionBankPage.questionCodeParserDisplay = QLabel() self.questionBankPage.questionCodeParserDisplay.setFixedSize(100, 50) subLayout.addWidget(self.questionBankPage.questionList) subLayout.addWidget(self.questionBankPage.questionTextDisplay) subLayout.addWidget(self.questionBankPage.questionAnswersList) subLayout.addWidget(self.questionBankPage.definedCorrectAnswerDisplay) subLayout.addWidget(self.questionBankPage.questionCodeParserDisplay) layout.addRow(subLayout) self.questionBankPage.newQuestionTitle = QLineEdit() self.questionBankPage.newQuestionContent = QPlainTextEdit() layout.addRow(self.questionBankPage.newQuestionTitle, self.questionBankPage.newQuestionContent) self.questionBankPage.newQuestionAnswerInput = QLineEdit() self.questionBankPage.newQuestionAnswerList = QListWidget() layout.addRow(self.questionBankPage.newQuestionAnswerInput, self.questionBankPage.newQuestionAnswerList) colorLayout = QFormLayout() colorButtonGroup = QButtonGroup(self.questionBankPage) self.questionBankPage.yellowRadio = QRadioButton() self.questionBankPage.blueRadio = QRadioButton() self.questionBankPage.redRadio = QRadioButton() self.questionBankPage.yellowRadio.toggled.connect( self.colorRadioToggle) self.questionBankPage.blueRadio.toggled.connect(self.colorRadioToggle) self.questionBankPage.redRadio.toggled.connect(self.colorRadioToggle) colorButtonGroup.addButton(self.questionBankPage.yellowRadio) colorButtonGroup.addButton(self.questionBankPage.blueRadio) colorButtonGroup.addButton(self.questionBankPage.redRadio) colorLayout.addRow("Yellow", self.questionBankPage.yellowRadio) colorLayout.addRow("Blue", self.questionBankPage.blueRadio) colorLayout.addRow("Red", self.questionBankPage.redRadio) combLayout = QHBoxLayout() combLayout.addLayout(colorLayout) layout.addRow(combLayout) self.questionBankPage.definedNewCorrectAnswerDisplay = QLabel() layout.addRow(self.questionBankPage.definedNewCorrectAnswerDisplay) self.questionBankPage.defineCorrectAnswerButton = QPushButton( "&Define Correct Answer") self.questionBankPage.defineCorrectAnswerButton.clicked.connect( self.defineCorrectAnswer) self.questionBankPage.submitNewAnswerButton = QPushButton( "Submit &Answer") self.questionBankPage.submitNewAnswerButton.clicked.connect( self.submitNewAnswer) layout.addRow(self.questionBankPage.defineCorrectAnswerButton, self.questionBankPage.submitNewAnswerButton) self.questionBankPage.submitNewQuestionButton = QPushButton( "Submit New &Question") self.questionBankPage.submitNewQuestionButton.clicked.connect( self.submitNewQuestion) layout.addRow(self.questionBankPage.submitNewQuestionButton) self.questionBankPage.backButton = QPushButton("&Back") self.questionBankPage.backButton.clicked.connect( self.goTo_FacilStartPage) self.questionBankPage.refreshButton = QPushButton("&Refresh") self.questionBankPage.refreshButton.clicked.connect( self.goTo_QuestionBankPage) layout.addRow(self.questionBankPage.backButton, self.questionBankPage.refreshButton) self.questionBankPage.setLayout(layout)
def __init__(self, parent: QWidget = None, platforms: List[Platform] = None): super(QWidget, self).__init__(parent) self.__platforms = platforms.copy() self.__platforms_to_save = [] self.setLayout(QVBoxLayout()) mid_section: QLayout = QHBoxLayout() mid_section_labels: QLayout = QVBoxLayout() platform_name_label: QLabel = QLabel("""Platform Name""", self) platform_warning_suppress_label: QLabel = QLabel( """Warning Suppression Type""", self) mid_section_labels.addWidget(platform_name_label) mid_section_labels.addWidget(platform_warning_suppress_label) mid_section_labels.setAlignment(platform_name_label, Qt.AlignmentFlag.AlignBottom) mid_section_labels.setAlignment(platform_warning_suppress_label, Qt.AlignmentFlag.AlignTop) mid_section_edits: QLayout = QVBoxLayout() platform_name_input: QLineEdit = QLineEdit(self) platform_warning_suppress_input: QComboBox = QComboBox(self) for item in all_platform_warning_types(): platform_warning_suppress_input.addItem(str(item), item) mid_section_edits.addWidget(platform_name_input) mid_section_edits.addWidget(platform_warning_suppress_input) mid_section_edits.setAlignment(platform_name_input, Qt.AlignmentFlag.AlignBottom) mid_section_edits.setAlignment(platform_warning_suppress_input, Qt.AlignmentFlag.AlignTop) mid_section_buttons: QLayout = QVBoxLayout() mid_section.addItem(mid_section_labels) mid_section.addItem(mid_section_edits) mid_section.addItem(mid_section_buttons) add_button: QPushButton = QPushButton("Add", self) add_button.setDisabled(True) remove_button: QPushButton = QPushButton("Remove", self) remove_button.setDisabled(True) mid_section_buttons.addWidget(add_button) mid_section_buttons.addItem( QSpacerItem(0, 20, QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Minimum)) mid_section_buttons.addWidget(remove_button) mid_section_buttons.setAlignment(add_button, Qt.AlignmentFlag.AlignBottom) mid_section_buttons.setAlignment(remove_button, Qt.AlignmentFlag.AlignTop) platform_list: QListWidget = QListWidget(self) mid_section.addWidget(platform_list) buttons_section: QLayout = QHBoxLayout() self.__ok_button: QPushButton = QPushButton('Ok', self) self.__cancel_button: QPushButton = QPushButton('Cancel', self) self.__apply_button: QPushButton = QPushButton('Apply', self) buttons_section.addWidget(self.ok_button) buttons_section.addWidget(self.cancel_button) buttons_section.addWidget(self.apply_button) self.ok_button.clicked.connect(lambda: self.ok()) self.apply_button.clicked.connect(lambda: self.apply()) self.cancel_button.clicked.connect(lambda: self.cancel()) self.layout().addWidget(QLabel('Platforms', self)) self.layout().addItem(mid_section) self.layout().addItem(buttons_section) platform_name_input.textChanged.connect( lambda content: add_button.setEnabled(len(content) > 0)) def reset_inputs() -> None: platform_name_input.clear() platform_warning_suppress_input.setCurrentIndex(0) add_button.clicked.connect(lambda: self.add_platform( Platform(platform_warning_suppress_input.currentData().value, platform_name_input.text()), platform_list)) add_button.clicked.connect(lambda: reset_inputs()) for platform in self.platforms: self.add_platform(platform, platform_list) platform_list.setSelectionMode( QAbstractItemView.SelectionMode.SingleSelection) platform_list.itemSelectionChanged.connect( lambda: remove_button.setEnabled(True)) self.apply_button.setDisabled(True) def remove_selected(window: PlatformWindow, list_widget: QListWidget) -> None: platform_to_remove = list_widget.itemWidget( list_widget.item(list_widget.currentRow())).to_platform() index_of_item = -1 for i in range(len(window.__platforms_to_save)): if window.__platforms_to_save[ i].platform_name == platform_to_remove.platform_name: index_of_item = i if index_of_item != -1: window.__platforms_to_save.remove( window.__platforms_to_save[index_of_item]) list_widget.takeItem(list_widget.currentRow()) window.apply_button.setEnabled(window.apply_possible()) remove_button.clicked.connect( lambda: remove_selected(self, platform_list))
def __init__(self): super().__init__() self.setWindowTitle("📸 Random Image Tools V1.2 🔨") self.image_list = [] # ToDo: Add a "rename?" flag. Like rename image files # to store the directory path for later use self.directory_path_name = "/" # Set up the layouts layer_one = QHBoxLayout() # Select a folder, selected directory layer_one_and_a_half = QHBoxLayout() # Selected directory contents layer_two = QHBoxLayout() # Second line of buttons layer_two_vertical_one = QVBoxLayout() # Store the first column w/checkbox and "Convert" layer_two_vertical_two = QVBoxLayout() # Store the second column w/checkbox and "Open in File Browser" layer_three = QHBoxLayout() # Conversion process state vertical_layout_parent = QVBoxLayout() # Parent widget widget = QWidget() # Displays selected directory self.directory_label = QLabel() self.directory_label.setText("Directory to be worked on will show here ") self.directory_label.show() # Displays "Select folder" button self.select_a_folder_button = QPushButton() self.select_a_folder_button.setText("Select a folder:") self.select_a_folder_button.clicked.connect(self.select_folder_prompt) self.select_a_folder_button.show() # Displays the image contents of the selected folder self.image_paths_list_widget = QListWidget() self.image_paths_list_widget.show() # Displays button to initiate image conversion self.convert_to_png_button = QPushButton() self.convert_to_png_button.setText("Convert to PNG") self.convert_to_png_button.clicked.connect(self.convert_folder_to_png) self.convert_to_png_button.show() # Check boxes for "Create new folder for PNGs" and "Delete original files after converting" self.create_new_folder_checkbox = QCheckBox() self.create_new_folder_checkbox.setText("Create new folder to store converted PNG's?") self.create_new_folder_checkbox.show() self.delete_original_files_checkbox = QCheckBox() self.delete_original_files_checkbox.setText("Delete original files after converting them to PNG?") self.create_new_folder_checkbox.show() # Displays button to open selected directory in the file browser self.show_folder_button = QPushButton() self.show_folder_button.setText("Open selected folder in file browser") self.show_folder_button.clicked.connect(self.open_folder) self.show_folder_button.show() # Displays label when conversion is finished, and the corresponding progress bar self.conversion_finished_or_error_label = QLabel() self.conversion_finished_or_error_label.setText("👀 waiting for you to press \"Convert to PNG\" ") # Put the find folder button and folder selected button together layer_one.addWidget(self.select_a_folder_button) layer_one.addWidget(self.directory_label) # Image paths of selected folder layer_one_and_a_half.addWidget(self.image_paths_list_widget) # Put the convert button and open-in-finder button together layer_two_vertical_one.addWidget(self.convert_to_png_button) layer_two_vertical_one.addWidget(self.delete_original_files_checkbox) layer_two.addLayout(layer_two_vertical_one) layer_two_vertical_two.addWidget(self.show_folder_button) layer_two_vertical_two.addWidget(self.create_new_folder_checkbox) layer_two.addLayout(layer_two_vertical_two) # Label and progress bar layer_three.addWidget(self.conversion_finished_or_error_label) layer_three.setAlignment(Qt.AlignmentFlag.AlignHCenter) # Put the "convert to png" button beneath vertical_layout_parent.addLayout(layer_one) vertical_layout_parent.addLayout(layer_one_and_a_half) vertical_layout_parent.addLayout(layer_two) vertical_layout_parent.addLayout(layer_three) widget.setLayout(vertical_layout_parent) self.setCentralWidget(widget)