-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
163 lines (130 loc) · 5.53 KB
/
main.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
import os
import sys
from PySide6 import QtCore as qtc
from PySide6 import QtWidgets as qtw
from assets.ui import Ui_main_window, global_stylesheet
from assets.ui import GlowingLogo
from screens.about import AboutScreen
from screens.encryption import ChooseFileEncryptScreen
from screens.decryption import ChooseFileDecryptScreen
from screens.keygen.select_keygen_screen import SelectKeygenScreen
from tools.toolkit import Tools as t
from backend import signal_manager
class MainWindow(qtw.QMainWindow, Ui_main_window):
def __init__(self):
"""
Initializes the main window of the application.
This constructor sets up the user interface, sets up the language
translation system, and connects various UI elements to their
respective event handlers.
:return: None
"""
super().__init__()
self.translator = qtc.QTranslator()
self.current_language = "en"
self.setupUi(self)
self.setupWebLogoAnimation()
self.actionEnglish.triggered.connect(lambda: self.change_language("en"))
self.actionEnglish.triggered.emit()
self.action.triggered.connect(lambda: self.change_language("ru"))
self.actionEspa_ol.triggered.connect(lambda: self.change_language("es"))
self.actionExit.triggered.connect(qtw.QApplication.quit)
self.encrypt_button.clicked.connect(self.handle_encrypt)
self.actionEncrypt.triggered.connect(self.handle_encrypt)
self.decrypt_button.clicked.connect(self.handle_decrypt)
self.actionDecrypt.triggered.connect(self.handle_decrypt)
self.generate_keys_button.clicked.connect(self.handle_generate_keys)
self.actionGenerateKeys.triggered.connect(self.handle_generate_keys)
self.actionAbout.triggered.connect(self.handle_about)
def setupWebLogoAnimation(self):
"""
Setup the logo animation.
This method creates an instance of GlowingLogo() and
adds it to the layout of the q_logo widget.
"""
glowing_log = GlowingLogo()
layout = qtw.QVBoxLayout(self.q_logo)
layout.addWidget(glowing_log)
self.q_logo.setLayout(layout)
@qtc.Slot()
def handle_encrypt(self):
"""
Slot connected to the encrypt button's clicked signal and
the "Encrypt" menu item's triggered signal.
This slot creates a ChooseFileEncryptScreen instance,
saves the current main window, closes the current window,
and shows the new window.
:return: None
"""
self.encrypt_window = t.qt.center_widget(ChooseFileEncryptScreen())
signal_manager.save_main_window.emit(self)
self.close()
self.encrypt_window.show()
@qtc.Slot()
def handle_decrypt(self):
"""
Slot connected to the decrypt button's clicked signal and
the "Decrypt" menu item's triggered signal.
This slot creates a ChooseFileDecryptScreen instance,
saves the current main window, closes the current window,
and shows the new window.
:return: None
"""
self.decrypt_window = t.qt.center_widget(ChooseFileDecryptScreen())
signal_manager.save_main_window.emit(self)
self.close()
self.decrypt_window.show()
@qtc.Slot()
def handle_generate_keys(self):
"""
Slot connected to the "Generate Keys" button's clicked signal and
the "Generate Keys" menu item's triggered signal.
This slot creates a SelectKeygenScreen instance, saves the current
main window, closes the current window, and shows the new window.
:return: None
"""
self.gen_keys_window = t.qt.center_widget(SelectKeygenScreen())
signal_manager.save_main_window.emit(self)
self.close()
self.gen_keys_window.show()
@qtc.Slot()
def handle_about(self):
"""
Slot connected to the "About" menu item's triggered signal.
This slot creates an AboutScreen instance, saves the current main window,
closes the current window, and shows the new window.
:return: None
"""
signal_manager.save_main_window.emit(self)
self.window = t.qt.center_widget(AboutScreen())
self.window.show()
self.close()
@qtc.Slot()
def change_language(self, language_code):
"""
Slot connected to the language change menu items' triggered signal.
Loads the translation file for the given language code and updates the
UI text with the new translation.
:param language_code: A string representing the language code (e.g., "en", "ru", etc.)
:return: None
"""
if hasattr(sys, "_MEIPASS"):
# If it's bundled, use the temporary folder
translation_file = os.path.join(
sys._MEIPASS, "translations", f"encryption_{language_code}.qm"
)
else:
# If running in development mode, use relative path
translation_file = f"translations/encryption_{language_code}.qm"
if self.translator.load(translation_file):
qtw.QApplication.instance().installTranslator(self.translator)
self.retranslateUi(self) # Update UI text with new translation
self.current_language = language_code
else:
print(f"Failed to load translation: {translation_file}")
if __name__ == "__main__":
app = qtw.QApplication(sys.argv)
app.setStyleSheet(global_stylesheet)
window = t.qt.center_widget(MainWindow())
window.show()
sys.exit(app.exec())