mirror of
https://github.com/Wanderson-Magalhaes/PyOneDark_Qt_Widgets_Modern_GUI.git
synced 2026-02-17 07:53:57 +00:00
01/06/2021
This commit is contained in:
@@ -27,14 +27,119 @@ from qt_core import *
|
||||
from . ui_main import *
|
||||
|
||||
# FUNCTIONS
|
||||
class FunctionsMain():
|
||||
class MainFunctions():
|
||||
def __init__(self):
|
||||
super(FunctionsMain, self).__init__()
|
||||
super().__init__()
|
||||
# SETUP MAIN WINDOw
|
||||
# Load widgets from "gui\uis\main_window\ui_main.py"
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
self.ui = UI_MainWindow()
|
||||
self.ui.setup_ui(self)
|
||||
|
||||
# SET MAIN WINDOW PAGES
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
def set_page(self, page):
|
||||
self.ui.load_pages.pages.setCurrentWidget(page)
|
||||
|
||||
# SET LEFT COLUMN PAGES
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
def set_left_column_menu(
|
||||
self,
|
||||
menu,
|
||||
title,
|
||||
icon_path
|
||||
):
|
||||
self.ui.left_column.menus.pages.setCurrentWidget(menu)
|
||||
self.ui.left_column.title_label.setText(title)
|
||||
self.ui.left_column.icon.load(icon_path)
|
||||
|
||||
# RETURN IF LEFT COLUMN IS VISIBLE
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
def left_column_is_visible(self):
|
||||
width = self.ui.left_column_frame.width()
|
||||
if width == 0:
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
# RETURN IF RIGHT COLUMN IS VISIBLE
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
def right_column_is_visible(self):
|
||||
width = self.ui.right_column_frame.width()
|
||||
if width == 0:
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
# SET RIGHT COLUMN PAGES
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
def set_right_column_menu(self, menu):
|
||||
self.ui.right_column.pages.setCurrentWidget(menu)
|
||||
|
||||
# GET TITLE BUTTON BY OBJECT NAME
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
def get_title_bar_btn(self, object_name):
|
||||
return self.ui.title_bar_frame.findChild(QPushButton, object_name)
|
||||
|
||||
# GET TITLE BUTTON BY OBJECT NAME
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
def get_left_menu_btn(self, object_name):
|
||||
return self.ui.left_menu.findChild(QPushButton, object_name)
|
||||
|
||||
# LEDT AND RIGHT COLUMNS / SHOW / HIDE
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
def toggle_left_column(self):
|
||||
# GET ACTUAL CLUMNS SIZE
|
||||
width = self.ui.left_column_frame.width()
|
||||
right_column_width = self.ui.right_column_frame.width()
|
||||
|
||||
MainFunctions.start_box_animation(self, width, right_column_width, "left")
|
||||
|
||||
def toggle_right_column(self):
|
||||
# GET ACTUAL CLUMNS SIZE
|
||||
left_column_width = self.ui.left_column_frame.width()
|
||||
width = self.ui.right_column_frame.width()
|
||||
|
||||
MainFunctions.start_box_animation(self, left_column_width, width, "right")
|
||||
|
||||
def start_box_animation(self, left_box_width, right_box_width, direction):
|
||||
right_width = 0
|
||||
left_width = 0
|
||||
time_animation = self.ui.settings["time_animation"]
|
||||
minimum_left = self.ui.settings["left_column_size"]["minimum"]
|
||||
maximum_left = self.ui.settings["left_column_size"]["maximum"]
|
||||
minimum_right = self.ui.settings["right_column_size"]["minimum"]
|
||||
maximum_right = self.ui.settings["right_column_size"]["maximum"]
|
||||
|
||||
# Check Left Values
|
||||
if left_box_width == minimum_left and direction == "left":
|
||||
left_width = maximum_left
|
||||
else:
|
||||
left_width = minimum_left
|
||||
|
||||
# Check Right values
|
||||
if right_box_width == minimum_right and direction == "right":
|
||||
right_width = maximum_right
|
||||
else:
|
||||
right_width = minimum_right
|
||||
|
||||
# ANIMATION LEFT BOX
|
||||
self.left_box = QPropertyAnimation(self.ui.left_column_frame, b"minimumWidth")
|
||||
self.left_box.setDuration(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.right_column_frame, b"minimumWidth")
|
||||
self.right_box.setDuration(time_animation)
|
||||
self.right_box.setStartValue(right_box_width)
|
||||
self.right_box.setEndValue(right_width)
|
||||
self.right_box.setEasingCurve(QEasingCurve.InOutQuart)
|
||||
|
||||
# GROUP ANIMATION
|
||||
self.group = QParallelAnimationGroup()
|
||||
self.group.stop()
|
||||
self.group.addAnimation(self.left_box)
|
||||
self.group.addAnimation(self.right_box)
|
||||
self.group.start()
|
||||
@@ -34,9 +34,20 @@ from gui.core.json_themes import Themes
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
from gui.widgets import *
|
||||
|
||||
# LOAD UI MAIN
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
from . ui_main import *
|
||||
|
||||
# PY WINDOW
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
class SetupMainWindow:
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
# SETUP MAIN WINDOw
|
||||
# Load widgets from "gui\uis\main_window\ui_main.py"
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
self.ui = UI_MainWindow()
|
||||
self.ui.setup_ui(self)
|
||||
|
||||
# ADD LEFT MENUS
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
@@ -112,7 +123,7 @@ class SetupMainWindow:
|
||||
"btn_icon" : "icon_settings.svg",
|
||||
"btn_id" : "btn_top_settings",
|
||||
"btn_tooltip" : "Top settings",
|
||||
"is_active" : True
|
||||
"is_active" : False
|
||||
}
|
||||
]
|
||||
|
||||
@@ -124,10 +135,12 @@ class SetupMainWindow:
|
||||
return self.ui.title_bar.sender()
|
||||
elif self.ui.left_menu.sender() != None:
|
||||
return self.ui.left_menu.sender()
|
||||
elif self.ui.left_column.sender() != None:
|
||||
return self.ui.left_column.sender()
|
||||
|
||||
# SETUP MAIN WINDOW WITH CUSTOM PARAMETERS
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
def setup(self):
|
||||
def setup_gui(self):
|
||||
# APP TITLE
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
self.setWindowTitle(self.settings["app_name"])
|
||||
|
||||
@@ -140,10 +140,9 @@ class UI_MainWindow(object):
|
||||
# ADD LEFT COLUMN
|
||||
# Add here the left column with Stacked Widgets
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
left_column_minimum = self.settings["left_column_size"]["minimum"]
|
||||
self.left_column_frame = QFrame()
|
||||
self.left_column_frame.setMaximumSize(left_column_minimum, 17280)
|
||||
self.left_column_frame.setMinimumSize(left_column_minimum, 0)
|
||||
self.left_column_frame.setMaximumWidth(self.settings["left_column_size"]["minimum"])
|
||||
self.left_column_frame.setMinimumWidth(self.settings["left_column_size"]["minimum"])
|
||||
self.left_column_frame.setStyleSheet(f"background: {self.themes['app_color']['bg_two']}")
|
||||
|
||||
# ADD LAYOUT TO LEFT COLUMN
|
||||
@@ -230,13 +229,13 @@ class UI_MainWindow(object):
|
||||
self.load_pages.setupUi(self.content_area_left_frame)
|
||||
|
||||
# RIGHT BAR
|
||||
self.content_area_right_frame = QFrame()
|
||||
self.content_area_right_frame.setMinimumWidth(self.settings["right_column_size"]["minimum"])
|
||||
self.content_area_right_frame.setMaximumWidth(self.settings["right_column_size"]["maximum"])
|
||||
self.right_column_frame = QFrame()
|
||||
self.right_column_frame.setMinimumWidth(self.settings["right_column_size"]["minimum"])
|
||||
self.right_column_frame.setMaximumWidth(self.settings["right_column_size"]["minimum"])
|
||||
|
||||
# IMPORT RIGHT COLUMN
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
self.content_area_right_layout = QVBoxLayout(self.content_area_right_frame)
|
||||
self.content_area_right_layout = QVBoxLayout(self.right_column_frame)
|
||||
self.content_area_right_layout.setContentsMargins(5,5,5,5)
|
||||
self.content_area_right_layout.setSpacing(0)
|
||||
|
||||
@@ -259,7 +258,7 @@ class UI_MainWindow(object):
|
||||
|
||||
# ADD TO LAYOUTS
|
||||
self.content_area_layout.addWidget(self.content_area_left_frame)
|
||||
self.content_area_layout.addWidget(self.content_area_right_frame)
|
||||
self.content_area_layout.addWidget(self.right_column_frame)
|
||||
|
||||
# CREDITS / BOTTOM APP FRAME
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -27,6 +27,10 @@ from . py_left_button import *
|
||||
from gui.uis.columns.ui_left_column import Ui_LeftColumn
|
||||
|
||||
class PyLeftColumn(QWidget):
|
||||
# SIGNALS
|
||||
clicked = Signal(object)
|
||||
released = Signal(object)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
parent,
|
||||
@@ -70,9 +74,23 @@ class PyLeftColumn(QWidget):
|
||||
self.setup_ui()
|
||||
|
||||
# ADD LEFT COLUMN TO BG FRAME
|
||||
self.left_column = Ui_LeftColumn()
|
||||
self.left_column.setupUi(self.content_frame)
|
||||
self.menus = Ui_LeftColumn()
|
||||
self.menus.setupUi(self.content_frame)
|
||||
|
||||
# CONNECT SIGNALS
|
||||
self.btn_close.clicked.connect(self.btn_clicked)
|
||||
self.btn_close.released.connect(self.btn_released)
|
||||
|
||||
# TITLE LEFT COLUMN EMIT SIGNALS
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
def btn_clicked(self):
|
||||
self.clicked.emit(self.btn_close)
|
||||
|
||||
def btn_released(self):
|
||||
self.released.emit(self.btn_close)
|
||||
|
||||
# WIDGETS
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
def setup_ui(self):
|
||||
# BASE LAYOUT
|
||||
self.base_layout = QVBoxLayout(self)
|
||||
@@ -148,7 +166,7 @@ class PyLeftColumn(QWidget):
|
||||
radius = 6,
|
||||
)
|
||||
self.btn_close.setParent(self.btn_frame)
|
||||
|
||||
self.btn_close.setObjectName("btn_close_left_column")
|
||||
|
||||
# ADD TO TITLE LAYOUT
|
||||
self.title_bg_layout.addWidget(self.icon_frame)
|
||||
|
||||
@@ -235,7 +235,7 @@ class PyLeftMenu(QWidget):
|
||||
|
||||
# BOTTOM LAYOUT
|
||||
self.bottom_layout = QVBoxLayout(self.bottom_frame)
|
||||
self.bottom_layout.setContentsMargins(0,0,0,0)
|
||||
self.bottom_layout.setContentsMargins(0,0,0,8)
|
||||
self.bottom_layout.setSpacing(1)
|
||||
|
||||
# ADD TOP AND BOTTOM FRAME
|
||||
|
||||
84
main.py
84
main.py
@@ -61,7 +61,7 @@ class MainWindow(QMainWindow):
|
||||
# SETUP MAIN WINDOW
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
self.hide_grips = True # Show/Hide resize grips
|
||||
SetupMainWindow.setup(self)
|
||||
SetupMainWindow.setup_gui(self)
|
||||
|
||||
# LEFT MENUS / GET SIGNALS WHEN LEFT MENU BTN IS CLICKED / RELEASED
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
@@ -87,9 +87,21 @@ class MainWindow(QMainWindow):
|
||||
else:
|
||||
self.ui.title_bar.set_title("Welcome to PyOneDark")
|
||||
|
||||
# SET INITIAL PAGE
|
||||
# LEFT COLUMN SET SIGNALS
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
FunctionsMain.set_page(self, self.ui.load_pages.page_1)
|
||||
self.ui.left_column.clicked.connect(self.btn_clicked)
|
||||
self.ui.left_column.released.connect(self.btn_released)
|
||||
|
||||
# SET INITIAL PAGE / SET LEFT AND RIGHT COLUMN MENUS
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
MainFunctions.set_page(self, self.ui.load_pages.page_1)
|
||||
MainFunctions.set_left_column_menu(
|
||||
self,
|
||||
menu = self.ui.left_column.menus.menu_1,
|
||||
title = "Settings Left Column",
|
||||
icon_path = Functions.set_svg_icon("icon_settings.svg")
|
||||
)
|
||||
MainFunctions.set_right_column_menu(self, self.ui.right_column.menu_1)
|
||||
|
||||
# SHOW MAIN WINDOW
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
@@ -112,7 +124,7 @@ class MainWindow(QMainWindow):
|
||||
self.ui.left_menu.select_only_one(btn.objectName())
|
||||
|
||||
# Load Page 1
|
||||
FunctionsMain.set_page(self, self.ui.load_pages.page_1)
|
||||
MainFunctions.set_page(self, self.ui.load_pages.page_1)
|
||||
|
||||
# Load Widgets Page
|
||||
if btn.objectName() == "btn_widgets":
|
||||
@@ -120,7 +132,8 @@ class MainWindow(QMainWindow):
|
||||
self.ui.left_menu.select_only_one(btn.objectName())
|
||||
|
||||
# Load Page 2
|
||||
FunctionsMain.set_page(self, self.ui.load_pages.page_2)
|
||||
MainFunctions.set_page(self, self.ui.load_pages.page_2)
|
||||
MainFunctions.set_right_column_menu(self, self.ui.right_column.menu_1)
|
||||
|
||||
# Load Add User
|
||||
if btn.objectName() == "btn_add_user":
|
||||
@@ -128,13 +141,68 @@ class MainWindow(QMainWindow):
|
||||
self.ui.left_menu.select_only_one(btn.objectName())
|
||||
|
||||
# Load Page 3
|
||||
FunctionsMain.set_page(self, self.ui.load_pages.page_3)
|
||||
MainFunctions.set_page(self, self.ui.load_pages.page_3)
|
||||
|
||||
# Change Left Column Menu
|
||||
MainFunctions.set_left_column_menu(
|
||||
self,
|
||||
menu = self.ui.left_column.menus.menu_2,
|
||||
title = "Add Users",
|
||||
icon_path = Functions.set_svg_icon("icon_settings.svg")
|
||||
)
|
||||
|
||||
# Settings Left
|
||||
if btn.objectName() == "btn_settings" or btn.objectName() == "btn_close_left_column":
|
||||
# Toogle Active
|
||||
if not MainFunctions.left_column_is_visible(self):
|
||||
btn.set_active(True)
|
||||
|
||||
# Show / Hide
|
||||
MainFunctions.toggle_left_column(self)
|
||||
else:
|
||||
btn.set_active(False)
|
||||
|
||||
# Show / Hide
|
||||
MainFunctions.toggle_left_column(self)
|
||||
|
||||
# Remove Selection If Clicked By "btn_close_left_column"
|
||||
if btn.objectName() != "btn_settings":
|
||||
btn_settings = MainFunctions.get_left_menu_btn(self, "btn_settings")
|
||||
btn_settings.set_active(False)
|
||||
|
||||
# Get Title Bar Btn
|
||||
top_settings = MainFunctions.get_title_bar_btn(self, "btn_top_settings")
|
||||
top_settings.set_active(False)
|
||||
|
||||
# Change Left Column Menu
|
||||
MainFunctions.set_left_column_menu(
|
||||
self,
|
||||
menu = self.ui.left_column.menus.menu_1,
|
||||
title = "Settings Left Column",
|
||||
icon_path = Functions.set_svg_icon("icon_settings.svg")
|
||||
)
|
||||
|
||||
# TITLE BAR MENU
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
if btn.objectName() == "btn_top_settings":
|
||||
# Select Menu
|
||||
btn.set_active(False) if btn.is_active() else btn.set_active(True)
|
||||
# Toogle Active
|
||||
if not MainFunctions.right_column_is_visible(self):
|
||||
btn.set_active(True)
|
||||
|
||||
# Show / Hide
|
||||
MainFunctions.toggle_right_column(self)
|
||||
else:
|
||||
btn.set_active(False)
|
||||
|
||||
# Show / Hide
|
||||
MainFunctions.toggle_right_column(self)
|
||||
|
||||
# Get Left Menu Btn
|
||||
top_settings = MainFunctions.get_left_menu_btn(self, "btn_settings")
|
||||
top_settings.set_active(False)
|
||||
|
||||
|
||||
|
||||
|
||||
# DEBUG
|
||||
print(f"Button {btn.objectName()}, clicked!")
|
||||
|
||||
@@ -19,13 +19,14 @@
|
||||
},
|
||||
"left_menu_content_margins" : 3,
|
||||
"left_column_size" : {
|
||||
"minimum" : 240,
|
||||
"minimum" : 0,
|
||||
"maximum" : 240
|
||||
},
|
||||
"right_column_size" : {
|
||||
"minimum" : 240,
|
||||
"minimum" : 0,
|
||||
"maximum" : 240
|
||||
},
|
||||
"time_animation" : 500,
|
||||
"font" : {
|
||||
"family" : "Segoe UI",
|
||||
"title_size" : 10,
|
||||
|
||||
Reference in New Issue
Block a user