-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui_functions.py
More file actions
338 lines (302 loc) · 12.4 KB
/
ui_functions.py
File metadata and controls
338 lines (302 loc) · 12.4 KB
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
# ///////////////////////////////////////////////////////////////
#
# 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 FILE
# ///////////////////////////////////////////////////////////////
from functools import partial
import importlib
import re
from usuarios import getAllPermisos
from main import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
# GLOBALS
# ///////////////////////////////////////////////////////////////
GLOBAL_STATE = False
GLOBAL_TITLE_BAR = True
lista_botones = []
def centerOnScreen (self):
'''centerOnScreen()
Centers the window on the screen.'''
resolution = QDesktopWidget().screenGeometry()
self.move(int((resolution.width() / 2) - (self.frameSize().width() / 2)),
int((resolution.height() / 2) - (self.frameSize().height() / 2)))
# MAXIMIZE/RESTORE
# ///////////////////////////////////////////////////////////////
def maximize_restore(self):
global GLOBAL_STATE
status = GLOBAL_STATE
if status == False:
self.showMaximized()
GLOBAL_STATE = True
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()
self.bottom_grip.hide()
else:
GLOBAL_STATE = False
self.showNormal()
self.resize(self.width()+1, self.height()+1)
self.appMargins.setContentsMargins(0, 0, 0, 0)
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()
self.bottom_grip.show()
# RETURN STATUS
# ///////////////////////////////////////////////////////////////
def returStatus(self):
return GLOBAL_STATE
# SET STATUS
# ///////////////////////////////////////////////////////////////
def setStatus(self, status):
global GLOBAL_STATE
GLOBAL_STATE = status
# TOGGLE MENU
# ///////////////////////////////////////////////////////////////
def toggleMenu(self, enable):
if enable:
# GET WIDTH
width = self.leftMenuBg.width()
maxExtend = 240
standard = 60
# SET MAX WIDTH
if width == 60:
widthExtended = maxExtend
else:
widthExtended = standard
# ANIMATION
self.animation = QPropertyAnimation(
self.leftMenuBg, b"minimumWidth")
self.animation.setDuration(500)
self.animation.setStartValue(width)
self.animation.setEndValue(widthExtended)
self.animation.setEasingCurve(QEasingCurve.InOutQuart)
self.animation.start()
# TOGGLE LEFT BOX
# ///////////////////////////////////////////////////////////////
def toggleLeftBox(self, enable):
if enable:
# GET WIDTH
width = self.extraLeftBox.width()
widthRightBox = self.extraRightBox.width()
maxExtend = 240
color = 'background-color: white;'
standard = 0
# GET BTN STYLE
style = self.toggleLeftBox.styleSheet()
# SET MAX WIDTH
if width == 0:
widthExtended = maxExtend
# SELECT BTN
self.toggleLeftBox.setStyleSheet(style + color)
if widthRightBox != 0:
style = self.settingsTopBtn.styleSheet()
self.settingsTopBtn.setStyleSheet(
style.replace('background-color: #e3ddcc;', ''))
else:
widthExtended = standard
# RESET BTN
self.toggleLeftBox.setStyleSheet(style.replace(color, ''))
start_box_animation(self, width, widthRightBox, "left")
# TOGGLE RIGHT BOX
# ///////////////////////////////////////////////////////////////
# def toggleRightBox(self, enable):
# if enable:
# # GET 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.settingsTopBtn.styleSheet()
# # SET MAX WIDTH
# if width == 0:
# widthExtended = maxExtend
# # SELECT BTN
# self.settingsTopBtn.setStyleSheet(style + color)
# if widthLeftBox != 0:
# style = self.toggleLeftBox.styleSheet()
# self.toggleLeftBox.setStyleSheet(
# style.replace(Settings.BTN_LEFT_BOX_COLOR, ''))
# else:
# widthExtended = standard
# # RESET BTN
# 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
# Check values
if left_box_width == 0 and direction == "left":
left_width = 240
else:
left_width = 0
# Check values
if right_box_width == 0 and direction == "right":
right_width = 240
else:
right_width = 0
# ANIMATION LEFT BOX
self.left_box = QPropertyAnimation(
self.extraLeftBox, b"minimumWidth")
self.left_box.setDuration(500)
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.extraRightBox, b"minimumWidth")
self.right_box.setDuration(500)
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.addAnimation(self.left_box)
self.group.addAnimation(self.right_box)
self.group.start()
# SELECT/DESELECT MENU
# ///////////////////////////////////////////////////////////////
# SELECT
def selectMenu(getStyle):
select = getStyle + """
border-left: 22px solid qlineargradient(spread:pad, x1:0.034, y1:0, x2:0.216, y2:0, stop:0.499 rgb(116, 91, 47), stop:0.5 rgba(85, 170, 255, 0));
background-color: #e3ddcc;
color:rgb(116, 91, 47) ;
"""
return select
# DESELECT
def deselectMenu(getStyle):
deselect = getStyle.replace("""
border-left: 22px solid qlineargradient(spread:pad, x1:0.034, y1:0, x2:0.216, y2:0, stop:0.499 rgb(116, 91, 47), stop:0.5 rgba(85, 170, 255, 0));
background-color: #e3ddcc;
color:rgb(116, 91, 47) ;
""", "")
return deselect
# START SELECTION
def selectStandardMenu(self, widget):
for w in self.topMenu.findChildren(QPushButton):
if w.objectName() == widget:
w.setStyleSheet(selectMenu(w.styleSheet()))
# RESET SELECTION
def resetStyle(self, widget):
for w in self.topMenu.findChildren(QPushButton):
if w.objectName() != widget:
w.setStyleSheet(deselectMenu(w.styleSheet()))
# IMPORT THEMES FILES QSS/CSS
# ///////////////////////////////////////////////////////////////
def theme(self, file, useCustomTheme):
if useCustomTheme:
str = open(file, 'r').read()
self.styleSheet.setStyleSheet(str)
# START - GUI DEFINITIONS
# ///////////////////////////////////////////////////////////////
def uiDefinitions(self):
# 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.bgApp.setGraphicsEffect(self.shadow)
def checarPermisos(self):
lista_botones.clear()
permisos_usuario = getAllPermisos()
for tabla, permisos in permisos_usuario.items():
if permisos['read'] != '':
if ['Tablas','cells'] not in lista_botones:
lista_botones.append(['Tablas','cells'])
if permisos['write'] != '':
if ['AgregarRegistro','add'] not in lista_botones:
lista_botones.append(['AgregarRegistro','add'])
if tabla == 'usuario':
lista_botones.clear()
lista_botones.extend([['Tablas','cells'],['AgregarRegistro','add'],['VerUsuarios','group'],['EditarPrivilegios','edit'], ['RegistrarUsuario','add-user']])
return
def createButtons(self):
sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
font = QFont()
font.setFamily(u"Segoe UI")
font.setPointSize(10)
font.setBold(False)
font.setItalic(False)
for button in lista_botones:
name = button[0]
icon = button[1]
setattr(self, f"btn_{name.lower()}", QPushButton(self.topMenu))
btn = getattr(self, f"btn_{name.lower()}")
btn.setObjectName(f"btn_{name.lower()}")
sizePolicy.setHeightForWidth(
btn.sizePolicy().hasHeightForWidth())
btn.setSizePolicy(sizePolicy)
btn.setMinimumSize(QSize(0, 45))
btn.setFont(font)
btn.setCursor(QCursor(Qt.PointingHandCursor))
btn.setLayoutDirection(Qt.LeftToRight)
btn.setStyleSheet(f"background-image: url(:/resources/resources/icons/{icon}.png);")
btn.setText(QCoreApplication.translate("MainWindow",re.sub(r"(\w)([A-Z])", r"\1 \2",name).capitalize(),None))
self.verticalLayout_8.addWidget(btn)
createWidget(self, name)
btn.clicked.connect(partial(buttonClick,self, btn))
def getListaBotones():
return lista_botones
def buttonClick(self, btn):
# GET BUTTON CLICKED
btnName = btn.objectName()
# SHOW HOME PAGE
if btnName == "btn_tablas":
self.stackedWidget.setCurrentWidget(self.tablas)
resetStyle(self, btnName)
btn.setStyleSheet(selectMenu(btn.styleSheet()))
# SHOW WIDGETS PAGE
if btnName == "btn_agregarregistro":
self.stackedWidget.setCurrentWidget(self.agregarregistro)
resetStyle(self, btnName)
btn.setStyleSheet(selectMenu(btn.styleSheet()))
# SHOW NEW PAGE
if btnName == "btn_registrarusuario":
self.stackedWidget.setCurrentWidget(
self.registrarusuario) # SET PAGE
# RESET ANOTHERS BUTTONS SELECTED
resetStyle(self, btnName)
btn.setStyleSheet(selectMenu(
btn.styleSheet())) # SELECT MENU
if btnName == "btn_verusuarios":
self.stackedWidget.setCurrentWidget(self.verusuarios)
resetStyle(self, btnName)
btn.setStyleSheet(selectMenu(btn.styleSheet()))
if btnName == "btn_editarprivilegios":
self.stackedWidget.setCurrentWidget(self.editarprivilegios)
resetStyle(self, btnName)
btn.setStyleSheet(selectMenu(btn.styleSheet()))
def createWidget(self, name):
module = importlib.import_module(f"pages.{name}")
instance = getattr(module, name)()
setattr(self, name.lower(), instance)
widget = getattr(self, name.lower())
self.stackedWidget.addWidget(widget)