From 1d115134634dc9beb19d6281608be6330c5ba976 Mon Sep 17 00:00:00 2001 From: VFX - Visual Effects Date: Thu, 6 May 2021 13:37:23 -0300 Subject: [PATCH] 06/05/2021 --- gui/uis/windows/main_window/__init__.py | 23 +++ .../windows/main_window/setup_main_window.py | 70 ++++++++++ gui/uis/windows/main_window/ui_main.py | 16 ++- gui/widgets/py_grips/py_grips.py | 132 +++++++++++++++--- gui/widgets/py_window/py_window.py | 22 +-- main.py | 22 ++- settings.json | 2 +- 7 files changed, 239 insertions(+), 48 deletions(-) create mode 100644 gui/uis/windows/main_window/__init__.py create mode 100644 gui/uis/windows/main_window/setup_main_window.py diff --git a/gui/uis/windows/main_window/__init__.py b/gui/uis/windows/main_window/__init__.py new file mode 100644 index 0000000..0239ed3 --- /dev/null +++ b/gui/uis/windows/main_window/__init__.py @@ -0,0 +1,23 @@ +# /////////////////////////////////////////////////////////////// +# +# BY: WANDERSON M.PIMENTA +# PROJECT MADE WITH: Qt Designer and PySide6 +# V: 1.0.0 +# +# This project can be used freely for all uses, as long as they maintain the +# respective credits only in the Python scripts, any information in the visual +# interface (GUI) can be modified without any implication. +# +# There are limitations on Qt licenses if you want to use your products +# commercially, I recommend reading them on the official website: +# https://doc.qt.io/qtforpython/licenses.html +# +# /////////////////////////////////////////////////////////////// + +# MAIN WINDOW +# /////////////////////////////////////////////////////////////// +from . ui_main import UI_MainWindow + +# SETUP MAIN WINDOW +# /////////////////////////////////////////////////////////////// +from . setup_main_window import SetupMainWindow \ No newline at end of file diff --git a/gui/uis/windows/main_window/setup_main_window.py b/gui/uis/windows/main_window/setup_main_window.py new file mode 100644 index 0000000..ea99d5e --- /dev/null +++ b/gui/uis/windows/main_window/setup_main_window.py @@ -0,0 +1,70 @@ +# /////////////////////////////////////////////////////////////// +# +# BY: WANDERSON M.PIMENTA +# PROJECT MADE WITH: Qt Designer and PySide6 +# V: 1.0.0 +# +# This project can be used freely for all uses, as long as they maintain the +# respective credits only in the Python scripts, any information in the visual +# interface (GUI) can be modified without any implication. +# +# There are limitations on Qt licenses if you want to use your products +# commercially, I recommend reading them on the official website: +# https://doc.qt.io/qtforpython/licenses.html +# +# /////////////////////////////////////////////////////////////// + +# IMPORT PACKAGES AND MODULES +# /////////////////////////////////////////////////////////////// +import sys + +# IMPORT QT CORE +# /////////////////////////////////////////////////////////////// +from qt_core import * + +# IMPORT SETTINGS +# /////////////////////////////////////////////////////////////// +from gui.core.json_settings import Settings + +# IMPORT THEME COLORS +# /////////////////////////////////////////////////////////////// +from gui.core.json_themes import Themes + +# IMPORT PY ONE DARK WIDGETS +# /////////////////////////////////////////////////////////////// +from gui.widgets import * + +# PY WINDOW +# /////////////////////////////////////////////////////////////// +class SetupMainWindow: + def setup(self): + # REMOVE TITLE BAR + # /////////////////////////////////////////////////////////////// + if self.settings["custom_title_bar"]: + self.setWindowFlag(Qt.FramelessWindowHint) + self.setAttribute(Qt.WA_TranslucentBackground) + + # ADD GRIPS + # /////////////////////////////////////////////////////////////// + if self.settings["custom_title_bar"]: + self.left_grip = PyGrips(self, "left", self.hide_grips) + self.right_grip = PyGrips(self, "right", self.hide_grips) + self.top_grip = PyGrips(self, "top", self.hide_grips) + self.bottom_grip = PyGrips(self, "bottom", self.hide_grips) + self.top_left_grip = PyGrips(self, "top_left", self.hide_grips) + self.top_right_grip = PyGrips(self, "top_right", self.hide_grips) + self.bottom_left_grip = PyGrips(self, "bottom_left", self.hide_grips) + self.bottom_right_grip = PyGrips(self, "bottom_right", self.hide_grips) + + # RESIZE GRIPS AND CHANGE POSITION + # Resize or change position when window is resized + # /////////////////////////////////////////////////////////////// + def resize_grips(self): + if self.settings["custom_title_bar"]: + self.left_grip.setGeometry(5, 10, 10, self.height()) + self.right_grip.setGeometry(self.width() - 15, 10, 10, self.height()) + self.top_grip.setGeometry(5, 5, self.width() - 10, 10) + self.bottom_grip.setGeometry(5, self.height() - 15, self.width() - 10, 10) + self.top_right_grip.setGeometry(self.width() - 20, 5, 15, 15) + self.bottom_left_grip.setGeometry(5, self.height() - 20, 15, 15) + self.bottom_right_grip.setGeometry(self.width() - 20, self.height() - 20, 15, 15) \ No newline at end of file diff --git a/gui/uis/windows/main_window/ui_main.py b/gui/uis/windows/main_window/ui_main.py index 416b801..b7351f4 100644 --- a/gui/uis/windows/main_window/ui_main.py +++ b/gui/uis/windows/main_window/ui_main.py @@ -34,6 +34,10 @@ from gui.core.json_themes import Themes # /////////////////////////////////////////////////////////////// from gui.widgets import * +# IMPORT SETUP MAIN WINDOW +# /////////////////////////////////////////////////////////////// +from . setup_main_window import * + # PY WINDOW # /////////////////////////////////////////////////////////////// class UI_MainWindow(object): @@ -64,12 +68,20 @@ class UI_MainWindow(object): text_color = self.themes["app_color"]["text_foreground"] ) + # If disable custom title bar + if not self.settings["custom_title_bar"]: + self.window.set_stylesheet(border_radius = 0, border_size = 0) + # ADD WIDGETS TO "PyWindow" # Add here your custom widgets or default widgets # /////////////////////////////////////////////////////////////// self.window.layout.addWidget(QLabel(self.settings["app_name"])) self.window.layout.addWidget(QLabel(self.settings["app_name"])) - # ADD CENTRAL WIDGET + # ADD CENTRAL WIDGET AND SET CONTENT MARGINS + # /////////////////////////////////////////////////////////////// parent.setCentralWidget(self.window) - parent.setContentsMargins(10,10,10,10) \ No newline at end of file + if self.settings["custom_title_bar"]: + parent.setContentsMargins(10,10,10,10) + else: + parent.setContentsMargins(0,0,0,0) \ No newline at end of file diff --git a/gui/widgets/py_grips/py_grips.py b/gui/widgets/py_grips/py_grips.py index 6fd9624..fbb465b 100644 --- a/gui/widgets/py_grips/py_grips.py +++ b/gui/widgets/py_grips/py_grips.py @@ -22,19 +22,71 @@ import sys # /////////////////////////////////////////////////////////////// from qt_core import * +# PY GRIPS +# /////////////////////////////////////////////////////////////// class PyGrips(QWidget): def __init__(self, parent, position, disable_color = False): # SETUP UI + # /////////////////////////////////////////////////////////////// QWidget.__init__(self) self.parent = parent self.setParent(parent) self.wi = Widgets() + # SHOW TOP LEFT GRIP + # /////////////////////////////////////////////////////////////// + if position == "top_left": + self.wi.top_left(self) + grip = QSizeGrip(self.wi.top_left_grip) + grip.setFixedSize(self.wi.top_left_grip.size()) + self.setGeometry(5, 5, 15, 15) + + # ENABLE COLOR + if disable_color: + self.wi.top_left_grip.setStyleSheet("background: transparent") + + # SHOW TOP RIGHT GRIP + # /////////////////////////////////////////////////////////////// + if position == "top_right": + self.wi.top_right(self) + grip = QSizeGrip(self.wi.top_right_grip) + grip.setFixedSize(self.wi.top_right_grip.size()) + self.setGeometry(self.parent.width() - 20, 5, 15, 15) + + # ENABLE COLOR + if disable_color: + self.wi.top_right_grip.setStyleSheet("background: transparent") + + # SHOW BOTTOM LEFT GRIP + # /////////////////////////////////////////////////////////////// + if position == "bottom_left": + self.wi.bottom_left(self) + grip = QSizeGrip(self.wi.bottom_left_grip) + grip.setFixedSize(self.wi.bottom_left_grip.size()) + self.setGeometry(5, self.parent.height() - 20, 15, 15) + + # ENABLE COLOR + if disable_color: + self.wi.bottom_left_grip.setStyleSheet("background: transparent") + + # SHOW BOTTOM RIGHT GRIP + # /////////////////////////////////////////////////////////////// + if position == "bottom_right": + self.wi.bottom_right(self) + grip = QSizeGrip(self.wi.bottom_right_grip) + grip.setFixedSize(self.wi.bottom_right_grip.size()) + self.setGeometry(self.parent.width() - 20, self.parent.height() - 20, 15, 15) + + # ENABLE COLOR + if disable_color: + self.wi.bottom_right_grip.setStyleSheet("background: transparent") + # SHOW TOP GRIP - if position == Qt.TopEdge: + # /////////////////////////////////////////////////////////////// + if position == "top": self.wi.top(self) - self.setGeometry(0, 0, self.parent.width(), 10) + self.setGeometry(0, 5, self.parent.width(), 10) self.setMaximumHeight(10) # RESIZE TOP @@ -52,7 +104,8 @@ class PyGrips(QWidget): self.wi.top_grip.setStyleSheet("background: transparent") # SHOW BOTTOM GRIP - elif position == Qt.BottomEdge: + # /////////////////////////////////////////////////////////////// + elif position == "bottom": self.wi.bottom(self) self.setGeometry(0, self.parent.height() - 10, self.parent.width(), 10) self.setMaximumHeight(10) @@ -67,10 +120,11 @@ class PyGrips(QWidget): # ENABLE COLOR if disable_color: - self.wi.bottom.setStyleSheet("background: transparent") + self.wi.bottom_grip.setStyleSheet("background: transparent") # SHOW LEFT GRIP - elif position == Qt.LeftEdge: + # /////////////////////////////////////////////////////////////// + elif position == "left": self.wi.left(self) self.setGeometry(0, 10, 10, self.parent.height()) self.setMaximumWidth(10) @@ -90,7 +144,8 @@ class PyGrips(QWidget): self.wi.left_grip.setStyleSheet("background: transparent") # RESIZE RIGHT - elif position == Qt.RightEdge: + # /////////////////////////////////////////////////////////////// + elif position == "right": self.wi.right(self) self.setGeometry(self.parent.width() - 10, 10, 10, self.parent.height()) self.setMaximumWidth(10) @@ -106,10 +161,13 @@ class PyGrips(QWidget): if disable_color: self.wi.right_grip.setStyleSheet("background: transparent") - + # MOUSE RELEASE + # /////////////////////////////////////////////////////////////// def mouseReleaseEvent(self, event): self.mousePos = None + # RESIZE EVENT + # /////////////////////////////////////////////////////////////// def resizeEvent(self, event): if hasattr(self.wi, 'top_grip'): self.wi.top_grip.setGeometry(0, 0, self.width(), 10) @@ -123,39 +181,67 @@ class PyGrips(QWidget): elif hasattr(self.wi, 'right_grip'): self.wi.right_grip.setGeometry(0, 0, 10, self.height() - 20) + elif hasattr(self.wi, 'top_right_grip'): + self.wi.top_right_grip.setGeometry(self.width() - 15, 0, 15, 15) + + elif hasattr(self.wi, 'bottom_left_grip'): + self.wi.bottom_left_grip.setGeometry(0, self.height() - 15, 15, 15) + + elif hasattr(self.wi, 'bottom_right_grip'): + self.wi.bottom_right_grip.setGeometry(self.width() - 15, self.height() - 15, 15, 15) + + +# GRIP WIDGTES +# /////////////////////////////////////////////////////////////// class Widgets(object): - def top(self, Form): - if not Form.objectName(): - Form.setObjectName(u"Form") - self.top_grip = QFrame(Form) + def top_left(self, form): + self.top_left_grip = QFrame(form) + self.top_left_grip.setObjectName(u"top_left_grip") + self.top_left_grip.setFixedSize(15, 15) + self.top_left_grip.setStyleSheet(u"background-color: #333; border: 2px solid #55FF00;") + + def top_right(self, form): + self.top_right_grip = QFrame(form) + self.top_right_grip.setObjectName(u"top_right_grip") + self.top_right_grip.setFixedSize(15, 15) + self.top_right_grip.setStyleSheet(u"background-color: #333; border: 2px solid #55FF00;") + + def bottom_left(self, form): + self.bottom_left_grip = QFrame(form) + self.bottom_left_grip.setObjectName(u"bottom_left_grip") + self.bottom_left_grip.setFixedSize(15, 15) + self.bottom_left_grip.setStyleSheet(u"background-color: #333; border: 2px solid #55FF00;") + + def bottom_right(self, form): + self.bottom_right_grip = QFrame(form) + self.bottom_right_grip.setObjectName(u"bottom_right_grip") + self.bottom_right_grip.setFixedSize(15, 15) + self.bottom_right_grip.setStyleSheet(u"background-color: #333; border: 2px solid #55FF00;") + + def top(self, form): + self.top_grip = QFrame(form) self.top_grip.setObjectName(u"top_grip") self.top_grip.setGeometry(QRect(0, 0, 500, 10)) self.top_grip.setStyleSheet(u"background-color: rgb(85, 255, 255);") self.top_grip.setCursor(QCursor(Qt.SizeVerCursor)) - def bottom(self, Form): - if not Form.objectName(): - Form.setObjectName(u"Form") - self.bottom_grip = QFrame(Form) + def bottom(self, form): + self.bottom_grip = QFrame(form) self.bottom_grip.setObjectName(u"bottom_grip") self.bottom_grip.setGeometry(QRect(0, 0, 500, 10)) self.bottom_grip.setStyleSheet(u"background-color: rgb(85, 170, 0);") self.bottom_grip.setCursor(QCursor(Qt.SizeVerCursor)) - def left(self, Form): - if not Form.objectName(): - Form.setObjectName(u"Form") - self.left_grip = QFrame(Form) + def left(self, form): + self.left_grip = QFrame(form) self.left_grip.setObjectName(u"left") self.left_grip.setGeometry(QRect(0, 10, 10, 480)) self.left_grip.setMinimumSize(QSize(10, 0)) self.left_grip.setCursor(QCursor(Qt.SizeHorCursor)) self.left_grip.setStyleSheet(u"background-color: rgb(255, 121, 198);") - def right(self, Form): - if not Form.objectName(): - Form.setObjectName(u"Form") - self.right_grip = QFrame(Form) + def right(self, form): + self.right_grip = QFrame(form) self.right_grip.setObjectName(u"right") self.right_grip.setGeometry(QRect(0, 0, 10, 500)) self.right_grip.setMinimumSize(QSize(10, 0)) diff --git a/gui/widgets/py_window/py_window.py b/gui/widgets/py_window/py_window.py index 3792a41..bb2961c 100644 --- a/gui/widgets/py_window/py_window.py +++ b/gui/widgets/py_window/py_window.py @@ -88,16 +88,6 @@ class PyWindow(QFrame): self.layout = QHBoxLayout(self) self.layout.setContentsMargins(margin, margin, margin, margin) - # ADD GRIPS - # /////////////////////////////////////////////////////////////// - if self.settings["custom_title_bar"]: - self.left_grip = PyGrips(parent, Qt.LeftEdge) - self.right_grip = PyGrips(parent, Qt.RightEdge) - self.top_grip = PyGrips(parent, Qt.TopEdge) - self.bottom_grip = PyGrips(parent, Qt.BottomEdge) - # UPDATE WHEN RESIZE - parent.resizeEvent = self._resize_grips - # ADD DROP SHADOW # /////////////////////////////////////////////////////////////// if self.settings["custom_title_bar"]: @@ -121,7 +111,7 @@ class PyWindow(QFrame): text_font = None ): # CHECK BG COLOR - if border_radius != None: internal_bg_color = bg_color + if bg_color != None: internal_bg_color = bg_color else: internal_bg_color = self.bg_color # CHECK BORDER RADIUS @@ -152,14 +142,4 @@ class PyWindow(QFrame): _text_color = internal_text_color, _text_font = internal_text_font )) - - # RESIZE GRIPS AND CHANGE POSITION - # Resize or change position when window is resized - # /////////////////////////////////////////////////////////////// - def _resize_grips(self, event): - if self.settings["custom_title_bar"]: - self.left_grip.setGeometry(0, 10, 10, self.parent.height()) - self.right_grip.setGeometry(self.parent.width() - 10, 10, 10, self.parent.height()) - self.top_grip.setGeometry(0, 0, self.parent.width(), 10) - self.bottom_grip.setGeometry(0, self.parent.height() - 10, self.parent.width(), 10) \ No newline at end of file diff --git a/main.py b/main.py index 1dff801..83189ad 100644 --- a/main.py +++ b/main.py @@ -17,6 +17,7 @@ # IMPORT PACKAGES AND MODULES # /////////////////////////////////////////////////////////////// import sys +import os # IMPORT QT CORE # /////////////////////////////////////////////////////////////// @@ -29,12 +30,16 @@ from gui.core.json_settings import Settings # IMPORT PY ONE DARK WINDOWS # /////////////////////////////////////////////////////////////// # MAIN WINDOW -from gui.uis.windows.main_window.ui_main import UI_MainWindow +from gui.uis.windows.main_window import * # IMPORT PY ONE DARK WIDGETS # /////////////////////////////////////////////////////////////// from gui.widgets import * +# ADJUST QT FONT DPI FOR HIGHT SCALE +# /////////////////////////////////////////////////////////////// +os.environ["QT_FONT_DPI"] = "96" + # MAIN WINDOW # /////////////////////////////////////////////////////////////// class MainWindow(QMainWindow): @@ -46,11 +51,26 @@ class MainWindow(QMainWindow): self.ui = UI_MainWindow() self.ui.setup_ui(self) + # LOAD SETTINGS + # /////////////////////////////////////////////////////////////// + settings = Settings() + self.settings = settings.items + + # SETUP MAIN WINDOW + # /////////////////////////////////////////////////////////////// + self.hide_grips = True # Show/Hide resize grips + SetupMainWindow.setup(self) # SHOW MAIN WINDOW # /////////////////////////////////////////////////////////////// self.show() + # RESIZE EVENT + # /////////////////////////////////////////////////////////////// + def resizeEvent(self, event): + SetupMainWindow.resize_grips(self) + + # SETTINGS WHEN TO START # Set the initial class and also additional parameters of the "QApplication" class # /////////////////////////////////////////////////////////////// diff --git a/settings.json b/settings.json index 3721ec0..cd258c2 100644 --- a/settings.json +++ b/settings.json @@ -1,6 +1,6 @@ { "app_name": "PyOneDark - Modern GUI", - "custom_title_bar": true, + "custom_title_bar": false, "startup_size": [ 1200, 720