-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconstants.py
104 lines (78 loc) · 3.03 KB
/
constants.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
"""
# READ-ONLY LIBRARY
- NO CUSTOM LIBRARIES IMPORTED HERE TO AVOID CONFLICTS AND RECIRCLE IMPORTING ISSUES
"""
from os import getcwd
from PySide6.QtWidgets import QDialog, QLabel, QVBoxLayout, QDialogButtonBox, QMessageBox
APP_VER = "v1.3.4"
class Path:
RESOURCES_PATH = "frontend/"
ROOT_PATH: str = getcwd() + "\\"
DATA_PATH: str = ROOT_PATH + "data\\"
TRASH_PATH: str = DATA_PATH + "trash\\"
CACHE_FILE: str = DATA_PATH + "Cache.json"
TRASH_CONTENT_FILE = f"{TRASH_PATH}content.json"
MOVED_CONTENT_FILE = f"{DATA_PATH}\\moved_content.json"
class Dialog:
def __init__(self):
self.widget = None
def __get_response(self, msg: str, mode: str = "I", is_dialog: bool = True) -> bool:
# A FIX: CANNOT USE QDIALOG BEFORE INIT THE QAPPLICATION
if not self.widget:
self.widget = QDialog() # CREATE OBJECT ONCE
layout = QVBoxLayout()
self.widget.setLayout(layout)
self.label = QLabel()
match mode.upper():
case "I":
title = "INFORMATION"
icon = QMessageBox.Information
case "W":
title = "WARNING"
icon = QMessageBox.Warning
case "C":
title = "CRITICAL"
icon = QMessageBox.Critical
case "Q":
title = "QUESTION"
icon = QMessageBox.Question
case _:
title = mode.upper()
icon = QMessageBox.NoIcon
if is_dialog:
# RENDER A DIALOG WINDOW WITH OK|CANCEL OPTIONS
self.options = QDialogButtonBox(
QDialogButtonBox.Ok | QDialogButtonBox.Cancel
)
self.options.rejected.connect(self.widget.reject)
self.options.accepted.connect(self.widget.accept)
layout.addWidget(self.label)
layout.addWidget(self.options)
self.label.setText(msg.upper())
self.widget.setWindowTitle(title)
# RETURN USER PERMISSION
return True if self.widget.exec() else False
# INFORMATIONAL BASED DIALOG. NO OPTIONS OTHER THAN ACCEPT
msg_box = QMessageBox()
msg_box.setIcon(icon)
msg_box.setWindowTitle(title)
msg_box.setText(msg.upper())
return True if msg_box.exec() else False
def show(self, msg: str, mode: str = "I", is_dialog: bool = True) -> bool:
"""
#### RENDER A WINDOW FOR INFO/PERMISSION
PARAMS:
* `msg` : MESSAGE TO DISPLAY
* `mode` : ONE CHAR TO DISPLAY THE CORRECT ICON & FOR WINDOW TITLE
- `I`nformation
- `W`arning
- `C`ritical
- `Q`uestion
* `is_dialog` : TYPE OF THE DIALOG
- `FALSE` : OK DIALOG
- `TRUE` : OK/CANCEL DIALOG
RETURNS BOOL
"""
return self.__get_response(
msg, mode, is_dialog
)