class BaseUI(QWidget): def __init__(self, parent=None): super(BaseUI, self).__init__(parent) self.main_layout = None self.setup_ui() def init_layout(self): self.main_layout = QGridLayout() self.main_layout.setHorizontalSpacing(4) self.main_layout.setVerticalSpacing(4) self.main_layout.setContentsMargins(10, 10, 10, 10) self.main_layout.setAlignment(QtCore.Qt.AlignTop | QtCore.Qt.AlignLeft) self.setLayout(self.main_layout) def setup_ui(self): self.init_layout() def check_is_ready(self): if not self.isEnabled() or not self.isVisible(): return False output_dir = Globals.config.get(Globals.UserData.output_dir) if not (os.path.exists(output_dir) and os.path.isdir(output_dir)): Message.show_error("无效的输出目录!", self) return False # save_as_path = os.path.join(output_dir, Globals.config.get(Globals.UserData.font_save_name) + ".png") # if os.path.exists(save_as_path): # Message.show_error("已存在同名文件!", self) # return False return True
def makeUI(self): self.setWindowTitle(self.title) self.setGeometry(self.left, self.top, self.width, self.height) self.createLayout() windowLayout = QGridLayout() windowLayout.addWidget(self.box0, 1, 1, 1, 1) windowLayout.addWidget(self.box4, 0, 0, 1, 1) windowLayout.addWidget(self.box6, 1, 0, 1, 1) windowLayout.addWidget(self.box7, 0, 1, 1, 1) windowLayout.addWidget(self.box5, 3, 0, 1, 2) windowLayout.addWidget(self.box8, 2, 0, 1, 2) windowLayout.setAlignment(QtCore.Qt.AlignTop) self.setLayout(windowLayout) self.show()
def MainUI(self): # Obtain the configs fp_config = open(THISDIR + "\\config\\config.json", "r", encoding="utf-8") self.config = json.loads(fp_config.read()) fp_config.close() # Obtain and List the teams fp_teams = open(THISDIR + "\\config\\teams.json", "r", encoding="utf-8") conf_teams = json.loads(fp_teams.read()) fp_teams.close() self.teams = conf_teams["teams"] self.players = conf_teams["players"] # Obtain all images needed to create the tablecloth self.background = Image.open(THISDIR + "\\images\\mat.png") self.table_border = Image.open(THISDIR + "\\images\\table_border.png") self.tech_lines = Image.open(THISDIR + "\\images\\technical_lines.png") # Check if there's no configuration set up # and prompt to create/import one if self.config["total_teams"] == 0: self.no_config = QMessageBox.question(self, "No configuration", "No configuration has been found. Do you wish to set up a new one?", QMessageBox.Yes | QMessageBox.No) if self.no_config == QMessageBox.Yes: self.CreateTeamsWindow() self.bg_image = self.config["image_route"] self.players_combobox = QComboBox() self.UpdatePlayersList() self.players_combobox.setEditable(True) self.players_combobox.completer()\ .setCompletionMode(QCompleter.PopupCompletion) self.players_combobox.setInsertPolicy(QComboBox.NoInsert) # Set up the GUI self.statusBar().showMessage("Remember: Rig responsibly.") # Bottom (EAST) self.label_east = QLabel(self) self.label_east.setText("<h1>East Seat</h1>") self.label_east.setAlignment(QtCore.Qt.AlignCenter) self.image_east = QLabel(self) self.image_east.setPixmap(QPixmap("images/logos/team1.png")\ .scaled(100,100)) self.image_east.setAlignment(QtCore.Qt.AlignCenter) self.search_east = QLineEdit() self.search_east.setAlignment(QtCore.Qt.AlignCenter) self.search_east.editingFinished.connect( lambda: self.searchPlayer(self.search_east.text(), self.cloth_east)) self.cloth_east = QComboBox() self.cloth_east.setModel(self.players_combobox.model()) self.cloth_east.currentIndexChanged.connect( lambda: self.SwitchImage(self.cloth_east, self.image_east)) # Right (SOUTH) self.label_south = QLabel(self) self.label_south.setText("<h1>South Seat</h1>") self.label_south.setAlignment(QtCore.Qt.AlignCenter) self.image_south = QLabel(self) self.image_south.setPixmap(QPixmap("images/logos/team1.png")\ .scaled(100,100)) self.image_south.setAlignment(QtCore.Qt.AlignCenter) self.image_south.show() self.search_south = QLineEdit() self.search_south.setAlignment(QtCore.Qt.AlignCenter) self.search_south.editingFinished.connect( lambda: self.searchPlayer(self.search_south.text(), self.cloth_south)) self.cloth_south = QComboBox() self.cloth_south.setModel(self.players_combobox.model()) self.cloth_south.currentIndexChanged.connect( lambda: self.SwitchImage(self.cloth_south, self.image_south)) # Top (WEST) self.label_west = QLabel(self) self.label_west.setText("<h1>West Seat</h1>") self.label_west.setAlignment(QtCore.Qt.AlignCenter) self.image_west = QLabel(self) self.image_west.setPixmap(QPixmap("images/logos/team1.png")\ .scaled(100,100)) self.image_west.setAlignment(QtCore.Qt.AlignCenter) self.image_west.show() self.cloth_west = QComboBox() self.search_west = QLineEdit() self.search_west.setAlignment(QtCore.Qt.AlignCenter) self.search_west.editingFinished.connect( lambda: self.searchPlayer(self.search_west.text(), self.cloth_west)) self.cloth_west.setModel(self.players_combobox.model()) self.cloth_west.currentIndexChanged.connect( lambda: self.SwitchImage(self.cloth_west, self.image_west)) # Left (NORTH) self.label_north = QLabel(self) self.label_north.setText("<h1>North Seat</h1>") self.label_north.setAlignment(QtCore.Qt.AlignCenter) self.image_north = QLabel(self) self.image_north.setPixmap(QPixmap("images/logos/team1.png")\ .scaled(100,100)) self.image_north.setAlignment(QtCore.Qt.AlignCenter) self.image_north.show() self.cloth_north = QComboBox() self.search_north = QLineEdit() self.search_north.setAlignment(QtCore.Qt.AlignCenter) self.search_north.editingFinished.connect( lambda: self.searchPlayer(self.search_north.text(), self.cloth_north)) self.cloth_north.setModel(self.players_combobox.model()) self.cloth_north.currentIndexChanged.connect( lambda: self.SwitchImage(self.cloth_north, self.image_north)) # Technical lines self.technical_lines = QCheckBox("Show Technical lines", self) # Generate button self.generate = QPushButton(self) self.generate.setText("Generate Tablecloth") self.generate.clicked.connect(self.GeneratePreview) # Add custom mat self.custom_mat = QPushButton(self) self.custom_mat.setText("Add Mat") self.custom_mat.clicked.connect(self.MatDialog) # Create the layout grid_layout = QGridLayout() grid_layout.setAlignment(QtCore.Qt.AlignCenter) grid_layout.setAlignment(QtCore.Qt.AlignTop) # Labels East, West grid_layout.addWidget(self.label_east, 1, 1) grid_layout.addWidget(self.label_west, 1, 2) # Image preview East, West grid_layout.addWidget(self.image_east, 2, 1) grid_layout.addWidget(self.image_west, 2, 2) # Search player East, West grid_layout.addWidget(self.search_east, 3, 1) grid_layout.addWidget(self.search_west, 3, 2) # Player combobox East, West grid_layout.addWidget(self.cloth_east, 4, 1) grid_layout.addWidget(self.cloth_west, 4, 2) # Labes South, North grid_layout.addWidget(self.label_south, 5, 1) grid_layout.addWidget(self.label_north, 5, 2) # Image preview South, North grid_layout.addWidget(self.image_south, 6, 1) grid_layout.addWidget(self.image_north, 6, 2) # Search player South, North grid_layout.addWidget(self.search_south, 7, 1) grid_layout.addWidget(self.search_north, 7, 2) # Player combobox South, North grid_layout.addWidget(self.cloth_south, 8, 1) grid_layout.addWidget(self.cloth_north, 8, 2) # Technical lines grid_layout.addWidget(self.technical_lines, 9, 1) # Custom mat/bg grid_layout.addWidget(self.custom_mat, 10, 1) # Generate grid_layout.addWidget(self.generate, 10, 2) self.centralWidget.setLayout(grid_layout) # Create the window self.show()
def __init__(self, heading, parent=None, counter=0, pastResults={}, grid=False): QWidget.__init__(self) self.setParent(parent) self.heading = heading self.counter = counter self.pastResults = pastResults # Set layout and spacings layout = QGridLayout() # The heading of the widget label = QLabel(heading) label.setAlignment(Qt.AlignCenter) label.setFixedHeight(40) # TODO: Change with global themes label.setStyleSheet("color: white;") # Font for the label font = QFont() font.setPixelSize(25) font.setBold(True) label.setFont(font) layout.addWidget(label, 0, 0) # Add back button if self.counter: backButton = QToolButton() backButton.setText("🡸") font = QFont() font.setPointSize(30) backButton.setFont(font) backButton.setFixedSize(QSize(40, 40)) backButton.setAutoRaise(True) backButton.setStyleSheet( "QToolButton { color: white; background-color: transparent;} QToolButton:pressed {background-color: rgba(255, 255, 255, 0.1);}" ) layout.addWidget(backButton, 0, 0) backButton.clicked.connect(self.goBack) # Sub heading if this is an indepth search sublabel = QLabel() sublabel.setFixedHeight(20) if self.pastResults: sublabel.setAlignment(Qt.AlignCenter) # TODO: Change with global themes sublabel.setStyleSheet("color: white;") if "artist_id" in self.pastResults: sublabel.setText("Artist: " + self.pastResults["artist_name"]) elif "language_id" in self.pastResults: sublabel.setText("Language: " + self.pastResults["language_name"]) elif "playlist_id" in self.pastResults: sublabel.setText("Playlist: " + self.pastResults["playlist_name"]) font = QFont() font.setPixelSize(15) font.setItalic(True) sublabel.setFont(font) layout.addWidget(sublabel, 1, 0) # Set searchbar self.searchBar = QLineEdit(self) # TODO: change with resizeEvent self.searchBar.setMinimumWidth(800) font = QFont() font.setPointSize(20) self.searchBar.setFont(font) layout.addWidget(self.searchBar, 2, 0) layout.setAlignment(self.searchBar, Qt.AlignCenter) # Set results page if (grid): self.results = self.ResultsGrid(self) layout.addWidget(self.results, 3, 0) else: self.results = self.ResultsList(self) layout.addWidget(self.results, 3, 0) self.searchBar.textEdited.connect(self.updateResults) self.updateResults() self.setLayout(layout)
def __init__(self, parameter: Parameter): super().__init__() self.parameter = parameter deleteButton = QToolButton() deleteButton.setText("X") deleteButton.clicked.connect( lambda: self.onRemoveParameter.emit(self.parameter)) upButton = QToolButton() upButton.setText("\u2191") upButton.clicked.connect( lambda: self.onMoveParameterUp.emit(self.parameter)) downButton = QToolButton() downButton.setText("\u2193") downButton.clicked.connect( lambda: self.onMoveParameterDown.emit(self.parameter)) buttonsLayout = QVBoxLayout() buttonsLayout.setAlignment(Qt.AlignTop) buttonsLayout.addWidget(deleteButton) buttonsLayout.addWidget(upButton) buttonsLayout.addWidget(downButton) self._nameLabel = QLabel("Name") self._nameField = QLineEdit() self._nameField.textChanged.connect(self.OnChanged) self._dataTypeLabel = QLabel("Data Type") self._dataTypeField = QComboBox() for dataType in DataType: self._dataTypeField.addItem(dataType.ToString(), userData=dataType) self._dataTypeField.currentIndexChanged.connect(self.OnChanged) self._defaultValueLabel = QLabel("Default Value") self._defaultInteger = QSpinBox() self._defaultInteger.valueChanged.connect(self.OnChanged) self._defaultFloat = QDoubleSpinBox() self._defaultFloat.valueChanged.connect(self.OnChanged) self._defaultBoolean = QComboBox() self._defaultBoolean.addItem("True", True) self._defaultBoolean.addItem("False", False) self._defaultBoolean.currentIndexChanged.connect(self.OnChanged) self._defaultString = QLineEdit() self._defaultString.textChanged.connect(self.OnChanged) self._minimumLabel = QLabel("Minimum") self._minimumFloat = QDoubleSpinBox() self._minimumFloat.valueChanged.connect(self.OnChanged) self._minimumInteger = QSpinBox() self._minimumInteger.valueChanged.connect(self.OnChanged) self._maximumLabel = QLabel("Maximum") self._maximumFloat = QDoubleSpinBox() self._maximumFloat.valueChanged.connect(self.OnChanged) self._maximumInteger = QSpinBox() self._maximumInteger.valueChanged.connect(self.OnChanged) gridLayout = QGridLayout() gridLayout.setAlignment(Qt.AlignTop) gridLayout.addWidget(self._nameLabel, 0, 0) gridLayout.addWidget(self._nameField, 0, 1) gridLayout.addWidget(self._dataTypeLabel, 1, 0) gridLayout.addWidget(self._dataTypeField, 1, 1) gridLayout.addWidget(self._defaultValueLabel, 2, 0) for defaultField in [ self._defaultInteger, self._defaultFloat, self._defaultBoolean, self._defaultString ]: gridLayout.addWidget(defaultField, 2, 1) gridLayout.addWidget(self._minimumLabel, 3, 0) gridLayout.addWidget(self._minimumInteger, 3, 1) gridLayout.addWidget(self._minimumFloat, 3, 1) gridLayout.addWidget(self._maximumLabel, 4, 0) gridLayout.addWidget(self._maximumInteger, 4, 1) gridLayout.addWidget(self._maximumFloat, 4, 1) layout = QHBoxLayout() layout.addLayout(buttonsLayout) layout.addLayout(gridLayout) self.setLayout(layout) self.SetFieldsFromParameter()