-
Notifications
You must be signed in to change notification settings - Fork 2
/
ui_functions.py
229 lines (189 loc) · 8.46 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
## ==> GUI FILE
from main import *
## ==> GLOBALS
GLOBAL_STATE = 0
GLOBAL_TITLE_BAR = True
## ==> COUT INITIAL MENU
count = 1
class UIFunctions(MainWindow):
## ==> GLOBALS
GLOBAL_STATE = 0
GLOBAL_TITLE_BAR = True
########################################################################
## START - GUI FUNCTIONS
########################################################################
## ==> MAXIMIZE/RESTORE
########################################################################
def maximize_restore(self):
global GLOBAL_STATE
status = GLOBAL_STATE
if status == 0:
self.showMaximized()
GLOBAL_STATE = 1
self.ui.verticalLayout_6.setContentsMargins(0, 0, 0, 0)
self.ui.btn_maximize_restore.setToolTip("Restore")
self.ui.btn_maximize_restore.setIcon(QtGui.QIcon(u":/16x16/icons/16x16/cil-window-restore.png"))
self.ui.frame_top_btns.setStyleSheet("background-color: rgb(27, 29, 35)")
self.ui.frame_size_grip.hide()
else:
GLOBAL_STATE = 0
self.showNormal()
self.resize(self.width()+1, self.height()+1)
self.ui.verticalLayout_6.setContentsMargins(10, 10, 10, 10)
self.ui.btn_maximize_restore.setToolTip("Maximize")
self.ui.btn_maximize_restore.setIcon(QtGui.QIcon(u":/16x16/icons/16x16/cil-window-maximize.png"))
self.ui.frame_top_btns.setStyleSheet("background-color: rgba(27, 29, 35, 200)")
self.ui.frame_size_grip.show()
## ==> RETURN STATUS
def returStatus():
return GLOBAL_STATE
## ==> SET STATUS
def setStatus(status):
global GLOBAL_STATE
GLOBAL_STATE = status
## ==> ENABLE MAXIMUM SIZE
########################################################################
def enableMaximumSize(self, width, height):
if width != '' and height != '':
self.setMaximumSize(QSize(width, height))
self.ui.frame_size_grip.hide()
self.ui.btn_maximize_restore.hide()
## ==> TOGGLE MENU
########################################################################
def toggleMenu(self, maxWidth, enable):
if enable:
# GET WIDTH
width = self.ui.frame_left_menu.width()
maxExtend = maxWidth
standard = 70
# SET MAX WIDTH
if width == 70:
widthExtended = maxExtend
else:
widthExtended = standard
# ANIMATION
self.animation = QPropertyAnimation(self.ui.frame_left_menu, b"minimumWidth")
self.animation.setDuration(300)
self.animation.setStartValue(width)
self.animation.setEndValue(widthExtended)
self.animation.setEasingCurve(QtCore.QEasingCurve.InOutQuart)
self.animation.start()
## ==> SET TITLE BAR
########################################################################
def removeTitleBar(status):
global GLOBAL_TITLE_BAR
GLOBAL_TITLE_BAR = status
## ==> HEADER TEXTS
########################################################################
# LABEL TITLE
def labelTitle(self, text):
self.ui.label_title_bar_top.setText(text)
# LABEL DESCRIPTION
def labelDescription(self, text):
self.ui.label_top_info_1.setText(text)
## ==> DYNAMIC MENUS
########################################################################
def addNewMenu(self, name, objName, icon, isTopMenu):
font = QFont()
font.setFamily(u"Segoe UI")
button = QPushButton(str(count),self)
button.setObjectName(objName)
sizePolicy3 = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
sizePolicy3.setHorizontalStretch(0)
sizePolicy3.setVerticalStretch(0)
sizePolicy3.setHeightForWidth(button.sizePolicy().hasHeightForWidth())
button.setSizePolicy(sizePolicy3)
button.setMinimumSize(QSize(0, 70))
button.setLayoutDirection(Qt.LeftToRight)
button.setFont(font)
button.setStyleSheet(Style.style_bt_standard.replace('ICON_REPLACE', icon))
button.setText(name)
button.setToolTip(name)
button.clicked.connect(self.Button)
if isTopMenu:
self.ui.layout_menus.addWidget(button)
else:
self.ui.layout_menu_bottom.addWidget(button)
## ==> SELECT/DESELECT MENU
########################################################################
## ==> SELECT
def selectMenu(getStyle):
select = getStyle + ("QPushButton { border-right: 7px solid rgb(44, 49, 60); }")
return select
## ==> DESELECT
def deselectMenu(getStyle):
deselect = getStyle.replace("QPushButton { border-right: 7px solid rgb(44, 49, 60); }", "")
return deselect
## ==> START SELECTION
def selectStandardMenu(self, widget):
for w in self.ui.frame_left_menu.findChildren(QPushButton):
if w.objectName() == widget:
w.setStyleSheet(UIFunctions.selectMenu(w.styleSheet()))
## ==> RESET SELECTION
def resetStyle(self, widget):
for w in self.ui.frame_left_menu.findChildren(QPushButton):
if w.objectName() != widget:
w.setStyleSheet(UIFunctions.deselectMenu(w.styleSheet()))
## ==> CHANGE PAGE LABEL TEXT
def labelPage(self, text):
newText = '| ' + text.upper()
self.ui.label_top_info_2.setText(newText)
## ==> USER ICON
########################################################################
def userIcon(self, initialsTooltip, icon, showHide):
if showHide:
# SET TEXT
self.ui.label_user_icon.setText(initialsTooltip)
# SET ICON
if icon:
style = self.ui.label_user_icon.styleSheet()
setIcon = "QLabel { background-image: " + icon + "; }"
self.ui.label_user_icon.setStyleSheet(style + setIcon)
self.ui.label_user_icon.setText('')
self.ui.label_user_icon.setToolTip(initialsTooltip)
else:
self.ui.label_user_icon.hide()
########################################################################
## END - GUI FUNCTIONS
########################################################################
########################################################################
## START - GUI DEFINITIONS
########################################################################
## ==> UI DEFINITIONS
########################################################################
def uiDefinitions(self):
def dobleClickMaximizeRestore(event):
# IF DOUBLE CLICK CHANGE STATUS
if event.type() == QtCore.QEvent.MouseButtonDblClick:
QtCore.QTimer.singleShot(250, lambda: UIFunctions.maximize_restore(self))
## REMOVE ==> STANDARD TITLE BAR
if GLOBAL_TITLE_BAR:
self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
self.setAttribute(QtCore.Qt.WA_TranslucentBackground)
self.ui.frame_label_top_btns.mouseDoubleClickEvent = dobleClickMaximizeRestore
else:
self.ui.horizontalLayout.setContentsMargins(0, 0, 0, 0)
self.ui.frame_label_top_btns.setContentsMargins(8, 0, 0, 5)
self.ui.frame_label_top_btns.setMinimumHeight(42)
self.ui.frame_icon_top_bar.hide()
self.ui.frame_btns_right.hide()
self.ui.frame_size_grip.hide()
## SHOW ==> DROP SHADOW
self.shadow = QGraphicsDropShadowEffect(self)
self.shadow.setBlurRadius(17)
self.shadow.setXOffset(0)
self.shadow.setYOffset(0)
self.shadow.setColor(QColor(0, 0, 0, 150))
self.ui.frame_main.setGraphicsEffect(self.shadow)
## ==> RESIZE WINDOW
self.sizegrip = QSizeGrip(self.ui.frame_size_grip)
self.sizegrip.setStyleSheet("width: 20px; height: 20px; margin 0px; padding: 0px;")
### ==> MINIMIZE
self.ui.btn_minimize.clicked.connect(lambda: self.showMinimized())
## ==> MAXIMIZE/RESTORE
self.ui.btn_maximize_restore.clicked.connect(lambda: UIFunctions.maximize_restore(self))
## SHOW ==> CLOSE APPLICATION
self.ui.btn_close.clicked.connect(lambda: self.close())
########################################################################
## END - GUI DEFINITIONS
########################################################################