From 16f2afec656ab5b35296429a0aed5dbd84bc05f5 Mon Sep 17 00:00:00 2001 From: "xingfu.fu" Date: Sat, 3 Dec 2022 20:41:47 +0800 Subject: [PATCH] feat: make code clear and like python style --- main.py | 146 ++------------------------- modules/__init__.py | 126 +++++++++++++++++++++-- modules/app_functions.py | 29 ++++-- modules/app_settings.py | 2 +- modules/resources_rc.py | 4 + modules/ui_beautify.py | 36 +++++++ modules/ui_functions.py | 135 +++++++++++++++---------- requirements.txt | 1 + widgets/__init__.py | 2 +- widgets/custom_grips/__init__.py | 2 +- widgets/custom_grips/custom_grips.py | 65 +++++++----- 11 files changed, 307 insertions(+), 241 deletions(-) create mode 100644 modules/ui_beautify.py create mode 100644 requirements.txt diff --git a/main.py b/main.py index bb2701fa..6523b74e 100644 --- a/main.py +++ b/main.py @@ -14,151 +14,25 @@ # # /////////////////////////////////////////////////////////////// -import sys import os -import platform +import sys + +from PySide6.QtGui import QIcon +from PySide6.QtWidgets import QApplication # IMPORT / GUI AND MODULES AND WIDGETS # /////////////////////////////////////////////////////////////// -from modules import * -from widgets import * -os.environ["QT_FONT_DPI"] = "96" # FIX Problem for High DPI and Scale above 100% +from modules import App + +os.environ["QT_FONT_DPI"] = "96" # FIX Problem for High DPI and Scale above 100% # SET AS GLOBAL WIDGETS # /////////////////////////////////////////////////////////////// widgets = None -class MainWindow(QMainWindow): - def __init__(self): - QMainWindow.__init__(self) - - # SET AS GLOBAL WIDGETS - # /////////////////////////////////////////////////////////////// - self.ui = Ui_MainWindow() - self.ui.setupUi(self) - global widgets - widgets = self.ui - - # USE CUSTOM TITLE BAR | USE AS "False" FOR MAC OR LINUX - # /////////////////////////////////////////////////////////////// - Settings.ENABLE_CUSTOM_TITLE_BAR = True - - # APP NAME - # /////////////////////////////////////////////////////////////// - title = "PyDracula - Modern GUI" - description = "PyDracula APP - Theme with colors based on Dracula for Python." - # APPLY TEXTS - self.setWindowTitle(title) - widgets.titleRightInfo.setText(description) - - # TOGGLE MENU - # /////////////////////////////////////////////////////////////// - widgets.toggleButton.clicked.connect(lambda: UIFunctions.toggleMenu(self, True)) - - # SET UI DEFINITIONS - # /////////////////////////////////////////////////////////////// - UIFunctions.uiDefinitions(self) - - # QTableWidget PARAMETERS - # /////////////////////////////////////////////////////////////// - widgets.tableWidget.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch) - - # BUTTONS CLICK - # /////////////////////////////////////////////////////////////// - - # LEFT MENUS - widgets.btn_home.clicked.connect(self.buttonClick) - widgets.btn_widgets.clicked.connect(self.buttonClick) - widgets.btn_new.clicked.connect(self.buttonClick) - widgets.btn_save.clicked.connect(self.buttonClick) - - # EXTRA LEFT BOX - def openCloseLeftBox(): - UIFunctions.toggleLeftBox(self, True) - widgets.toggleLeftBox.clicked.connect(openCloseLeftBox) - widgets.extraCloseColumnBtn.clicked.connect(openCloseLeftBox) - - # EXTRA RIGHT BOX - def openCloseRightBox(): - UIFunctions.toggleRightBox(self, True) - widgets.settingsTopBtn.clicked.connect(openCloseRightBox) - - # SHOW APP - # /////////////////////////////////////////////////////////////// - self.show() - - # SET CUSTOM THEME - # /////////////////////////////////////////////////////////////// - useCustomTheme = False - themeFile = "themes\py_dracula_light.qss" - - # SET THEME AND HACKS - if useCustomTheme: - # LOAD AND APPLY STYLE - UIFunctions.theme(self, themeFile, True) - - # SET HACKS - AppFunctions.setThemeHack(self) - - # SET HOME PAGE AND SELECT MENU - # /////////////////////////////////////////////////////////////// - widgets.stackedWidget.setCurrentWidget(widgets.home) - widgets.btn_home.setStyleSheet(UIFunctions.selectMenu(widgets.btn_home.styleSheet())) - - - # BUTTONS CLICK - # Post here your functions for clicked buttons - # /////////////////////////////////////////////////////////////// - def buttonClick(self): - # GET BUTTON CLICKED - btn = self.sender() - btnName = btn.objectName() - - # SHOW HOME PAGE - if btnName == "btn_home": - widgets.stackedWidget.setCurrentWidget(widgets.home) - UIFunctions.resetStyle(self, btnName) - btn.setStyleSheet(UIFunctions.selectMenu(btn.styleSheet())) - - # SHOW WIDGETS PAGE - if btnName == "btn_widgets": - widgets.stackedWidget.setCurrentWidget(widgets.widgets) - UIFunctions.resetStyle(self, btnName) - btn.setStyleSheet(UIFunctions.selectMenu(btn.styleSheet())) - - # SHOW NEW PAGE - if btnName == "btn_new": - widgets.stackedWidget.setCurrentWidget(widgets.new_page) # SET PAGE - UIFunctions.resetStyle(self, btnName) # RESET ANOTHERS BUTTONS SELECTED - btn.setStyleSheet(UIFunctions.selectMenu(btn.styleSheet())) # SELECT MENU - - if btnName == "btn_save": - print("Save BTN clicked!") - - # PRINT BTN NAME - print(f'Button "{btnName}" pressed!') - - - # RESIZE EVENTS - # /////////////////////////////////////////////////////////////// - def resizeEvent(self, event): - # Update Size Grips - UIFunctions.resize_grips(self) - - # MOUSE CLICK EVENTS - # /////////////////////////////////////////////////////////////// - def mousePressEvent(self, event): - # SET DRAG POS WINDOW - self.dragPos = event.globalPos() - - # PRINT MOUSE EVENTS - if event.buttons() == Qt.LeftButton: - print('Mouse click: LEFT CLICK') - if event.buttons() == Qt.RightButton: - print('Mouse click: RIGHT CLICK') - if __name__ == "__main__": app = QApplication(sys.argv) app.setWindowIcon(QIcon("icon.ico")) - window = MainWindow() - sys.exit(app.exec_()) + window = App() + window.launch() + sys.exit(app.exec()) diff --git a/modules/__init__.py b/modules/__init__.py index 79ce35b8..f3057b92 100644 --- a/modules/__init__.py +++ b/modules/__init__.py @@ -13,18 +13,122 @@ # https://doc.qt.io/qtforpython/licenses.html # # /////////////////////////////////////////////////////////////// -from PySide6.QtCore import * -from PySide6.QtGui import * -from PySide6.QtWidgets import * -# GUI FILE -from . ui_main import Ui_MainWindow +from PySide6.QtWidgets import QHeaderView -# APP SETTINGS -from . app_settings import Settings +from modules.app_settings import Settings +from modules.ui_main import Ui_MainWindow +from modules.ui_beautify import UiBeautify +from modules.ui_functions import UIFunctions +from modules.app_functions import AppFunctions -# IMPORT FUNCTIONS -from . ui_functions import * -# APP FUNCTIONS -from . app_functions import * +class App(UiBeautify): + + def __init__(self): + super().__init__() + + def launch(self): + self.setupUi(self) + + # USE CUSTOM TITLE BAR | USE AS "False" FOR MAC OR LINUX + # /////////////////////////////////////////////////////////////// + Settings.ENABLE_CUSTOM_TITLE_BAR = True + + # APP NAME + # /////////////////////////////////////////////////////////////// + title = "PyDracula - Modern GUI" + description = "PyDracula APP - Theme with colors based on Dracula for Python." + + # APPLY TEXTS + self.setWindowTitle(title) + self.titleRightInfo.setText(description) + self.tableWidget.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeMode.Stretch) + self.connect_event() + + # show app ui + self.show() + + # SET CUSTOM THEME + # /////////////////////////////////////////////////////////////// + useCustomTheme = False + themeFile = "themes/py_dracula_light.qss" + + # SET THEME AND HACKS + if useCustomTheme: + # LOAD AND APPLY STYLE + UIFunctions.theme(self, themeFile, True) + + # SET HACKS + AppFunctions.setThemeHack(self) + + # SET HOME PAGE AND SELECT MENU + # /////////////////////////////////////////////////////////////// + self.stackedWidget.setCurrentWidget(self.home) + self.btn_home.setStyleSheet(UIFunctions.selectMenu(self.btn_home.styleSheet())) + + def connect_event(self): + # TOGGLE MENU + # /////////////////////////////////////////////////////////////// + self.toggleButton.clicked.connect(lambda: UIFunctions.ex_toggleMenu(self, True)) + + # SET UI DEFINITIONS + # /////////////////////////////////////////////////////////////// + UIFunctions.uiDefinitions(self) + + # LEFT MENUS + self.btn_home.clicked.connect(self.buttonClick) + self.btn_widgets.clicked.connect(self.buttonClick) + self.btn_new.clicked.connect(self.buttonClick) + self.btn_save.clicked.connect(self.buttonClick) + + # EXTRA LEFT BOX + def openCloseLeftBox(): + UIFunctions.ex_toggleLeftBox(self, True) + + self.toggleLeftBox.clicked.connect(openCloseLeftBox) + self.extraCloseColumnBtn.clicked.connect(openCloseLeftBox) + + # EXTRA RIGHT BOX + def openCloseRightBox(): + UIFunctions.ex_toggleRightBox(self, True) + + self.settingsTopBtn.clicked.connect(openCloseRightBox) + + # RESIZE EVENTS + # /////////////////////////////////////////////////////////////// + def resizeEvent(self, event): + # Update Size Grips + UIFunctions.resize_grips(self) + + # BUTTONS CLICK + # Post here your functions for clicked buttons + # /////////////////////////////////////////////////////////////// + def buttonClick(self): + # GET BUTTON CLICKED + btn = self.sender() + btnName = btn.objectName() + + # SHOW HOME PAGE + if btnName == "btn_home": + self.stackedWidget.setCurrentWidget(self.home) + UIFunctions.resetStyle(self, btnName) + btn.setStyleSheet(UIFunctions.selectMenu(btn.styleSheet())) + + # SHOW WIDGETS PAGE + if btnName == "btn_widgets": + self.stackedWidget.setCurrentWidget(self.widgets) + UIFunctions.resetStyle(self, btnName) + btn.setStyleSheet(UIFunctions.selectMenu(btn.styleSheet())) + + # SHOW NEW PAGE + if btnName == "btn_new": + self.stackedWidget.setCurrentWidget(self.new_page) # SET PAGE + UIFunctions.resetStyle(self, btnName) # RESET ANOTHERS BUTTONS SELECTED + btn.setStyleSheet(UIFunctions.selectMenu(btn.styleSheet())) # SELECT MENU + + if btnName == "btn_save": + print("Save BTN clicked!") + + # PRINT BTN NAME + print(f'Button "{btnName}" pressed!') diff --git a/modules/app_functions.py b/modules/app_functions.py index 95d5e412..82cfe2df 100644 --- a/modules/app_functions.py +++ b/modules/app_functions.py @@ -16,11 +16,16 @@ # MAIN FILE # /////////////////////////////////////////////////////////////// -from main import * +from modules import ( + UiBeautify, + Settings +) + # WITH ACCESS TO MAIN WINDOW WIDGETS # /////////////////////////////////////////////////////////////// -class AppFunctions(MainWindow): +class AppFunctions(UiBeautify): + def setThemeHack(self): Settings.BTN_LEFT_BOX_COLOR = "background-color: #495474;" Settings.BTN_RIGHT_BOX_COLOR = "background-color: #495474;" @@ -30,12 +35,14 @@ def setThemeHack(self): """ # SET MANUAL STYLES - self.ui.lineEdit.setStyleSheet("background-color: #6272a4;") - self.ui.pushButton.setStyleSheet("background-color: #6272a4;") - self.ui.plainTextEdit.setStyleSheet("background-color: #6272a4;") - self.ui.tableWidget.setStyleSheet("QScrollBar:vertical { background: #6272a4; } QScrollBar:horizontal { background: #6272a4; }") - self.ui.scrollArea.setStyleSheet("QScrollBar:vertical { background: #6272a4; } QScrollBar:horizontal { background: #6272a4; }") - self.ui.comboBox.setStyleSheet("background-color: #6272a4;") - self.ui.horizontalScrollBar.setStyleSheet("background-color: #6272a4;") - self.ui.verticalScrollBar.setStyleSheet("background-color: #6272a4;") - self.ui.commandLinkButton.setStyleSheet("color: #ff79c6;") + self.lineEdit.setStyleSheet("background-color: #6272a4;") + self.pushButton.setStyleSheet("background-color: #6272a4;") + self.plainTextEdit.setStyleSheet("background-color: #6272a4;") + self.tableWidget.setStyleSheet( + "QScrollBar:vertical { background: #6272a4; } QScrollBar:horizontal { background: #6272a4; }") + self.scrollArea.setStyleSheet( + "QScrollBar:vertical { background: #6272a4; } QScrollBar:horizontal { background: #6272a4; }") + self.comboBox.setStyleSheet("background-color: #6272a4;") + self.horizontalScrollBar.setStyleSheet("background-color: #6272a4;") + self.verticalScrollBar.setStyleSheet("background-color: #6272a4;") + self.commandLinkButton.setStyleSheet("color: #ff79c6;") diff --git a/modules/app_settings.py b/modules/app_settings.py index 59913892..990dbfb1 100644 --- a/modules/app_settings.py +++ b/modules/app_settings.py @@ -1,4 +1,4 @@ -class Settings(): +class Settings(object): # APP SETTINGS # /////////////////////////////////////////////////////////////// ENABLE_CUSTOM_TITLE_BAR = True diff --git a/modules/resources_rc.py b/modules/resources_rc.py index 4ceb0ec1..24925ff7 100644 --- a/modules/resources_rc.py +++ b/modules/resources_rc.py @@ -5,6 +5,7 @@ from PySide6 import QtCore + qt_resource_data = b"\ \x00\x00\x07b\ \x89\ @@ -34141,10 +34142,13 @@ \x00\x00\x01v+M\xdd\xa0\ " + def qInitResources(): QtCore.qRegisterResourceData(0x03, qt_resource_struct, qt_resource_name, qt_resource_data) + def qCleanupResources(): QtCore.qUnregisterResourceData(0x03, qt_resource_struct, qt_resource_name, qt_resource_data) + qInitResources() diff --git a/modules/ui_beautify.py b/modules/ui_beautify.py new file mode 100644 index 00000000..b37b3d43 --- /dev/null +++ b/modules/ui_beautify.py @@ -0,0 +1,36 @@ +from abc import abstractmethod + +from PySide6.QtCore import ( + Qt +) +from PySide6.QtWidgets import ( + QMainWindow, +) + +from modules import ( + Ui_MainWindow, +) + + +class UiBeautify(Ui_MainWindow, QMainWindow): + + def __init__(self): + super().__init__() + + @abstractmethod + def launch(self): + pass + + @abstractmethod + def connect_event(self): + pass + + def mousePressEvent(self, event): + # SET DRAG POS WINDOW + self.dragPos = event.globalPos() + + # PRINT MOUSE EVENTS + if event.buttons() == Qt.LeftButton: + print('Mouse click: LEFT CLICK') + if event.buttons() == Qt.RightButton: + print('Mouse click: RIGHT CLICK') diff --git a/modules/ui_functions.py b/modules/ui_functions.py index 087b7d42..faeaeb74 100644 --- a/modules/ui_functions.py +++ b/modules/ui_functions.py @@ -13,29 +13,51 @@ # https://doc.qt.io/qtforpython/licenses.html # # /////////////////////////////////////////////////////////////// +from PySide6.QtCore import ( + QPropertyAnimation, + QEasingCurve, + QParallelAnimationGroup, + QTimer, + QEvent, + Qt +) +from PySide6.QtGui import ( + QIcon, + QColor +) +from PySide6.QtWidgets import ( + QPushButton, + QGraphicsDropShadowEffect, + QSizeGrip +) # MAIN FILE # /////////////////////////////////////////////////////////////// -from main import * +from modules import ( + UiBeautify, + Settings +) +from widgets.custom_grips import CustomGrip # GLOBALS # /////////////////////////////////////////////////////////////// GLOBAL_STATE = False GLOBAL_TITLE_BAR = True -class UIFunctions(MainWindow): + +class UIFunctions(UiBeautify): # MAXIMIZE/RESTORE # /////////////////////////////////////////////////////////////// def maximize_restore(self): global GLOBAL_STATE status = GLOBAL_STATE - if status == False: + if not status: self.showMaximized() GLOBAL_STATE = True - self.ui.appMargins.setContentsMargins(0, 0, 0, 0) - self.ui.maximizeRestoreAppBtn.setToolTip("Restore") - self.ui.maximizeRestoreAppBtn.setIcon(QIcon(u":/icons/images/icons/icon_restore.png")) - self.ui.frame_size_grip.hide() + self.appMargins.setContentsMargins(0, 0, 0, 0) + self.maximizeRestoreAppBtn.setToolTip("Restore") + self.maximizeRestoreAppBtn.setIcon(QIcon(u":/icons/images/icons/icon_restore.png")) + self.frame_size_grip.hide() self.left_grip.hide() self.right_grip.hide() self.top_grip.hide() @@ -43,11 +65,11 @@ def maximize_restore(self): else: GLOBAL_STATE = False self.showNormal() - self.resize(self.width()+1, self.height()+1) - self.ui.appMargins.setContentsMargins(10, 10, 10, 10) - self.ui.maximizeRestoreAppBtn.setToolTip("Maximize") - self.ui.maximizeRestoreAppBtn.setIcon(QIcon(u":/icons/images/icons/icon_maximize.png")) - self.ui.frame_size_grip.show() + self.resize(self.width() + 1, self.height() + 1) + self.appMargins.setContentsMargins(10, 10, 10, 10) + self.maximizeRestoreAppBtn.setToolTip("Maximize") + self.maximizeRestoreAppBtn.setIcon(QIcon(u":/icons/images/icons/icon_maximize.png")) + self.frame_size_grip.show() self.left_grip.show() self.right_grip.show() self.top_grip.show() @@ -66,10 +88,10 @@ def setStatus(self, status): # TOGGLE MENU # /////////////////////////////////////////////////////////////// - def toggleMenu(self, enable): + def ex_toggleMenu(self, enable): if enable: # GET WIDTH - width = self.ui.leftMenuBg.width() + width = self.leftMenuBg.width() maxExtend = Settings.MENU_WIDTH standard = 60 @@ -80,7 +102,7 @@ def toggleMenu(self, enable): widthExtended = standard # ANIMATION - self.animation = QPropertyAnimation(self.ui.leftMenuBg, b"minimumWidth") + self.animation = QPropertyAnimation(self.leftMenuBg, b"minimumWidth") self.animation.setDuration(Settings.TIME_ANIMATION) self.animation.setStartValue(width) self.animation.setEndValue(widthExtended) @@ -89,65 +111,65 @@ def toggleMenu(self, enable): # TOGGLE LEFT BOX # /////////////////////////////////////////////////////////////// - def toggleLeftBox(self, enable): + def ex_toggleLeftBox(self, enable): if enable: # GET WIDTH - width = self.ui.extraLeftBox.width() - widthRightBox = self.ui.extraRightBox.width() + width = self.extraLeftBox.width() + widthRightBox = self.extraRightBox.width() maxExtend = Settings.LEFT_BOX_WIDTH color = Settings.BTN_LEFT_BOX_COLOR standard = 0 # GET BTN STYLE - style = self.ui.toggleLeftBox.styleSheet() + style = self.toggleLeftBox.styleSheet() # SET MAX WIDTH if width == 0: widthExtended = maxExtend # SELECT BTN - self.ui.toggleLeftBox.setStyleSheet(style + color) + self.toggleLeftBox.setStyleSheet(style + color) if widthRightBox != 0: - style = self.ui.settingsTopBtn.styleSheet() - self.ui.settingsTopBtn.setStyleSheet(style.replace(Settings.BTN_RIGHT_BOX_COLOR, '')) + style = self.settingsTopBtn.styleSheet() + self.settingsTopBtn.setStyleSheet(style.replace(Settings.BTN_RIGHT_BOX_COLOR, '')) else: widthExtended = standard # RESET BTN - self.ui.toggleLeftBox.setStyleSheet(style.replace(color, '')) - - UIFunctions.start_box_animation(self, width, widthRightBox, "left") + self.toggleLeftBox.setStyleSheet(style.replace(color, '')) + + UIFunctions.start_box_animation(self, width, widthRightBox, "left") # TOGGLE RIGHT BOX # /////////////////////////////////////////////////////////////// - def toggleRightBox(self, enable): + def ex_toggleRightBox(self, enable): if enable: # GET WIDTH - width = self.ui.extraRightBox.width() - widthLeftBox = self.ui.extraLeftBox.width() + width = self.extraRightBox.width() + widthLeftBox = self.extraLeftBox.width() maxExtend = Settings.RIGHT_BOX_WIDTH color = Settings.BTN_RIGHT_BOX_COLOR standard = 0 # GET BTN STYLE - style = self.ui.settingsTopBtn.styleSheet() + style = self.settingsTopBtn.styleSheet() # SET MAX WIDTH if width == 0: widthExtended = maxExtend # SELECT BTN - self.ui.settingsTopBtn.setStyleSheet(style + color) + self.settingsTopBtn.setStyleSheet(style + color) if widthLeftBox != 0: - style = self.ui.toggleLeftBox.styleSheet() - self.ui.toggleLeftBox.setStyleSheet(style.replace(Settings.BTN_LEFT_BOX_COLOR, '')) + style = self.toggleLeftBox.styleSheet() + self.toggleLeftBox.setStyleSheet(style.replace(Settings.BTN_LEFT_BOX_COLOR, '')) else: widthExtended = standard # RESET BTN - self.ui.settingsTopBtn.setStyleSheet(style.replace(color, '')) + self.settingsTopBtn.setStyleSheet(style.replace(color, '')) UIFunctions.start_box_animation(self, widthLeftBox, width, "right") def start_box_animation(self, left_box_width, right_box_width, direction): right_width = 0 - left_width = 0 + left_width = 0 # Check values if left_box_width == 0 and direction == "left": @@ -158,17 +180,17 @@ def start_box_animation(self, left_box_width, right_box_width, direction): if right_box_width == 0 and direction == "right": right_width = 240 else: - right_width = 0 + right_width = 0 - # ANIMATION LEFT BOX - self.left_box = QPropertyAnimation(self.ui.extraLeftBox, b"minimumWidth") + # ANIMATION LEFT BOX + self.left_box = QPropertyAnimation(self.extraLeftBox, b"minimumWidth") self.left_box.setDuration(Settings.TIME_ANIMATION) self.left_box.setStartValue(left_box_width) self.left_box.setEndValue(left_width) self.left_box.setEasingCurve(QEasingCurve.InOutQuart) # ANIMATION RIGHT BOX - self.right_box = QPropertyAnimation(self.ui.extraRightBox, b"minimumWidth") + self.right_box = QPropertyAnimation(self.extraRightBox, b"minimumWidth") self.right_box.setDuration(Settings.TIME_ANIMATION) self.right_box.setStartValue(right_box_width) self.right_box.setEndValue(right_width) @@ -183,24 +205,26 @@ def start_box_animation(self, left_box_width, right_box_width, direction): # SELECT/DESELECT MENU # /////////////////////////////////////////////////////////////// # SELECT + @staticmethod def selectMenu(getStyle): select = getStyle + Settings.MENU_SELECTED_STYLESHEET return select # DESELECT + @staticmethod def deselectMenu(getStyle): deselect = getStyle.replace(Settings.MENU_SELECTED_STYLESHEET, "") return deselect # START SELECTION def selectStandardMenu(self, widget): - for w in self.ui.topMenu.findChildren(QPushButton): + for w in self.topMenu.findChildren(QPushButton): if w.objectName() == widget: w.setStyleSheet(UIFunctions.selectMenu(w.styleSheet())) # RESET SELECTION def resetStyle(self, widget): - for w in self.ui.topMenu.findChildren(QPushButton): + for w in self.topMenu.findChildren(QPushButton): if w.objectName() != widget: w.setStyleSheet(UIFunctions.deselectMenu(w.styleSheet())) @@ -209,7 +233,7 @@ def resetStyle(self, widget): def theme(self, file, useCustomTheme): if useCustomTheme: str = open(file, 'r').read() - self.ui.styleSheet.setStyleSheet(str) + self.styleSheet.setStyleSheet(str) # START - GUI DEFINITIONS # /////////////////////////////////////////////////////////////// @@ -218,10 +242,11 @@ def dobleClickMaximizeRestore(event): # IF DOUBLE CLICK CHANGE STATUS if event.type() == QEvent.MouseButtonDblClick: QTimer.singleShot(250, lambda: UIFunctions.maximize_restore(self)) - self.ui.titleRightInfo.mouseDoubleClickEvent = dobleClickMaximizeRestore + + self.titleRightInfo.mouseDoubleClickEvent = dobleClickMaximizeRestore if Settings.ENABLE_CUSTOM_TITLE_BAR: - #STANDARD TITLE BAR + # STANDARD TITLE BAR self.setWindowFlags(Qt.FramelessWindowHint) self.setAttribute(Qt.WA_TranslucentBackground) @@ -235,20 +260,20 @@ def moveWindow(event): self.move(self.pos() + event.globalPos() - self.dragPos) self.dragPos = event.globalPos() event.accept() - self.ui.titleRightInfo.mouseMoveEvent = moveWindow + + self.titleRightInfo.mouseMoveEvent = moveWindow # CUSTOM GRIPS self.left_grip = CustomGrip(self, Qt.LeftEdge, True) self.right_grip = CustomGrip(self, Qt.RightEdge, True) self.top_grip = CustomGrip(self, Qt.TopEdge, True) self.bottom_grip = CustomGrip(self, Qt.BottomEdge, True) - else: - self.ui.appMargins.setContentsMargins(0, 0, 0, 0) - self.ui.minimizeAppBtn.hide() - self.ui.maximizeRestoreAppBtn.hide() - self.ui.closeAppBtn.hide() - self.ui.frame_size_grip.hide() + self.appMargins.setContentsMargins(0, 0, 0, 0) + self.minimizeAppBtn.hide() + self.maximizeRestoreAppBtn.hide() + self.closeAppBtn.hide() + self.frame_size_grip.hide() # DROP SHADOW self.shadow = QGraphicsDropShadowEffect(self) @@ -256,20 +281,20 @@ def moveWindow(event): self.shadow.setXOffset(0) self.shadow.setYOffset(0) self.shadow.setColor(QColor(0, 0, 0, 150)) - self.ui.bgApp.setGraphicsEffect(self.shadow) + self.bgApp.setGraphicsEffect(self.shadow) # RESIZE WINDOW - self.sizegrip = QSizeGrip(self.ui.frame_size_grip) + self.sizegrip = QSizeGrip(self.frame_size_grip) self.sizegrip.setStyleSheet("width: 20px; height: 20px; margin 0px; padding: 0px;") # MINIMIZE - self.ui.minimizeAppBtn.clicked.connect(lambda: self.showMinimized()) + self.minimizeAppBtn.clicked.connect(lambda: self.showMinimized()) # MAXIMIZE/RESTORE - self.ui.maximizeRestoreAppBtn.clicked.connect(lambda: UIFunctions.maximize_restore(self)) + self.maximizeRestoreAppBtn.clicked.connect(lambda: UIFunctions.maximize_restore(self)) # CLOSE APPLICATION - self.ui.closeAppBtn.clicked.connect(lambda: self.close()) + self.closeAppBtn.clicked.connect(lambda: self.close()) def resize_grips(self): if Settings.ENABLE_CUSTOM_TITLE_BAR: diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 00000000..804be7c2 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +pyside6~=6.4.1 \ No newline at end of file diff --git a/widgets/__init__.py b/widgets/__init__.py index edc45ae1..d85d04ea 100644 --- a/widgets/__init__.py +++ b/widgets/__init__.py @@ -14,4 +14,4 @@ # # /////////////////////////////////////////////////////////////// -from . custom_grips import CustomGrip +from widgets.custom_grips import CustomGrip diff --git a/widgets/custom_grips/__init__.py b/widgets/custom_grips/__init__.py index edc45ae1..37837b26 100644 --- a/widgets/custom_grips/__init__.py +++ b/widgets/custom_grips/__init__.py @@ -14,4 +14,4 @@ # # /////////////////////////////////////////////////////////////// -from . custom_grips import CustomGrip +from widgets.custom_grips.custom_grips import CustomGrip diff --git a/widgets/custom_grips/custom_grips.py b/widgets/custom_grips/custom_grips.py index 53a15a1d..053f592e 100644 --- a/widgets/custom_grips/custom_grips.py +++ b/widgets/custom_grips/custom_grips.py @@ -14,12 +14,23 @@ # # /////////////////////////////////////////////////////////////// -from PySide6.QtCore import * -from PySide6.QtGui import * -from PySide6.QtWidgets import * +from PySide6.QtCore import ( + Qt, + QRect, + QSize +) +from PySide6.QtGui import QCursor + +from PySide6.QtWidgets import ( + QWidget, + QSizeGrip, + QFrame, + QHBoxLayout +) + class CustomGrip(QWidget): - def __init__(self, parent, position, disable_color = False): + def __init__(self, parent, position, disable_color=False): # SETUP UI QWidget.__init__(self) @@ -45,6 +56,7 @@ def resize_top(event): geo.setTop(geo.bottom() - height) self.parent.setGeometry(geo) event.accept() + self.wi.top.mouseMoveEvent = resize_top # ENABLE COLOR @@ -69,6 +81,7 @@ def resize_bottom(event): height = max(self.parent.minimumHeight(), self.parent.height() + delta.y()) self.parent.resize(self.parent.width(), height) event.accept() + self.wi.bottom.mouseMoveEvent = resize_bottom # ENABLE COLOR @@ -91,6 +104,7 @@ def resize_left(event): geo.setLeft(geo.right() - width) self.parent.setGeometry(geo) event.accept() + self.wi.leftgrip.mouseMoveEvent = resize_left # ENABLE COLOR @@ -108,13 +122,13 @@ def resize_right(event): width = max(self.parent.minimumWidth(), self.parent.width() + delta.x()) self.parent.resize(width, self.parent.height()) event.accept() + self.wi.rightgrip.mouseMoveEvent = resize_right # ENABLE COLOR if disable_color: self.wi.rightgrip.setStyleSheet("background: transparent") - def mouseReleaseEvent(self, event): self.mousePos = None @@ -131,6 +145,7 @@ def resizeEvent(self, event): elif hasattr(self.wi, 'rightgrip'): self.wi.rightgrip.setGeometry(0, 0, 10, self.height() - 20) + class Widgets(object): def top(self, Form): if not Form.objectName(): @@ -140,8 +155,8 @@ def top(self, Form): self.container_top.setGeometry(QRect(0, 0, 500, 10)) self.container_top.setMinimumSize(QSize(0, 10)) self.container_top.setMaximumSize(QSize(16777215, 10)) - self.container_top.setFrameShape(QFrame.NoFrame) - self.container_top.setFrameShadow(QFrame.Raised) + self.container_top.setFrameShape(QFrame.Shape.NoFrame) + self.container_top.setFrameShadow(QFrame.Shadow.Raised) self.top_layout = QHBoxLayout(self.container_top) self.top_layout.setSpacing(0) self.top_layout.setObjectName(u"top_layout") @@ -152,15 +167,15 @@ def top(self, Form): self.top_left.setMaximumSize(QSize(10, 10)) self.top_left.setCursor(QCursor(Qt.SizeFDiagCursor)) self.top_left.setStyleSheet(u"background-color: rgb(33, 37, 43);") - self.top_left.setFrameShape(QFrame.NoFrame) - self.top_left.setFrameShadow(QFrame.Raised) + self.top_left.setFrameShape(QFrame.Shape.NoFrame) + self.top_left.setFrameShadow(QFrame.Shadow.Raised) self.top_layout.addWidget(self.top_left) self.top = QFrame(self.container_top) self.top.setObjectName(u"top") self.top.setCursor(QCursor(Qt.SizeVerCursor)) self.top.setStyleSheet(u"background-color: rgb(85, 255, 255);") - self.top.setFrameShape(QFrame.NoFrame) - self.top.setFrameShadow(QFrame.Raised) + self.top.setFrameShape(QFrame.Shape.NoFrame) + self.top.setFrameShadow(QFrame.Shadow.Raised) self.top_layout.addWidget(self.top) self.top_right = QFrame(self.container_top) self.top_right.setObjectName(u"top_right") @@ -168,8 +183,8 @@ def top(self, Form): self.top_right.setMaximumSize(QSize(10, 10)) self.top_right.setCursor(QCursor(Qt.SizeBDiagCursor)) self.top_right.setStyleSheet(u"background-color: rgb(33, 37, 43);") - self.top_right.setFrameShape(QFrame.NoFrame) - self.top_right.setFrameShadow(QFrame.Raised) + self.top_right.setFrameShape(QFrame.Shape.NoFrame) + self.top_right.setFrameShadow(QFrame.Shadow.Raised) self.top_layout.addWidget(self.top_right) def bottom(self, Form): @@ -180,8 +195,8 @@ def bottom(self, Form): self.container_bottom.setGeometry(QRect(0, 0, 500, 10)) self.container_bottom.setMinimumSize(QSize(0, 10)) self.container_bottom.setMaximumSize(QSize(16777215, 10)) - self.container_bottom.setFrameShape(QFrame.NoFrame) - self.container_bottom.setFrameShadow(QFrame.Raised) + self.container_bottom.setFrameShape(QFrame.Shape.NoFrame) + self.container_bottom.setFrameShadow(QFrame.Shadow.Raised) self.bottom_layout = QHBoxLayout(self.container_bottom) self.bottom_layout.setSpacing(0) self.bottom_layout.setObjectName(u"bottom_layout") @@ -192,15 +207,15 @@ def bottom(self, Form): self.bottom_left.setMaximumSize(QSize(10, 10)) self.bottom_left.setCursor(QCursor(Qt.SizeBDiagCursor)) self.bottom_left.setStyleSheet(u"background-color: rgb(33, 37, 43);") - self.bottom_left.setFrameShape(QFrame.NoFrame) - self.bottom_left.setFrameShadow(QFrame.Raised) + self.bottom_left.setFrameShape(QFrame.Shape.NoFrame) + self.bottom_left.setFrameShadow(QFrame.Shadow.Raised) self.bottom_layout.addWidget(self.bottom_left) self.bottom = QFrame(self.container_bottom) self.bottom.setObjectName(u"bottom") self.bottom.setCursor(QCursor(Qt.SizeVerCursor)) self.bottom.setStyleSheet(u"background-color: rgb(85, 170, 0);") - self.bottom.setFrameShape(QFrame.NoFrame) - self.bottom.setFrameShadow(QFrame.Raised) + self.bottom.setFrameShape(QFrame.Shape.NoFrame) + self.bottom.setFrameShadow(QFrame.Shadow.Raised) self.bottom_layout.addWidget(self.bottom) self.bottom_right = QFrame(self.container_bottom) self.bottom_right.setObjectName(u"bottom_right") @@ -208,8 +223,8 @@ def bottom(self, Form): self.bottom_right.setMaximumSize(QSize(10, 10)) self.bottom_right.setCursor(QCursor(Qt.SizeFDiagCursor)) self.bottom_right.setStyleSheet(u"background-color: rgb(33, 37, 43);") - self.bottom_right.setFrameShape(QFrame.NoFrame) - self.bottom_right.setFrameShadow(QFrame.Raised) + self.bottom_right.setFrameShape(QFrame.Shape.NoFrame) + self.bottom_right.setFrameShadow(QFrame.Shadow.Raised) self.bottom_layout.addWidget(self.bottom_right) def left(self, Form): @@ -221,8 +236,8 @@ def left(self, Form): self.leftgrip.setMinimumSize(QSize(10, 0)) self.leftgrip.setCursor(QCursor(Qt.SizeHorCursor)) self.leftgrip.setStyleSheet(u"background-color: rgb(255, 121, 198);") - self.leftgrip.setFrameShape(QFrame.NoFrame) - self.leftgrip.setFrameShadow(QFrame.Raised) + self.leftgrip.setFrameShape(QFrame.Shape.NoFrame) + self.leftgrip.setFrameShadow(QFrame.Shadow.Raised) def right(self, Form): if not Form.objectName(): @@ -234,5 +249,5 @@ def right(self, Form): self.rightgrip.setMinimumSize(QSize(10, 0)) self.rightgrip.setCursor(QCursor(Qt.SizeHorCursor)) self.rightgrip.setStyleSheet(u"background-color: rgb(255, 0, 127);") - self.rightgrip.setFrameShape(QFrame.NoFrame) - self.rightgrip.setFrameShadow(QFrame.Raised) + self.rightgrip.setFrameShape(QFrame.Shape.NoFrame) + self.rightgrip.setFrameShadow(QFrame.Shadow.Raised)