class TitleBar(QWidget): # Сигнал минимизации окна windowMinimumed = Signal() # увеличить максимальный сигнал окна windowMaximumed = Signal() # сигнал восстановления окна windowNormaled = Signal() # сигнал закрытия окна windowClosed = Signal() # Окно мобильных windowMoved = Signal(QPoint) # Сигнал Своя Кнопка +++ signalButtonMy = Signal() def __init__(self, *args, **kwargs): super(TitleBar, self).__init__(*args, **kwargs) # Поддержка настройки фона qss self.setAttribute(Qt.WA_StyledBackground, True) self.mPos = None self.iconSize = 20 # Размер значка по умолчанию # Установите цвет фона по умолчанию, иначе он будет прозрачным из-за влияния родительского окна self.setAutoFillBackground(True) palette = self.palette() palette.setColor(palette.Window, QColor(240, 240, 240)) self.setPalette(palette) # Подключение стиля self.setStyleSheet('Titlebar.qss') self.setStyleSheet(open("Titlebar.qss", "r").read()) # макет layout = QHBoxLayout(self) layout.setSpacing(0) layout.setContentsMargins(0, 0, 0, 0) # значок окна # название окна self.titleLabel = QLabel(self) self.titleLabel.setMargin(2) self.font_id = QFontDatabase.addApplicationFont( "Roboto/Roboto-Bold.ttf") font = QFont("Roboto-Bold", 12) font.setFamily(u"Roboto") font.setBold(True) self.buttonMy = QPushButton(self, clicked=self.showButtonMy, objectName='buttonMy') self.buttonMy.setIcon(QIcon('icon-white.ico')) layout.addWidget(self.buttonMy) layout.addStretch() self.titleLabel.setFont(font) layout.addStretch() layout.addWidget(self.titleLabel, alignment=Qt.AlignCenter) # Средний телескопический бар layout.addSpacerItem( QSpacerItem(40, 100, QSizePolicy.Expanding, QSizePolicy.Minimum)) # Использовать шрифты Webdings для отображения значков font = self.font() or QFont() font.setFamily('Webdings') # Своя Кнопка # Свернуть кнопку self.buttonMinimum = QPushButton('0', self, clicked=self.windowMinimumed.emit, font=font, objectName='buttonMinimum') layout.addWidget(self.buttonMinimum) # Кнопка Max / restore self.buttonMaximum = QPushButton('1', self, clicked=self.showMaximized, font=font, objectName='buttonMaximum') layout.addWidget(self.buttonMaximum) # Кнопка закрытия self.buttonClose = QPushButton('r', self, clicked=self.windowClosed.emit, font=font, objectName='buttonClose') layout.addWidget(self.buttonClose) # начальная высота self.setHeight() # +++ Вызывается по нажатию кнопки buttonMy def showButtonMy(self): print("Своя Кнопка ") self.signalButtonMy.emit() def showMaximized(self): if self.buttonMaximum.text() == '1': # Максимизировать self.buttonMaximum.setText('2') self.windowMaximumed.emit() else: # Восстановить self.buttonMaximum.setText('1') self.windowNormaled.emit() def setHeight(self, height=38): """ Установка высоты строки заголовка """ self.setMinimumHeight(height) self.setMaximumHeight(height) # Задайте размер правой кнопки ? self.buttonMinimum.setMinimumSize(height, height) self.buttonMinimum.setMaximumSize(height, height) self.buttonMaximum.setMinimumSize(height, height) self.buttonMaximum.setMaximumSize(height, height) self.buttonClose.setMinimumSize(height, height) self.buttonClose.setMaximumSize(height, height) self.buttonMy.setMinimumSize(height, height) self.buttonMy.setMaximumSize(height, height) def setTitle(self, title): """ Установить заголовок """ self.titleLabel.setText(title) def setIcon(self, icon): """ настройки значокa """ self.iconLabel.setPixmap(icon.pixmap(self.iconSize, self.iconSize)) def setIconSize(self, size): """ Установить размер значка """ self.iconSize = size def enterEvent(self, event): self.setCursor(Qt.ArrowCursor) super(TitleBar, self).enterEvent(event) def mouseDoubleClickEvent(self, event): super(TitleBar, self).mouseDoubleClickEvent(event) self.showMaximized() def mousePressEvent(self, event): """ Событие клика мыши """ if event.button() == Qt.LeftButton: self.mPos = event.pos() event.accept() def mouseReleaseEvent(self, event): ''' Событие отказов мыши ''' self.mPos = None event.accept() def mouseMoveEvent(self, event): if event.buttons() == Qt.LeftButton and self.mPos: self.windowMoved.emit(self.mapToGlobal(event.pos() - self.mPos)) event.accept()
class UIBuilder(object): """Constructs the UI for a main application window""" def setup(self, main_window: QMainWindow) -> None: """ Initialize the UI. :param main_window: An instance of the `QMainWindow` class. :type main_window: :class:`QMainWindow` """ main_window.setObjectName("main_window") main_window.setWindowTitle("TeaseAI") main_window.resize(1137, 751) main_window.setSizePolicy(*EXP_EXP) main_window.setTabShape(QTabWidget.Rounded) self.menubar = QMenuBar(main_window) self.menubar.setObjectName("menubar") self.menubar.setGeometry(0, 0, 1137, 23) self.file_menu = QMenu("File", self.menubar) self.file_menu.setObjectName("file_men") self.server_menu = QMenu("Server", self.menubar) self.server_menu.setObjectName("server_men") self.options_menu = QMenu("Options", self.menubar) self.options_menu.setObjectName("options_men") self.media_menu = QMenu("Media", self.menubar) self.media_menu.setObjectName("media_men") main_window.setMenuBar(self.menubar) self.exit = QAction("Exit", main_window) self.exit.setObjectName("exit") self.start_server = QAction("Start Server", main_window) self.start_server.setObjectName("start_server") self.connect_server = QAction("Connect to Server", main_window) self.connect_server.setObjectName("connect_server") self.kill_server = QAction("Kill Server", main_window) self.kill_server.setObjectName("kill_server") self.options = QAction("Options", main_window) self.options.setObjectName("options") self.start_webcam = QAction("Start Webcam", main_window) self.start_webcam.setObjectName("start_webcam") self.start_webcam.setCheckable(False) self.centralwidget = QWidget(main_window) self.centralwidget.setObjectName("centralwidget") self.centralwidget.setContentsMargins(QMargins(0, 0, 0, 0)) self.centralwidget.setSizePolicy(*EXP_EXP) self.grid_layout = QGridLayout(self.centralwidget) self.media = QFrame(self.centralwidget) self.media.setObjectName("media") self.media.setSizePolicy(*EXP_EXP) self.media.setMinimumSize(200, 200) self.media.setStyleSheet("background: #000;") self.grid_layout.addWidget(self.media, 0, 0, 5, 1) self.users_label = QLabel(" Online users:", self.centralwidget) self.users_label.setObjectName("users_label") self.users_label.setMinimumSize(300, 15) self.users_label.setMaximumSize(300, 15) self.grid_layout.addWidget(self.users_label, 0, 1, 1, 2) self.online = QPlainTextEdit("", self.centralwidget) self.online.setObjectName("online") self.online.setSizePolicy(*FIX_FIX) self.online.setMinimumSize(300, 50) self.online.setMaximumSize(300, 50) self.online.setStyleSheet("margin-left: 3px;" + SUNKEN) self.online.setLineWidth(2) self.online.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.online.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.online.setSizeAdjustPolicy(QAbstractScrollArea.AdjustIgnored) self.online.setReadOnly(True) self.grid_layout.addWidget(self.online, 1, 1, 1, 2) self.chat = QPlainTextEdit("", self.centralwidget) self.chat.setObjectName("chat") self.chat.setSizePolicy(*FIX_EXP) self.chat.setMinimumSize(300, 0) self.chat.setMaximumSize(300, INFINITE) self.chat.setStyleSheet("margin-bottom: 3px; margin-top: 8px;" + SUNKEN) self.chat.setLineWidth(2) self.chat.setReadOnly(True) self.chat.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.grid_layout.addWidget(self.chat, 2, 1, 1, 2) self.input = QLineEdit(self.centralwidget) self.input.setObjectName("input") self.input.setSizePolicy(*FIX_FIX) self.input.setMinimumSize(224, 30) self.input.setMaximumSize(224, 30) self.input.setStyleSheet(SUNKEN) self.input.setEchoMode(QLineEdit.Normal) self.input.setClearButtonEnabled(True) self.grid_layout.addWidget(self.input, 3, 1, 1, 1) self.submit = QPushButton("Submit", self.centralwidget) self.submit.setObjectName("submit") self.submit.setSizePolicy(*FIX_FIX) self.submit.setMinimumSize(70, 30) self.submit.setMaximumSize(70, 30) self.grid_layout.addWidget(self.submit, 3, 2, 1, 1) self.tabs = QTabWidget(self.centralwidget) self.tabs.setObjectName("tabs") self.tabs.setSizePolicy(*FIX_FIX) self.tabs.setMinimumSize(300, 150) self.tabs.setMaximumSize(300, 150) self.tab = QWidget() self.tab.setObjectName("tab") self.tabs.addTab(self.tab, "Actions") self.tab2 = QWidget() self.tab2.setObjectName("tab2") self.tabs.addTab(self.tab2, "My Media") self.tab3 = QWidget() self.tab3.setObjectName("tab3") self.tab3.setSizePolicy(*FIX_FIX) self.grid_layout2 = QGridLayout(self.tab3) self.grid_layout2.setHorizontalSpacing(0) self.grid_layout2.setVerticalSpacing(3) self.grid_layout2.setContentsMargins(3, -1, 3, -1) self.server_folder = QLineEdit(self.tab3) self.server_folder.setObjectName("server_folder") self.grid_layout2.addWidget(self.server_folder, 0, 0, 1, 3) self.srv_browse = QPushButton("BROWSE", self.tab3) self.srv_browse.setObjectName("srv_browse") self.srv_browse.setStyleSheet("background: transparent;\n" " color: #4d4940;\n" " font-size: 8pt;\n" " font-weight: 450;\n" " padding: 6px;\n") self.grid_layout2.addWidget(self.srv_browse, 0, 3, 1, 1) self.back_button = QPushButton("", self.tab3) self.back_button.setObjectName("back_button") self.back_button.setSizePolicy(*FIX_FIX) self.back_button.setMaximumSize(SEVENTY_FIVE) self.back_button.setCursor(QCursor(Qt.PointingHandCursor)) self.back_button.setStyleSheet("border: 0;\n" "background: transparent;") icon = QIcon() icon.addFile(":/newPrefix/back_button.png", SIXTY_FOUR, QIcon.Normal, QIcon.Off) self.back_button.setIcon(icon) self.back_button.setIconSize(SIXTY_FOUR) self.grid_layout2.addWidget(self.back_button, 1, 0, 1, 1) self.play_button = QPushButton("", self.tab3) self.play_button.setObjectName("play_button") self.play_button.setSizePolicy(*FIX_FIX) self.play_button.setMaximumSize(SEVENTY_FIVE) self.play_button.setCursor(QCursor(Qt.PointingHandCursor)) self.play_button.setStyleSheet("border: 0;\n" "background: transparent;") icon1 = QIcon() icon1.addFile(":/newPrefix/play_button.png", SIXTY_FOUR, QIcon.Normal, QIcon.Off) self.play_button.setIcon(icon1) self.play_button.setIconSize(SIXTY_FOUR) self.grid_layout2.addWidget(self.play_button, 1, 1, 1, 1) self.stop_button = QPushButton("", self.tab3) self.stop_button.setObjectName("stop_button") self.stop_button.setSizePolicy(*FIX_FIX) self.stop_button.setMaximumSize(SEVENTY_FIVE) self.stop_button.setCursor(QCursor(Qt.PointingHandCursor)) self.stop_button.setStyleSheet("border: 0;\n" "background: transparent;") icon2 = QIcon() icon2.addFile(":/newPrefix/stop_button.png", SIXTY_FOUR, QIcon.Normal, QIcon.Off) self.stop_button.setIcon(icon2) self.stop_button.setIconSize(SIXTY_FOUR) self.grid_layout2.addWidget(self.stop_button, 1, 2, 1, 1) self.fast_forward = QPushButton("", self.tab3) self.fast_forward.setObjectName("fast_forward") self.fast_forward.setSizePolicy(*FIX_FIX) self.fast_forward.setMaximumSize(SEVENTY_FIVE) self.fast_forward.setCursor(QCursor(Qt.PointingHandCursor)) self.fast_forward.setStyleSheet("border: 0;\n" "background: transparent;") icon3 = QIcon() icon3.addFile(":/newPrefix/fast_forward.png", SIXTY_FOUR, QIcon.Normal, QIcon.Off) self.fast_forward.setIcon(icon3) self.fast_forward.setIconSize(SIXTY_FOUR) self.grid_layout2.addWidget(self.fast_forward, 1, 3, 1, 1) self.tabs.addTab(self.tab3, "Server Media") self.grid_layout.addWidget(self.tabs, 4, 1, 1, 2) main_window.setCentralWidget(self.centralwidget) self.statusbar = QStatusBar(main_window) self.statusbar.setObjectName("statusbar") self.statusbar.setEnabled(True) self.statusbar.setStyleSheet("margin-bottom: 5px;") self.statusbar.setSizePolicy(*EXP_FIX) self.statusbar.setMinimumSize(INFINITE, 30) self.statusbar.setMaximumSize(INFINITE, 30) self.statusbar.setSizeGripEnabled(False) main_window.setStatusBar(self.statusbar) self.menubar.addAction(self.file_menu.menuAction()) self.menubar.addAction(self.server_menu.menuAction()) self.menubar.addAction(self.options_menu.menuAction()) self.menubar.addAction(self.media_menu.menuAction()) self.file_menu.addAction(self.exit) self.server_menu.addAction(self.start_server) self.server_menu.addAction(self.connect_server) self.server_menu.addAction(self.kill_server) self.options_menu.addAction(self.options) self.media_menu.addAction(self.start_webcam) self.exit.triggered.connect(main_window.close) self.tabs.setCurrentIndex(0) QMetaObject.connectSlotsByName(main_window) self.exit.setStatusTip("Exit the program.") self.start_server.setStatusTip("Initialize a local server instance.") self.connect_server.setStatusTip("Connect to a remote server.") self.kill_server.setStatusTip("Shut down a running local server.") self.options.setStatusTip("Open the options menu.") self.start_webcam.setStatusTip("Start webcam feed.") self.tooltip = QLabel("", self.statusbar) tooltip_policy = QSizePolicy(*EXP_FIX) tooltip_policy.setHorizontalStretch(100) self.tooltip.setSizePolicy(tooltip_policy) self.tooltip.setMinimumSize(INFINITE, 26) self.tooltip.setMaximumSize(INFINITE, 26) self.server_status = QLabel("Server status:", self.statusbar) self.server_status.setSizePolicy(*FIX_FIX) self.server_status.setMinimumSize(300, 26) self.server_status.setMaximumSize(300, 26) self.client_status = QLabel("Client status:", self.statusbar) self.client_status.setSizePolicy(*FIX_FIX) self.client_status.setMinimumSize(302, 26) self.client_status.setMaximumSize(302, 26) self.statusbar.addPermanentWidget(self.tooltip) self.statusbar.addPermanentWidget(self.server_status) self.statusbar.addPermanentWidget(self.client_status) self.tooltip.setStyleSheet(SUNKEN + "margin-left: 4px;\ margin-right: 0px;") self.client_status.setStyleSheet(SUNKEN + "margin-right: 7px;") self.server_status.setStyleSheet(SUNKEN + "margin-right: 2px;\ margin-left: 2px;") self.statusbar.messageChanged.connect(main_window.status_tip)
class Ui_Form(object): def setupUi(self, Form): if not Form.objectName(): Form.setObjectName(u"Form") Form.resize(600, 500) Form.setStyleSheet(u"QWidget#Form{\n" " background-color: rgb(225, 243, 254);\n" "}") self.verticalLayout_2 = QVBoxLayout(Form) self.verticalLayout_2.setObjectName(u"verticalLayout_2") self.horizontalLayout_2 = QHBoxLayout() self.horizontalLayout_2.setSpacing(6) self.horizontalLayout_2.setObjectName(u"horizontalLayout_2") self.lineEdit_headers_path = HeaderFileQLineEdit(Form) self.lineEdit_headers_path.setObjectName(u"lineEdit_headers_path") sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.lineEdit_headers_path.sizePolicy().hasHeightForWidth()) self.lineEdit_headers_path.setSizePolicy(sizePolicy) self.horizontalLayout_2.addWidget(self.lineEdit_headers_path) self.pushButton_select = QPushButton(Form) self.pushButton_select.setObjectName(u"pushButton_select") sizePolicy1 = QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Expanding) sizePolicy1.setHorizontalStretch(0) sizePolicy1.setVerticalStretch(0) sizePolicy1.setHeightForWidth( self.pushButton_select.sizePolicy().hasHeightForWidth()) self.pushButton_select.setSizePolicy(sizePolicy1) self.pushButton_select.setMaximumSize(QSize(16777215, 40)) self.horizontalLayout_2.addWidget(self.pushButton_select) self.verticalLayout_2.addLayout(self.horizontalLayout_2) self.horizontalLayout = QHBoxLayout() self.horizontalLayout.setSpacing(6) self.horizontalLayout.setObjectName(u"horizontalLayout") self.textEdit_headers_content = HeadersQTextEdit(Form) self.textEdit_headers_content.setObjectName( u"textEdit_headers_content") self.horizontalLayout.addWidget(self.textEdit_headers_content) self.verticalLayout = QVBoxLayout() self.verticalLayout.setSpacing(6) self.verticalLayout.setObjectName(u"verticalLayout") self.pushButton_save = QPushButton(Form) self.pushButton_save.setObjectName(u"pushButton_save") sizePolicy1.setHeightForWidth( self.pushButton_save.sizePolicy().hasHeightForWidth()) self.pushButton_save.setSizePolicy(sizePolicy1) self.pushButton_save.setMaximumSize(QSize(16777215, 40)) self.verticalLayout.addWidget(self.pushButton_save) self.pushButton_add = QPushButton(Form) self.pushButton_add.setObjectName(u"pushButton_add") sizePolicy1.setHeightForWidth( self.pushButton_add.sizePolicy().hasHeightForWidth()) self.pushButton_add.setSizePolicy(sizePolicy1) self.pushButton_add.setMaximumSize(QSize(16777215, 40)) self.verticalLayout.addWidget(self.pushButton_add) self.horizontalLayout.addLayout(self.verticalLayout) self.verticalLayout_2.addLayout(self.horizontalLayout) self.horizontalLayout_3 = QHBoxLayout() self.horizontalLayout_3.setObjectName(u"horizontalLayout_3") self.listWidget_headers_key = QListWidget(Form) self.listWidget_headers_key.setObjectName(u"listWidget_headers_key") self.horizontalLayout_3.addWidget(self.listWidget_headers_key) self.listWidget_headers_value = QListWidget(Form) self.listWidget_headers_value.setObjectName( u"listWidget_headers_value") self.horizontalLayout_3.addWidget(self.listWidget_headers_value) self.horizontalLayout_3.setStretch(0, 1) self.horizontalLayout_3.setStretch(1, 4) self.verticalLayout_2.addLayout(self.horizontalLayout_3) self.verticalLayout_2.setStretch(0, 1) self.verticalLayout_2.setStretch(1, 3) self.verticalLayout_2.setStretch(2, 6) self.retranslateUi(Form) QMetaObject.connectSlotsByName(Form) # setupUi def retranslateUi(self, Form): Form.setWindowTitle( QCoreApplication.translate("Form", u"headers editor", None)) self.lineEdit_headers_path.setPlaceholderText( QCoreApplication.translate("Form", u"headers.json", None)) #if QT_CONFIG(tooltip) self.pushButton_select.setToolTip( QCoreApplication.translate( "Form", u"<html><head/><body><p>load headers.json file</p></body></html>", None)) #endif // QT_CONFIG(tooltip) self.pushButton_select.setText( QCoreApplication.translate("Form", u"select", None)) #if QT_CONFIG(tooltip) self.pushButton_save.setToolTip( QCoreApplication.translate( "Form", u"<html><head/><body><p>save to headers.json</p></body></html>", None)) #endif // QT_CONFIG(tooltip) self.pushButton_save.setText( QCoreApplication.translate("Form", u"save", None)) #if QT_CONFIG(tooltip) self.pushButton_add.setToolTip( QCoreApplication.translate( "Form", u"<html><head/><body><p>add a group of header key-value</p></body></html>", None)) #endif // QT_CONFIG(tooltip) self.pushButton_add.setText( QCoreApplication.translate("Form", u"add", None))
class Ui_Img(object): def setupUi(self, Img): if not Img.objectName(): Img.setObjectName(u"Img") Img.resize(620, 559) self.gridLayout = QGridLayout(Img) self.gridLayout.setObjectName(u"gridLayout") self.graphicsView = QGraphicsView(Img) self.graphicsView.setObjectName(u"graphicsView") self.gridLayout.addWidget(self.graphicsView, 0, 0, 1, 1) self.verticalLayout = QVBoxLayout() self.verticalLayout.setObjectName(u"verticalLayout") self.line_3 = QFrame(Img) self.line_3.setObjectName(u"line_3") self.line_3.setFrameShape(QFrame.VLine) self.line_3.setFrameShadow(QFrame.Sunken) self.verticalLayout.addWidget(self.line_3) self.verticalLayout_2 = QVBoxLayout() self.verticalLayout_2.setObjectName(u"verticalLayout_2") self.line_5 = QFrame(Img) self.line_5.setObjectName(u"line_5") self.line_5.setFrameShape(QFrame.VLine) self.line_5.setFrameShadow(QFrame.Sunken) self.verticalLayout_2.addWidget(self.line_5) self.checkBox = QCheckBox(Img) self.checkBox.setObjectName(u"checkBox") self.checkBox.setMaximumSize(QSize(100, 16777215)) self.checkBox.setChecked(True) self.verticalLayout_2.addWidget(self.checkBox) self.ttaModel = QCheckBox(Img) self.ttaModel.setObjectName(u"ttaModel") self.ttaModel.setMaximumSize(QSize(70, 16777215)) self.verticalLayout_2.addWidget(self.ttaModel) self.horizontalLayout_3 = QHBoxLayout() self.horizontalLayout_3.setObjectName(u"horizontalLayout_3") self.scaleRadio = QRadioButton(Img) self.buttonGroup_2 = QButtonGroup(Img) self.buttonGroup_2.setObjectName(u"buttonGroup_2") self.buttonGroup_2.addButton(self.scaleRadio) self.scaleRadio.setObjectName(u"scaleRadio") self.scaleRadio.setMaximumSize(QSize(80, 16777215)) self.scaleRadio.setChecked(True) self.horizontalLayout_3.addWidget(self.scaleRadio) self.scaleEdit = QLineEdit(Img) self.scaleEdit.setObjectName(u"scaleEdit") self.scaleEdit.setMaximumSize(QSize(160, 16777215)) self.scaleEdit.setAlignment(Qt.AlignCenter) self.horizontalLayout_3.addWidget(self.scaleEdit) self.verticalLayout_2.addLayout(self.horizontalLayout_3) self.horizontalLayout_4 = QHBoxLayout() self.horizontalLayout_4.setObjectName(u"horizontalLayout_4") self.heighRadio = QRadioButton(Img) self.buttonGroup_2.addButton(self.heighRadio) self.heighRadio.setObjectName(u"heighRadio") self.heighRadio.setMaximumSize(QSize(80, 16777215)) self.horizontalLayout_4.addWidget(self.heighRadio) self.widthEdit = QLineEdit(Img) self.widthEdit.setObjectName(u"widthEdit") self.widthEdit.setEnabled(False) self.widthEdit.setMaximumSize(QSize(60, 16777215)) self.widthEdit.setAlignment(Qt.AlignCenter) self.horizontalLayout_4.addWidget(self.widthEdit) self.label_2 = QLabel(Img) self.label_2.setObjectName(u"label_2") self.label_2.setMaximumSize(QSize(20, 16777215)) self.horizontalLayout_4.addWidget(self.label_2) self.heighEdit = QLineEdit(Img) self.heighEdit.setObjectName(u"heighEdit") self.heighEdit.setEnabled(False) self.heighEdit.setMaximumSize(QSize(60, 16777215)) self.heighEdit.setAlignment(Qt.AlignCenter) self.horizontalLayout_4.addWidget(self.heighEdit) self.verticalLayout_2.addLayout(self.horizontalLayout_4) self.horizontalLayout_5 = QHBoxLayout() self.horizontalLayout_5.setObjectName(u"horizontalLayout_5") self.label_4 = QLabel(Img) self.label_4.setObjectName(u"label_4") self.label_4.setMaximumSize(QSize(60, 16777215)) self.horizontalLayout_5.addWidget(self.label_4) self.noiseCombox = QComboBox(Img) self.noiseCombox.addItem("") self.noiseCombox.addItem("") self.noiseCombox.addItem("") self.noiseCombox.addItem("") self.noiseCombox.addItem("") self.noiseCombox.setObjectName(u"noiseCombox") self.noiseCombox.setMaximumSize(QSize(160, 16777215)) self.horizontalLayout_5.addWidget(self.noiseCombox) self.verticalLayout_2.addLayout(self.horizontalLayout_5) self.horizontalLayout_6 = QHBoxLayout() self.horizontalLayout_6.setObjectName(u"horizontalLayout_6") self.label_5 = QLabel(Img) self.label_5.setObjectName(u"label_5") self.label_5.setMaximumSize(QSize(60, 16777215)) self.horizontalLayout_6.addWidget(self.label_5) self.comboBox = QComboBox(Img) self.comboBox.addItem("") self.comboBox.addItem("") self.comboBox.addItem("") self.comboBox.setObjectName(u"comboBox") self.comboBox.setMaximumSize(QSize(160, 16777215)) self.horizontalLayout_6.addWidget(self.comboBox) self.verticalLayout_2.addLayout(self.horizontalLayout_6) self.horizontalLayout_7 = QHBoxLayout() self.horizontalLayout_7.setObjectName(u"horizontalLayout_7") self.changeJpg = QPushButton(Img) self.changeJpg.setObjectName(u"changeJpg") self.changeJpg.setMaximumSize(QSize(100, 16777215)) self.horizontalLayout_7.addWidget(self.changeJpg) self.changePng = QPushButton(Img) self.changePng.setObjectName(u"changePng") self.changePng.setMaximumSize(QSize(100, 16777215)) self.horizontalLayout_7.addWidget(self.changePng) self.changeLabel = QLabel(Img) self.changeLabel.setObjectName(u"changeLabel") self.changeLabel.setMaximumSize(QSize(100, 16777215)) self.changeLabel.setAlignment(Qt.AlignCenter) self.horizontalLayout_7.addWidget(self.changeLabel) self.verticalLayout_2.addLayout(self.horizontalLayout_7) self.horizontalLayout_11 = QHBoxLayout() self.horizontalLayout_11.setObjectName(u"horizontalLayout_11") self.verticalLayout_2.addLayout(self.horizontalLayout_11) self.verticalLayout.addLayout(self.verticalLayout_2) self.line = QFrame(Img) self.line.setObjectName(u"line") self.line.setFrameShape(QFrame.VLine) self.line.setFrameShadow(QFrame.Sunken) self.verticalLayout.addWidget(self.line) self.line_4 = QFrame(Img) self.line_4.setObjectName(u"line_4") self.line_4.setFrameShape(QFrame.HLine) self.line_4.setFrameShadow(QFrame.Sunken) self.verticalLayout.addWidget(self.line_4) self.verticalLayout_3 = QVBoxLayout() self.verticalLayout_3.setObjectName(u"verticalLayout_3") self.horizontalLayout_8 = QHBoxLayout() self.horizontalLayout_8.setObjectName(u"horizontalLayout_8") self.label_8 = QLabel(Img) self.label_8.setObjectName(u"label_8") self.label_8.setMaximumSize(QSize(60, 16777215)) self.horizontalLayout_8.addWidget(self.label_8) self.resolutionLabel = QLabel(Img) self.resolutionLabel.setObjectName(u"resolutionLabel") self.resolutionLabel.setMaximumSize(QSize(160, 16777215)) self.horizontalLayout_8.addWidget(self.resolutionLabel) self.verticalLayout_3.addLayout(self.horizontalLayout_8) self.horizontalLayout_9 = QHBoxLayout() self.horizontalLayout_9.setObjectName(u"horizontalLayout_9") self.label_10 = QLabel(Img) self.label_10.setObjectName(u"label_10") self.label_10.setMaximumSize(QSize(60, 16777215)) self.horizontalLayout_9.addWidget(self.label_10) self.sizeLabel = QLabel(Img) self.sizeLabel.setObjectName(u"sizeLabel") self.sizeLabel.setMaximumSize(QSize(160, 16777215)) self.horizontalLayout_9.addWidget(self.sizeLabel) self.verticalLayout_3.addLayout(self.horizontalLayout_9) self.horizontalLayout = QHBoxLayout() self.horizontalLayout.setObjectName(u"horizontalLayout") self.label = QLabel(Img) self.label.setObjectName(u"label") self.label.setMaximumSize(QSize(60, 16777215)) self.horizontalLayout.addWidget(self.label) self.gpuName = QLabel(Img) self.gpuName.setObjectName(u"gpuName") self.gpuName.setMaximumSize(QSize(160, 16777215)) self.horizontalLayout.addWidget(self.gpuName) self.verticalLayout_3.addLayout(self.horizontalLayout) self.horizontalLayout_10 = QHBoxLayout() self.horizontalLayout_10.setObjectName(u"horizontalLayout_10") self.label_6 = QLabel(Img) self.label_6.setObjectName(u"label_6") self.label_6.setMaximumSize(QSize(60, 16777215)) self.horizontalLayout_10.addWidget(self.label_6) self.tickLabel = QLabel(Img) self.tickLabel.setObjectName(u"tickLabel") self.tickLabel.setMaximumSize(QSize(160, 16777215)) self.horizontalLayout_10.addWidget(self.tickLabel) self.verticalLayout_3.addLayout(self.horizontalLayout_10) self.oepnButton = QPushButton(Img) self.oepnButton.setObjectName(u"oepnButton") self.oepnButton.setMaximumSize(QSize(100, 16777215)) self.verticalLayout_3.addWidget(self.oepnButton) self.horizontalLayout_2 = QHBoxLayout() self.horizontalLayout_2.setObjectName(u"horizontalLayout_2") self.verticalLayout_3.addLayout(self.horizontalLayout_2) self.pushButton_3 = QPushButton(Img) self.pushButton_3.setObjectName(u"pushButton_3") self.pushButton_3.setMaximumSize(QSize(100, 16777215)) self.verticalLayout_3.addWidget(self.pushButton_3) self.pushButton = QPushButton(Img) self.pushButton.setObjectName(u"pushButton") self.pushButton.setMaximumSize(QSize(100, 16777215)) self.verticalLayout_3.addWidget(self.pushButton) self.saveButton = QPushButton(Img) self.saveButton.setObjectName(u"saveButton") self.saveButton.setMaximumSize(QSize(100, 16777215)) self.verticalLayout_3.addWidget(self.saveButton) self.verticalLayout.addLayout(self.verticalLayout_3) self.line_6 = QFrame(Img) self.line_6.setObjectName(u"line_6") self.line_6.setFrameShape(QFrame.HLine) self.line_6.setFrameShadow(QFrame.Sunken) self.verticalLayout.addWidget(self.line_6) self.verticalSpacer = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding) self.verticalLayout.addItem(self.verticalSpacer) self.line_2 = QFrame(Img) self.line_2.setObjectName(u"line_2") self.line_2.setFrameShape(QFrame.VLine) self.line_2.setFrameShadow(QFrame.Sunken) self.verticalLayout.addWidget(self.line_2) self.gridLayout.addLayout(self.verticalLayout, 0, 1, 1, 1) self.retranslateUi(Img) self.checkBox.clicked.connect(Img.SwithPicture) self.saveButton.clicked.connect(Img.SavePicture) self.heighEdit.textChanged.connect(Img.CheckScaleRadio) self.pushButton_3.clicked.connect(Img.ReduceScalePic) self.heighRadio.clicked.connect(Img.CheckScaleRadio) self.ttaModel.clicked.connect(Img.CheckScaleRadio) self.oepnButton.clicked.connect(Img.OpenPicture) self.widthEdit.textChanged.connect(Img.CheckScaleRadio) self.pushButton.clicked.connect(Img.AddScalePic) self.scaleEdit.textChanged.connect(Img.CheckScaleRadio) self.scaleRadio.clicked.connect(Img.CheckScaleRadio) self.comboBox.currentIndexChanged.connect(Img.ChangeModel) self.changeJpg.clicked.connect(Img.StartWaifu2x) self.noiseCombox.currentIndexChanged.connect(Img.CheckScaleRadio) self.changePng.clicked.connect(Img.StartWaifu2xPng) self.changeJpg.clicked.connect(Img.StartWaifu2xJPG) QMetaObject.connectSlotsByName(Img) # setupUi def retranslateUi(self, Img): Img.setWindowTitle(QCoreApplication.translate("Img", u"Form", None)) self.checkBox.setText( QCoreApplication.translate("Img", u"waifu2x", None)) #if QT_CONFIG(tooltip) self.ttaModel.setToolTip( QCoreApplication.translate( "Img", u"\u753b\u8d28\u63d0\u5347\uff0c\u8017\u65f6\u589e\u52a0", None)) #endif // QT_CONFIG(tooltip) self.ttaModel.setText( QCoreApplication.translate("Img", u"tta\u6a21\u5f0f", None)) self.scaleRadio.setText( QCoreApplication.translate("Img", u"\u500d\u6570\u653e\u5927", None)) self.scaleEdit.setText(QCoreApplication.translate("Img", u"2", None)) self.heighRadio.setText( QCoreApplication.translate("Img", u"\u56fa\u5b9a\u957f\u5bbd", None)) self.label_2.setText(QCoreApplication.translate("Img", u"x", None)) self.label_4.setText( QCoreApplication.translate("Img", u"\u964d\u566a\uff1a", None)) self.noiseCombox.setItemText( 0, QCoreApplication.translate("Img", u"3", None)) self.noiseCombox.setItemText( 1, QCoreApplication.translate("Img", u"2", None)) self.noiseCombox.setItemText( 2, QCoreApplication.translate("Img", u"1", None)) self.noiseCombox.setItemText( 3, QCoreApplication.translate("Img", u"0", None)) self.noiseCombox.setItemText( 4, QCoreApplication.translate("Img", u"-1", None)) self.label_5.setText( QCoreApplication.translate("Img", u"\u6a21\u578b\uff1a", None)) self.comboBox.setItemText( 0, QCoreApplication.translate("Img", u"cunet", None)) self.comboBox.setItemText( 1, QCoreApplication.translate("Img", u"photo", None)) self.comboBox.setItemText( 2, QCoreApplication.translate("Img", u"anime_style_art_rgb", None)) self.changeJpg.setText( QCoreApplication.translate("Img", u"\u8f6c\u6362JPG", None)) self.changePng.setText( QCoreApplication.translate("Img", u"\u8f6c\u6362PNG", None)) self.changeLabel.setText("") self.label_8.setText( QCoreApplication.translate("Img", u"\u5206\u8fa8\u7387\uff1a", None)) self.resolutionLabel.setText( QCoreApplication.translate("Img", u"TextLabel", None)) self.label_10.setText( QCoreApplication.translate("Img", u"\u5927 \u5c0f\uff1a", None)) self.sizeLabel.setText( QCoreApplication.translate("Img", u"TextLabel", None)) self.label.setText(QCoreApplication.translate("Img", u"GPU:", None)) self.gpuName.setText( QCoreApplication.translate("Img", u"TextLabel", None)) self.label_6.setText( QCoreApplication.translate("Img", u"\u8017\u65f6\uff1a", None)) self.tickLabel.setText("") self.oepnButton.setText( QCoreApplication.translate("Img", u"\u6253\u5f00\u56fe\u7247", None)) self.pushButton_3.setText( QCoreApplication.translate("Img", u"\u7f29\u5c0f", None)) self.pushButton.setText( QCoreApplication.translate("Img", u"\u653e\u5927", None)) self.saveButton.setText( QCoreApplication.translate("Img", u"\u4fdd\u5b58\u56fe\u7247", None))
class MainWindow(QMainWindow): """Main application window""" def __init__(self) -> None: QMainWindow.__init__(self) self.setSizePolicy( QSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum)) self.setMaximumSize(QSize(1920, 1080)) self.setStyleSheet("padding: 0px; margin: 0px;") self.setIconSize(QSize(32, 32)) self.setWindowTitle("BossyBot 2000 - Image Tagger") self.setWindowIcon(self.load_icon(icon)) self.menubar = QMenuBar(self) self.menubar.setSizePolicy(EXP_MAX) self.menubar.setMaximumSize(QSize(INFINITE, 30)) self.menu_file = QMenu('File', self.menubar) self.menu_options = QMenu('Options', self.menubar) self.menu_help = QMenu('Help', self.menubar) self.menubar.addAction(self.menu_file.menuAction()) self.menubar.addAction(self.menu_options.menuAction()) self.menubar.addAction(self.menu_help.menuAction()) self.open = QAction('Open', self) self.menu_file.addAction(self.open) self.open.triggered.connect(self.open_file) self.exit_button = QAction('Exit', self) self.exit_button.triggered.connect(lambda: sys.exit(0), Qt.QueuedConnection) self.menu_file.addAction(self.exit_button) self.setMenuBar(self.menubar) self.previous_button = QAction(self.load_icon(previous), '<<', self) self.next_button = QAction(self.load_icon(next_icon), '>>', self) self.rotate_left_button = QAction(self.load_icon(left), '', self) self.rotate_right_button = QAction(self.load_icon(right), '', self) self.play_button = QAction(self.load_icon(play), '', self) self.play_button.setCheckable(True) self.delete_button = QAction(self.load_icon(delete), '', self) self.reload_button = QAction(self.load_icon(reload), '', self) self.mirror_button = QAction('Mirror', self) self.actual_size_button = QAction('Actual Size', self) self.browser_button = QAction('Browser', self) self.browser_button.setCheckable(True) self.browser_button.setChecked(True) self.crop_button = QAction('Crop', self) self.crop_button.setCheckable(True) self.toolbuttons = { self.rotate_left_button: { 'shortcut': ',', 'connect': lambda: self.pixmap.setRotation(self.pixmap.rotation() - 90) }, self.rotate_right_button: { 'shortcut': '.', 'connect': lambda: self.pixmap.setRotation(self.pixmap.rotation() + 90) }, self.delete_button: { 'shortcut': 'Del', 'connect': self.delete }, self.previous_button: { 'shortcut': 'Left', 'connect': self.previous }, self.play_button: { 'shortcut': 'Space', 'connect': self.play }, self.next_button: { 'shortcut': 'Right', 'connect': self.next }, self.reload_button: { 'shortcut': 'F5', 'connect': self.reload } } self.toolbar = QToolBar(self) self.toolbar.setSizePolicy(EXP_MAX) self.toolbar.setMaximumSize(QSize(INFINITE, 27)) for _ in (self.browser_button, self.crop_button, self.mirror_button, self.actual_size_button): self.toolbar.addAction(_) self.addToolBar(Qt.TopToolBarArea, self.toolbar) for button in self.toolbuttons: button.setShortcut(self.toolbuttons[button]['shortcut']) button.triggered.connect(self.toolbuttons[button]['connect']) self.toolbar.addAction(button) self.centralwidget = QWidget(self) self.centralwidget.setSizePolicy(EXP_EXP) self.setCentralWidget(self.centralwidget) self.grid = QGridLayout(self.centralwidget) self.media = QGraphicsScene(self) self.media.setItemIndexMethod(QGraphicsScene.NoIndex) self.media.setBackgroundBrush(QBrush(Qt.black)) self.view = MyView(self.media, self) self.view.setSizePolicy(EXP_EXP) self.media.setSceneRect(0, 0, self.view.width(), self.view.height()) self.grid.addWidget(self.view, 0, 0, 1, 1) self.frame = QFrame(self.centralwidget) self.frame.setSizePolicy( QSizePolicy(QSizePolicy.Fixed, QSizePolicy.MinimumExpanding)) self.frame.setMinimumSize(QSize(325, 500)) self.frame.setStyleSheet( "QFrame { border: 4px inset #222; border-radius: 10; }") self.layout_widget = QWidget(self.frame) self.layout_widget.setGeometry(QRect(0, 400, 321, 91)) self.layout_widget.setContentsMargins(15, 15, 15, 15) self.grid2 = QGridLayout(self.layout_widget) self.grid2.setContentsMargins(0, 0, 0, 0) self.save_button = QPushButton('Yes (Save)', self.layout_widget) self.save_button.setSizePolicy(FIX_FIX) self.save_button.setMaximumSize(QSize(120, 26)) self.save_button.setVisible(False) self.grid2.addWidget(self.save_button, 1, 0, 1, 1) self.no_save_button = QPushButton('No (Reload)', self.layout_widget) self.no_save_button.setSizePolicy(FIX_FIX) self.no_save_button.setMaximumSize(QSize(120, 26)) self.no_save_button.setVisible(False) self.grid2.addWidget(self.no_save_button, 1, 1, 1, 1) self.label = QLabel("Current image modified, save it?", self.layout_widget) self.label.setSizePolicy(FIX_FIX) self.label.setMaximumSize(QSize(325, 60)) self.label.setVisible(False) self.label.setAlignment(Qt.AlignCenter) self.grid2.addWidget(self.label, 0, 0, 1, 2) self.layout_widget = QWidget(self.frame) self.layout_widget.setGeometry(QRect(0, 0, 321, 213)) self.ass = QRadioButton('Ass', self.layout_widget) self.ass_exposed = QRadioButton('Ass (exposed)', self.layout_widget) self.ass_reset = QRadioButton(self.frame) self.ass_group = QButtonGroup(self) self.breasts = QRadioButton('Breasts', self.layout_widget) self.breasts_exposed = QRadioButton('Breasts (exposed)', self.layout_widget) self.breasts_reset = QRadioButton(self.frame) self.breasts_group = QButtonGroup(self) self.pussy = QRadioButton('Pussy', self.layout_widget) self.pussy_exposed = QRadioButton('Pussy (exposed)', self.layout_widget) self.pussy_reset = QRadioButton(self.frame) self.pussy_group = QButtonGroup(self) self.fully_clothed = QRadioButton('Fully Clothed', self.layout_widget) self.fully_nude = QRadioButton('Fully Nude', self.layout_widget) self.nudity_reset = QRadioButton(self.frame) self.nudity = QButtonGroup(self) self.smiling = QRadioButton('Smiling', self.layout_widget) self.glaring = QRadioButton('Glaring', self.layout_widget) self.expression_reset = QRadioButton(self.frame) self.expression = QButtonGroup(self) self.grid3 = QGridLayout(self.layout_widget) self.grid3.setVerticalSpacing(15) self.grid3.setContentsMargins(0, 15, 0, 0) self.radios = { self.ass: { 'this': 'ass', 'that': 'ass_exposed', 'group': self.ass_group, 'reset': self.ass_reset, 'grid': (0, 0, 1, 1) }, self.ass_exposed: { 'this': 'ass_exposed', 'that': 'ass', 'group': self.ass_group, 'reset': self.ass_reset, 'grid': (0, 1, 1, 1) }, self.breasts: { 'this': 'breasts', 'that': 'breasts_exposed', 'group': self.breasts_group, 'reset': self.breasts_reset, 'grid': (1, 0, 1, 1) }, self.breasts_exposed: { 'this': 'breasts_exposed', 'that': 'breasts', 'group': self.breasts_group, 'reset': self.breasts_reset, 'grid': (1, 1, 1, 1) }, self.pussy: { 'this': 'pussy', 'that': 'pussy_exposed', 'group': self.pussy_group, 'reset': self.pussy_reset, 'grid': (2, 0, 1, 1) }, self.pussy_exposed: { 'this': 'pussy_exposed', 'that': 'pussy', 'group': self.pussy_group, 'reset': self.pussy_reset, 'grid': (2, 1, 1, 1) }, self.fully_clothed: { 'this': 'fully_clothed', 'that': 'fully_nude', 'group': self.nudity, 'reset': self.nudity_reset, 'grid': (3, 0, 1, 1) }, self.fully_nude: { 'this': 'fully_nude', 'that': 'fully_clothed', 'group': self.nudity, 'reset': self.nudity_reset, 'grid': (3, 1, 1, 1) }, self.smiling: { 'this': 'smiling', 'that': 'glaring', 'group': self.expression, 'reset': self.expression_reset, 'grid': (4, 0, 1, 1) }, self.glaring: { 'this': 'glaring', 'that': 'smiling', 'group': self.expression, 'reset': self.expression_reset, 'grid': (4, 1, 1, 1) }, } for radio in self.radios: radio.setSizePolicy(FIX_FIX) radio.setMaximumSize(QSize(150, 22)) self.radios[radio]['reset'].setGeometry(QRect(0, 0, 0, 0)) self.grid3.addWidget(radio, *self.radios[radio]['grid']) if self.radios[radio]['group'] != self.nudity: radio.toggled.connect( lambda x=_, y=radio: self.annotate(self.radios[y]['this'])) self.radios[radio]['group'].addButton(radio) self.radios[radio]['group'].addButton(self.radios[radio]['reset']) self.save_tags_button = QPushButton('Save Tags', self.layout_widget) self.save_tags_button.setSizePolicy(FIX_FIX) self.save_tags_button.setMaximumSize(QSize(120, 26)) self.grid3.addWidget(self.save_tags_button, 5, 1, 1, 1) self.grid.addWidget(self.frame, 0, 1, 1, 1) self.browse_bar = QLabel(self.centralwidget) self.browse_bar.setSizePolicy(EXP_FIX) self.browse_bar.setMinimumSize(QSize(0, 100)) self.browse_bar.setMaximumSize(QSize(INFINITE, 100)) self.browse_bar.setStyleSheet("background: #000;") self.browse_bar.setAlignment(Qt.AlignCenter) self.h_box2 = QHBoxLayout(self.browse_bar) self.h_box2.setContentsMargins(4, 0, 0, 0) self.grid.addWidget(self.browse_bar, 1, 0, 1, 2) hiders = [ self.no_save_button.clicked, self.save_button.clicked, self.reload_button.triggered ] for hider in hiders: hider.connect(self.save_button.hide) hider.connect(self.no_save_button.hide) hider.connect(self.label.hide) showers = [ self.mirror_button.triggered, self.rotate_right_button.triggered, self.rotate_left_button.triggered ] for shower in showers: shower.connect(self.save_button.show) shower.connect(self.no_save_button.show) shower.connect(self.label.show) self.no_save_button.clicked.connect(self.reload) self.browser_button.toggled.connect(self.browse_bar.setVisible) self.play_button.toggled.connect(lambda: self.frame.setVisible( (True, False)[self.frame.isVisible()])) self.reload_button.triggered.connect(self.reload) self.mirror_button.triggered.connect(lambda: self.pixmap.setScale(-1)) self.save_button.clicked.connect(self.save_image) self.play_button.toggled.connect( lambda: self.browser_button.setChecked( (True, False)[self.browse_bar.isVisible()])) self.crop_button.toggled.connect(self.view.reset) self.actual_size_button.triggered.connect(self.actual_size) self.browser_button.triggered.connect(self.browser) self.save_tags_button.clicked.connect(self.save_tags) self.view.got_rect.connect(self.set_rect) self.crop_rect = QRect(QPoint(0, 0), QSize(0, 0)) self.dir_now = os.getcwd() self.files = [] self.index = 0 self.refresh_files() self.pixmap_is_scaled = False self.pixmap = QGraphicsPixmapItem() self.active_tag = '' self.reset_browser = False self.txt = PngInfo() def set_rect(self, rect: tuple[QPointF, QPointF]): """Converts the crop rectangle to a QRect after a crop action""" self.crop_rect = QRect(rect[0].toPoint(), rect[1].toPoint()) def keyPressEvent(self, event: QKeyEvent): # pylint: disable=invalid-name; """Keyboard event handler.""" if event.key() == Qt.Key_Escape and self.play_button.isChecked(): self.play_button.toggle() self.browser_button.setChecked((True, False)[self.reset_browser]) elif (event.key() in [16777220, 16777221] and self.view.g_rect.rect().width() > 0): self.view.got_rect.emit((self.view.g_rect.rect().topLeft(), self.view.g_rect.rect().bottomRight())) if self.view.g_rect.pen().color() == Qt.red: new_pix = self.pixmap.pixmap().copy(self.crop_rect) if self.pixmap_is_scaled: new_pix = new_pix.transformed( self.view.transform().inverted()[0], Qt.SmoothTransformation) self.update_pixmap(new_pix) elif self.view.g_rect.pen().color() == Qt.magenta: self.annotate_rect() self.view.annotation = False for _ in (self.label, self.save_button, self.no_save_button): _.show() self.view.reset() def play(self): """Starts a slideshow.""" if self.play_button.isChecked(): if self.browser_button.isChecked(): self.reset_browser = True else: self.reset_browser = False QTimer.singleShot(3000, self.play) self.next() def _yield_radio(self): """Saves code connecting signals from all the radio buttons.""" yield from self.radios.keys().__str__() def load_icon(self, icon_file): """Loads an icon from Base64 encoded strings in icons.py.""" pix = QPixmap() pix.loadFromData(icon_file) return QIcon(pix) def open_file(self, file: str) -> None: """ Open an image file and display it. :param file: The filename of the image to open """ if not os.path.isfile(file): file = QFileDialog(self, self.dir_now, self.dir_now).getOpenFileName()[0] self.dir_now = os.path.dirname(file) self.refresh_files() for i, index_file in enumerate(self.files): if file.split('/')[-1] == index_file: self.index = i self.view.setTransform(QTransform()) self.update_pixmap(QPixmap(file)) self.browser() self.load_tags() def refresh_files(self) -> list[str]: """Updates the file list when the directory is changed. Returns a list of image files available in the current directory.""" files = os.listdir(self.dir_now) self.files = [ file for file in sorted(files, key=lambda x: x.lower()) if file.endswith((".png", ".jpg", ".gif", ".bmp", ".jpeg")) ] def next(self) -> None: """Opens the next image in the file list.""" self.index = (self.index + 1) % len(self.files) self.reload() def previous(self) -> None: """Opens the previous image in the file list.""" self.index = (self.index + (len(self.files) - 1)) % len(self.files) self.reload() def save_image(self) -> None: """ Save the modified image file. If the current pixmap has been scaled, we need to load a non-scaled pixmap from the original file and re-apply the transformations that have been performed to prevent it from being saved as the scaled-down image. """ if self.pixmap_is_scaled: rotation = self.pixmap.rotation() mirror = self.pixmap.scale() < 0 pix = QPixmap(self.files[self.index]) pix = pix.transformed(QTransform().rotate(rotation)) if mirror: pix = pix.transformed(QTransform().scale(-1, 1)) pix.save(self.files[self.index], quality=-1) else: self.pixmap.pixmap().save(self.files[self.index], quality=-1) self.save_tags() def delete(self) -> None: """Deletes the current image from the file system.""" with suppress(OSError): os.remove(f"{self.dir_now}/{self.files.pop(self.index)}") self.refresh_files() def reload(self) -> None: """Reloads the current pixmap; used to update the screen when the current file is changed.""" self.open_file(f"{self.dir_now}/{self.files[self.index]}") def annotate(self, tag): """Starts an annotate action""" self.txt = PngInfo() self.view.annotation = True self.active_tag = tag self.view.reset() def wheelEvent(self, event: QWheelEvent) -> None: # pylint: disable=invalid-name """With Ctrl depressed, zoom the current image, otherwise fire the next/previous functions.""" modifiers = QApplication.keyboardModifiers() if event.angleDelta().y() == 120 and modifiers == Qt.ControlModifier: self.view.scale(0.75, 0.75) elif event.angleDelta().y() == 120: self.previous() elif event.angleDelta().y( ) == -120 and modifiers == Qt.ControlModifier: self.view.scale(1.25, 1.25) elif event.angleDelta().y() == -120: self.next() def actual_size(self) -> None: """Display the current image at its actual size, rather than scaled to fit the viewport.""" self.update_pixmap(QPixmap(self.files[self.index]), False) self.view.setDragMode(QGraphicsView.ScrollHandDrag) def mousePressEvent(self, event: QMouseEvent) -> None: # pylint: disable=invalid-name """Event handler for mouse button presses.""" if event.button() == Qt.MouseButton.ForwardButton: self.next() elif event.button() == Qt.MouseButton.BackButton: self.previous() def update_pixmap(self, new: QPixmap, scaled: bool = True) -> None: """ Updates the currently displayed image. :param new: The new `QPixmap` to be displayed. :param scaled: If False, don't scale the image to fit the viewport. """ self.pixmap_is_scaled = scaled self.media.clear() self.pixmap = self.media.addPixmap(new) self.pixmap.setTransformOriginPoint( self.pixmap.boundingRect().width() / 2, self.pixmap.boundingRect().height() / 2) if scaled and (new.size().width() > self.view.width() or new.size().height() > self.view.height()): self.view.fitInView(self.pixmap, Qt.KeepAspectRatio) self.media.setSceneRect(self.pixmap.boundingRect()) def annotate_rect(self): """Creates image coordinate annotation data.""" self.txt.add_itxt( f'{str(self.active_tag)}-rect', f'{str(self.crop_rect.x())}, {str(self.crop_rect.y())}, {str(self.crop_rect.width())}, {str(self.crop_rect.height())}' ) def browser(self): """Slot function to initialize image thumbnails for the 'browse mode.'""" while self.h_box2.itemAt(0): self.h_box2.takeAt(0).widget().deleteLater() index = (self.index + (len(self.files) - 2)) % len(self.files) for i, file in enumerate(self.files): file = self.dir_now + '/' + self.files[index] label = ClickableLabel(self, file) self.h_box2.addWidget(label) pix = QPixmap(file) if (pix.size().width() > self.browse_bar.width() / 5 or pix.size().height() > 100): pix = pix.scaled(self.browse_bar.width() / 5, 100, Qt.KeepAspectRatio) label.setPixmap(pix) index = (index + 1) % len(self.files) if i == 4: break def save_tags(self): """Save tags for currently loaded image into its iTxt data.""" file = self.files[self.index] img = Image.open(file) img.load() for key, value, in img.text.items(): self.txt.add_itxt(key, value) for key in self.radios: if key.isChecked(): self.txt.add_itxt(self.radios[key]['this'], 'True') self.txt.add_itxt(self.radios[key]['that'], 'False') img.save(file, pnginfo=self.txt) def load_tags(self): """Load tags from iTxt data.""" for radio in self.radios: if radio.isChecked(): self.radios[radio]['reset'].setChecked(True) filename = self.files[self.index] fqp = filename img = Image.open(fqp) img.load() with suppress(AttributeError): for key, value in img.text.items(): if value == 'True': for radio in self.radios: if key == self.radios[radio]['this']: radio.setChecked(True) self.view.annotation = False self.active_tag = '' self.view.reset() for key, value in img.text.items(): if key.endswith('-rect'): btn = [ radio for radio in self.radios if self.radios[radio]['this'] == key.split('-')[0] ] print(key, value) if btn[0].isChecked(): coords = [int(coord) for coord in value.split(', ')] rect = QGraphicsRectItem(*coords) rect.setPen(QPen(Qt.magenta, 1, Qt.SolidLine)) rect.setBrush(QBrush(Qt.magenta, Qt.Dense4Pattern)) self.view.scene().addItem(rect) text = self.view.scene().addText( key.split('-')[0], QFont('monospace', 20, 400, False)) text.font().setPointSize(text.font().pointSize() * 2) text.update() text.setX(rect.rect().x() + 10) text.setY(rect.rect().y() + 10) print(f'set {key}')
class Ui_Dialog(object): def setupUi(self, Dialog): if not Dialog.objectName(): Dialog.setObjectName(u"Dialog") Dialog.resize(400, 150) self.verticalLayout = QVBoxLayout(Dialog) self.verticalLayout.setObjectName(u"verticalLayout") self.gridLayout = QGridLayout() self.gridLayout.setObjectName(u"gridLayout") self.label_3 = QLabel(Dialog) self.label_3.setObjectName(u"label_3") self.gridLayout.addWidget(self.label_3, 1, 0, 1, 1) self.label = QLabel(Dialog) self.label.setObjectName(u"label") self.gridLayout.addWidget(self.label, 0, 0, 1, 1) self.txtName = QLineEdit(Dialog) self.txtName.setObjectName(u"txtName") self.gridLayout.addWidget(self.txtName, 0, 1, 1, 1) self.txtPassword2 = QLineEdit(Dialog) self.txtPassword2.setObjectName(u"txtPassword2") self.txtPassword2.setEchoMode(QLineEdit.Password) self.gridLayout.addWidget(self.txtPassword2, 2, 1, 1, 1) self.btnFileChooser = QPushButton(Dialog) self.btnFileChooser.setObjectName(u"btnFileChooser") self.btnFileChooser.setMinimumSize(QSize(30, 0)) self.btnFileChooser.setMaximumSize(QSize(30, 16777215)) self.gridLayout.addWidget(self.btnFileChooser, 3, 2, 1, 1) self.label_4 = QLabel(Dialog) self.label_4.setObjectName(u"label_4") self.gridLayout.addWidget(self.label_4, 2, 0, 1, 1) self.txtPassword1 = QLineEdit(Dialog) self.txtPassword1.setObjectName(u"txtPassword1") self.txtPassword1.setEchoMode(QLineEdit.Password) self.gridLayout.addWidget(self.txtPassword1, 1, 1, 1, 1) self.label_2 = QLabel(Dialog) self.label_2.setObjectName(u"label_2") self.gridLayout.addWidget(self.label_2, 3, 0, 1, 1) self.txtPath = QLineEdit(Dialog) self.txtPath.setObjectName(u"txtPath") self.gridLayout.addWidget(self.txtPath, 3, 1, 1, 1) self.horizontalLayout = QHBoxLayout() self.horizontalLayout.setObjectName(u"horizontalLayout") self.horizontalSpacer = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) self.horizontalLayout.addItem(self.horizontalSpacer) self.btnOk = QPushButton(Dialog) self.btnOk.setObjectName(u"btnOk") self.horizontalLayout.addWidget(self.btnOk) self.btnCancel = QPushButton(Dialog) self.btnCancel.setObjectName(u"btnCancel") self.horizontalLayout.addWidget(self.btnCancel) self.gridLayout.addLayout(self.horizontalLayout, 4, 0, 1, 3) self.verticalLayout.addLayout(self.gridLayout) QWidget.setTabOrder(self.txtName, self.txtPassword1) QWidget.setTabOrder(self.txtPassword1, self.txtPassword2) QWidget.setTabOrder(self.txtPassword2, self.txtPath) QWidget.setTabOrder(self.txtPath, self.btnFileChooser) QWidget.setTabOrder(self.btnFileChooser, self.btnOk) QWidget.setTabOrder(self.btnOk, self.btnCancel) self.retranslateUi(Dialog) QMetaObject.connectSlotsByName(Dialog) # setupUi def retranslateUi(self, Dialog): Dialog.setWindowTitle( QCoreApplication.translate("Dialog", u"Dialog", None)) self.label_3.setText( QCoreApplication.translate("Dialog", u"\u5bc6\u78011", None)) self.label.setText( QCoreApplication.translate("Dialog", u"\u540d\u79f0", None)) self.btnFileChooser.setText( QCoreApplication.translate("Dialog", u"...", None)) self.label_4.setText( QCoreApplication.translate("Dialog", u"\u5bc6\u78012", None)) self.label_2.setText( QCoreApplication.translate("Dialog", u"\u8def\u5f84", None)) self.btnOk.setText( QCoreApplication.translate("Dialog", u"\u4fdd\u5b58", None)) self.btnCancel.setText( QCoreApplication.translate("Dialog", u"\u53d6\u6d88", None))
class Ui_Dialog(object): def setupUi(self, Dialog): if not Dialog.objectName(): Dialog.setObjectName(u"Dialog") Dialog.resize(400, 103) self.horizontalLayout = QHBoxLayout(Dialog) self.horizontalLayout.setObjectName(u"horizontalLayout") self.gridLayout = QGridLayout() self.gridLayout.setObjectName(u"gridLayout") self.label = QLabel(Dialog) self.label.setObjectName(u"label") self.gridLayout.addWidget(self.label, 0, 0, 1, 1) self.label_2 = QLabel(Dialog) self.label_2.setObjectName(u"label_2") self.gridLayout.addWidget(self.label_2, 1, 0, 1, 1) self.tbSelectDir = QToolButton(Dialog) self.tbSelectDir.setObjectName(u"tbSelectDir") self.gridLayout.addWidget(self.tbSelectDir, 1, 2, 1, 1) self.tbSelectFiles = QToolButton(Dialog) self.tbSelectFiles.setObjectName(u"tbSelectFiles") self.gridLayout.addWidget(self.tbSelectFiles, 0, 2, 1, 1) self.txtInputFile = QLineEdit(Dialog) self.txtInputFile.setObjectName(u"txtInputFile") self.txtInputFile.setReadOnly(True) self.gridLayout.addWidget(self.txtInputFile, 0, 1, 1, 1) self.txtOutputDir = QLineEdit(Dialog) self.txtOutputDir.setObjectName(u"txtOutputDir") self.txtOutputDir.setReadOnly(True) self.gridLayout.addWidget(self.txtOutputDir, 1, 1, 1, 1) self.horizontalLayout_2 = QHBoxLayout() self.horizontalLayout_2.setObjectName(u"horizontalLayout_2") self.horizontalSpacer = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) self.horizontalLayout_2.addItem(self.horizontalSpacer) self.btnOk = QPushButton(Dialog) self.btnOk.setObjectName(u"btnOk") self.btnOk.setMaximumSize(QSize(80, 16777215)) self.horizontalLayout_2.addWidget(self.btnOk) self.btnCancel = QPushButton(Dialog) self.btnCancel.setObjectName(u"btnCancel") self.btnCancel.setMaximumSize(QSize(80, 16777215)) self.horizontalLayout_2.addWidget(self.btnCancel) self.gridLayout.addLayout(self.horizontalLayout_2, 2, 0, 1, 3) self.horizontalLayout.addLayout(self.gridLayout) self.retranslateUi(Dialog) QMetaObject.connectSlotsByName(Dialog) # setupUi def retranslateUi(self, Dialog): Dialog.setWindowTitle( QCoreApplication.translate("Dialog", u"Dialog", None)) self.label.setText( QCoreApplication.translate("Dialog", u"\u56fe\u7247", None)) self.label_2.setText( QCoreApplication.translate("Dialog", u"\u8f93\u51fa\u76ee\u5f55", None)) self.tbSelectDir.setText( QCoreApplication.translate("Dialog", u"...", None)) self.tbSelectFiles.setText( QCoreApplication.translate("Dialog", u"...", None)) self.btnOk.setText( QCoreApplication.translate("Dialog", u"\u786e\u5b9a", None)) self.btnCancel.setText( QCoreApplication.translate("Dialog", u"\u53d6\u6d88", None))