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 __init__(self): super().__init__() groupBox = QGroupBox( "Library to look up the Airport or Airline Code: ") groupBox.setFont(QtGui.QFont("MS Sans Serif", 10)) vbox = QVBoxLayout() #label = QLabel("Library to look up the Airport or Airline Code: ") #label.setFont(QtGui.QFont("MS Sans Serif", 10)) code = QLineEdit() #vbox.addWidget(label) vbox.addWidget(code) groupBox.setLayout(vbox) groupBox2 = QGroupBox("") vbox2 = QHBoxLayout() radiobtn1 = QRadioButton("Airport") radiobtn1.setFont(QtGui.QFont("MS Sans Serif", 10)) radiobtn1.setIcon(QtGui.QIcon("airport.png")) radiobtn1.setChecked(True) vbox2.addWidget(radiobtn1) radiobtn2 = QRadioButton("Airline") radiobtn2.setFont(QtGui.QFont("MS Sans Serif", 10)) radiobtn2.setIcon(QtGui.QIcon("airline.png")) vbox2.addWidget(radiobtn2) groupBox2.setLayout(vbox2) groupBox3 = QGroupBox("") vbox3 = QHBoxLayout() button = QPushButton("Search", self) button.setIcon(QtGui.QIcon("library.png")) button.setFont(QtGui.QFont("MS Sans Serif", 10)) button.setIconSize(QtCore.QSize(25, 25)) button.setToolTip( "<h4>Search the IATA code from the Aviation Library.<h4>") button2 = QPushButton("More", self) button2.setIcon(QtGui.QIcon("more info.png")) button2.setFont(QtGui.QFont("MS Sans Serif", 10)) button2.setIconSize(QtCore.QSize(25, 25)) button2.setToolTip( "<h4>This will obtain the more information of the airport or airline.<h4>" ) vbox3.addWidget(button) vbox3.addWidget(button2) groupBox3.setLayout(vbox3) table = QTableWidget(self) # Create a table table.setColumnCount(4) # Set three columns table.setRowCount(1) table.setHorizontalHeaderLabels(["IATA", "ICAO", "Name", "Country"]) table.resizeColumnsToContents() mainLayout = QVBoxLayout() mainLayout.addWidget(groupBox) mainLayout.addWidget(groupBox2) mainLayout.addWidget(groupBox3) mainLayout.addWidget(table) self.setLayout(mainLayout)
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 = "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())
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())
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 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(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())
def setupTab1(self, tab1): """Basic widgets for preview panel""" scrollContainer = QVBoxLayout() scrollArea = QScrollArea() scrollArea.setWidgetResizable(True) mainWidget = QWidget() layout = QVBoxLayout() mainWidget.setLayout(layout) mainWidget.setMinimumSize(QSize(420, 800)) scrollArea.setWidget(mainWidget) scrollContainer.addWidget(scrollArea) tab1.setLayout(scrollContainer) # Label TextBox group1 = QGroupBox("Text") group1.setCheckable(True) group1layout = QHBoxLayout() group1.setLayout(group1layout) layout.addWidget(group1) layoutCol1 = QFormLayout() layoutCol2 = QFormLayout() group1layout.addLayout(layoutCol1) group1layout.addLayout(layoutCol2) label1 = QLabel(self.tr("User Name(&Id):")) text1 = QLineEdit("default") label1.setBuddy(text1) label2 = QLabel(self.tr("data 1:")) text2 = QLineEdit() text2.setPlaceholderText(self.tr("input")) lebel3 = QLabel(self.tr("<b>Pasword</b>:")) text3 = QLineEdit("******") text3.setEchoMode(QLineEdit.Password) label4 = QLabel(self.tr("link label:")) label5 = QLabel( self. tr("<a href='https://github.com/hustlei/'>github.com/hustlei</a>")) label5.setOpenExternalLinks(True) label6 = QLabel(self.tr("icon label:")) label7 = QLabel("icon") label7.setPixmap(QPixmap(":appres.img/book_address.png")) layoutCol1.addRow(label1, text1) layoutCol1.addRow(label2, text2) layoutCol1.addRow(lebel3, text3) layoutCol1.addRow(label4, label5) layoutCol1.addRow(label6, label7) text4 = QLineEdit() text4.setInputMask("0000-00-00") text5 = QLineEdit() text5.setInputMask("HH:HH:HH:HH:HH:HH;_") text6 = QLineEdit() text6.setInputMask("XXXXXX") text7 = QLineEdit() validator1 = QDoubleValidator() validator1.setRange(0, 100) validator1.setDecimals(2) text7.setValidator(validator1) text8 = QLineEdit() validator2 = QRegExpValidator() reg = QRegExp("[a-zA-Z0-9]+$") validator2.setRegExp(reg) text8.setValidator(validator2) layoutCol2.addRow(self.tr("Date Mask:"), text4) layoutCol2.addRow(self.tr("Mac Mask"), text5) layoutCol2.addRow(self.tr("String Mask"), text6) layoutCol2.addRow(self.tr("Double Validate:"), text7) layoutCol2.addRow(self.tr("Regexp Validate:"), text8) text9 = QLineEdit() text9.setPlaceholderText("input email") text9.setToolTip("please input a email address.") model = QStandardItemModel(0, 1, self) completer = QCompleter(model, self) text9.setCompleter(completer) def textch(texts): if "@" in texts: return strList = [ "@163.com", "@qq.com", "@gmail.com", "@hotmail.com", "@126.com" ] model.removeRows(0, model.rowCount()) for i in strList: model.insertRow(0) model.setData(model.index(0, 0), texts + i) text9.textChanged.connect(textch) text10 = QLineEdit("ReadOnly") text10.setReadOnly(True) layoutCol1.addRow(self.tr("auto complete:"), text9) layoutCol2.addRow("Readonly:", text10) # Button group2 = QGroupBox("Button") group2.setCheckable(True) group2layout = QVBoxLayout() group2.setLayout(group2layout) layout.addWidget(group2) layoutRow1 = QHBoxLayout() layoutRow2 = QHBoxLayout() group2layout.addLayout(layoutRow1) group2layout.addLayout(layoutRow2) btn1 = QPushButton("Button") btn2 = QPushButton("IconBtn") btn2.setIcon(QIcon(":appres.img/yes.png")) btn3 = QPushButton("Disabled") btn3.setEnabled(False) btn4 = QPushButton("Default") btn4.setDefault(True) btn5 = QPushButton("Switch") btn5.setCheckable(True) btn6 = QToolButton() # btn6.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) btn6.setText("ToolButton") btn6.setPopupMode(QToolButton.MenuButtonPopup) m = QMenu() m.addAction("action1") m.addAction("action2") m.addAction("action3") btn6.setMenu(m) btn7 = QCommandLinkButton("LinkBtn") layoutRow1.addWidget(btn1) layoutRow1.addWidget(btn2) layoutRow1.addWidget(btn3) layoutRow1.addWidget(btn4) layoutRow2.addWidget(btn5) layoutRow2.addWidget(btn6) layoutRow2.addWidget(btn7) # Checkable Item group3 = QGroupBox("Checkable") group3Layout = QVBoxLayout() layoutRow1 = QHBoxLayout() layoutRow2 = QHBoxLayout() group3Layout.addLayout(layoutRow1) group3Layout.addLayout(layoutRow2) group3.setLayout(group3Layout) layout.addWidget(group3) group3.setCheckable(True) ch1 = QRadioButton("Radio") ch2 = QRadioButton("Iconradio") ch2.setIcon(QIcon(":appres.img/Flag_blueHS.png")) ch3 = QRadioButton("Iconradio") ch3.setIcon(QIcon(":appres.img/Flag_greenHS.png")) ch4 = QRadioButton("Disable") ch4.setEnabled(False) ch5 = QCheckBox("CheckBox") ch6 = QCheckBox("CheckBox") ch6.setIcon(QIcon(":appres.img/Flag_blueHS.png")) ch7 = QCheckBox("TriState") ch7.setTristate(True) ch7.setCheckState(Qt.PartiallyChecked) ch8 = QCheckBox("Disable") ch8.setEnabled(False) layoutRow1.addWidget(ch1) layoutRow1.addWidget(ch2) layoutRow1.addWidget(ch3) layoutRow1.addWidget(ch4) layoutRow2.addWidget(ch5) layoutRow2.addWidget(ch6) layoutRow2.addWidget(ch7) layoutRow2.addWidget(ch8) # Selecting Input group4 = QGroupBox("Selectable") group4.setCheckable(True) group4Layout = QVBoxLayout() layoutRow1 = QHBoxLayout() group4Layout.addLayout(layoutRow1) group4.setLayout(group4Layout) layout.addWidget(group4) s1 = QSpinBox() s1.setValue(50) s2 = QDoubleSpinBox() s2.setRange(0, 1) s2.setValue(0.5) s3 = QComboBox() s3.addItems(["aaa", "bbb", "ccc"]) s3.setEditable(True) s3.setCurrentIndex(2) s4 = QComboBox() s4.addItems(["aaa", "bbb", "ccc"]) layoutRow1.addWidget(s1) layoutRow1.addWidget(s2) layoutRow1.addWidget(s3) layoutRow1.addWidget(s4) # TextEdit group5 = QGroupBox("TextEdit") group5.setCheckable(True) group5Layout = QVBoxLayout() group5.setLayout(group5Layout) layout.addWidget(group5) group5Layout.addWidget( QTextEdit( self. tr("If you do not leave me, I will be by your side until the end." ))) layout.addStretch(1)
class wallTexture(QWidget): def __init__(self): super().__init__() # set wall texture layout self.wallG = QGroupBox(self) # set button layout self.button_layout1 = QVBoxLayout() # create buttons self.texture1 = QRadioButton("Metall wall") self.texture2 = QRadioButton("Metall Bar") self.texture3 = QRadioButton("Mosaik wall") self.texture4 = QRadioButton("Metall Fence") self.texture5 = QRadioButton("Rusty Bar") self.btn = QPushButton("Select") self.btn.setStyleSheet('background-color: white') self.currentRBtn = self.texture1 self.label = QLabel(self) # change style of lettering self.style = QFont() self.style.setBold(True) self.label.setFont(self.style) self.chk_RBtn() self.iniUt() def iniUt(self): self.wallG.setTitle("Texture Wall") # adjust icons on buttons self.texture1.setIcon(QIcon(Server.wallTextures["Metall wall"])) self.texture2.setIcon(QIcon(Server.wallTextures["Metall Bar"])) self.texture3.setIcon(QIcon(Server.wallTextures["Mosaik wall"])) self.texture4.setIcon(QIcon(Server.wallTextures["Metall Fence"])) self.texture5.setIcon(QIcon(Server.wallTextures["Rusty Bar"])) self.button_layout1.addWidget(self.texture1) self.button_layout1.addWidget(self.texture2) self.button_layout1.addWidget(self.texture3) self.button_layout1.addWidget(self.texture4) self.button_layout1.addWidget(self.texture5) self.button_layout1.addWidget(self.btn) self.button_layout1.addWidget(self.label) # add button layout in wall layout self.wallG.setLayout(self.button_layout1) # set wall texture box semi-transparent self.wallG.setStyleSheet('background-color: rgba(255, 255, 255, 0.5);') # click buttons self.texture1.clicked.connect(lambda: self.currBtn_clk(self.texture1)) self.texture2.clicked.connect(lambda: self.currBtn_clk(self.texture2)) self.texture3.clicked.connect(lambda: self.currBtn_clk(self.texture3)) self.texture4.clicked.connect(lambda: self.currBtn_clk(self.texture4)) self.texture5.clicked.connect(lambda: self.currBtn_clk(self.texture5)) self.btn.clicked.connect(lambda: self.btn_clk(self.currentRBtn)) # show new setting, after returing to options def chk_RBtn(self): global CurWall self.texture2.setChecked(False) self.texture3.setChecked(False) self.texture4.setChecked(False) self.texture5.setChecked(False) if CurWall == "Metall wall": self.texture1.setChecked(True) elif CurWall == "Metall Bar": self.texture2.setChecked(True) elif CurWall == "Mosaik wall": self.texture3.setChecked(True) elif CurWall == "Metall Fence": self.texture4.setChecked(True) elif CurWall == "Rusty Bar": self.texture5.setChecked(True) else: self.texture1.setChecked(True) self.label.setText('currently used\n' + CurWall) self.label.update() def currBtn_clk(self, button): self.currentRBtn = button def btn_clk(self, button): global CurWall if button == self.texture1: Server.wtexture = "Metall wall" CurWall = "Metall wall" elif button == self.texture2: Server.wtexture = "Metall Bar" CurWall = "Metall Bar" elif button == self.texture3: Server.wtexture = "Mosaik wall" CurWall = "Mosaik wall" elif button == self.texture4: Server.wtexture = "Metall Fence" CurWall = "Metall Fence" elif button == self.texture5: Server.wtexture = "Rusty Bar" CurWall = "Rusty Bar" else: pass self.label.setText("You selected: \n" + button.text()) QtGui.QGuiApplication.processEvents()
class floorTexture(QWidget): def __init__(self): super().__init__() # set floor texture layout self.floorG = QGroupBox(self) # set button layout self.button_layout2 = QVBoxLayout() # create floor texture buttons self.texture1 = QRadioButton("White Stone") self.texture2 = QRadioButton("Brown Stone") self.texture3 = QRadioButton("Dirt") self.texture4 = QRadioButton("Dirt (Moving)") self.texture5 = QRadioButton("Pattern (Moving)") self.texture6 = QRadioButton("Sakura (Moving)") self.texture7 = QRadioButton("Water (Moving)") # create selector self.btn = QPushButton("Select") self.btn.setStyleSheet('background-color: white') self.currentRBtn = self.texture1 # set texture choice self.label = QLabel(self) # change style of lettering self.style = QFont() self.style.setBold(True) self.label.setFont(self.style) self.chk_RBtn() self.iniUt() def iniUt(self): self.floorG.setTitle("Texture Floor") # title cant be set bold #self.setStyleSheet('QGroupBox:title {color: blue;}') # alternatives, but not really efficient #self.floorG.setStyleSheet("font-weight: bold;") #self.setStyleSheet("font-weight: bold;") # add button icons self.texture1.setIcon(QIcon(floorIcon["White Stone small"])) self.texture2.setIcon(QIcon(floorIcon["Brown Stone small"])) self.texture3.setIcon(QIcon(floorIcon["Dirt small"])) self.texture4.setIcon(QIcon(floorIcon["Background Dirt small"])) self.texture5.setIcon(QIcon(floorIcon["Background Pattern small"])) self.texture6.setIcon(QIcon(floorIcon["Background Sakura small"])) self.texture7.setIcon(QIcon(floorIcon["Background Water small"])) # clicked buttons self.texture1.clicked.connect(lambda: self.currBtn_clk(self.texture1)) self.texture2.clicked.connect(lambda: self.currBtn_clk(self.texture2)) self.texture3.clicked.connect(lambda: self.currBtn_clk(self.texture3)) self.texture4.clicked.connect(lambda: self.currBtn_clk(self.texture4)) self.texture5.clicked.connect(lambda: self.currBtn_clk(self.texture5)) self.texture6.clicked.connect(lambda: self.currBtn_clk(self.texture6)) self.texture7.clicked.connect(lambda: self.currBtn_clk(self.texture7)) self.btn.clicked.connect(lambda: self.btn_clk(self.currentRBtn)) # add buttons to layout self.button_layout2.addWidget(self.texture1) self.button_layout2.addWidget(self.texture2) self.button_layout2.addWidget(self.texture3) self.button_layout2.addWidget(self.texture4) self.button_layout2.addWidget(self.texture5) self.button_layout2.addWidget(self.texture6) self.button_layout2.addWidget(self.texture7) self.button_layout2.addWidget(self.btn) self.button_layout2.addWidget(self.label) # add button layout in floor layout self.floorG.setLayout(self.button_layout2) #set floor textures box semi-transparent self.floorG.setStyleSheet('background-color: rgba(255, 255, 255, 0.5);') # show new setting, after returing to options def chk_RBtn(self): global CurFloor self.texture1.setChecked(False) self.texture2.setChecked(False) self.texture3.setChecked(False) self.texture4.setChecked(False) self.texture5.setChecked(False) self.texture6.setChecked(False) if CurFloor == "White Stone": self.texture1.setChecked(True) elif CurFloor == "Brown Stone": self.texture2.setChecked(True) elif CurFloor == "Dirt": self.texture3.setChecked(True) elif CurFloor == "Background Dirt": self.texture4.setChecked(True) elif CurFloor == "Background Pattern": self.texture5.setChecked(True) elif CurFloor == "Background Sakura": self.texture6.setChecked(True) elif CurFloor == "Background Water": self.texture7.setChecked(True) else: self.texture1.setChecked(True) self.label.setText('currently used\n' + CurFloor) def currBtn_clk(self, button): self.currentRBtn = button def btn_clk(self, button): global CurFloor if button == self.texture1: Server.ftexture = "White Stone" CurFloor = "White Stone" elif button == self.texture2: Server.ftexture = "Brown Stone" CurFloor = "Brown Stone" elif button == self.texture3: Server.ftexture = "Dirt" CurFloor = "Dirt" if button == self.texture4: Server.ftexture = "Background Dirt" CurFloor = "Background Dirt" elif button == self.texture5: Server.ftexture = "Background Pattern" CurFloor = "Background Pattern" elif button == self.texture6: Server.ftexture = "Background Sakura" CurFloor = "Background Sakura" elif button == self.texture7: Server.ftexture = "Background Water" CurFloor = "Background Water" else: pass self.label.setText("You selected: \n" + button.text())
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 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 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(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 Ui_Dialog(object): def __init__(self, Dialog): super(Ui_Dialog, self).__init__() # ----- App Design ----- # # To make this to work in Fullscreen; set 'self.window_width' and 'self.window_height' to 'size.width()' and 'size.height()' # To make this to work in Fullscreen-Windowed; set 'self.window_width' and 'self.window_height' to 'rect.width()' and 'rect.height()' self.window_width = 500 self.window_height = 800 # self.window_width = size.width() # Fullscreen # self.window_height = size.height() # Fullscreen self.drop_down_width = self.window_width // 2 + 50 self.notation_width = self.drop_down_width // 2 self.widget_height = self.window_height // 20 self.label_width = self.window_width // 4 self.label_padding_left = self.window_width // 20 self.content_padding_left = self.label_padding_left + self.label_width self.padding_top = self.window_height // 10 self.v_space_between_widgets = self.window_height // 5 self.app_font = QFont() self.output_text_font = QFont() self.app_font.setPointSize( (self.window_width + self.window_height) // 100) self.output_text_font.setPointSize( (self.window_width + self.window_height) // 120) self.label_style = 'color: rgb(176, 85, 87);' self.option_menu_style = 'color: rgb(158, 212, 124);' self.input_menu_style = 'color: rgb(15, 99, 189);' self.output_text_style = 'color: rgba(255, 255, 255, 150);' self.reset_button_style = '\ background-color: red;\ border-radius: 15px;\ color: rgb(0, 0, 0);' # ----- App Window Settings ----- # Dialog.setObjectName("Dialog") self.set_window_resizable(window_obj=Dialog, width=self.window_width, height=self.window_height, flag=False) # ----- Widgets ----- # self.notation_label = QLabel(Dialog) self.notation_S = QRadioButton(Dialog) self.notation_b = QRadioButton(Dialog) self.option_label = QLabel(Dialog) self.option_menu = QComboBox(Dialog) self.input_label = QLabel(Dialog) self.input_menu = QComboBox(Dialog) self.output_label = QLabel(Dialog) self.output_text = QLineEdit(Dialog) self.reset_button = QPushButton(Dialog) self.va_button = QPushButton(Dialog) # ----- Music Logic ----- # music = Music() self.notesS = music.notesS self.notesb = music.notesb self.notes = self.notesS self.options_menu_vals = tuple() with open(features, 'r') as f: self.options_menu_vals = tuple([x.strip() for x in f.readlines()]) self.input_menu_vals = tuple() self.rel_maj_min_options = ('Relative Major', 'Relative Minor') self.major_minor_options = ('Major', 'Minor') self.guitar_frets_options = tuple([str(i) for i in range(1, 23) ]) # For Capo position entry self.sub_menu_selected = dict() # To Keep track of options selected self.select_data = '--Select--' self.option_change_detect = '' self.input_change_detect = '' # ----- Voice Assistant ----- # self.va = Voice_Assistant() def setupUi(self, Dialog): # Notations self.notation_label.setFont(self.app_font) self.notation_label.setGeometry( QtCore.QRect(self.label_padding_left, self.padding_top, self.label_width, self.widget_height)) self.notation_label.setObjectName("notation_label") self.notation_label.setStyleSheet(self.label_style) self.notation_S.setFont(self.app_font) self.notation_S.setGeometry( QtCore.QRect(self.content_padding_left, self.padding_top, self.notation_width, self.widget_height)) self.notation_S.setObjectName("notation_S") self.notation_S.setChecked(True) self.notation_b.setFont(self.app_font) self.notation_b.setGeometry( QtCore.QRect(self.content_padding_left + self.notation_width, self.padding_top, self.notation_width, self.widget_height)) self.notation_b.setObjectName("notation_b") self.padding_top += self.v_space_between_widgets # Option Menu self.option_label.setFont(self.app_font) self.option_label.setGeometry( QtCore.QRect(self.label_padding_left, self.padding_top, self.label_width, self.widget_height)) self.option_label.setObjectName("options_label") self.option_label.setStyleSheet(self.label_style) self.option_menu.setFont(self.app_font) self.option_menu.setGeometry( QtCore.QRect(self.content_padding_left, self.padding_top - 2, self.drop_down_width, self.widget_height)) self.option_menu.setObjectName("option_menu") self.option_menu.addItem(self.select_data) self.option_menu.addItems(self.options_menu_vals) self.option_menu.currentIndexChanged.connect( self.option_selection_change) # self.option_menu.lineEdit().setAlignment(QtCore.Qt.AlignCenter) self.option_menu.setStyleSheet(self.option_menu_style) self.padding_top += self.v_space_between_widgets # Input Menu self.input_label.setFont(self.app_font) self.input_label.setGeometry( QtCore.QRect(self.label_padding_left, self.padding_top, self.label_width, self.widget_height)) self.input_label.setObjectName("input_label") self.input_label.setStyleSheet(self.label_style) self.input_menu.setFont(self.app_font) self.input_menu.setGeometry( QtCore.QRect(self.content_padding_left, self.padding_top - 2, self.drop_down_width, self.widget_height)) self.input_menu.setObjectName("input_menu") self.input_menu.setDisabled(True) self.input_menu.setStyleSheet(self.input_menu_style) self.padding_top += self.v_space_between_widgets # Output self.output_label.setFont(self.app_font) self.output_label.setGeometry( QtCore.QRect(self.label_padding_left, self.padding_top, self.label_width, self.widget_height)) self.output_label.setObjectName("output_label") self.output_label.setStyleSheet(self.label_style) self.output_text.setFont(self.output_text_font) self.output_text.setGeometry( QtCore.QRect(self.content_padding_left, self.padding_top - 2, self.drop_down_width, self.widget_height)) self.output_text.setObjectName("output_text") self.output_text.setDisabled(True) self.output_text.setStyleSheet(self.output_text_style) self.padding_top += self.v_space_between_widgets // 2 # App RESET self.reset_button.setFont(self.app_font) self.reset_button.setGeometry( QtCore.QRect(self.label_padding_left, self.padding_top, self.label_width + self.drop_down_width, self.widget_height)) self.reset_button.setObjectName("reset_button") self.reset_button.clicked.connect(self.reset) self.reset_button.setIcon(QtGui.QIcon(reset_icon)) self.reset_button.setIconSize( QtCore.QSize(self.widget_height, self.widget_height)) self.reset_button.setStyleSheet(self.reset_button_style) self.padding_top += self.v_space_between_widgets // 2 # Voice Assitant self.va_button.setFont(self.app_font) self.va_button.setGeometry( QtCore.QRect(self.label_padding_left, self.padding_top, self.label_width + self.drop_down_width, self.widget_height)) self.va_button.setObjectName("va_button") self.va_button.clicked.connect(self.Voice_Assistant_Call) self.va_button.setIcon(QtGui.QIcon(app_logo)) self.va_button.setIconSize( QtCore.QSize(self.widget_height, self.widget_height)) self.va_button.setStyleSheet(self.reset_button_style) self.retranslateUi(Dialog) QtCore.QMetaObject.connectSlotsByName(Dialog) def option_selection_change(self): selected_text = self.option_menu.currentText() # ----- Detect change in menu selection ----- # if self.option_change_detect != selected_text: print(self.sub_menu_selected) print('Option Menu Change Detected') # self.input_menu.clear() self.output_text.clear( ) # This is working; "input_menu.clear()" getting hanged self.input_menu.addItem(self.select_data) print('Input Menu cleared') self.option_change_detect = selected_text print('New opt change detect set') # ----- Change Input Menu Values ----- # if selected_text != self.select_data: print('Option Item Selected:', selected_text) self.input_menu.setDisabled(False) if selected_text == self.options_menu_vals[0]: # Major Scale print('maj scale') if self.notation_S.isChecked(): self.notes = self.notesS elif self.notation_b.isChecked(): self.notes = self.notesb self.input_menu_vals = self.notes elif selected_text == self.options_menu_vals[1]: # Major Chord print('maj chord') if self.notation_S.isChecked(): self.notes = self.notesS elif self.notation_b.isChecked(): self.notes = self.notesb self.input_menu_vals = self.notes elif selected_text == self.options_menu_vals[ 2]: # Chords in Major Scale print('chords in maj scale') if self.notation_S.isChecked(): self.notes = self.notesS elif self.notation_b.isChecked(): self.notes = self.notesb self.input_menu_vals = self.notes print('rcvd inp menu vals') self.input_menu.addItems(self.input_menu_vals) self.input_menu.currentIndexChanged.connect( self.input_selection_change) print('set inp menu vals') else: self.input_menu.clear() self.input_menu.setDisabled(True) # ----- To Keep track of Selections ----- # if self.option_menu.currentText( ) not in self.sub_menu_selected and self.option_menu.currentText( ) != self.select_data: self.sub_menu_selected[self.option_menu.currentText()] = [] def input_selection_change(self): selected_text = self.input_menu.currentText() # ----- Detect change in menu selection ----- # if self.input_change_detect != selected_text: self.input_change_detect = selected_text # ----- Action performed on Input Menu Values ----- # if selected_text != self.select_data: option_menu_selected_text = self.option_menu.currentText() if option_menu_selected_text == self.options_menu_vals[ 0]: # Major Scale note = selected_text music = Music(note) result = music.major_scale() self.output_text.setText(' '.join(result)) elif option_menu_selected_text == self.options_menu_vals[ 1]: # Major Chord note = selected_text music = Music(note) result = music.major_chord() self.output_text.setText(' '.join(result)) elif option_menu_selected_text == self.options_menu_vals[ 2]: # Chords in Major Scale note = selected_text music = Music(note) result = music.chords_in_major_scale() self.output_text.setText(' '.join(result)) # ----- To Keep track of Selections ----- # if self.option_menu.currentText() != self.select_data: if self.option_menu.currentText() in self.sub_menu_selected: self.sub_menu_selected[self.option_menu.currentText()].append( selected_text) self.sub_menu_selected[self.option_menu.currentText()] = list( set(self.sub_menu_selected[ self.option_menu.currentText()])) else: self.sub_menu_selected[self.option_menu.currentText()] = list( set([selected_text])) def retranslateUi(self, Dialog): _translate = QtCore.QCoreApplication.translate Dialog.setWindowTitle(_translate("Dialog", "Music Theory Guide")) self.notation_label.setText(_translate("Dialog", "Notation")) self.notation_S.setIcon(QtGui.QIcon(sharp_icon)) self.notation_b.setIcon(QtGui.QIcon(flat_icon)) self.option_label.setText(_translate("Dialog", "Options")) self.input_label.setText(_translate("Dialog", "Input")) self.output_label.setText(_translate("Dialog", "Output")) self.output_text.setText(_translate("Dialog", "")) self.reset_button.setText(_translate("Dialog", "Reset Application")) self.va_button.setText(_translate("Dialog", "Voice Assistant")) def set_window_resizable(self, window_obj, width, height, flag=False): if not flag: window_obj.setGeometry(rect.width() // 2 - width // 2, rect.height() // 2 - height // 2, width, height) window_obj.setMaximumHeight(height) window_obj.setMinimumHeight(height) window_obj.setMaximumWidth(width) window_obj.setMinimumWidth(width) else: window_obj.resize(width, height) def reset(self): self.notation_S.setChecked(True) self.option_menu.setCurrentIndex(0) self.input_menu.clear() self.output_text.setText('') def Voice_Assistant_Call(self): self.va.start_AI_engine()
def __init__(self): super().__init__() groupBox = QGroupBox("") vbox = QVBoxLayout() label = QLabel("Airport: ") label.setFont(QtGui.QFont("MS Sans Serif", 10)) code = QLineEdit() vbox.addWidget(label) vbox.addWidget(code) label2 = QLabel("Airline: ") label2.setFont(QtGui.QFont("MS Sans Serif", 10)) airline = QLineEdit() vbox.addWidget(label2) vbox.addWidget(airline) label3 = QLabel("Origin/Arrival: ") label3.setFont(QtGui.QFont("MS Sans Serif", 10)) dest = QLineEdit() vbox.addWidget(label3) vbox.addWidget(dest) label4 = QLabel("Flight #: ") label4.setFont(QtGui.QFont("MS Sans Serif", 10)) flightnum = QLineEdit() vbox.addWidget(label4) vbox.addWidget(flightnum) groupBox.setLayout(vbox) groupBox2 = QGroupBox("") vbox2 = QHBoxLayout() radiobtn1 = QRadioButton("Departure") radiobtn1.setFont(QtGui.QFont("MS Sans Serif", 10)) radiobtn1.setIcon(QtGui.QIcon("dep.png")) radiobtn1.setChecked(True) vbox2.addWidget(radiobtn1) radiobtn2 = QRadioButton("Arrival") radiobtn2.setFont(QtGui.QFont("MS Sans Serif", 10)) radiobtn2.setIcon(QtGui.QIcon("arr.png")) vbox2.addWidget(radiobtn2) groupBox2.setLayout(vbox2) groupBox3 = QGroupBox("") vbox3 = QHBoxLayout() check1 = QCheckBox("No CodeShare") check1.setFont(QtGui.QFont("MS Sans Serif", 10)) vbox3.addWidget(check1) check2 = QCheckBox("No Cargo") check2.setFont(QtGui.QFont("MS Sans Serif", 10)) vbox3.addWidget(check2) groupBox3.setLayout(vbox3) groupBox4 = QGroupBox("") vbox4 = QVBoxLayout() lst = [ '12 AM - 3 AM', '3 AM - 6 AM', '6 AM - 9 AM', '9 AM - 12 PM', '12 PM - 3 PM', '3 PM - 6 PM', '6 PM - 9 PM', '9 PM - 12 AM', "All Day" ] combo = QComboBox() combo.addItems(lst) combo.setFont(QtGui.QFont("MS Sans Serif", 10)) vbox4.addWidget(combo) button = QPushButton("Search", self) button.setIcon(QtGui.QIcon("search.png")) button.setFont(QtGui.QFont("MS Sans Serif", 10)) button.setIconSize(QtCore.QSize(25, 25)) button.setToolTip("<h4>Search for today's flight<h4>") button.clicked.connect(self.on_click) vbox4.addWidget(button) groupBox4.setLayout(vbox4) mainLayout = QVBoxLayout() mainLayout.addWidget(groupBox) mainLayout.addWidget(groupBox2) mainLayout.addWidget(groupBox3) mainLayout.addWidget(groupBox4) self.setLayout(mainLayout)
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 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(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_()
class MainWindow(QMainWindow): """ Represents main window that extends QMainWindow and that is used for interaction with user. """ def __init__(self, faces_number, draw_rectangles, parent=None): """Initializes main window. :param self: self :param faces_number: number of expected faces in frame :param draw_rectangles: indicator whether rectangles that bound detected faces should be drawn :param parent: parent of window """ super(MainWindow, self).__init__(parent) self.setWindowTitle("FaceSnap") self.setWindowIcon(QIcon("stickers/icon.png")) self.faces_number = faces_number self.draw_rectangles = draw_rectangles self.file_name = "" self.chosen_filter = "" self.processing = False self.layout = QVBoxLayout() # layout for the central widget widget = QWidget(self) # central widget widget.setLayout(self.layout) self.setGeometry(0, 0, 650, 550) self.center_on_screen() self.existing_video_layout = QHBoxLayout() # layout for existing video self.existing_video_widget = QWidget() self.existing_video_widget.setLayout(self.existing_video_layout) self.cam_video_layout = QHBoxLayout() # layout for recorder video self.cam_video_widget = QWidget() self.cam_video_widget.setLayout(self.cam_video_layout) self.choice_group = QButtonGroup( widget) # radio button group for input file choice self.filter_group = QButtonGroup( widget) # radio button group for filter choice self.existing_video_radio = QRadioButton("Choose existing video") self.existing_video_button = QPushButton("Choose video file") self.cam_video_radio = QRadioButton("Capture video with camera") self.cam_video_button = QPushButton("Record video") self.mask_button = QRadioButton() self.cat_button = QRadioButton() self.ears_button = QRadioButton() self.flowers_button = QRadioButton() self.mustache_button = QRadioButton() self.glasses_button = QRadioButton() self.mouse_button = QRadioButton() self.pirate_button = QRadioButton() self.rainbow_button = QRadioButton() self.init_video_choice() self.init_filter_choice() self.process_button = QPushButton("Process video") self.process_button.clicked.connect(self.process_chosen_video) self.layout.addWidget(QWidget()) self.layout.addWidget(QWidget()) self.layout.addWidget(QWidget()) self.layout.addWidget(self.process_button) self.layout.addWidget(QWidget()) self.status = QStatusBar() self.layout.addWidget(self.status) self.setCentralWidget(widget) def center_on_screen(self): """Centers window on screen. :param self: self """ resolution = QDesktopWidget().screenGeometry() self.move( (resolution.width() / 2) - (self.frameSize().width() / 2), (resolution.height() / 4 + 20) - (self.frameSize().height() / 2)) def init_video_choice(self): """Initializes radio button group for video choice. :param self: self """ self.cam_video_radio.clicked.connect(self.cam_video_chosen) self.choice_group.addButton(self.cam_video_radio) self.existing_video_radio.clicked.connect(self.existing_video_chosen) self.choice_group.addButton(self.existing_video_radio) self.existing_video_button.clicked.connect(self.open_file) self.existing_video_layout.addWidget(self.existing_video_radio) self.existing_video_layout.addWidget(self.existing_video_button) self.cam_video_button.clicked.connect(self.record_video) self.cam_video_layout.addWidget(self.cam_video_radio) self.cam_video_layout.addWidget(self.cam_video_button) self.layout.addWidget(self.existing_video_widget) self.layout.addWidget(self.cam_video_widget) self.existing_video_radio.click() def init_filter_choice(self): """Initializes radio button group for filter choice. :param self: self """ self.layout.addWidget(QWidget()) self.layout.addWidget(QWidget()) sticker_rows = QVBoxLayout() first_row_layout = QHBoxLayout() first_row_widget = QWidget() first_row_widget.setLayout(first_row_layout) second_row_layout = QHBoxLayout() second_row_widget = QWidget() second_row_widget.setLayout(second_row_layout) third_row_layout = QHBoxLayout() third_row_widget = QWidget() third_row_widget.setLayout(third_row_layout) sticker_rows.addWidget(first_row_widget) sticker_rows.addWidget(second_row_widget) sticker_rows.addWidget(third_row_widget) filter_widget = QWidget() filter_widget.setLayout(sticker_rows) self.init_first_row_filters(first_row_layout) self.init_second_row_filters(second_row_layout) self.init_third_row_filters(third_row_layout) self.layout.addWidget(filter_widget) def init_first_row_filters(self, first_row_layout): """Initializes first row of radio button group for filter choice. :param self: self :param first_row_layout: layout for first row of filters """ self.mask_button.clicked.connect(self.filter_chosen) self.filter_group.addButton(self.mask_button) self.mask_button.setIcon(QIcon(stickers.mask_sticker())) first_row_layout.addWidget(self.mask_button) # add mask to widget first_row_layout.addWidget(QWidget()) # add empty space self.cat_button.clicked.connect(self.filter_chosen) self.filter_group.addButton(self.cat_button) self.cat_button.setIcon(QIcon(stickers.cat_sticker())) first_row_layout.addWidget(self.cat_button) # add cat to widget first_row_layout.addWidget(QWidget()) # add empty space self.ears_button.clicked.connect(self.filter_chosen) self.filter_group.addButton(self.ears_button) self.ears_button.setIcon(QIcon(stickers.ears_sticker())) first_row_layout.addWidget(self.ears_button) # add ears to widget def init_second_row_filters(self, second_row_layout): """Initializes second row of radio button group for filter choice. :param self: self :param second_row_layout: layout for second row of filters """ self.flowers_button.clicked.connect(self.filter_chosen) self.filter_group.addButton(self.flowers_button) self.flowers_button.setIcon(QIcon(stickers.flowers_sticker())) second_row_layout.addWidget( self.flowers_button) # add flowers to widget second_row_layout.addWidget(QWidget()) # add empty space self.mustache_button.clicked.connect(self.filter_chosen) self.filter_group.addButton(self.mustache_button) self.mustache_button.setIcon(QIcon(stickers.mustache_sticker())) second_row_layout.addWidget( self.mustache_button) # add mustache to widget second_row_layout.addWidget(QWidget()) # add empty space self.glasses_button.clicked.connect(self.filter_chosen) self.filter_group.addButton(self.glasses_button) self.glasses_button.setIcon(QIcon(stickers.glasses_sticker())) second_row_layout.addWidget( self.glasses_button) # add glasses to widget def init_third_row_filters(self, third_row_layout): """Initializes third row of radio button group for filter choice. :param self: self :param third_row_layout: layout for third row of filters """ self.mouse_button.clicked.connect(self.filter_chosen) self.filter_group.addButton(self.mouse_button) self.mouse_button.setIcon(QIcon(stickers.mouse_sticker())) third_row_layout.addWidget(self.mouse_button) # add mouse to wiget third_row_layout.addWidget(QWidget()) # add empty space self.pirate_button.clicked.connect(self.filter_chosen) self.filter_group.addButton(self.pirate_button) self.pirate_button.setIcon(QIcon(stickers.pirate_sticker())) third_row_layout.addWidget(self.pirate_button) # add pirate to widget third_row_layout.addWidget(QWidget()) # add empty space self.rainbow_button.clicked.connect(self.filter_chosen) self.filter_group.addButton(self.rainbow_button) self.rainbow_button.setIcon(QIcon(stickers.rainbow_sticker())) third_row_layout.addWidget( self.rainbow_button) # add rainbow to widget def filter_chosen(self): """Detects which filter is chosen. :param self: self """ if self.mask_button.isChecked(): self.chosen_filter = "mask" elif self.cat_button.isChecked(): self.chosen_filter = "cat" elif self.ears_button.isChecked(): self.chosen_filter = "ears" elif self.flowers_button.isChecked(): self.chosen_filter = "flowers" elif self.mustache_button.isChecked(): self.chosen_filter = "mustache" elif self.glasses_button.isChecked(): self.chosen_filter = "glasses" elif self.mouse_button.isChecked(): self.chosen_filter = "mouse" elif self.pirate_button.isChecked(): self.chosen_filter = "pirate" elif self.rainbow_button.isChecked(): self.chosen_filter = "rainbow" else: self.chosen_filter = "" def process_chosen_video(self): """Starts processing chosen video and informs user about process success. :param self: self """ if self.file_name == "": print("Video for processing is not chosen!") self.status.showMessage("Video for processing is not chosen!") else: if self.processing: self.status.showMessage("Processing video in progress!") else: self.processing = True self.status.showMessage("Processing video in progress!") if process_video(self.file_name, self.faces_number, self.draw_rectangles, self.chosen_filter, self): self.status.showMessage("Processing video is successful!") self.processing = False else: self.status.showMessage("Error opening video!") self.processing = False def existing_video_chosen(self): """Disables cam video button and enables existing video button. :param self: self """ self.cam_video_button.setEnabled(False) self.existing_video_button.setEnabled(True) def cam_video_chosen(self): """Enables cam video button and disables existing video button. :param self: self """ self.cam_video_button.setEnabled(True) self.existing_video_button.setEnabled(False) def open_file(self): """Opens dialog for file choice. :param self: self """ self.file_name, _ = QFileDialog.getOpenFileName( self, "Open Video", QDir.homePath()) if self.file_name != "": print(self.file_name) self.status.showMessage("Video successfully chosen!") def record_video(self): """Opens dialog for directory choice where file is saved. :param self: self """ self.file_name = str( QFileDialog.getExistingDirectory( self, "Select Directory Where Video Will Be Saved", QDir.homePath())) if self.file_name != '': self.file_name += "/output_video.avi" print(self.file_name) self.file_name = record_from_camera(self.file_name, self) self.status.showMessage("Video successfully recorded!")
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 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)