-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathui_functions.py
140 lines (111 loc) · 5.49 KB
/
ui_functions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
################################################################################
##
## BY: ONCESCU IONUT-COSMIN
## PROJECT MADE WITH: Qt Designer, PySide2 and SQLite
## DATE: 15.01.2021
## V: 1.0.0
## WITH THANKS TO: WANDERSON M.PIMENTA
##
################################################################################
### GUI FILE
from main import *
## ==>> GLOBALS
GLOBAL_STATE = 0
GLOBAL_TITLE_BAR = True
## ==>> COUNT INITIAL MENU
count = 1
class UIFunctions(MainWindow):
########################################
# MAXIMIZE RESTORE FUNCTION
########################################
def maximize_restore(self):
global GLOBAL_STATE
status = GLOBAL_STATE
# IF NOT MAXIMIZED
if status == 0:
self.showMaximized()
# SET GLOBAL TO 1
GLOBAL_STATE = 1
#IF MAXIMIZED REMOVE MARGINS
self.ui.centralwidget.setContentsMargins(0,0,0,0)
#self.ui.centralwidget.setStyleSheet("")
self.ui.Btn_Maximize.setToolTip("Restore")
else:
GLOBAL_STATE = 0
self.showNormal()
self.resize(self.width()+1, self.height()+1)
self.ui.centralwidget.setContentsMargins(0,0,0,0)
self.ui.Btn_Maximize.setToolTip("Maximize")
########################################
# UI DEFINITIONS
########################################
def uiDefinitions(self):
# REMOVE TITLE BAR
self.setWindowFlag(QtCore.Qt.FramelessWindowHint)
self.setAttribute(QtCore.Qt.WA_TranslucentBackground)
def doubleClickMaximizeRestore(event):
# IF DOUBLE CLICK CHANGE STATUS
if event.type() == QtCore.QEvent.MouseButtonDblClick:
QtCore.QTimer.singleShot(250, lambda: UIFunctions.maximize_restore(self))
# MAXIMIZE / RESTORE
self.ui.Btn_Maximize.clicked.connect(lambda: UIFunctions.maximize_restore(self))
self.ui.Top_Btns_Frame.mouseDoubleClickEvent = doubleClickMaximizeRestore
# MINIMIZE
self.ui.Btn_Minimize.clicked.connect(lambda: self.showMinimized())
# CLOSE APPLICATION
self.ui.Btn_Close.clicked.connect(lambda: self.close())
self.ui.Btn_Close.setToolTip('Close')
## ==>> CREATE SIZE GRIP TO RESIZE WINDOW
self.sizegrip = QSizeGrip(self.ui.SizeGrip_Frame)
self.sizegrip.setStyleSheet("QSizeGrip {width: 20px; height: 20px; border-radius:10px} QSizeGrip:hover {background-color: rgb(124, 138, 162)}")
self.sizegrip.setToolTip("Resize Window")
## RETURN STATUS IF WINDOW IS MAXIMIZED OR RESTORED
def returnStatus():
return GLOBAL_STATE
## CHANGE PAGE LABEL TEXT
def labelPage(self, text):
newText = '| ' + text.upper()
self.ui.label.setText(newText)
########################################
# TOGGLE MENU ANIMATION
########################################
def toggleMenu(self, maxWidth, enable):
if enable:
# GET WIDTH
width = self.ui.Menu_Left_Frame.width()
maxExtend = maxWidth
# Standard width variable from qt (80px)
standard = 80
# SET MAX WIDTH
if width == 80:
widthExtend = maxExtend
else:
widthExtend = standard
# ANIMATION
self.animation = QPropertyAnimation(self.ui.Menu_Left_Frame, b"minimumWidth")
self.animation.setDuration(300)
self.animation.setStartValue(width)
self.animation.setEndValue(widthExtend)
self.animation.setEasingCurve(QtCore.QEasingCurve.InOutQuart)
self.animation.start()
# ADD TEXT TO BUTTONS
if widthExtend == maxExtend:
self.ui.Btn_Home_Menu.setStyleSheet(Style.style_bt_standard.replace('ICON_REPLACE', "url(:/24x24/icons/24x24/cil-home.png)"))
self.ui.Btn_Home_Menu.setText('Home')
self.ui.Btn_OpenFiles_Menu.setStyleSheet(Style.style_bt_standard.replace('ICON_REPLACE', "url(:/24x24/icons/24x24/cil-folder-open.png)"))
self.ui.Btn_OpenFiles_Menu.setText('Open Files')
self.ui.Btn_GroupElm_Menu.setStyleSheet(Style.style_bt_standard.replace('ICON_REPLACE', "url(:/24x24/icons/24x24/mesh.png)"))
self.ui.Btn_GroupElm_Menu.setText('Group Elements')
self.ui.Btn_Composite_Menu.setStyleSheet(Style.style_bt_standard.replace('ICON_REPLACE', "url(:/24x24/icons/24x24/composite.png)"))
self.ui.Btn_Composite_Menu.setText('Composite Materials')
self.ui.Btn_Metallic_Menu.setStyleSheet(Style.style_bt_standard.replace('ICON_REPLACE', "url(:/24x24/icons/24x24/cil-settings.png)"))
self.ui.Btn_Metallic_Menu.setText('Metallic Materials')
self.ui.Btn_Run_Menu.setStyleSheet(Style.style_bt_standard.replace('ICON_REPLACE', "url(:/24x24/icons/24x24/cil-media-play.png)"))
self.ui.Btn_Run_Menu.setText('Run Analysis')
else:
self.ui.Btn_Home_Menu.setText('')
self.ui.Btn_OpenFiles_Menu.setText('')
self.ui.Btn_GroupElm_Menu.setText('')
self.ui.Btn_Composite_Menu.setText('')
self.ui.Btn_Metallic_Menu.setText('')
self.ui.Btn_Run_Menu.setText('')