def settingv2rayshelltableWidget(self): v2rayConfigFiles = self.bridgetreasureChest.getV2raycoreconfigFiles() if v2rayConfigFiles == False: return v2rayConfigFilesNumber = len(v2rayConfigFiles) if (v2rayConfigFilesNumber > 0): self.tableWidgetBridge.setRowCount(0) for i in range(v2rayConfigFilesNumber): try: enable = bool(v2rayConfigFiles[i]["enable"]) hostName = str(v2rayConfigFiles[i]["hostName"]) configFileName = str(v2rayConfigFiles[i]["configFileName"]) except Exception: pass radioButtonStopStart = QRadioButton(self) radioButtonStopStart.setIcon( self.iconStop if not enable else self.iconStart) radioButtonStopStart.setChecked(True if enable else False) radioButtonStopStart.setIconSize(self.__iconSize) self.radioButtonGroup.addButton(radioButtonStopStart) self.tableWidgetBridge.setRowCount(i + 1) self.tableWidgetBridge.setCellWidget(i, 0, radioButtonStopStart) self.tableWidgetBridge.setItem(i, 1, QTableWidgetItem(hostName)) self.tableWidgetBridge.setItem( i, 2, QTableWidgetItem(configFileName)) self.tableWidgetBridge.setItem( i, 3, QTableWidgetItem( self.getProxyAddressFromJSONFile(configFileName))) self.tableWidgetBridge.resizeColumnsToContents()
def _create_effect_parameter_controls(self, zone, effect_id, effect_options): """ Creates a set of radio buttons for changing the current effect's parameter. """ widgets = [] def _clicked_param_button(): for radio in self.btn_grps["radio_param_" + zone]: if not radio.isChecked(): continue self.dbg.stdout( "Setting parameter {} for {} on {} device {} (zone: {}, colours: {})" .format(radio.option_data, radio.option_id, self.current_backend, self.current_uid, radio.zone, str(radio.colour_hex)), self.dbg.action, 1) self.middleman.set_device_state(self.current_backend, self.current_uid, self.current_serial, radio.zone, radio.option_id, radio.option_data, radio.colour_hex) self.reload_device() for effect in effect_options: if not effect["id"] == effect_id: continue for param in effect["parameters"]: label = param["label"] radio = QRadioButton() radio.setText(label) radio.clicked.connect(_clicked_param_button) radio.option_id = effect_id radio.option_data = param["data"] radio.zone = zone radio.colour_hex = param["colours"] if param["active"]: radio.setChecked(True) icon = common.get_icon("params", param["id"]) if icon: radio.setIcon(QIcon(icon)) radio.setIconSize(QSize(22, 22)) widgets.append(radio) if not widgets: return None self.btn_grps["radio_param_" + zone] = widgets return self.widgets.create_row_widget(self._("Effect Mode"), widgets, vertical=True)
class Window(QDialog): def __init__(self): super().__init__() self.title = "PyQt Image" self.left = 500 self.top = 200 self.width = 500 self.height = 500 self.IconName = "Icon/python.png" self.InitWindow() def InitWindow(self): self.setWindowTitle("Radio Button!") self.setWindowIcon(QtGui.QIcon(self.IconName)) self.setGeometry(self.left, self.top, self.width, self.height) self.RadioButton() vbox = QVBoxLayout() vbox.addWidget(self.groupBox) self.label = QLabel(self) vbox.addWidget(self.label) self.label.setFont(QtGui.QFont("Sanserif", 15)) self.setLayout(vbox) self.show() def RadioButton(self): self.groupBox = QGroupBox("What is your name?") self.groupBox.setFont(QtGui.QFont("Sanserif", 10)) hboxLayout = QHBoxLayout() self.radiobutton1 = QRadioButton("Mihir") self.radiobutton1.setChecked(True) self.radiobutton1.setIcon(QtGui.QIcon(self.IconName)) self.radiobutton1.setIconSize(QtCore.QSize(40, 40)) self.radiobutton1.setFont(QtGui.QFont("Sanserif", 10)) self.radiobutton1.toggled.connect(self.OnRadioButton) self.radiobutton2 = QRadioButton("Not Mihir") self.radiobutton2.setChecked(False) self.radiobutton2.setIcon(QtGui.QIcon(self.IconName)) self.radiobutton2.setIconSize(QtCore.QSize(40, 40)) self.radiobutton2.setFont(QtGui.QFont("Sanserif", 10)) self.radiobutton2.toggled.connect(self.OnRadioButton) hboxLayout.addWidget(self.radiobutton1) hboxLayout.addWidget(self.radiobutton2) self.groupBox.setLayout(hboxLayout) def OnRadioButton(self): radioButton = self.sender() if radioButton.isChecked(): self.label.setText("You have selected " + radioButton.text())
def show_available_colormaps(self): height = 50 selected = colormaps.read_selected_colormap_name_from_settings() for colormap_name in sorted(colormaps.maps.keys()): image = Spectrogram.create_colormap_image(colormap_name, height=height) rb = QRadioButton(colormap_name) rb.setObjectName(colormap_name) rb.setChecked(colormap_name == selected) rb.setIcon(QIcon(QPixmap.fromImage(image))) rb.setIconSize(QSize(256, height)) self.ui.scrollAreaWidgetSpectrogramColormapContents.layout().addWidget(rb)
class Submodule_Widget(QWidget): # Module Variant widget with a Name, RadioButton and an Image def __init__(self,Iterative,parent): super().__init__() Module_Name,Image_Path,Object_Name=Iterative layout=QVBoxLayout() self.setLayout(layout) label=QLabel(Module_Name) layout.addWidget(label) label.setObjectName('module_name_label') self.rdbtn=QRadioButton() self.rdbtn.setObjectName(Object_Name) self.rdbtn.setIcon(QIcon(Image_Path)) self.rdbtn.setIconSize(QSize(scale*300, scale*300)) layout.addWidget(self.rdbtn) self.setSizePolicy(QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed))
def tableWidgetBridgeAddNewV2rayConfigFile(self): configFileNames = self.onopenV2rayConfigJSONFile() if (configFileNames): for configFileName in configFileNames: rowCount = self.tableWidgetBridge.rowCount() radioButtonStopStart = QRadioButton(self) radioButtonStopStart.setIcon(self.iconStop) radioButtonStopStart.setIconSize(self.__iconSize) self.radioButtonGroup.addButton(radioButtonStopStart) self.tableWidgetBridge.setRowCount(rowCount+1) self.tableWidgetBridge.setCellWidget(rowCount, 0, radioButtonStopStart) self.tableWidgetBridge.setItem(rowCount, 1, QTableWidgetItem("")) self.tableWidgetBridge.setItem(rowCount, 2, QTableWidgetItem(configFileName)) self.tableWidgetBridge.setItem(rowCount, 3, QTableWidgetItem(self.getProxyAddressFromJSONFile(configFileName))) self.tableWidgetBridge.resizeColumnsToContents() else: pass
def Radiobutton(self): self.groupbox = QGroupBox("Choose your language!") self.groupbox.setFont(QtGui.QFont("Sansrif", 13)) hboxlayout = QVBoxLayout() radiobutton1 = QRadioButton("Python") radiobutton1.setIcon(QtGui.QIcon("python.jpg")) radiobutton1.setIconSize(QtCore.QSize(40, 40)) radiobutton1.setFont(QtGui.QFont("Sansrif", 10)) radiobutton1.setChecked(True) radiobutton1.toggled.connect(self.onselect) hboxlayout.addWidget(radiobutton1) radiobutton2 = QRadioButton("C#") radiobutton2.setIcon(QtGui.QIcon("csharp.png")) radiobutton2.setIconSize(QtCore.QSize(40, 40)) radiobutton2.setFont(QtGui.QFont("Sansrif", 10)) radiobutton2.toggled.connect(self.onselect) hboxlayout.addWidget(radiobutton2) radiobutton3 = QRadioButton("C++") radiobutton3.setIcon(QtGui.QIcon("cpp.png")) radiobutton3.setIconSize(QtCore.QSize(40, 40)) radiobutton3.setFont(QtGui.QFont("Sansrif", 10)) radiobutton3.toggled.connect(self.onselect) hboxlayout.addWidget(radiobutton3) self.groupbox.setLayout(hboxlayout)
class Window(QDialog): def __init__(self): super().__init__() self.title = 'Radio Buttom' self.top = 200 self.left = 400 self.width = 400 self.height = 200 self.iconName = 'avatar.png' self.initWindow() def initWindow(self): self.setWindowIcon(QtGui.QIcon(self.iconName)) self.setWindowTitle(self.title) self.setGeometry(self.left, self.top, self.width, self.height) self.CreateLayout() vbox = QVBoxLayout() vbox.addWidget(self.groupBox) self.label = QLabel('你选择了牛奶', self) self.label.setFont(QtGui.QFont('Sanserif', 15)) vbox.addWidget(self.label) self.setLayout(vbox) self.show() def CreateLayout(self): self.groupBox = QGroupBox("请选择一个。。。") self.groupBox.setFont(QtGui.QFont('Sanserif', 13)) hboxLayout = QHBoxLayout() self.radiobutton1 = QRadioButton('牛奶') self.radiobutton1.setChecked(True) self.radiobutton1.setIcon(QtGui.QIcon('avatar.png')) self.radiobutton1.setIconSize(QtCore.QSize(25, 25)) self.radiobutton1.setFont(QtGui.QFont('Sanserif', 13)) self.radiobutton1.toggled.connect(self.onRadioBtn) hboxLayout.addWidget(self.radiobutton1) self.radiobtn2 = QRadioButton("蛋糕") self.radiobtn2.setIcon(QtGui.QIcon("avatar.png")) self.radiobtn2.setIconSize(QtCore.QSize(25, 25)) self.radiobtn2.setFont(QtGui.QFont("Sanserif", 13)) self.radiobtn2.toggled.connect(self.onRadioBtn) hboxLayout.addWidget(self.radiobtn2) self.radiobtn3 = QRadioButton("奶茶") self.radiobtn3.setIcon(QtGui.QIcon("avatar.png")) self.radiobtn3.setIconSize(QtCore.QSize(25, 25)) self.radiobtn3.setFont(QtGui.QFont("Sanserif", 13)) self.radiobtn3.toggled.connect(self.onRadioBtn) hboxLayout.addWidget(self.radiobtn3) self.groupBox.setLayout(hboxLayout) def onRadioBtn(self): randioBtn = self.sender() if randioBtn.isChecked(): self.label.setText('你选择了' + randioBtn.text())
class Window(QDialog): def __init__(self): super(Window, self).__init__() self.ui() def ui(self): self.setWindowTitle('Диалоговое окно,выполнения дествия при нажатии радио кнопки.') self.setGeometry(320,320,200,150) # Создаем горизонтальный контейнер. self.hbox = QHBoxLayout() # Создание радио кнопки. self.radio_btn = QRadioButton('Футбол') # Устанавливаем шрифт текста. self.radio_btn.setFont(QFont('ubuntu',15)) self.radio_btn.setIcon(QIcon('user_blank.png')) self.radio_btn.setIconSize(QSize(40,40)) self.radio_btn.toggled.connect(self.button_actions) # Упаковываем горизонтальный модуль. self.hbox.addWidget(self.radio_btn) # Создание радио кнопки. self.radio_btn_2 = QRadioButton('Баскетбол') # Устанавливаем шрифт текста. self.radio_btn_2.setFont(QFont('ubuntu', 15)) self.radio_btn_2.setIcon(QIcon('basketball.png')) self.radio_btn_2.setIconSize(QSize(40, 40)) self.radio_btn_2.toggled.connect(self.button_actions) # Упаковываем горизонтальный модуль. self.hbox.addWidget(self.radio_btn_2) # Создание радио кнопки. self.radio_btn_3 = QRadioButton('Воллебол') # Устанавливаем шрифт текста. self.radio_btn_3.setFont(QFont('ubuntu', 15)) self.radio_btn_3.setIcon(QIcon('bbb.png')) self.radio_btn_3.setIconSize(QSize(40, 40)) self.radio_btn_3.toggled.connect(self.button_actions) # Упаковываем горизонтальный модуль. self.hbox.addWidget(self.radio_btn_3) self.label = QLabel(self) self.label.setFont(QFont('ubuntu',20)) # Создаем вертикальный модуль. self.vbox = QVBoxLayout() # Комплектовка вертикального модуля. self.vbox.addLayout(self.hbox) self.vbox.addWidget(self.label) # Отображаем виджеты на мониторе. self.setLayout(self.vbox) self.show() def button_actions(self): if self.radio_btn.isChecked(): self.label.setText('Мой любимый вид спорта {0}'.format(self.radio_btn.text())) elif self.radio_btn_2.isChecked(): self.label.setText('Мой любимый вид спорта {0}'.format(self.radio_btn_2.text())) elif self.radio_btn_3.isChecked(): self.label.setText('Мой любимый вид спорта {0}'.format(self.radio_btn_3.text()))
class Window(QDialog): def __init__(self): super().__init__() self.title = "Pyqt Window" self.top = 500 self.left = 500 self.width = 100 self.height = 400 self.iconName = "transistor.jpg" self.InitWindow() def InitWindow(self): self.setWindowIcon(QtGui.QIcon("transistor.jpg")) self.setWindowTitle(self.title) self.setGeometry(self.top, self.width, self.height, self.width) self.radioButton() vbox = QVBoxLayout() vbox.addWidget(self.groupBox) self.label = QLabel("") self.label.setFont(QtGui.QFont("Sanserif", 15)) vbox.addWidget(self.label) self.setLayout(vbox) self.show() def radioButton(self): self.groupBox = QGroupBox("What is your favorite tit ?") self.groupBox.setFont(QtGui.QFont("sanserif", 13)) hboxlayout = QHBoxLayout() self.radiobtn1 = QRadioButton("P**n") self.radiobtn1.setChecked(True) self.radiobtn1.setIcon(QtGui.QIcon(self.iconName)) self.radiobtn1.setIconSize(QtCore.QSize(40, 40)) self.radiobtn1.setFont(QtGui.QFont("Sanserif", 13)) self.radiobtn1.toggled.connect(self.OnRadioBtn) hboxlayout.addWidget(self.radiobtn1) self.radiobtn2 = QRadioButton("Mango") self.radiobtn2.setIcon(QtGui.QIcon(self.iconName)) self.radiobtn2.setIconSize(QtCore.QSize(40, 40)) self.radiobtn2.setFont(QtGui.QFont("Sanserif", 13)) self.radiobtn2.toggled.connect(self.OnRadioBtn) hboxlayout.addWidget(self.radiobtn2) self.radiobtn3 = QRadioButton("Vodka") self.radiobtn3.setIcon(QtGui.QIcon(self.iconName)) self.radiobtn3.setIconSize(QtCore.QSize(40, 40)) self.radiobtn3.setFont(QtGui.QFont("Sanserif", 13)) self.radiobtn3.toggled.connect(self.OnRadioBtn) hboxlayout.addWidget(self.radiobtn3) self.groupBox.setLayout(hboxlayout) def OnRadioBtn(self): radioBtn = self.sender() if radioBtn.isChecked(): self.label.setText("you have selected " + radioBtn.text())
class Window(QDialog): def __init__(self): super().__init__() self.title = "PyQt5 Redio Button" self.left = 300 self.top = 200 self.width = 400 self.height = 100 self.iconName = "icon.png" self.InitWindow() def InitWindow(self): self.setWindowIcon(QtGui.QIcon(self.iconName)) self.setWindowTitle(self.title) self.setGeometry(self.left, self.top, self.width, self.height) self.radioButton() vbox = QVBoxLayout() vbox.addWidget(self.groupBox) self.label = QLabel() self.label.setFont(QtGui.QFont("Sanserif",13)) vbox.addWidget(self.label) self.setLayout(vbox) self.show() def radioButton(self): self.groupBox = QGroupBox("What is your Favorite Sport?") self.groupBox.setFont(QtGui.QFont("Sanserif",13)) hboxlayout = QHBoxLayout() self.radiobtn1 = QRadioButton("Football") self.radiobtn1.setIcon(QtGui.QIcon("football.png")) self.radiobtn1.setIconSize(QtCore.QSize(40,40)) self.radiobtn1.toggled.connect(self.OnRadioBtn) hboxlayout.addWidget(self.radiobtn1) self.radiobtn2 = QRadioButton("Cricket") self.radiobtn2.setIcon(QtGui.QIcon("cricket.png")) self.radiobtn2.setIconSize(QtCore.QSize(40,40)) self.radiobtn2.setFont(QtGui.QFont("Sanserif",13)) self.radiobtn2.toggled.connect(self.OnRadioBtn) hboxlayout.addWidget(self.radiobtn2) self.radiobtn3 = QRadioButton("Tennis") self.radiobtn3.setIcon(QtGui.QIcon("tennis.png")) self.radiobtn3.setIconSize(QtCore.QSize(40,40)) self.radiobtn3.setFont(QtGui.QFont("Sanserif",13)) self.radiobtn3.toggled.connect(self.OnRadioBtn) hboxlayout.addWidget(self.radiobtn3) self.groupBox.setLayout(hboxlayout) def OnRadioBtn(self): radioBtn = self.sender() if radioBtn.isChecked(): self.label.setText("You Have selected " + radioBtn.text())
def crt_radio_btn(self): groupbox = QGroupBox("What's ur sportsmanship??") groupbox.setFont(QFont("Sanserif", 15)) hbox = QHBoxLayout() rbtn1 = QRadioButton("Soccer") rbtn1.setChecked(True) rbtn1.setIcon(QIcon("src\\shoe.png")) rbtn1.setIconSize(QSize(40, 40)) rbtn1.setFont(QFont("Sanserif", 14)) rbtn1.toggled.connect(self.select) rbtn2 = QRadioButton("Baseball") rbtn2.setIcon(QIcon("src\\ball.png")) rbtn2.setIconSize(QSize(40, 40)) rbtn2.setFont(QFont("Sanserif", 14)) rbtn2.toggled.connect(self.select) rbtn3 = QRadioButton("Football") rbtn3.setIcon(QIcon("src\\landscape.jpg")) rbtn3.setIconSize(QSize(40, 40)) rbtn3.setFont(QFont("Sanserif", 14)) rbtn3.toggled.connect(self.select) rbtn4 = QRadioButton("Basketball") rbtn4.setIcon(QIcon("src\\chessboard.png")) rbtn4.setIconSize(QSize(40, 40)) rbtn4.setFont(QFont("Sanserif", 14)) rbtn4.toggled.connect(self.select) hbox.addWidget(rbtn1) hbox.addWidget(rbtn2) hbox.addWidget(rbtn3) hbox.addWidget(rbtn4) groupbox.setLayout(hbox) # Group everything in the group box vbox = QVBoxLayout() vbox.addWidget(groupbox) vbox.addWidget(self.label) # Group the group box in the vbox self.setLayout(vbox)
class InstallDB(QMainWindow): def __init__(self): super(InstallDB, self).__init__() self.db = None self.url = None self.setGeometry(0, 0, 610, 400) self.setWindowTitle(texts.window_principal_title) screen = QDesktopWidget().screenGeometry() self.x = (screen.width() / 2) - (self.frameSize().width() / 2) self.y = (screen.height() / 2) - (self.frameSize().height() / 2) self.move(self.x, self.y) self.setStyleSheet("background-color: rgb(239, 235, 231);") self.centralwidget = QWidget(self) self.centralwidget.setGeometry(0, 0, 610, 400) # Install Part 1 self.widget_1 = QWidget(self.centralwidget) self.widget_1.setGeometry(0, 0, 610, 400) self.widget_1.setHidden(False) self.vbox_main_1 = QWidget(self.widget_1) self.vbox_main_1.setGeometry(0, 0, 610, 400) self.vbox_part_1 = QVBoxLayout(self.vbox_main_1) self.vbox_part_1.setContentsMargins(20, 20, 20, 20) self.vbox_part_1.setSpacing(10) self.tb_1 = QTextBrowser() self.tb_1.setText(texts.install_text_1) self.vbox_part_1.addWidget(self.tb_1) self.line_1 = QFrame(self.vbox_main_1) self.line_1.setFrameShape(QFrame.HLine) self.line_1.setFrameShadow(QFrame.Sunken) self.vbox_part_1.addWidget(self.line_1) self.hbox_rbs = QHBoxLayout() self.label = QLabel(texts.lb_label) self.hbox_rbs.addWidget(self.label) self.rb_sqlite = QRadioButton('SQLite') icon = QIcon() icon.addPixmap(QPixmap("images/sqlite.ico"), QIcon.Normal, QIcon.Off) self.rb_sqlite.setIcon(icon) self.rb_sqlite.setIconSize(QSize(24, 24)) self.rb_sqlite.setChecked(True) self.hbox_rbs.addWidget(self.rb_sqlite) self.rb_postgres = QRadioButton('PostgreSQL') icon1 = QIcon() icon1.addPixmap(QPixmap("images/postgresql-24x24.png"), QIcon.Normal, QIcon.Off) self.rb_postgres.setIcon(icon1) self.rb_postgres.setIconSize(QSize(24, 24)) self.hbox_rbs.addWidget(self.rb_postgres) self.rb_mysql = QRadioButton('MySQL') icon2 = QIcon() icon2.addPixmap(QPixmap("images/mysql-24x24.png"), QIcon.Normal, QIcon.Off) self.rb_mysql.setIcon(icon2) self.rb_mysql.setIconSize(QSize(24, 24)) self.hbox_rbs.addWidget(self.rb_mysql) self.vbox_part_1.addLayout(self.hbox_rbs) self.line_2 = QFrame(self.vbox_main_1) self.line_2.setFrameShape(QFrame.HLine) self.line_2.setFrameShadow(QFrame.Sunken) self.vbox_part_1.addWidget(self.line_2) self.hbox_pb_next = QHBoxLayout() self.hbox_pb_next.setContentsMargins(150, 10, 200, -1) self.hbox_pb_next = QHBoxLayout() self.hbox_pb_next.setContentsMargins(150, 10, 200, -1) self.pb_next = QPushButton() self.pb_next.clicked.connect(self.pb_next_clicked) sizePolicy = QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.pb_next.sizePolicy().hasHeightForWidth()) self.pb_next.setSizePolicy(sizePolicy) self.pb_next.setMaximumSize(QSize(400, 40)) icon3 = QIcon() icon3.addPixmap(QPixmap("images/bt-next-24x24.png"), QIcon.Normal, QIcon.Off) self.pb_next.setIcon(icon3) self.pb_next.setIconSize(QSize(400, 40)) self.pb_next.setStyleSheet("background-color: rgb(211, 215, 207);\n" "alternate-background-color: " "qradialgradient(spread:repeat, cx:0.5, " "cy:0.5, radius:0.5, fx:0.5, fy:0.5, " "stop:0 rgba(184,184,184, 255), " "stop:.5 rgba(211,211,211, 255), " "stop:1 rgba(255, 255, 255, 255));") self.hbox_pb_next.addWidget(self.pb_next) self.vbox_part_1.addLayout(self.hbox_pb_next) # Install Part 2 self.widget_2 = QWidget(self.centralwidget) self.widget_2.setGeometry(0, 0, 621, 521) self.widget_2.setObjectName("widget_2") self.widget_2.setHidden(True) self.vbox_main_2 = QWidget(self.widget_2) self.vbox_main_2.setGeometry(0, 0, 621, 521) self.vbox_main_2.setObjectName("verticalLayoutWidget_2") self.vbox_part_2 = QVBoxLayout(self.vbox_main_2) self.vbox_part_2.setContentsMargins(20, 20, 20, 20) self.vbox_part_2.setSpacing(10) self.tb_2 = QTextBrowser() self.vbox_part_2.addWidget(self.tb_2) self.line_3 = QFrame(self.vbox_main_2) self.line_3.setFrameShape(QFrame.HLine) self.line_3.setFrameShadow(QFrame.Sunken) self.vbox_part_2.addWidget(self.line_3) self.fm_part_2 = QFormLayout() self.fm_part_2.setSpacing(10) self.lb_bd_name = QLabel(texts.lb_db_name) self.le_bd_name = QLineEdit('ms_collection') self.fm_part_2.setWidget(0, QFormLayout.LabelRole, self.lb_bd_name) self.fm_part_2.setWidget(0, QFormLayout.FieldRole, self.le_bd_name) self.lb_host = QLabel(texts.lb_host) self.le_host = QLineEdit('localhost') self.fm_part_2.setWidget(1, QFormLayout.LabelRole, self.lb_host) self.fm_part_2.setWidget(1, QFormLayout.FieldRole, self.le_host) self.lb_port = QLabel(texts.lb_port) self.le_port = QLineEdit() self.fm_part_2.setWidget(2, QFormLayout.FieldRole, self.le_port) self.fm_part_2.setWidget(2, QFormLayout.LabelRole, self.lb_port) self.lb_user = QLabel(texts.lb_user) self.le_user = QLineEdit('root') self.fm_part_2.setWidget(3, QFormLayout.LabelRole, self.lb_user) self.fm_part_2.setWidget(3, QFormLayout.FieldRole, self.le_user) self.lb_pw = QLabel(texts.lb_pw) self.le_pw = QLineEdit() self.fm_part_2.setWidget(4, QFormLayout.LabelRole, self.lb_pw) self.fm_part_2.setWidget(4, QFormLayout.FieldRole, self.le_pw) self.vbox_part_2.addLayout(self.fm_part_2) self.hbox_pb_send = QHBoxLayout() spacer = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) self.hbox_pb_send.addItem(spacer) self.pb_ok = QPushButton() self.pb_ok.clicked.connect(self.pb_ok_clicked) icon3 = QIcon() icon3.addPixmap(QPixmap("images/bt-ok-24x24.png"), QIcon.Normal, QIcon.Off) self.pb_ok.setIcon(icon3) self.pb_ok.setIconSize(QSize(250, 40)) self.pb_ok.setStyleSheet( "background-color: rgb(211, 215, 207); " "alternate-background-color: " "qradialgradient(spread:repeat, cx:0.5, " "cy:0.5, radius:0.5, fx:0.5, fy:0.5, " "stop:0 rgba(184,184,184, 255), " "stop:.5 rgba(211,211,211, 255), " "stop:1 rgba(255, 255, 255, 255));" ) self.hbox_pb_send.addWidget(self.pb_ok) self.hbox_pb_send.addItem(spacer) self.line_3 = QFrame(self.vbox_main_2) self.line_3.setFrameShape(QFrame.HLine) self.line_3.setFrameShadow(QFrame.Sunken) self.vbox_part_2.addWidget(self.line_3) self.vbox_part_2.addLayout(self.hbox_pb_send) def pb_next_clicked(self): if self.rb_sqlite.isChecked(): self.db = 'sqlite' self.url = 'sqlite:///db//mscollection.sqlite3' self.create_database() self.create_tables() self.close() elif self.rb_postgres.isChecked(): self.db = 'postgres' text = texts.install_db_select('PostgreSQL') self.tb_2.setText(text) self.le_user.setText('postgres') self.le_port.setText('5432') self.change_window() elif self.rb_mysql.isChecked(): self.db = 'mysql' text = texts.install_db_select('MySQL') self.tb_2.setText(text) self.le_port.setText('3306') self.change_window() def pb_ok_clicked(self): db_name = self.le_bd_name.text() db_host = self.le_host.text() db_port = (self.le_port.text()) db_user = self.le_user.text() db_pw = self.le_pw.text() name = 'name = \'' + db_name + '\'\n' host = 'host = \'' + db_host + '\'\n' port = 'port = ' + db_port + '\n' user = '******'' + db_user + '\'\n' pw = 'pw = \'' + db_pw + '\'\n' with open('db/db_values.py', 'w') as f: f.writelines([name, host, port, user, pw]) int_port = int(db_port) if self.db == 'postgres': self.url = '{0}://{1}:{2}@{3}:{4}/{5}'.format( self.db, db_user, db_pw, db_host, int_port, db_name ) else: self.url = '{0}+pymysql://{1}:{2}@{3}:{4}/{5}'. \ format(self.db, db_user, db_pw, db_host, int_port, db_name) self.create_database() self.create_tables() def set_file_settings(self): abs_path = os.getcwd() print(abs_path) new_file = abs_path + '/db/db_settings.py' print(new_file) old_file = abs_path + '/install/' + self.db + '_settings.py' print(old_file) try: shutil.copyfile(old_file, new_file) self.close() except EnvironmentError as error: text = texts.cant_copy(self.db) self.show_msg('Erro', text, QMessageBox.Critical, QMessageBox.Close) def create_database(self): # utf8mb4 in MySQl and not utf8 see: # [https://www.eversql.com/mysql-utf8-vs-utf8mb4-whats-the-difference-between-utf8-and-utf8mb4/] # [https://medium.com/@adamhooper/in-mysql-never-use-utf8-use-utf8mb4-11761243e434] try: exist = database_exists(self.url) if not exist: if self.db == 'sqlite': create_database(self.url) if self.db == 'postgres': create_database(self.url) self.set_file_settings() elif self.db == 'mysql': create_database(self.url, 'utf8mb4') self.set_file_settings() else: text = texts.database_exist self.show_msg(texts.windows_error_database, text, QMessageBox.Critical, QMessageBox.Close) except ProgrammingError as error: text = texts.connection_rejected self.show_msg(texts.windows_error_database, text, QMessageBox.Critical, QMessageBox.Close, str(error)) self.set_file_settings() def create_tables(self): import install.install_tables as ins ins.create_tables(self.url) def change_window(self): self.widget_1.setHidden(False) self.setGeometry(self.x, self.y, 621, 520) self.centralwidget.setGeometry(0, 0, 621, 520) self.widget_2.setGeometry(0, 0, 621, 520) self.widget_2.setHidden(False) # Messages Box def show_msg(self, title, text, icon, button, detail='', info='', ): msg = QMessageBox() msg.setIcon(icon) msg.setText(text) msg.setInformativeText(info) msg.setWindowTitle(title) msg.setDetailedText(detail) msg.setStandardButtons(button) msg.exec_()
class MainWindow(QDialog): def __init__(self): super().__init__() self.title = "Fleet Study Automation Tool Home" self.left = 300 self.top = 400 self.width = 1000 self.height = 350 self.iconName = "images/corcentric_logo.jpg" # call init function self.InitWindow() def InitWindow(self): self.setWindowTitle(self.title) self.setWindowIcon(QtGui.QIcon(self.iconName)) self.setGeometry(self.left, self.top, self.width, self.height) self.radioButton() vbox = QVBoxLayout() vbox.addWidget(self.groupBox) # add start button self.button1 = QPushButton("Start Study") self.button1.setFont(QtGui.QFont("Calibri", 12)) self.button1.clicked.connect(self.onStartStudy) vbox.addWidget(self.button1) self.label = QLabel(self) self.label.setFont(QtGui.QFont("Calibri", 12)) vbox.addWidget(self.label) # add layout self.setLayout(vbox) self.show() def radioButton(self): self.groupBox = QGroupBox("Select a Fleet Study Category") self.groupBox.setFont(QtGui.QFont("Calibri", 16)) hboxLayout = QHBoxLayout() # Create radio buttons # Create Utilization button self.radiobtn1 = QRadioButton("Utilization") # makes radio option the default checked # self.radiobtn1.setChecked(True) self.radiobtn1.setIcon(QtGui.QIcon("images/utilization_icon.png")) self.radiobtn1.setIconSize(QtCore.QSize(40, 40)) self.radiobtn1.setFont(QtGui.QFont("Calibri", 14)) #connect radio button to method self.radiobtn1.toggled.connect(self.onRadioBtn) # add radio button to layout hboxLayout.addWidget(self.radiobtn1) # Create fuel economy button self.radiobtn2 = QRadioButton("Fuel Economy") self.radiobtn2.setIcon(QtGui.QIcon("images/fuel_icon.jpg")) # makes radio option the default checked # self.radiobtn2.setChecked(True) self.radiobtn2.setIconSize(QtCore.QSize(40, 40)) self.radiobtn2.setFont(QtGui.QFont("Calibri", 14)) #connect radio button to method self.radiobtn2.toggled.connect(self.onRadioBtn) # add radio button to layout hboxLayout.addWidget(self.radiobtn2) # Create Maintenance and Repair Radio Button self.radiobtn3 = QRadioButton("Maintenance and Repair") # makes radio option the default checked # self.radiobtn3.setChecked(True) self.radiobtn3.setIcon(QtGui.QIcon("images/maintenance_icon.jpg")) self.radiobtn3.setIconSize(QtCore.QSize(40, 40)) self.radiobtn3.setFont(QtGui.QFont("Calibri", 14)) #connect radio button to method self.radiobtn3.toggled.connect(self.onRadioBtn) # add radio button to layout hboxLayout.addWidget(self.radiobtn3) # Create RunCost radio button self.radiobtn4 = QRadioButton("Run Cost") # makes radio option the default checked # self.radiobtn4.setChecked(True) self.radiobtn4.setIcon(QtGui.QIcon("images/runcost_icon.png")) self.radiobtn4.setIconSize(QtCore.QSize(40, 40)) self.radiobtn4.setFont(QtGui.QFont("Calibri", 14)) #connect radio button to method self.radiobtn4.toggled.connect(self.onRadioBtn) # add radio button to layout hboxLayout.addWidget(self.radiobtn4) # Create Special Projects Button self.radiobtn5 = QRadioButton("Special Projects") # makes radio option the default checked # self.radiobtn5.setChecked(True) self.radiobtn5.setIcon(QtGui.QIcon("images/special_projects_icon.png")) self.radiobtn5.setIconSize(QtCore.QSize(40, 40)) self.radiobtn5.setFont(QtGui.QFont("Calibri", 14)) #connect radio button to method self.radiobtn5.toggled.connect(self.onRadioBtn) # add radio button to layout hboxLayout.addWidget(self.radiobtn5) # add groupbox to layout self.groupBox.setLayout(hboxLayout) def onRadioBtn(self): radioBtn = self.sender() if radioBtn.isChecked(): self.label.setText(radioBtn.text()) # slot @pyqtSlot() def onStartStudy(self): if (self.label.text() == "Utilization"): self.label.setText("Start + Utilization button pressed") self.util_window = QtWidgets.QMainWindow() self.ui = HomeUtilizationUIClass() self.ui.setupUi(self.util_window) self.util_window.show() elif (self.label.text() == "Fuel Economy"): self.label.setText("Start + Fuel Economy button pressed") elif (self.label.text() == "Maintenance and Repair"): self.label.setText("Start + Maintenance and Repair button pressed") elif (self.label.text() == "Run Cost"): self.label.setText("Start + Run Cost button pressed") elif (self.label.text() == "Special Projects"): self.label.setText("Start + Special Projects button pressed") self.special_window = QtWidgets.QMainWindow() self.ui = SpecialProjectsClass() self.ui.setupUi(self.special_window) self.special_window.show() else: self.label.setText("Please make a selection to start study")
class Window(QWidget): def __init__(self): super().__init__() self.title = "PyQt5 - Votação" self.top = 400 self.left = 100 self.width = 400 self.height = 300 self.setWindowIcon(QtGui.QIcon("_imagens/stuart.ico")) self.mainbox = QVBoxLayout() self.genderGroupBox = QGroupBox("Selecione o seu sexo") self.mainbox.addWidget(self.genderGroupBox) self.buttonMale = QRadioButton("Masculino") self.buttonMale.setIcon(QtGui.QIcon("_imagens/male.ico")) self.buttonMale.setIconSize(QtCore.QSize(30, 30)) self.buttonMale.setFont(QtGui.QFont("Sanserif", 13)) self.buttonFemale = QRadioButton("Feminino") self.buttonFemale.setIcon(QtGui.QIcon("_imagens/female.png")) self.buttonFemale.setIconSize(QtCore.QSize(30, 30)) self.buttonFemale.setFont(QtGui.QFont("Sanserif", 13)) self.buttonNone = QRadioButton("Não informado") self.buttonNone.setIcon(QtGui.QIcon("_imagens/none.png")) self.buttonNone.setIconSize(QtCore.QSize(30, 30)) self.buttonNone.setFont(QtGui.QFont("Sanserif", 13)) self.genderButtonBox = QHBoxLayout() self.genderButtonBox.addWidget(self.buttonMale) self.genderButtonBox.addWidget(self.buttonFemale) self.genderButtonBox.addWidget(self.buttonNone) self.genderGroupBox.setLayout(self.genderButtonBox) self.sportsGroupBox = QGroupBox("Selecione o seu esporte favorito") self.mainbox.addWidget(self.sportsGroupBox) self.buttonSoccer = QRadioButton("Soccer") self.buttonSoccer.setIcon(QtGui.QIcon("_imagens/soccer.png")) self.buttonSoccer.setIconSize(QtCore.QSize(30, 30)) self.buttonSoccer.setFont(QtGui.QFont("Sanserif", 13)) self.buttonNFL = QRadioButton("NFL") self.buttonNFL.setIcon(QtGui.QIcon("_imagens/nfl.png")) self.buttonNFL.setIconSize(QtCore.QSize(30, 30)) self.buttonNFL.setFont(QtGui.QFont("Sanserif", 13)) self.buttonNBA = QRadioButton("NBA") self.buttonNBA.setIcon(QtGui.QIcon("_imagens/nba.png")) self.buttonNBA.setIconSize(QtCore.QSize(30, 30)) self.buttonNBA.setFont(QtGui.QFont("Sanserif", 13)) self.sportsButtonBox = QHBoxLayout() self.sportsButtonBox.addWidget(self.buttonSoccer) self.sportsButtonBox.addWidget(self.buttonNFL) self.sportsButtonBox.addWidget(self.buttonNBA) self.sportsGroupBox.setLayout(self.sportsButtonBox) self.choiceGroupBox = QGroupBox("Selecione uma opção") self.mainbox.addWidget(self.choiceGroupBox) self.okButton = QPushButton("Votar") self.okButton.clicked.connect(self.confirm_vote) self.okButton.setMaximumSize(QtCore.QSize(200, 50)) self.closeButton = QPushButton("Fechar") self.closeButton.clicked.connect(self.close_app) self.closeButton.setMaximumSize(QtCore.QSize(200, 50)) self.choiceButtonBox = QHBoxLayout() self.choiceButtonBox.addWidget(self.okButton) self.choiceButtonBox.addWidget(self.closeButton) self.choiceGroupBox.setLayout(self.choiceButtonBox) self.setLayout(self.mainbox) self.InitWindow() def InitWindow(self): self.setWindowTitle(self.title) self.setGeometry(self.top, self.left, self.width, self.height) self.show() def confirm_vote(self): mydb = mysql.connector.connect(host="localhost", user="******", passwd="Stuart@2812", database="pyqt5") mycursor = mydb.cursor() if self.buttonMale.isChecked() and self.buttonSoccer.isChecked(): sql = "INSERT INTO VOTOS (FK_ESPORTE, SEXO) VALUES (%s, %s)" val = ("1", "M") mycursor.execute(sql, val) mydb.commit() if self.buttonMale.isChecked() and self.buttonNFL.isChecked(): sql = "INSERT INTO VOTOS (FK_ESPORTE, SEXO) VALUES (%s, %s)" val = ("2", "M") mycursor.execute(sql, val) mydb.commit() if self.buttonMale.isChecked() and self.buttonNBA.isChecked(): sql = "INSERT INTO VOTOS (FK_ESPORTE, SEXO) VALUES (%s, %s)" val = ("3", "M") mycursor.execute(sql, val) mydb.commit() if self.buttonFemale.isChecked() and self.buttonSoccer.isChecked(): sql = "INSERT INTO VOTOS (FK_ESPORTE, SEXO) VALUES (%s, %s)" val = ("1", "F") mycursor.execute(sql, val) mydb.commit() if self.buttonFemale.isChecked() and self.buttonNFL.isChecked(): sql = "INSERT INTO VOTOS (FK_ESPORTE, SEXO) VALUES (%s, %s)" val = ("2", "F") mycursor.execute(sql, val) mydb.commit() if self.buttonFemale.isChecked() and self.buttonNBA.isChecked(): sql = "INSERT INTO VOTOS (FK_ESPORTE, SEXO) VALUES (%s, %s)" val = ("3", "F") mycursor.execute(sql, val) mydb.commit() if self.buttonNone.isChecked() and self.buttonSoccer.isChecked(): sql = "INSERT INTO VOTOS (FK_ESPORTE, SEXO) VALUES (%s, %s)" val = ("1", "N") mycursor.execute(sql, val) mydb.commit() if self.buttonNone.isChecked() and self.buttonNFL.isChecked(): sql = "INSERT INTO VOTOS (FK_ESPORTE, SEXO) VALUES (%s, %s)" val = ("2", "N") mycursor.execute(sql, val) mydb.commit() if self.buttonNone.isChecked() and self.buttonNBA.isChecked(): sql = "INSERT INTO VOTOS (FK_ESPORTE, SEXO) VALUES (%s, %s)" val = ("3", "N") mycursor.execute(sql, val) mydb.commit() self.close_app() def show_popup(self): mydb = mysql.connector.connect(host="localhost", user="******", passwd="Stuart@2812", database="pyqt5") mycursor = mydb.cursor() model = QSqlTableModel() # model.setTable("esportes") model.setQuery("""SELECT E.ESPORTE, SUM(V.FK_ESPORTE) AS "TOTAL VOTOS" FROM ESPORTES E INNER JOIN VOTOS V ON E.ID = V.FK_ESPORTE GROUP BY V.FK_ESPORTE;""") model.setEditStrategy(QSqlTableModel.OnManualSubmit) model.select() # model.removeColumn(0) # don't show the ID model.setHeaderData(0, Qt.Horizontal, tr("esporte")) model.setHeaderData(1, Qt.Horizontal, tr("votos")) view = QTableView() view.setModel(model) view.show() def close_app(self): self.show_popup() sys.exit()
class Window(QDialog): def __init__(self): super().__init__() self.title = "PyQt5 - Radio Button" self.left = 300 self.top = 400 self.width = 400 self.height = 300 self.iconName = "_imagens/mouse.ico" self.InitWindow() def InitWindow(self): self.setWindowIcon(QtGui.QIcon(self.iconName)) self.setGeometry(self.left, self.top, self.width, self.height) self.setWindowTitle(self.title) self.radioButton() vbox = QVBoxLayout() vbox.addWidget(self.groupBox) self.label = QLabel(self) self.label.setFont(QtGui.QFont("Sanserif", 15)) vbox.addWidget(self.label) self.setLayout(vbox) self.show() def radioButton(self): self.groupBox = QGroupBox("Escolha o seu sexo") self.groupBox.setFont(QtGui.QFont("Sanserif", 13)) hboxLayout = QHBoxLayout() self.radioMale = QRadioButton("Masculino") self.radioMale.setChecked(True) self.radioMale.setIcon(QtGui.QIcon("_imagens/male.jpg")) self.radioMale.setIconSize(QtCore.QSize(30, 30)) self.radioMale.setFont(QtGui.QFont("Sanserif", 13)) self.radioMale.toggled.connect(self.OnRadioBtn) self.radioFemale = QRadioButton("Feminino") self.radioFemale.setIcon(QtGui.QIcon("_imagens/female.ico")) self.radioFemale.setIconSize(QtCore.QSize(30, 30)) self.radioFemale.setFont(QtGui.QFont("Sanserif", 13)) self.radioFemale.toggled.connect(self.OnRadioBtn) self.radioNone = QRadioButton("Prefiro não informar") self.radioNone.setIcon(QtGui.QIcon("_imagens/none.png")) self.radioNone.setIconSize(QtCore.QSize(30, 30)) self.radioNone.setFont(QtGui.QFont("Sanserif", 13)) self.radioNone.toggled.connect(self.OnRadioBtn) hboxLayout.addWidget(self.radioMale) hboxLayout.addWidget(self.radioFemale) hboxLayout.addWidget(self.radioNone) self.groupBox.setLayout(hboxLayout) def OnRadioBtn(self): radioBtn = self.sender() if radioBtn.isChecked(): self.label.setText("Selecionado: " + radioBtn.text())
class Window(QDialog): def __init__(self): super().__init__() self.title = "This is first thing" self.height = 700 self.width = 1100 self.top = 100 self.left = 200 self.iconName = "plioky.ico" self.groupBox = QGroupBox("What is your favorite sport?") self.radiobtn1 = QRadioButton("Football") self.radiobtn2 = QRadioButton("Basketball") self.radiobtn3 = QRadioButton("Tennis") self.label = QLabel() self.init_window() def init_window(self): self.setWindowIcon(QtGui.QIcon(self.iconName)) self.setWindowTitle(self.title) self.setGeometry(self.left, self.top, self.width, self.height) self.radio_button() vbox = QVBoxLayout() vbox.addWidget(self.groupBox) vbox.addWidget(self.label) self.label.setFont(QtGui.QFont("Sanserif", 25)) self.setLayout(vbox) self.show() def radio_button(self): self.groupBox.setFont(QtGui.QFont("Sanserif", 15)) hboxlayout = QHBoxLayout() self.radiobtn1.setIcon(QtGui.QIcon(self.iconName)) self.radiobtn1.setIconSize(QtCore.QSize(40, 40)) self.radiobtn1.setFont(QtGui.QFont("Sanserif", 20)) self.radiobtn1.toggled.connect(self.on_radio_btn) hboxlayout.addWidget(self.radiobtn1) self.radiobtn2.setIcon(QtGui.QIcon(self.iconName)) self.radiobtn2.setIconSize(QtCore.QSize(40, 40)) self.radiobtn2.setFont(QtGui.QFont("Sanserif", 20)) self.radiobtn2.toggled.connect(self.on_radio_btn) hboxlayout.addWidget(self.radiobtn2) self.radiobtn3.setIcon(QtGui.QIcon(self.iconName)) self.radiobtn3.setIconSize(QtCore.QSize(40, 40)) self.radiobtn3.setFont(QtGui.QFont("Sanserif", 20)) self.radiobtn3.toggled.connect(self.on_radio_btn) hboxlayout.addWidget(self.radiobtn3) self.groupBox.setLayout(hboxlayout) def on_radio_btn(self): radiobtn = self.sender() if radiobtn.isChecked(): self.label.setText("You have selected " + radiobtn.text())
class ThemePage(QWidget): def __init__(self, parent=None): super(ThemePage, self).__init__(parent) self.parent = parent self.setObjectName('settingsthemepage') mainLayout = QVBoxLayout() mainLayout.setSpacing(10) pen = QPen( QColor('#4D5355' if self.parent.theme == 'dark' else '#B9B9B9')) pen.setWidth(2) theme_light = QPixmap(':/images/theme-light.png', 'PNG') painter = QPainter(theme_light) painter.setPen(pen) painter.setBrush(Qt.NoBrush) painter.drawRect(0, 0, theme_light.width(), theme_light.height()) theme_dark = QPixmap(':/images/theme-dark.png', 'PNG') painter = QPainter(theme_dark) painter.setPen(pen) painter.setBrush(Qt.NoBrush) painter.drawRect(0, 0, theme_dark.width(), theme_dark.height()) self.lightRadio = QRadioButton(self) self.lightRadio.setIcon(QIcon(theme_light)) self.lightRadio.setIconSize(QSize(165, 121)) self.lightRadio.setCursor(Qt.PointingHandCursor) self.lightRadio.clicked.connect(self.switchTheme) self.lightRadio.setChecked(self.parent.theme == 'light') self.darkRadio = QRadioButton(self) self.darkRadio.setIcon(QIcon(theme_dark)) self.darkRadio.setIconSize(QSize(165, 121)) self.darkRadio.setCursor(Qt.PointingHandCursor) self.darkRadio.clicked.connect(self.switchTheme) self.darkRadio.setChecked(self.parent.theme == 'dark') themeLayout = QGridLayout() themeLayout.setColumnStretch(0, 1) themeLayout.addWidget(self.lightRadio, 0, 1) themeLayout.addWidget(self.darkRadio, 0, 3) themeLayout.addWidget(QLabel('Light', self), 1, 1, Qt.AlignHCenter) themeLayout.setColumnStretch(2, 1) themeLayout.addWidget(QLabel('Dark', self), 1, 3, Qt.AlignHCenter) themeLayout.setColumnStretch(4, 1) themeGroup = QGroupBox('Theme') themeGroup.setLayout(themeLayout) mainLayout.addWidget(themeGroup) index_leftRadio = QRadioButton('Clips on left') index_leftRadio.setToolTip('Display Clip Index on the left hand side') index_leftRadio.setCursor(Qt.PointingHandCursor) index_leftRadio.setChecked(self.parent.parent.indexLayout == 'left') index_rightRadio = QRadioButton('Clips on right') index_rightRadio.setToolTip( 'Display Clip Index on the right hand side') index_rightRadio.setCursor(Qt.PointingHandCursor) index_rightRadio.setChecked(self.parent.parent.indexLayout == 'right') index_buttonGroup = QButtonGroup(self) index_buttonGroup.addButton(index_leftRadio, 1) index_buttonGroup.addButton(index_rightRadio, 2) # noinspection PyUnresolvedReferences index_buttonGroup.buttonClicked[int].connect( self.parent.parent.setClipIndexLayout) indexLayout = QHBoxLayout() indexLayout.addWidget(index_leftRadio) indexLayout.addWidget(index_rightRadio) layoutGroup = QGroupBox('Layout') layoutGroup.setLayout(indexLayout) mainLayout.addWidget(layoutGroup) toolbar_labels = self.parent.settings.value('toolbarLabels', 'beside', type=str) toolbar_notextRadio = QRadioButton('No text (buttons only)', self) toolbar_notextRadio.setToolTip('No text (buttons only)') toolbar_notextRadio.setCursor(Qt.PointingHandCursor) toolbar_notextRadio.setChecked(toolbar_labels == 'none') toolbar_underRadio = QRadioButton('Text under buttons', self) toolbar_underRadio.setToolTip('Text under buttons') toolbar_underRadio.setCursor(Qt.PointingHandCursor) toolbar_underRadio.setChecked(toolbar_labels == 'under') toolbar_besideRadio = QRadioButton('Text beside buttons', self) toolbar_besideRadio.setToolTip('Text beside buttons') toolbar_besideRadio.setCursor(Qt.PointingHandCursor) toolbar_besideRadio.setChecked(toolbar_labels == 'beside') toolbar_buttonGroup = QButtonGroup(self) toolbar_buttonGroup.addButton(toolbar_besideRadio, 1) toolbar_buttonGroup.addButton(toolbar_underRadio, 2) toolbar_buttonGroup.addButton(toolbar_notextRadio, 3) # noinspection PyUnresolvedReferences toolbar_buttonGroup.buttonClicked[int].connect(self.setLabelStyle) toolbarLayout = QGridLayout() toolbarLayout.addWidget(toolbar_besideRadio, 0, 0) toolbarLayout.addWidget(toolbar_underRadio, 0, 1) toolbarLayout.addWidget(toolbar_notextRadio, 1, 0) toolbarGroup = QGroupBox('Toolbar') toolbarGroup.setLayout(toolbarLayout) mainLayout.addWidget(toolbarGroup) nativeDialogsCheckbox = QCheckBox('Use native dialogs', self) nativeDialogsCheckbox.setToolTip('Use native file dialogs') nativeDialogsCheckbox.setCursor(Qt.PointingHandCursor) nativeDialogsCheckbox.setChecked(self.parent.parent.nativeDialogs) nativeDialogsCheckbox.stateChanged.connect(self.setNativeDialogs) nativeDialogsLabel = QLabel( ''' <b>ON:</b> use native dialog widgets as provided by your operating system <br/> <b>OFF:</b> use a generic file open & save dialog widget provided by the Qt toolkit <br/><br/> <b>NOTE:</b> native dialogs should always be used if working ''', self) nativeDialogsLabel.setObjectName('nativedialogslabel') nativeDialogsLabel.setTextFormat(Qt.RichText) nativeDialogsLabel.setWordWrap(True) advancedLayout = QVBoxLayout() advancedLayout.addWidget(nativeDialogsCheckbox) advancedLayout.addWidget(nativeDialogsLabel) advancedGroup = QGroupBox('Advanced') advancedGroup.setLayout(advancedLayout) mainLayout.addWidget(advancedGroup) mainLayout.addStretch(1) self.setLayout(mainLayout) @pyqtSlot(int) def setLabelStyle(self, button_id: int) -> None: if button_id == 2: style = 'under' elif button_id == 3: style = 'none' else: style = 'beside' self.parent.settings.setValue('toolbarLabels', style) self.parent.parent.setToolBarStyle(style) @pyqtSlot(int) def setNativeDialogs(self, state: int) -> None: self.parent.parent.saveSetting('nativeDialogs', state == Qt.Checked) self.parent.parent.nativeDialogs = (state == Qt.Checked) @pyqtSlot(bool) def switchTheme(self) -> None: if self.darkRadio.isChecked(): newtheme = 'dark' else: newtheme = 'light' if newtheme != self.parent.theme: # noinspection PyArgumentList mbox = QMessageBox(icon=QMessageBox.NoIcon, windowTitle='Restart required', minimumWidth=500, textFormat=Qt.RichText, objectName='genericdialog') mbox.setWindowFlags(Qt.Dialog | Qt.WindowCloseButtonHint) mbox.setText( ''' <style> h1 { color: %s; font-family: "Futura-Light", sans-serif; font-weight: 400; } </style> <h1>Warning</h1> <p>The application needs to be restarted in order to switch themes. Attempts will be made to reopen media files and add back all clip times from your clip index.</p> <p>Would you like to restart and switch themes now?</p>''' % ('#C681D5' if self.parent.theme == 'dark' else '#642C68')) mbox.setStandardButtons(QMessageBox.Yes | QMessageBox.No) mbox.setDefaultButton(QMessageBox.Yes) response = mbox.exec_() if response == QMessageBox.Yes: self.parent.settings.setValue('theme', newtheme) self.parent.parent.theme = newtheme self.parent.parent.parent.reboot() else: self.darkRadio.setChecked( True ) if newtheme == 'light' else self.lightRadio.setChecked(True)
class Ui_Main(QtWidgets.QWidget): def setupUi(self, Main, host): Main.setObjectName("Main") self.sHost = host # host name of server # self.sPort = port # port at which server accepts connections self.maxClients = 0 # max number of clients to connect with the server self.QtStack = QStackedLayout() self.stack0 = QWidget() # the main screen self.stack1 = QWidget() # server port and clients entry self.stack2 = QWidget() # client enter info self.stack3 = QWidget() # client connected self.stack4 = QWidget() # server proceed btn display self.stack5 = QWidget() # server music select self.stack6 = QWidget() # server player self.stack7 = QWidget() # error window # initialize UI windows self.startUI() self.serverInit() self.clientUI() self.clientConnectedUI() self.errorDisp() # add UI windows to Qt Stack self.QtStack.addWidget(self.stack0) self.QtStack.addWidget(self.stack1) self.QtStack.addWidget(self.stack2) self.QtStack.addWidget(self.stack3) self.QtStack.addWidget(self.stack4) self.QtStack.addWidget(self.stack5) self.QtStack.addWidget(self.stack6) self.QtStack.addWidget(self.stack7) def finishUI(self): # initialize remaining UI windows self.serverUI(self.sHost, self.sPort) self.clientsFileVerify() self.clientsListUI() return def startUI(self): self.stack0.setFixedSize(500, 200) self.stack0.setWindowTitle("Sync") # Intro msg self.intro = QLabel("What do you want to be?") self.intro.setStyleSheet( "font-size: 20px; qproperty-alignment: AlignCenter; font-family: Helvetica, Arial" ) # Server Button self.serverBtn = QRadioButton("Server") self.serverBtn.setStyleSheet( "font-size: 14px; font-family: Helvetica, Arial") icon = QIcon('images/server.png') self.serverBtn.setIcon(icon) self.serverBtn.setIconSize(QSize(75, 75)) self.serverBtn.setChecked(True) # Client Button self.clientBtn = QRadioButton("Client") self.clientBtn.setStyleSheet( "font-size: 14px; font-family: Helvetica, Arial") icon = QIcon('images/client.png') self.clientBtn.setIcon(icon) self.clientBtn.setIconSize(QSize(75, 75)) # Button group to maintain exclusivity self.bGroup = QButtonGroup() self.bGroup.addButton(self.serverBtn, 1) self.bGroup.addButton(self.clientBtn, 2) # Next Button self.nextBtn = QPushButton("Next") self.nextBtn.setStyleSheet( "font-size: 14px; font-family: Helvetica, Arial") # Integrate grid layout self.layout = QGridLayout() self.layout.addWidget(self.intro, 0, 0, 1, 3) self.layout.addWidget(self.serverBtn, 1, 0, Qt.AlignCenter) self.layout.addWidget(self.clientBtn, 1, 2, Qt.AlignCenter) self.layout.addWidget(self.nextBtn, 3, 1) self.stack0.setLayout(self.layout) return def serverInit(self): self.stack1.setFixedSize(500, 200) self.stack1.setWindowTitle("Sync") # Server intro message self.sIIntro = QLabel("Operating as a server") self.sIIntro.setStyleSheet( "font-size: 20px; qproperty-alignment: AlignCenter; font-family: Helvetica, Arial" ) # port helper self.sIPortKey = QLabel("Port to listen on: ") self.sIPortKey.setStyleSheet( "font-size: 20px; qproperty-alignment: AlignLeft; font-family: Helvetica, Arial" ) # port helper self.sIPortVal = QSpinBox() self.sIPortVal.setValue(9077) self.sIPortVal.setMaximum(65535) self.sIPortVal.setMinimum(1024) # helper label self.sIHelper = QLabel("Number of clients: ") self.sIHelper.setStyleSheet( "font-size: 20px; qproperty-alignment: AlignLeft; font-family: Helvetica, Arial" ) # text field for number of clients self.sIBox = QSpinBox() self.sIBox.setValue(2) self.sIBox.setMaximum(16) self.sIBox.setMinimum(1) # next Btn self.sNextBtn = QPushButton("Next") self.sNextBtn.setStyleSheet( "font-size: 14px; font-family: Helvetica, Arial") # Integrate grid layout self.sILayout = QGridLayout() self.sILayout.addWidget(self.sIIntro, 0, 0, 1, 3) self.sILayout.addWidget(self.sIPortKey, 1, 0, 1, 2) self.sILayout.addWidget(self.sIPortVal, 1, 1, 1, 2) self.sILayout.addWidget(self.sIHelper, 2, 0, 1, 2) self.sILayout.addWidget(self.sIBox, 2, 1, 1, 2) self.sILayout.addWidget(self.sNextBtn, 3, 1) self.stack1.setLayout(self.sILayout) return def clientUI(self): self.stack2.setFixedSize(500, 200) self.stack2.setWindowTitle("Sync") # client intro message self.cIntro = QLabel("Operating as a client") self.cIntro.setStyleSheet( "font-size: 20px; qproperty-alignment: AlignCenter; font-family: Helvetica, Arial" ) # Client host key & val self.cHostKey = QLabel("Host: ") self.cHostKey.setStyleSheet( "font-size: 20px; qproperty-alignment: AlignHCenter; font-family: Helvetica, Arial" ) self.cHostVal = QLineEdit() self.cHostVal.setPlaceholderText("Say Dell-G3") # Client port key & val self.cPortKey = QLabel("Port: ") self.cPortKey.setStyleSheet( "font-size: 20px; qproperty-alignment: AlignHCenter; font-family: Helvetica, Arial" ) self.cPortVal = QLineEdit() self.cPortVal.setPlaceholderText("Say 9077") # client connect button self.cntBtn = QPushButton("Connect") self.cntBtn.setStyleSheet( "font-size: 14px; font-family: Helvetica, Arial") # Integrate grid layout self.cLayout = QGridLayout() self.cLayout.addWidget(self.cIntro, 0, 0, 1, 3) self.cLayout.addWidget(self.cHostKey, 1, 0) self.cLayout.addWidget(self.cHostVal, 1, 1, 1, 2) self.cLayout.addWidget(self.cPortKey, 2, 0) self.cLayout.addWidget(self.cPortVal, 2, 1, 1, 2) self.cLayout.addWidget(self.cntBtn, 4, 1) self.stack2.setLayout(self.cLayout) return def serverUI(self, host, port): self.stack3.setFixedSize(500, 200) self.stack3.setWindowTitle("Sync") # Server intro message self.sIntro = QLabel("Operating as a server") self.sIntro.setStyleSheet( "font-size: 20px; qproperty-alignment: AlignCenter; font-family: Helvetica, Arial" ) # Server host key & val self.sHostKey = QLabel("Host: ") self.sHostKey.setStyleSheet( "font-size: 20px; qproperty-alignment: AlignHCenter; font-family: Helvetica, Arial" ) self.sHostVal = QLabel(host) self.sHostVal.setStyleSheet( "font-size: 20px; qproperty-alignment: AlignHCenter; font-family: Helvetica, Arial" ) # Server port key & val self.sPortKey = QLabel("Port: ") self.sPortKey.setStyleSheet( "font-size: 20px; qproperty-alignment: AlignHCenter; font-family: Helvetica, Arial" ) self.sPortVal = QLabel(str(port)) self.sPortVal.setStyleSheet( "font-size: 20px; qproperty-alignment: AlignHCenter; font-family: Helvetica, Arial" ) # Server msg self.sMsg = QLabel("Share this info with your clients!") self.sMsg.setStyleSheet( "font-size: 20px; qproperty-alignment: AlignHCenter; font-family: Helvetica, Arial" ) # Server proceed button self.proBtn = QPushButton("Proceed") self.proBtn.setStyleSheet( "font-size: 14px; font-family: Helvetica, Arial") # Integrate grid layout self.sLayout = QGridLayout() self.sLayout.addWidget(self.sIntro, 0, 0, 1, 3) self.sLayout.addWidget(self.sHostKey, 1, 0) self.sLayout.addWidget(self.sHostVal, 1, 1) self.sLayout.addWidget(self.sPortKey, 2, 0) self.sLayout.addWidget(self.sPortVal, 2, 1) self.sLayout.addWidget(self.sMsg, 3, 0, 1, 3) self.sLayout.addWidget(self.proBtn, 4, 1) self.stack3.setLayout(self.sLayout) return def clientConnectedUI(self): self.stack4.setFixedSize(500, 200) self.stack4.setWindowTitle("Sync") # client intro message self.cCIntro = QLabel("Operating as a client") self.cCIntro.setStyleSheet( "font-size: 20px; qproperty-alignment: AlignCenter; font-family: Helvetica, Arial" ) # Client welcome msg self.cConnected = QLabel("Connected!") self.cConnected.setStyleSheet( "font-size: 20px; qproperty-alignment: AlignHCenter; font-family: Helvetica, Arial" ) # Integrate grid layout self.cCLayout = QGridLayout() self.cCLayout.addWidget(self.cCIntro, 0, 0, 1, 3) self.cCLayout.addWidget(self.cConnected, 1, 0, 1, 3) self.stack4.setLayout(self.cCLayout) return def clientsFileVerify(self): self.stack5.setFixedWidth(500) self.stack5.setWindowTitle("Sync") # Server intro message self.cFVIntro = QLabel("Operating as a server") self.cFVIntro.setStyleSheet( "font-size: 20px; qproperty-alignment: AlignCenter; font-family: Helvetica, Arial" ) # Server host key & val self.cFVHostKey = QLabel("Host: ") self.cFVHostKey.setStyleSheet( "font-size: 20px; qproperty-alignment: AlignHCenter; font-family: Helvetica, Arial" ) self.cFVHostVal = QLabel(self.sHost) self.cFVHostVal.setStyleSheet( "font-size: 20px; qproperty-alignment: AlignHCenter; font-family: Helvetica, Arial" ) # Server port key & val self.cFVPortKey = QLabel("Port: ") self.cFVPortKey.setStyleSheet( "font-size: 20px; qproperty-alignment: AlignHCenter; font-family: Helvetica, Arial" ) self.cFVPortVal = QLabel(str(self.sPort)) self.cFVPortVal.setStyleSheet( "font-size: 20px; qproperty-alignment: AlignHCenter; font-family: Helvetica, Arial" ) # clients list display self.cFVMsg = QLabel("Clients Connected:") self.cFVMsg.setStyleSheet( "font-size: 20px; qproperty-alignment: AlignHCenter; font-family: Helvetica, Arial" ) # music pick drop down self.cFVmusicBox = QComboBox() for m in self.musicFiles: self.cFVmusicBox.addItem(m) # music helper label self.cFVmHelper = QLabel("Select Music") self.cFVmHelper.setStyleSheet( "font-size: 20px; qproperty-alignment: AlignHCenter; font-family: Helvetica, Arial" ) # verify button self.vfyBtn = QPushButton("Verify") self.vfyBtn.setStyleSheet( "font-size: 14px; font-family: Helvetica, Arial") # List of clients connected self.clientLabels = [] for _ in range(self.maxClients): self.clientLabels.append(QLabel("")) # integrate into grid layout self.cFVLayout = QGridLayout() self.cFVLayout.addWidget(self.cFVIntro, 0, 0, 1, 3) self.cFVLayout.addWidget(self.cFVHostKey, 1, 0) self.cFVLayout.addWidget(self.cFVHostVal, 1, 1) self.cFVLayout.addWidget(self.cFVPortKey, 2, 0) self.cFVLayout.addWidget(self.cFVPortVal, 2, 1) self.cFVLayout.addWidget(self.cFVMsg, 3, 0, 1, 3) for i, c in enumerate(self.clientLabels): self.cFVLayout.addWidget(c, 3 + (i + 1), 0, 1, 3) self.cFVLayout.addWidget(self.cFVmHelper, self.maxClients + 4, 0) self.cFVLayout.addWidget(self.cFVmusicBox, self.maxClients + 4, 1, 1, 2) self.cFVLayout.addWidget(self.vfyBtn, self.maxClients + 5, 1) self.stack5.setLayout(self.cFVLayout) return def clientsListUI(self): self.stack6.setFixedWidth(500) self.stack6.setWindowTitle("Sync") # Server intro message self.cLIntro = QLabel("Operating as a server") self.cLIntro.setStyleSheet( "font-size: 20px; qproperty-alignment: AlignCenter; font-family: Helvetica, Arial" ) # Server host key & val self.cLHostKey = QLabel("Host: ") self.cLHostKey.setStyleSheet( "font-size: 20px; qproperty-alignment: AlignHCenter; font-family: Helvetica, Arial" ) self.cLHostVal = QLabel(self.sHost) self.cLHostVal.setStyleSheet( "font-size: 20px; qproperty-alignment: AlignHCenter; font-family: Helvetica, Arial" ) # Server port key & val self.cLPortKey = QLabel("Port: ") self.cLPortKey.setStyleSheet( "font-size: 20px; qproperty-alignment: AlignHCenter; font-family: Helvetica, Arial" ) self.cLPortVal = QLabel(str(self.sPort)) self.cLPortVal.setStyleSheet( "font-size: 20px; qproperty-alignment: AlignHCenter; font-family: Helvetica, Arial" ) # song name label self.songName = QLabel("") self.songName.setStyleSheet( "font-size: 20px; qproperty-alignment: AlignHCenter; font-family: Helvetica, Arial" ) # file verifier label self.vfyMsg = QLabel("File verification complete: ") self.vfyMsg.setStyleSheet( "font-size: 20px; qproperty-alignment: AlignHCenter; font-family: Helvetica, Arial" ) self.filePresence = [] # file verificatin results for _ in range(self.maxClients): self.filePresence.append(QLabel("")) # play button self.playBtn = QPushButton("Play") self.playBtn.setStyleSheet( "font-size: 14px; font-family: Helvetica, Arial") # pause button self.pauseBtn = QPushButton("Pause") self.pauseBtn.setStyleSheet( "font-size: 14px; font-family: Helvetica, Arial") # stop button self.stopBtn = QPushButton("Stop") self.stopBtn.setStyleSheet( "font-size: 14px; font-family: Helvetica, Arial") # end button self.endBtn = QPushButton("End") self.endBtn.setStyleSheet( "font-size: 14px; font-family: Helvetica, Arial") # back button self.backBtn = QPushButton("Go Back") self.backBtn.setStyleSheet( "font-size: 14px; font-family: Helvetica, Arial") # integrate into grid layout self.cLLayout = QGridLayout() self.cLLayout.addWidget(self.cLIntro, 0, 0, 1, 3) self.cLLayout.addWidget(self.cLHostKey, 1, 0) self.cLLayout.addWidget(self.cLHostVal, 1, 1) self.cLLayout.addWidget(self.cLPortKey, 2, 0) self.cLLayout.addWidget(self.cLPortVal, 2, 1) self.cLLayout.addWidget(self.songName, 3, 1) self.cLLayout.addWidget(self.vfyMsg, 4, 0, 1, 3) for i, c in enumerate(self.filePresence): self.cLLayout.addWidget(c, 4 + (i + 1), 0, 1, 3) self.cLLayout.addWidget(self.playBtn, self.maxClients + 5, 0) self.cLLayout.addWidget(self.pauseBtn, self.maxClients + 5, 1) self.cLLayout.addWidget(self.stopBtn, self.maxClients + 5, 2) self.cLLayout.addWidget(self.backBtn, self.maxClients + 6, 1) self.cLLayout.addWidget(self.endBtn, self.maxClients + 7, 0, 1, 3) self.stack6.setLayout(self.cLLayout) return def errorDisp(self): self.stack7.setFixedWidth(500) self.stack7.setWindowTitle("Sync") # Server intro message self.eIntro = QLabel("Operating as a server") self.eIntro.setStyleSheet( "font-size: 20px; qproperty-alignment: AlignCenter; font-family: Helvetica, Arial" ) # Server intro message self.eMsg = QLabel() self.eMsg.setStyleSheet( "font-size: 20px; qproperty-alignment: AlignCenter; font-family: Helvetica, Arial" ) self.eLayout = QGridLayout() self.eLayout.addWidget(self.eIntro, 0, 0, 1, 3) self.eLayout.addWidget(self.eMsg, 1, 0, 1, 3) self.stack7.setLayout(self.eLayout) return
class UI_demo(QDialog): """用户界面""" def __init__(self): super().__init__() # 窗口信息 self.title = 'PyQt5 demo' self.left = 600 self.top = 200 self.width = 800 self.height = 600 self.initWindow() def initWindow(self): # 窗口信息 self.setWindowIcon(QtGui.QIcon('./img/home.ico')) # 图标设置 # self.setGeometry(self.left, self.top, self.width, self.height) # 大小位置设置 self.setWindowTitle(self.title) # 窗口标题 self.resize(800, 600) # 窗口大小 self.center() # 窗口居中 # 按钮 # self.button1() # 布局 # self.createLayout() # vbox = QVBoxLayout() # vbox.addWidget(self.groupBox) # # 标签 # label = QLabel('This is Label.') # vbox.addWidget(label) # # label2 = QLabel('This is Label.') # label2.setFont(QtGui.QFont("Sanserif", 20)) # 设置字体和大小 # label2.setStyleSheet("color:red") # 设置颜色 # vbox.addWidget(label2) # # # 背景图 # labelImage = QLabel(self) # pixmap = QtGui.QPixmap('./img/home') # labelImage.setPixmap(pixmap) # vbox.addWidget(labelImage) # self.setLayout(vbox) # 单选按钮 self.radioButton() vbox = QVBoxLayout() vbox.addWidget(self.groupBox) self.label = QLabel(self) self.label.setFont(QtGui.QFont("sanserif", 12)) vbox.addWidget(self.label) self.setLayout(vbox) # 展示窗口 self.show() def button1(self): """按钮1""" btn = QPushButton('click me', self) # btn.resize(100, 34) # 按钮大小 # btn.move(290, 550) # 移动按钮 # 合并 btn.setGeometry(QtCore.QRect(290, 550, 100, 34)) # 按钮图标 btn.setIcon(QtGui.QIcon('./img/home.ico')) btn.setIconSize(QtCore.QSize(40, 40)) # 设置图标大小 # 设置按钮提示 btn.setToolTip('按钮提示') # 触发事件 btn.clicked.connect(self.ClickMe) def ClickMe(self): print('Hello World') # 退出 sys.exit() def center(self): """窗口居中""" qr = self.frameGeometry() cp = QDesktopWidget().availableGeometry().center() qr.moveCenter(cp) self.move(qr.topLeft()) # def createLayout(self): # """布局""" # self.groupBox = QGroupBox('Whick one?') # # 第一种布局 # # hboxlayout = QHBoxLayout() # # # # btn = QPushButton('One', self) # # btn.setIcon(QtGui.QIcon('./img/home.ico')) # # btn.setIconSize(QtCore.QSize(40, 40)) # # btn.setMinimumHeight((40)) # # hboxlayout.addWidget(btn) # # # # btn1 = QPushButton('Two', self) # # btn1.setIcon(QtGui.QIcon('./img/home.ico')) # # btn1.setIconSize(QtCore.QSize(40, 40)) # # btn1.setMinimumHeight((40)) # # hboxlayout.addWidget(btn1) # # # # btn2 = QPushButton('Three', self) # # btn2.setIcon(QtGui.QIcon('./img/home.ico')) # # btn2.setIconSize(QtCore.QSize(40, 40)) # # btn2.setMinimumHeight((40)) # # hboxlayout.addWidget(btn2) # # self.groupBox.setLayout(hboxlayout) # # 第二种布局 # gridLayout = QGridLayout() # btn = QPushButton('Python', self) # btn.setIcon(QtGui.QIcon('./img/home.ico')) # btn.setIconSize(QtCore.QSize(40, 40)) # btn.setMinimumHeight((40)) # gridLayout.addWidget(btn, 0, 0) # # btn1 = QPushButton('java', self) # btn1.setIcon(QtGui.QIcon('./img/home.ico')) # btn1.setIconSize(QtCore.QSize(40, 40)) # btn1.setMinimumHeight((40)) # gridLayout.addWidget(btn1, 0, 1) # # btn2 = QPushButton('php', self) # btn2.setIcon(QtGui.QIcon('./img/home.ico')) # btn2.setIconSize(QtCore.QSize(40, 40)) # btn2.setMinimumHeight((40)) # gridLayout.addWidget(btn2, 1, 0) # # btn3 = QPushButton('c++', self) # btn3.setIcon(QtGui.QIcon('./img/home.ico')) # btn3.setIconSize(QtCore.QSize(40, 40)) # btn3.setMinimumHeight((40)) # gridLayout.addWidget(btn3, 1, 1) # self.groupBox.setLayout(gridLayout) def radioButton(self): """单选按钮""" self.groupBox = QGroupBox("radio button") self.groupBox.setFont(QtGui.QFont("sanserif", 12)) hboxlayout = QHBoxLayout() self.radiobtn1 = QRadioButton('one') self.radiobtn1.setChecked(True) # 选中状态 self.radiobtn1.setIcon(QtGui.QIcon('./img/home.ico')) self.radiobtn1.setIconSize(QtCore.QSize(40, 40)) self.radiobtn1.setFont(QtGui.QFont('sanserif', 13)) self.radiobtn1.toggled.connect(self.OnRadioBtn) # 选中事件 hboxlayout.addWidget(self.radiobtn1) self.radiobtn2 = QRadioButton('two') self.radiobtn2.setIcon(QtGui.QIcon('./img/home.ico')) self.radiobtn2.setIconSize(QtCore.QSize(40, 40)) self.radiobtn2.setFont(QtGui.QFont('sanserif', 13)) self.radiobtn2.toggled.connect(self.OnRadioBtn) hboxlayout.addWidget(self.radiobtn2) self.groupBox.setLayout(hboxlayout) def OnRadioBtn(self): """单选框选中事件""" radioBtn = self.sender() if radioBtn.isChecked(): self.label.setText("You have selected " + radioBtn.text())
class Window(QDialog): def __init__(self): super().__init__() self.title = "PyQt Radio Button" self.top = 400 self.left = 300 self.height = 100 self.width = 400 self.init_window() def init_window(self): self.setWindowTitle(self.title) self.setGeometry(self.left, self.top, self.width, self.height) self.radio_button() vbox = QVBoxLayout() vbox.addWidget(self.groupBox) self.label = QLabel(self) self.label.setFont(QtGui.QFont('Sanserif', 15)) vbox.addWidget(self.label) self.setLayout(vbox) self.show() def radio_button(self): self.groupBox = QGroupBox("What is your favorite sport?") self.groupBox.setFont(QtGui.QFont('Sanserif', 13)) hboxlayout = QHBoxLayout() self.radiobtn1 = QRadioButton("Football") self.radiobtn1.setChecked(True) self.radiobtn1.setIcon(QtGui.QIcon('football.png')) self.radiobtn1.setIconSize(QtCore.QSize(20, 20)) self.radiobtn1.setFont(QtGui.QFont('Sanserif', 13)) self.radiobtn1.toggled.connect(self.on_radio_button) hboxlayout.addWidget(self.radiobtn1) self.radiobtn2 = QRadioButton("Cricket") self.radiobtn2.setIcon(QtGui.QIcon('cricket.png')) self.radiobtn2.setIconSize(QtCore.QSize(20, 20)) self.radiobtn2.setFont(QtGui.QFont('Sanserif', 13)) self.radiobtn2.toggled.connect(self.on_radio_button) hboxlayout.addWidget(self.radiobtn2) self.radiobtn3 = QRadioButton("Tennis") self.radiobtn3.setIcon(QtGui.QIcon('tennis.png')) self.radiobtn3.setIconSize(QtCore.QSize(20, 20)) self.radiobtn3.setFont(QtGui.QFont('Sanserif', 13)) self.radiobtn3.toggled.connect(self.on_radio_button) hboxlayout.addWidget(self.radiobtn3) self.groupBox.setLayout(hboxlayout) def on_radio_button(self): radioBtn = self.sender() if radioBtn.isChecked(): self.label.setText("You have selected " + radioBtn.text())
class Window(QDialog): def __init__(self): super().__init__() #winow requirement self.setGeometry(200,200, 400,300) self.setWindowTitle("PyQt5 QRadioButton") self.setWindowIcon(QIcon('python.png')) #our method call self.create_radiobutton() #we need to create vertical layout vbox = QVBoxLayout() vbox.addWidget(self.groupbox) #this is our label self.label = QLabel("") self.label.setFont(QFont("Sanserif", 14)) #add your widgets in the vbox layout vbox.addWidget(self.label) #set your main window layout self.setLayout(vbox) def create_radiobutton(self): #this is our groupbox self.groupbox = QGroupBox("What is your favorite sport ?") self.groupbox.setFont(QFont("Sanserif", 15)) #this is hbox layout hbox = QHBoxLayout() #these are the radiobuttons self.rad1 = QRadioButton("Football") self.rad1.setChecked(True) self.rad1.setIcon(QIcon('football.png')) self.rad1.setIconSize(QSize(40,40)) self.rad1.setFont(QFont("Sanserif", 14)) self.rad1.toggled.connect(self.on_selected) hbox.addWidget(self.rad1) self.rad2 = QRadioButton("Cricket") self.rad2.setIcon(QIcon('cricket.png')) self.rad2.setIconSize(QSize(40, 40)) self.rad2.setFont(QFont("Sanserif", 14)) self.rad2.toggled.connect(self.on_selected) hbox.addWidget(self.rad2) self.rad3 = QRadioButton("Tennis") self.rad3.setIcon(QIcon('tennis.png')) self.rad3.setIconSize(QSize(40, 40)) self.rad3.setFont(QFont("Sanserif", 14)) self.rad3.toggled.connect(self.on_selected) hbox.addWidget(self.rad3) self.groupbox.setLayout(hbox) #method or slot for the toggled signal def on_selected(self): radio_button = self.sender() if radio_button.isChecked(): self.label.setText("You have selected : " + radio_button.text())
class Window(QDialog): def __init__(self): super().__init__() self.title="Learning PyQt5" self.top=100 self.left=100 self.width=400 self.height=300 self.iconName = "logo.png" self.InitWindow() def InitWindow(self): self.setWindowIcon(QtGui.QIcon(self.iconName)) self.setWindowTitle(self.title) self.setGeometry(self.left, self.top, self.width, self.height) self.radioButton() vbox = QVBoxLayout() vbox.addWidget(self.groupBox) self.label = QLabel(self) self.label.setFont(QtGui.QFont("Britannic",20)) vbox.addWidget(self.label) self.setLayout(vbox) self.show() def radioButton(self): self.groupBox = QGroupBox("What is your favorite sport?") self.groupBox.setFont(QtGui.QFont("Comic Sans MS",14)) hboxLayout = QHBoxLayout() self.radiobtn1 = QRadioButton("Football") self.radiobtn1.setChecked(True) self.radiobtn1.setIcon(QtGui.QIcon("football.png")) self.radiobtn1.setIconSize(QtCore.QSize(40,40)) self.radiobtn1.setFont(QtGui.QFont("Bernard MT",12)) self.radiobtn1.toggled.connect(self.onRadioBtn) hboxLayout.addWidget(self.radiobtn1) self.radiobtn2 = QRadioButton("Cricket") self.radiobtn2.setChecked(False) self.radiobtn2.setIcon(QtGui.QIcon("cricket.png")) self.radiobtn2.setIconSize(QtCore.QSize(40,40)) self.radiobtn2.setFont(QtGui.QFont("Bernard MT",12)) self.radiobtn2.toggled.connect(self.onRadioBtn) hboxLayout.addWidget(self.radiobtn2) self.radiobtn3 = QRadioButton("Tennis") self.radiobtn3.setChecked(False) self.radiobtn3.setIcon(QtGui.QIcon("tennis.png")) self.radiobtn3.setIconSize(QtCore.QSize(40,40)) self.radiobtn3.setFont(QtGui.QFont("Bernard MT",12)) self.radiobtn3.toggled.connect(self.onRadioBtn) hboxLayout.addWidget(self.radiobtn3) self.groupBox.setLayout(hboxLayout) def onRadioBtn(self): radioBtn = self.sender() if radioBtn.isChecked(): self.label.setText("You have selected " + radioBtn.text())
class MainWindow(QDialog): def __init__(self): super().__init__() self.title = "PyQt5 Radio Button" self.top = 400 self.left = 200 self.width = 400 self.height = 150 self.icon_name = "images/home.png" self._init_window() def _init_window(self): self.setWindowIcon(QtGui.QIcon(self.icon_name)) self.setWindowTitle(self.title) self.setGeometry(self.left, self.top, self.width, self.height) self._create_ui_components() vbox = QVBoxLayout() vbox.addWidget(self.group_box) self.lbl_Info = QLabel(self) self.lbl_Info.setFont(QtGui.QFont("Sanserif", 15)) vbox.addWidget(self.lbl_Info) self.setLayout(vbox) self.show() def _create_ui_components(self): self.group_box = QGroupBox("What is your favorite sport?") self.group_box.setFont(QtGui.QFont("Sanserif", 13)) hbox_layout = QHBoxLayout() self.rdbtn_soccer = QRadioButton("Soccer") self.rdbtn_soccer.setIcon(QtGui.QIcon("images/soccer.png")) self.rdbtn_soccer.setIconSize(QtCore.QSize(30, 30)) self.rdbtn_soccer.setFont(QtGui.QFont("Sanserif", 13)) self.rdbtn_soccer.toggled.connect(self._on_radiobutton_checked) hbox_layout.addWidget(self.rdbtn_soccer) self.rdbtn_basketball = QRadioButton("Basketball") self.rdbtn_basketball.setIcon(QtGui.QIcon("images/basketball.png")) self.rdbtn_basketball.setIconSize(QtCore.QSize(30, 30)) self.rdbtn_basketball.setFont(QtGui.QFont("Sanserif", 13)) self.rdbtn_basketball.toggled.connect(self._on_radiobutton_checked) hbox_layout.addWidget(self.rdbtn_basketball) self.rdbtn_tennis = QRadioButton("Tennis") self.rdbtn_tennis.setIcon(QtGui.QIcon("images/tennis.png")) self.rdbtn_tennis.setIconSize(QtCore.QSize(30, 30)) self.rdbtn_tennis.setFont(QtGui.QFont("Sanserif", 13)) self.rdbtn_tennis.toggled.connect(self._on_radiobutton_checked) hbox_layout.addWidget(self.rdbtn_tennis) self.group_box.setLayout(hbox_layout) def _on_radiobutton_checked(self): rdbtn = self.sender() if rdbtn.isChecked(): self.lbl_Info.setText(f"Sport selected: {rdbtn.text()}")
class Settings(QDialog): # +++++++++++++++++++++++++++++++++++++++++++++++++++++ __init__ +++++++++++++++++++++++++++++++++++++++++++++++++++ def __init__(self, temp_config, parent=None): QDialog.__init__(self, parent) self.setStyleSheet(""" QWidget{background-color: rgba(0,41,59,255); border-color: rgba(0,41,59,255); color:white; font-weight:bold;}""") self.default_temp_config = temp_config self.temp_config = temp_config if self.temp_config['language'] == "georgian": Geo_Checked = True Eng_Checked = False else: Geo_Checked = False Eng_Checked = True self.setWindowTitle("პარამეტრები") self.setWindowIcon( QtGui.QIcon("img/settings.png")) # Set main window icon self.groupBox_language = QGroupBox("ენა") # create groupbox with lane self.groupBox_language.setAlignment(Qt.AlignCenter) self.groupBox_window_size = QGroupBox( "ფანჯრის ზომა") # create groupbox with lane self.groupBox_window_size.setAlignment(Qt.AlignCenter) VLbox = QVBoxLayout() VLbox.addWidget(self.groupBox_language) VLbox.addWidget(self.groupBox_window_size) hboxLayout_language = QHBoxLayout() hboxLayout_size = QHBoxLayout() self.Edit_length = QLineEdit() self.Edit_width = QLineEdit() self.Label_length = QLabel("სიგრძე") self.Label_width = QLabel("სიგანე") self.Edit_length.setText(str(self.temp_config['length'])) self.Edit_width.setText(str(self.temp_config['width'])) hboxLayout_size.addWidget(self.Label_length) hboxLayout_size.addWidget(self.Edit_length) hboxLayout_size.addWidget(self.Label_width) hboxLayout_size.addWidget(self.Edit_width) self.radioButton1 = QRadioButton("ქართული") # create radiobutton1 self.radioButton1.setChecked( Geo_Checked) # set radiobutton1 as default ticked self.radioButton1.setIcon( QtGui.QIcon("img/georgia.png")) # set icon on radiobutton1 self.radioButton1.setIconSize(QtCore.QSize(40, 40)) # set icon size self.radioButton1.toggled.connect( self.geo ) # create radiobutton1 and "OnRadioBtn" function conection hboxLayout_language.addWidget( self.radioButton1) # add radiobutton1 in horizontal layout self.radioButton2 = QRadioButton("ინგლისური") # create radiobutton2 self.radioButton2.setChecked(Eng_Checked) self.radioButton2.setIcon( QtGui.QIcon("img/english.png")) # set icon on radiobutton2 self.radioButton2.setIconSize(QtCore.QSize(40, 40)) # set icon size hboxLayout_language.addWidget( self.radioButton2) # add radiobutton2 in horizontal layout self.radioButton2.toggled.connect(self.eng) self.ApplySet = PushBut("დადასტურება") self.CancelSet = PushBut("გაუქმება") self.ApplySet.clicked.connect(self.applySettings) self.CancelSet.clicked.connect(self.CancelSettings) self.groupBox_language.setLayout( hboxLayout_language) # in group box set horizontal layout self.groupBox_window_size.setLayout( hboxLayout_size) # in group box set horizontal layout VLbox.addWidget(self.ApplySet) VLbox.addWidget(self.CancelSet) if self.temp_config['language'] == "georgian": self.geo() else: self.eng() self.setLayout(VLbox) # ++++++++++++++++++++++++++++++++++++++++++++ Georgian language option ++++++++++++++++++++++++++++++++++++++++++++ def geo(self): if self.radioButton1.isChecked(): self.ApplySet.setText("დადასტურება") self.CancelSet.setText("გაუქმება") self.groupBox_language.setTitle("ენა") self.groupBox_window_size.setTitle("ფანჯრის ზომა") self.setWindowTitle("პარამეტრები") self.radioButton1.setText("ქართული") self.radioButton2.setText("ინგლისური") self.Label_length.setText("სიგრძე") self.Label_width.setText("სიგანე") self.temp_config['language'] = "georgian" # +++++++++++++++++++++++++++++++++++++++++++++ English language option ++++++++++++++++++++++++++++++++++++++++++++ def eng(self): if self.radioButton2.isChecked(): self.ApplySet.setText("Apply") self.CancelSet.setText("Cancel") self.groupBox_language.setTitle("Language") self.groupBox_window_size.setTitle("Window Size") self.setWindowTitle("Settings") self.radioButton1.setText("Georgian") self.radioButton2.setText("English") self.Label_length.setText("Length") self.Label_width.setText("width") self.temp_config['language'] = "english" # +++++++++++++++++++++++++++++++++++++++++++++++++ Apply Settings +++++++++++++++++++++++++++++++++++++++++++++++++ def applySettings(self): try: self.temp_config['length'] = int(self.Edit_length.text()) self.temp_config['width'] = int(self.Edit_width.text()) except ValueError: pass self.close() # +++++++++++++++++++++++++++++++++++++++++++++++++ Cancel Settings ++++++++++++++++++++++++++++++++++++++++++++++++ def CancelSettings(self): self.temp_config = self.default_temp_config self.close()
class ThemePage(QWidget): def __init__(self, parent=None): super(ThemePage, self).__init__(parent) self.parent = parent self.setObjectName('settingsthemepage') mainLayout = QVBoxLayout() mainLayout.setSpacing(10) if sys.platform != 'darwin': self.lightRadio = QRadioButton(self) self.lightRadio.setIcon( QIcon(':/images/%s/theme-light.png' % self.parent.theme)) self.lightRadio.setToolTip( '<img src=":/images/theme-light-large.jpg" />') self.lightRadio.setIconSize(QSize(165, 121)) self.lightRadio.setCursor(Qt.PointingHandCursor) self.lightRadio.clicked.connect(self.switchTheme) self.lightRadio.setChecked(self.parent.theme == 'light') self.darkRadio = QRadioButton(self) self.darkRadio.setIcon( QIcon(':/images/%s/theme-dark.png' % self.parent.theme)) self.darkRadio.setToolTip( '<img src=":/images/theme-dark-large.jpg" />') self.darkRadio.setIconSize(QSize(165, 121)) self.darkRadio.setCursor(Qt.PointingHandCursor) self.darkRadio.clicked.connect(self.switchTheme) self.darkRadio.setChecked(self.parent.theme == 'dark') themeLayout = QGridLayout() themeLayout.setColumnStretch(0, 1) themeLayout.addWidget(self.lightRadio, 0, 1) themeLayout.addWidget(self.darkRadio, 0, 3) themeLayout.addWidget(QLabel('Light', self), 1, 1, Qt.AlignHCenter) themeLayout.setColumnStretch(2, 1) themeLayout.addWidget(QLabel('Dark', self), 1, 3, Qt.AlignHCenter) themeLayout.setColumnStretch(4, 1) themeGroup = QGroupBox('Theme') themeGroup.setLayout(themeLayout) mainLayout.addWidget(themeGroup) toolbar_labels = self.parent.settings.value('toolbarLabels', 'beside', type=str) toolbar_iconsRadio = QRadioButton('Icons only', self) toolbar_iconsRadio.setToolTip('Icons only') toolbar_iconsRadio.setCursor(Qt.PointingHandCursor) toolbar_iconsRadio.setChecked(toolbar_labels == 'none') toolbar_underRadio = QRadioButton('Text under icons', self) toolbar_underRadio.setToolTip('Text under icons') toolbar_underRadio.setCursor(Qt.PointingHandCursor) toolbar_underRadio.setChecked(toolbar_labels == 'under') toolbar_besideRadio = QRadioButton('Text beside icons', self) toolbar_besideRadio.setToolTip('Text beside icons') toolbar_besideRadio.setCursor(Qt.PointingHandCursor) toolbar_besideRadio.setChecked(toolbar_labels == 'beside') toolbar_buttonGroup = QButtonGroup(self) toolbar_buttonGroup.addButton(toolbar_iconsRadio, 1) toolbar_buttonGroup.addButton(toolbar_underRadio, 2) toolbar_buttonGroup.addButton(toolbar_besideRadio, 3) # noinspection PyUnresolvedReferences toolbar_buttonGroup.buttonClicked[int].connect( self.parent.parent.toolbar.setLabels) toolbarLayout = QGridLayout() toolbarLayout.addWidget(toolbar_besideRadio, 0, 0) toolbarLayout.addWidget(toolbar_underRadio, 0, 1) toolbarLayout.addWidget(toolbar_iconsRadio, 1, 0) toolbarGroup = QGroupBox('Toolbar') toolbarGroup.setLayout(toolbarLayout) mainLayout.addWidget(toolbarGroup) mainLayout.addStretch(1) self.setLayout(mainLayout) @pyqtSlot(bool) def switchTheme(self) -> None: if self.darkRadio.isChecked(): newtheme = 'dark' else: newtheme = 'light' if newtheme != self.parent.theme: # noinspection PyArgumentList mbox = QMessageBox(icon=QMessageBox.NoIcon, windowTitle='Restart required', minimumWidth=500, textFormat=Qt.RichText, objectName='genericdialog') mbox.setWindowFlags(Qt.Dialog | Qt.WindowCloseButtonHint) mbox.setText( ''' <style> h1 { color: %s; font-family: "Futura-Light", sans-serif; font-weight: 400; } p { font-size: 15px; } </style> <h1>Warning</h1> <p>The application needs to be restarted in order to switch themes. Ensure you have saved your project or finished any cut ror join tasks in progress.</p> <p>Would you like to restart and switch themes now?</p>''' % ('#C681D5' if self.parent.theme == 'dark' else '#642C68')) mbox.setStandardButtons(QMessageBox.Yes | QMessageBox.No) mbox.setDefaultButton(QMessageBox.Yes) response = mbox.exec_() if response == QMessageBox.Yes: self.parent.settings.setValue('theme', newtheme) self.parent.parent.theme = newtheme self.parent.parent.parent.reboot() else: self.darkRadio.setChecked( True ) if newtheme == 'light' else self.lightRadio.setChecked(True)
class Window(QMainWindow): def __init__(self): super().__init__() """ Sets some default settings of the window such as the name, the size and the icon. """ self.setWindowTitle("QPaint") self.setGeometry(100, 100, 800, 600) # top, left, width, height self.setWindowIcon(QIcon("./icons/paint-brush.png")) """ Initializes layouts and call the methods that will initialize specific parts of the window. """ self.grid = QGridLayout() self.box = ToolBox() self.imageArea = DrawingArea() self.setBrushSlider() self.setBrushStyle() self.setBrushCap() self.setBrushJoin() self.setColorChanger() """ Creates a grid with the toolbox and the drawing area, which we both set in a widget which is the central widget of our window. """ self.grid.addWidget(self.box, 0, 0, 1, 1) self.grid.addWidget(self.imageArea, 0, 1, 1, 6) win = QWidget() win.setLayout(self.grid) self.setCentralWidget(win) """ Creates the menu bar of our window with 3 menus. """ # menus mainMenu = self.menuBar() fileMenu = mainMenu.addMenu( " File") # the space is required as "File" is reserved in Mac drawMenu = mainMenu.addMenu("Draw") helpMenu = mainMenu.addMenu("Help") """ Creates the Save action and adds it to the "File" menu. """ saveAction = QAction(QIcon("./icons/save.png"), "Save", self) saveAction.setShortcut("Ctrl+S") fileMenu.addAction(saveAction) """ When the menu option is selected or the shortcut is used the save action is triggered. """ saveAction.triggered.connect(self.save) """ Creates the Open action and adds it to the "File" menu. """ openAction = QAction(QIcon("./icons/open.png"), "Open", self) openAction.setShortcut("Ctrl+O") fileMenu.addAction(openAction) """ When the menu option is selected or the shortcut is used the open action is triggered. """ openAction.triggered.connect(self.open) """ Creates the Undo action and adds it to the "File" menu. """ undoAction = QAction(QIcon("./icons/undo.png"), "Undo", self) undoAction.setShortcut("Ctrl+Z") fileMenu.addAction(undoAction) """ When the menu option is selected or the shortcut is used the undo action is triggered. """ undoAction.triggered.connect(self.undo) """ Creates the Clear action and adds it to the "File" menu. """ clearAction = QAction(QIcon("./icons/clear.png"), "Clear", self) clearAction.setShortcut("Ctrl+C") fileMenu.addAction(clearAction) """ When the menu option is selected or the shortcut is used the clear action is triggered. """ clearAction.triggered.connect(self.clear) """ Creates the Exit action and adds it to the "File" menu. """ exitAction = QAction(QIcon("./icons/exit.png"), "Exit", self) exitAction.setShortcut("Ctrl+Q") fileMenu.addAction(exitAction) """ When the menu option is selected or the shortcut is used the exit action is triggered. """ exitAction.triggered.connect(self.exitProgram) """ Creates the Point action and adds it to the "Draw" menu. """ self.pointAction = QAction("Point", self, checkable=True) self.pointAction.setShortcut("Ctrl+P") self.pointAction.setChecked(True) drawMenu.addAction(self.pointAction) """ When the menu option is selected or the shortcut is used the change draw mode action is triggered. """ self.pointAction.triggered.connect( lambda: self.changeDrawMode(self.pointAction)) """ Creates the Line action and adds it to the "Draw" menu. """ self.lineAction = QAction("Line", self, checkable=True) self.lineAction.setShortcut("Ctrl+L") drawMenu.addAction(self.lineAction) """ When the menu option is selected or the shortcut is used the change draw mode action is triggered. """ self.lineAction.triggered.connect( lambda: self.changeDrawMode(self.lineAction)) """ Creates the About action and adds it to the "Help" menu. """ aboutAction = QAction(QIcon("./icons/about.png"), "About", self) aboutAction.setShortcut("Ctrl+I") helpMenu.addAction(aboutAction) """ When the menu option is selected or the shortcut is used the about action is triggered. """ aboutAction.triggered.connect(self.about) """ Creates the Help action and adds it to the "Help" menu. """ helpAction = QAction(QIcon("./icons/help.png"), "Help", self) helpAction.setShortcut("Ctrl+H") helpMenu.addAction(helpAction) """ When the menu option is selected or the shortcut is used the help action is triggered. """ helpAction.triggered.connect(self.help) """ Updates the widget with the default settings. """ self.imageArea.update() """ Method which changes the draw mode depending on which action has been called. """ def changeDrawMode(self, check): if check.text() == "Point": self.pointAction.setChecked(True) self.lineAction.setChecked(False) self.imageArea.drawMode = DrawMode.Point elif check.text() == "Line": self.pointAction.setChecked(False) self.lineAction.setChecked(True) self.imageArea.drawMode = DrawMode.Line """ Resets the saved point. """ self.imageArea.lastPoint = QPoint() """ Initializes the layout on which we can change the Join setting of the brush. """ def setBrushJoin(self): self.brush_join_type = QGroupBox("Brush join") self.brush_join_type.setMaximumHeight(100) """ Creates the radio buttons to let us make a choice between these 3 options. Each one is connected to a method which will change the setting depending on which button is clicked. """ self.joinBtn1 = QRadioButton("Round") self.joinBtn1.clicked.connect( lambda: self.changeBrushJoin(self.joinBtn1)) self.joinBtn2 = QRadioButton("Miter") self.joinBtn2.clicked.connect( lambda: self.changeBrushJoin(self.joinBtn2)) self.joinBtn3 = QRadioButton("Bevel") self.joinBtn3.clicked.connect( lambda: self.changeBrushJoin(self.joinBtn3)) """ Sets a default value. Adds the buttons to the layout which is added to the parent box. """ self.joinBtn1.setChecked(True) qv = QVBoxLayout() qv.addWidget(self.joinBtn1) qv.addWidget(self.joinBtn2) qv.addWidget(self.joinBtn3) self.brush_join_type.setLayout(qv) self.box.vbox.addWidget(self.brush_join_type) """ Initializes the layout on which we can change the Type setting of the brush. """ def setBrushStyle(self): self.brush_line_type = QGroupBox("Brush style") self.brush_line_type.setMaximumHeight(100) """ Creates the radio buttons to let us make a choice between these 3 options. Each one is connected to a method which will change the setting depending on which button is clicked. """ self.styleBtn1 = QRadioButton(" Solid") self.styleBtn1.setIcon(QIcon("./icons/solid.png")) self.styleBtn1.setIconSize(QSize(32, 64)) self.styleBtn1.clicked.connect( lambda: self.changeBrushStyle(self.styleBtn1)) self.styleBtn2 = QRadioButton(" Dash") self.styleBtn2.setIcon(QIcon("./icons/dash.png")) self.styleBtn2.setIconSize(QSize(32, 64)) self.styleBtn2.clicked.connect( lambda: self.changeBrushStyle(self.styleBtn2)) self.styleBtn3 = QRadioButton(" Dot") self.styleBtn3.setIcon(QIcon("./icons/dot.png")) self.styleBtn3.setIconSize(QSize(32, 64)) self.styleBtn3.clicked.connect( lambda: self.changeBrushStyle(self.styleBtn3)) """ Sets a default value. Adds the buttons to the layout which is added to the parent box. """ self.styleBtn1.setChecked(True) qv = QVBoxLayout() qv.addWidget(self.styleBtn1) qv.addWidget(self.styleBtn2) qv.addWidget(self.styleBtn3) self.brush_line_type.setLayout(qv) self.box.vbox.addWidget(self.brush_line_type) """ Initializes the layout on which we can change the Cap setting of the brush. """ def setBrushCap(self): self.brush_cap_type = QGroupBox("Brush cap") self.brush_cap_type.setMaximumHeight(100) """ Creates the radio buttons to let us make a choice between these 3 options. Each one is connected to a method which will change the setting depending on which button is clicked. """ self.capBtn1 = QRadioButton("Square") self.capBtn1.clicked.connect(lambda: self.changeBrushCap(self.capBtn1)) self.capBtn2 = QRadioButton("Flat") self.capBtn2.clicked.connect(lambda: self.changeBrushCap(self.capBtn2)) self.capBtn3 = QRadioButton("Round") self.capBtn3.clicked.connect(lambda: self.changeBrushCap(self.capBtn3)) """ Sets a default value. Adds the buttons to the layout which is added to the parent box. """ self.capBtn3.setChecked(True) qv = QVBoxLayout() qv.addWidget(self.capBtn1) qv.addWidget(self.capBtn2) qv.addWidget(self.capBtn3) self.brush_cap_type.setLayout(qv) self.box.vbox.addWidget(self.brush_cap_type) """ Method which changes the Join setting of the brush depending on which button has been previously clicked. """ def changeBrushJoin(self, btn): if btn.text() == "Round": if btn.isChecked(): self.imageArea.brushJoin = Qt.RoundJoin if btn.text() == "Miter": if btn.isChecked(): self.imageArea.brushJoin = Qt.MiterJoin if btn.text() == "Bevel": if btn.isChecked(): self.imageArea.brushJoin = Qt.BevelJoin """ Method which changes the Cap setting of the brush depending on which button has been previously clicked. """ def changeBrushCap(self, btn): if btn.text() == "Square": if btn.isChecked(): self.imageArea.brushCap = Qt.SquareCap if btn.text() == "Flat": if btn.isChecked(): self.imageArea.brushCap = Qt.FlatCap if btn.text() == "Round": if btn.isChecked(): self.imageArea.brushCap = Qt.RoundCap """ Method which changes the Type setting of the brush depending on which button has been previously clicked. """ def changeBrushStyle(self, btn): if btn.text() == " Solid": if btn.isChecked(): self.imageArea.brushStyle = Qt.SolidLine if btn.text() == " Dash": if btn.isChecked(): self.imageArea.brushStyle = Qt.DashLine if btn.text() == " Dot": if btn.isChecked(): self.imageArea.brushStyle = Qt.DotLine """ Initializes the layout on which we can change the brush size. """ def setBrushSlider(self): self.groupBoxSlider = QGroupBox("Brush size") self.groupBoxSlider.setMaximumHeight(100) """ Sets a vertical slider with a min and a max value. """ self.brush_thickness = QSlider(Qt.Horizontal) self.brush_thickness.setMinimum(1) self.brush_thickness.setMaximum(40) self.brush_thickness.valueChanged.connect(self.sizeSliderChange) """ Sets a label to display the size of the brush. """ self.brushSizeLabel = QLabel() self.brushSizeLabel.setText("%s px" % self.imageArea.brushSize) """ Adds the buttons to the layout which is added to the parent box. """ qv = QVBoxLayout() qv.addWidget(self.brush_thickness) qv.addWidget(self.brushSizeLabel) self.groupBoxSlider.setLayout(qv) self.box.vbox.addWidget(self.groupBoxSlider) """ Method which changes the brush size depending on the value sent from the slider. """ def sizeSliderChange(self, value): self.imageArea.brushSize = value self.brushSizeLabel.setText("%s px" % value) """ Initializes the layout on which we can change the color of the brush. """ def setColorChanger(self): self.groupBoxColor = QGroupBox("Color") self.groupBoxColor.setMaximumHeight(100) """ Initializes a color and sets a button with this color as background. """ self.col = QColor(0, 0, 0) self.brush_colour = QPushButton() self.brush_colour.setFixedSize(60, 60) self.brush_colour.clicked.connect(self.showColorDialog) self.brush_colour.setStyleSheet("background-color: %s" % self.col.name()) self.box.vbox.addWidget(self.brush_colour) """ Adds the buttons to the layout which is added to the parent box. """ qv = QVBoxLayout() qv.addWidget(self.brush_colour) self.groupBoxColor.setLayout(qv) self.box.vbox.addWidget(self.groupBoxColor) """ Method which displays a color picker and sets the brush color. """ def showColorDialog(self): self.col = QColorDialog.getColor() if self.col.isValid(): self.brush_colour.setStyleSheet("background-color: %s" % self.col.name()) self.imageArea.brushColor = self.col """ Method called when the main window is resized. Scales the image area with the new size. """ def resizeEvent(self, a0: QtGui.QResizeEvent): if self.imageArea.resizeSavedImage.width() != 0: self.imageArea.image = self.imageArea.resizeSavedImage.scaled( self.imageArea.width(), self.imageArea.height(), QtCore.Qt.IgnoreAspectRatio) self.imageArea.update() """ Method called when we execute the save action. It opens a file dialog in which the user can choose the path of where he would like to save the current image. """ def save(self): filePath, _ = QFileDialog.getSaveFileName( self, "Save Image", "", "PNG(*.png);;JPG(*.jpg *.jpeg);;All Files (*.*)") if filePath == "": return self.imageArea.image.save(filePath) """ Method called when we execute the open action. It opens a file dialog in which the user can choose the path of the image he wants to open in the program. """ def open(self): filePath, _ = QFileDialog.getOpenFileName( self, "Open Image", "", "PNG(*.png);;JPG(*.jpg *.jpeg);;All Files (*.*)") if filePath == "": return with open(filePath, 'rb') as f: content = f.read() """ Loads the data from the file to the image. Scales it and updates the drawing area. """ self.imageArea.image.loadFromData(content) self.imageArea.image = self.imageArea.image.scaled( self.imageArea.width(), self.imageArea.height(), QtCore.Qt.IgnoreAspectRatio) self.imageArea.resizeSavedImage = self.imageArea.image # saves the image for later resizing self.imageArea.update() """ Method called when we execute the undo action. The user can go back to the previous state of the image before the last modification he made. """ def undo(self): copyImage = self.imageArea.image if self.imageArea.savedImage.width() != 0: """ If the saved image exists, we set the actual image to the saved one scaled to the right size. """ self.imageArea.image = self.imageArea.savedImage.scaled( self.imageArea.width(), self.imageArea.height(), QtCore.Qt.IgnoreAspectRatio) else: """ If no saved image exist we just clean the current one. """ self.imageArea.image = QImage(self.imageArea.width(), self.imageArea.height(), QImage.Format_RGB32) self.imageArea.image.fill(Qt.white) """ Sets the saved image as the copy from the screen. """ self.imageArea.savedImage = copyImage self.imageArea.update() """ Method called when we execute the clear action. It fills the image in white and updates it. """ def clear(self): self.imageArea.image.fill(Qt.white) self.imageArea.update() """ Method called when we execute the exit action. Exits the program. """ def exitProgram(self): QtCore.QCoreApplication.quit() """ Method called when we execute the about action. Displays a message about the program. """ def about(self): QMessageBox.about( self, "About QPaint", "<p>This Qt Application is a basic paint program made with PyQt. " "You can draw something by yourself and then save it as a file. " "PNG and JPG files can also be opened and edited.</p>") """ Method called when we execute the help action. Displays a help message about the program. """ def help(self): msg = QMessageBox() msg.setText( "Help" "<p>Welcome on QPaint.</p> " "<p>On the left side of the screen you can see a toolbox on which you have different boxes. " "Each of these boxes contains buttons or sliders which allow you to customize the brush you want to" "draw with.</p>" "<p>The right size of the screen is the drawing area, where you can draw.</p> " "<p>The program also has different menus you can see at the top of the window. " "<p>These menus allow you to open a file, save your image, clean it, or even exit the program.</p>" "We hope you will enjoy your experience." "If you encounter any difficulty or need any information " "you can send an email to [email protected].</p>") msg.setWindowTitle("Help") msg.move(self.width() / 2, self.height() / 2) msg.exec_()
def createElement(line: str, widget_gallery) -> 'AbstractClass': els = line.split('"') els = [el.strip() for el in els] button_type, button_label, _discard, button_text, other = els try: button_type = ButtonType(button_type) except: button_type = None if button_label != "": label = QLabel(button_label) else: label = None var_name, val_value, initial_setting, ticked_state = other.split(' ') if val_value == "None": val_value = None elif val_value.find('/'): val_value = val_value.split('/') if button_type == ButtonType.RADIO_BUTTON: inputButton = None button = QRadioButton(button_text) if initial_setting == "off": button.setEnabled(False) elif button_type == ButtonType.TEXT_EDIT_BUTTON: inputButton = QLineEdit(widget_gallery) inputButton.setPlaceholderText(var_name) button = QRadioButton(button_text) if initial_setting == "off": button.setEnabled(False) inputButton.setEnabled(False) elif button_type == ButtonType.TEXT_EDIT_BOX: inputButton = QLineEdit(widget_gallery) inputButton.setPlaceholderText(var_name) button = None if initial_setting == "off": inputButton.setEnabled(False) elif button_type == ButtonType.FILE_INPUT: inputButton = QLineEdit(widget_gallery) inputButton.setPlaceholderText(var_name) # commented this line for now, since the "choose file" option doesn't work from inside container #button = QPushButton(button_text) button = None if initial_setting == "off": inputButton.setEnabled(False) # commented this line for now, since the "choose file" option doesn't work from inside container #button.setEnabled(False) elif button_type == ButtonType.TOGGLE_BUTTON: inputButton = None button = QCheckBox(button_text) if initial_setting == "off": button.setEnabled(False) if ticked_state == "ticked": button.setChecked(True) elif button_type == ButtonType.DROPDOWN_LIST: inputButton = None button = QComboBox(widget_gallery) for _value in val_value: button.addItem(_value) button.move(50, 250) if initial_setting == "off": button.setEnabled(False) elif button_type == ButtonType.PUSH_BUTTON: inputButton = None pixmap = QPixmap('images/audioicon.png') button = QPushButton(button_text) button.setGeometry(200, 150, 50, 50) button.setIcon(QIcon(pixmap)) button.setIconSize(QSize(50, 50)) elif button_type == ButtonType.AUDIO_INPUT: inputButton = None pixmap = QPixmap('images/audioicon.png') button = QPushButton(button_text) button.setGeometry(200, 150, 50, 50) button.setIcon(QIcon(pixmap)) button.setIconSize(QSize(50, 50)) return OptionButton(button_type.value, button, var_name, inputButton, val_value, label)
class Settings(QDialog): # ++++++++++++++++++++++++++++ __init__ +++++++++++++++++++++++++++++++ def __init__(self, config, parent=None): QDialog.__init__(self, parent) self.applayState = False self.config = config self.language = config['language'] if self.language == "georgian": Geo_Checked = True Eng_Checked = False else: Geo_Checked = False Eng_Checked = True self.setWindowTitle("პარამეტრები") self.setWindowIcon(QtGui.QIcon("icon/setting.svg")) self.groupBox_language = QGroupBox("ენა") self.groupBox_language.setAlignment(Qt.AlignCenter) self.groupBox_window_size = QGroupBox("ფანჯრის ზომა") self.groupBox_window_size.setAlignment(Qt.AlignCenter) VLbox = QVBoxLayout() VLbox.addWidget(self.groupBox_language) VLbox.addWidget(self.groupBox_window_size) hboxLayout_language = QHBoxLayout() hboxLayout_size = QHBoxLayout() self.Edit_length = QLineEdit() self.Edit_width = QLineEdit() self.Label_length = QLabel("სიგრძე") self.Label_width = QLabel("სიგანე") self.Edit_length.setText(str(self.config['length'])) self.Edit_width.setText(str(self.config['width'])) hboxLayout_size.addWidget(self.Label_length) hboxLayout_size.addWidget(self.Edit_length) hboxLayout_size.addWidget(self.Label_width) hboxLayout_size.addWidget(self.Edit_width) self.Geo_radioButton = QRadioButton("ქართული") self.Geo_radioButton.setChecked(Geo_Checked) self.Geo_radioButton.setIcon(QtGui.QIcon("icon/georgia.png")) self.Geo_radioButton.setIconSize(QtCore.QSize(40, 40)) self.Geo_radioButton.toggled.connect(self.geo) hboxLayout_language.addWidget(self.Geo_radioButton) self.Eng_radioButton = QRadioButton("ინგლისური") self.Eng_radioButton.setChecked(Eng_Checked) self.Eng_radioButton.setIcon(QtGui.QIcon("icon/english.png")) self.Eng_radioButton.setIconSize(QtCore.QSize(40, 40)) hboxLayout_language.addWidget(self.Eng_radioButton) self.Eng_radioButton.toggled.connect(self.eng) self.ApplySet = QPushButton("დადასტურება", self) self.CancelSet = QPushButton("გაუქმება", self) self.ApplySet.clicked.connect(self.applySettings) self.CancelSet.clicked.connect(self.CancelSettings) self.groupBox_language.setLayout(hboxLayout_language) self.groupBox_window_size.setLayout(hboxLayout_size) VLbox.addWidget(self.ApplySet) VLbox.addWidget(self.CancelSet) if self.language == "georgian": self.geo() else: self.eng() self.setLayout(VLbox) # ++++++++++++++++++++ Georgian language option +++++++++++++++++++++++ def geo(self): if self.Geo_radioButton.isChecked(): self.ApplySet.setText("დადასტურება") self.CancelSet.setText("გაუქმება") self.groupBox_language.setTitle("ენა") self.groupBox_window_size.setTitle("ფანჯრის ზომა") self.setWindowTitle("პარამეტრები") self.Geo_radioButton.setText("ქართული") self.Eng_radioButton.setText("ინგლისური") self.Label_length.setText("სიგრძე") self.Label_width.setText("სიგანე") self.language = "georgian" # +++++++++++++++++++++ English language option +++++++++++++++++++++++ def eng(self): if self.Eng_radioButton.isChecked(): self.ApplySet.setText("Apply") self.CancelSet.setText("Cancel") self.groupBox_language.setTitle("Language") self.groupBox_window_size.setTitle("Window Size") self.setWindowTitle("Settings") self.Geo_radioButton.setText("Georgian") self.Eng_radioButton.setText("English") self.Label_length.setText("Length") self.Label_width.setText("width") self.language = "english" # +++++++++++++++++++++++++++ get Settings ++++++++++++++++++++++++++++ def getSettings(self): return self.config, self.applayState # +++++++++++++++++++++++++ Apply Settings ++++++++++++++++++++++++++++ def applySettings(self): try: self.config['length'] = int(self.Edit_length.text()) self.config['width'] = int(self.Edit_width.text()) self.config['language'] = self.language except ValueError: pass self.applayState = True self.close() # +++++++++++++++++++++++++ Cancel Settings +++++++++++++++++++++++++++ def CancelSettings(self): self.applayState = False self.close()
class VisualGroup(QGroupBoxCollapsible): """ This class is a subclass of class QGroupBox. """ def __init__(self, path_prj, name_prj, send_log, title): super().__init__() self.path_prj = path_prj self.name_prj = name_prj self.send_log = send_log self.path_last_file_loaded = self.path_prj self.process_manager = MyProcessManager("hs_plot") self.axe_mod_choosen = 1 self.setTitle(title) self.init_ui() self.process_prog_show_input = ProcessProgShow(send_log=self.send_log, run_function=self.plot_hs_class, computation_pushbutton=self.input_class_plot_button) self.process_prog_show_area = ProcessProgShow(send_log=self.send_log, run_function=self.plot_hs_area, computation_pushbutton=self.result_plot_button_area) self.process_prog_show_volume = ProcessProgShow(send_log=self.send_log, run_function=self.plot_hs_volume, computation_pushbutton=self.result_plot_button_volume) def init_ui(self): # file_selection file_selection_label = QLabel(self.tr("HS files :")) self.file_selection_listwidget = QListWidget() self.file_selection_listwidget.itemSelectionChanged.connect(self.names_hdf5_change) file_selection_layout = QVBoxLayout() file_selection_layout.addWidget(file_selection_label) file_selection_layout.addWidget(self.file_selection_listwidget) # reach reach_label = QLabel(self.tr('reach(s)')) self.reach_QListWidget = QListWidget() self.reach_QListWidget.setSelectionMode(QAbstractItemView.ExtendedSelection) self.reach_QListWidget.itemSelectionChanged.connect(self.reach_hdf5_change) reach_layout = QVBoxLayout() reach_layout.addWidget(reach_label) reach_layout.addWidget(self.reach_QListWidget) # units units_label = QLabel(self.tr('unit(s)')) self.units_QListWidget = QListWidget() self.units_QListWidget.setSelectionMode(QAbstractItemView.ExtendedSelection) self.units_QListWidget.itemSelectionChanged.connect(self.unit_hdf5_change) units_layout = QVBoxLayout() units_layout.addWidget(units_label) units_layout.addWidget(self.units_QListWidget) # axe self.axe_mod_choosen = load_specific_properties(self.path_prj, ["hs_axe_mod"])[0] axe_label = QLabel(self.tr("Axe orientation :")) self.axe_mod_1_radio = QRadioButton() if self.axe_mod_choosen == 1: self.axe_mod_1_radio.setChecked(True) self.axe_mod_1_radio.setIcon(QIcon(r"file_dep/axe_mod_1.png")) self.axe_mod_1_radio.setIconSize(QSize(75, 75)) self.axe_mod_1_radio.clicked.connect(self.change_axe_mod) self.axe_mod_2_radio = QRadioButton() if self.axe_mod_choosen == 2: self.axe_mod_2_radio.setChecked(True) self.axe_mod_2_radio.setIcon(QIcon(r"file_dep/axe_mod_2.png")) self.axe_mod_2_radio.setIconSize(QSize(75, 75)) self.axe_mod_2_radio.clicked.connect(self.change_axe_mod) self.axe_mod_3_radio = QRadioButton() if self.axe_mod_choosen == 3: self.axe_mod_3_radio.setChecked(True) self.axe_mod_3_radio.setIcon(QIcon(r"file_dep/axe_mod_3.png")) self.axe_mod_3_radio.setIconSize(QSize(75, 75)) self.axe_mod_3_radio.clicked.connect(self.change_axe_mod) axe_mod_layout = QHBoxLayout() axe_mod_layout.addWidget(self.axe_mod_1_radio) axe_mod_layout.addWidget(self.axe_mod_2_radio) axe_mod_layout.addWidget(self.axe_mod_3_radio) axe_layout = QVBoxLayout() axe_layout.addWidget(axe_label) axe_layout.addLayout(axe_mod_layout) axe_layout.addStretch() selection_layout = QHBoxLayout() selection_layout.addLayout(file_selection_layout) selection_layout.addLayout(reach_layout) selection_layout.addLayout(units_layout) selection_layout.addLayout(axe_layout) # input_class input_class_label = QLabel(self.tr("Input class :")) input_class_h_label = QLabel(self.tr("h (m)")) self.input_class_h_lineedit = QLineEdit("") input_class_v_label = QLabel(self.tr("v (m)")) self.input_class_v_lineedit = QLineEdit("") self.input_class_plot_button = QPushButton(self.tr("Show input")) self.input_class_plot_button.clicked.connect(self.plot_hs_class) change_button_color(self.input_class_plot_button, "#47B5E6") self.input_class_plot_button.setEnabled(False) input_class_layout = QGridLayout() input_class_layout.addWidget(input_class_label, 0, 0, 1, 2) input_class_layout.addWidget(input_class_h_label, 1, 0) input_class_layout.addWidget(input_class_v_label, 2, 0) input_class_layout.addWidget(self.input_class_h_lineedit, 1, 1) input_class_layout.addWidget(self.input_class_v_lineedit, 2, 1) input_class_layout.addWidget(self.input_class_plot_button, 1, 2, 2, 1) # from row, from column, nb row, nb column # result result_label = QLabel(self.tr("Result :")) self.result_tableview = QTableView() self.result_tableview.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding) self.result_tableview.verticalHeader().setVisible(False) self.result_tableview.horizontalHeader().setVisible(False) self.result_plot_button_area = QPushButton(self.tr("Show area")) self.result_plot_button_area.clicked.connect(self.plot_hs_area) self.result_plot_button_area.setEnabled(False) change_button_color(self.result_plot_button_area, "#47B5E6") self.result_plot_button_volume = QPushButton(self.tr("Show volume")) self.result_plot_button_volume.clicked.connect(self.plot_hs_volume) self.result_plot_button_volume.setEnabled(False) change_button_color(self.result_plot_button_volume, "#47B5E6") pushbutton_layout = QVBoxLayout() pushbutton_layout.addWidget(self.result_plot_button_area) pushbutton_layout.addWidget(self.result_plot_button_volume) result_layout = QGridLayout() result_layout.addWidget(result_label, 0, 0) result_layout.addWidget(self.result_tableview, 1, 0, 2, 1) result_layout.addLayout(pushbutton_layout, 1, 1) self.input_result_group = QGroupBox() input_result_layout = QVBoxLayout() input_result_layout.addLayout(input_class_layout) input_result_layout.addLayout(result_layout) self.input_result_group.setLayout(input_result_layout) self.input_result_group.hide() general_layout = QVBoxLayout() general_layout.addLayout(selection_layout) general_layout.addWidget(self.input_result_group) self.setLayout(general_layout) def update_gui(self): hs_names = get_filename_hs(os.path.join(self.path_prj, "hdf5")) self.file_selection_listwidget.blockSignals(True) self.file_selection_listwidget.clear() if hs_names: self.file_selection_listwidget.addItems(hs_names) self.file_selection_listwidget.blockSignals(False) def change_axe_mod(self): if self.axe_mod_1_radio.isChecked(): self.axe_mod_choosen = 1 elif self.axe_mod_2_radio.isChecked(): self.axe_mod_choosen = 2 elif self.axe_mod_3_radio.isChecked(): self.axe_mod_choosen = 3 change_specific_properties(self.path_prj, ["hs_axe_mod"], [self.axe_mod_choosen]) def names_hdf5_change(self): self.reach_QListWidget.clear() self.units_QListWidget.clear() selection = self.file_selection_listwidget.selectedItems() if selection: # read hdf5name = selection[0].text() hdf5 = Hdf5Management(self.path_prj, hdf5name, new=False, edit=False) hdf5.get_hdf5_attributes(close_file=True) # check reach self.reach_QListWidget.addItems(hdf5.data_2d.reach_list) self.input_class_h_lineedit.setText(", ".join(list(map(str, hdf5.hs_input_class[0])))) self.input_class_v_lineedit.setText(", ".join(list(map(str, hdf5.hs_input_class[1])))) self.input_class_plot_button.setEnabled(True) self.toggle_group(False) self.input_result_group.show() self.toggle_group(True) else: self.input_result_group.hide() def reach_hdf5_change(self): selection_file = self.file_selection_listwidget.selectedItems() selection_reach = self.reach_QListWidget.selectedItems() self.units_QListWidget.clear() # one file selected if len(selection_reach) == 1: hdf5name = selection_file[0].text() # create hdf5 class hdf5 = Hdf5Management(self.path_prj, hdf5name, new=False, edit=False) hdf5.get_hdf5_attributes(close_file=True) # add units for item_text in hdf5.data_2d.unit_list[self.reach_QListWidget.currentRow()]: item = QListWidgetItem(item_text) item.setTextAlignment(Qt.AlignRight) self.units_QListWidget.addItem(item) if len(selection_reach) > 1: # add units item = QListWidgetItem("all units") item.setTextAlignment(Qt.AlignRight) self.units_QListWidget.addItem(item) self.units_QListWidget.selectAll() def unit_hdf5_change(self): selection_unit = self.units_QListWidget.selectedItems() # one file selected if len(selection_unit) > 0: hdf5name = self.file_selection_listwidget.selectedItems()[0].text() # create hdf5 class hdf5 = Hdf5Management(self.path_prj, hdf5name, new=False, edit=False) hdf5.load_hydrosignature() hdf5.close_file() if len(selection_unit) == 1 and selection_unit[0].text() == "all units": # get hs data hdf5.data_2d.get_hs_summary_data([element.row() for element in self.reach_QListWidget.selectedIndexes()], list(range(hdf5.nb_unit))) else: # get hs data hdf5.data_2d.get_hs_summary_data([element.row() for element in self.reach_QListWidget.selectedIndexes()], [element.row() for element in self.units_QListWidget.selectedIndexes()]) # table mytablemodel = MyTableModel(hdf5.data_2d.hs_summary_data) self.result_tableview.setModel(mytablemodel) # set model self.result_plot_button_area.setEnabled(True) self.result_plot_button_volume.setEnabled(True) else: mytablemodel = MyTableModel(["", ""]) self.result_tableview.setModel(mytablemodel) # set model self.result_plot_button_area.setEnabled(False) self.result_plot_button_volume.setEnabled(False) def plot_hs_class(self): plot_attr = lambda: None plot_attr.nb_plot = 1 plot_attr.axe_mod_choosen = self.axe_mod_choosen plot_attr.hs_plot_type = "input_class" # process_manager self.process_manager.set_plot_hdf5_mode(self.path_prj, [self.file_selection_listwidget.selectedItems()[0].text()], plot_attr, load_project_properties(self.path_prj)) # process_prog_show self.process_prog_show_input.start_show_prog(self.process_manager) def plot_hs_area(self): plot_attr = lambda: None plot_attr.axe_mod_choosen = self.axe_mod_choosen plot_attr.hs_plot_type = "area" plot_attr.reach = [element.row() for element in self.reach_QListWidget.selectedIndexes()] plot_attr.units = [element.row() for element in self.units_QListWidget.selectedIndexes()] plot_attr.nb_plot = len(plot_attr.units) # process_manager self.process_manager.set_plot_hdf5_mode(self.path_prj, [self.file_selection_listwidget.selectedItems()[0].text()], plot_attr, load_project_properties(self.path_prj)) # process_prog_show self.process_prog_show_area.start_show_prog(self.process_manager) def plot_hs_volume(self): plot_attr = lambda: None plot_attr.axe_mod_choosen = self.axe_mod_choosen plot_attr.hs_plot_type = "volume" plot_attr.reach = [element.row() for element in self.reach_QListWidget.selectedIndexes()] plot_attr.units = [element.row() for element in self.units_QListWidget.selectedIndexes()] plot_attr.nb_plot = len(plot_attr.units) # process_manager self.process_manager.set_plot_hdf5_mode(self.path_prj, [self.file_selection_listwidget.selectedItems()[0].text()], plot_attr, load_project_properties(self.path_prj)) # process_prog_show self.process_prog_show_volume.start_show_prog(self.process_manager)