-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
88 lines (79 loc) · 3.29 KB
/
Copy pathmain.py
File metadata and controls
88 lines (79 loc) · 3.29 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
import argparse
import multiprocessing
import sys
from os import path
from PySide6 import QtGui, QtCore
from PySide6.QtWidgets import QApplication, QMainWindow, QFileDialog, QMessageBox
from Interface.Interface import Ui_MainWindow
from utils.Generate import Generate
from utils.WriteFile import WriteFile
from utils.PackageManager import PackageManager
version = "1.0.0"
class MainWindow(QMainWindow):
def GenerateButton(self,action:bool)-> None:
"""
Enable or disable the buttons and labels when the generation starts or ends.
:param action: If True, enable the buttons and labels, else disable them.
"""
self.ui.pushButton_2.setEnabled(action)
self.ui.pushButton_3.setEnabled(action)
self.ui.label.setEnabled(action)
self.ui.label_2.setEnabled(action)
self.ui.spinBox.setEnabled(action)
self.ui.spinBox_2.setEnabled(action)
def __init__(self)-> None:
"""
Initialize the main window.
"""
super(MainWindow, self).__init__()
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.fileName:tuple[str,str]
self.GenerateButton(False)
self.output:list[str]
self.setWindowTitle(f"DictGenerator4OI {version}")
if getattr(sys, 'frozen', False):
base_path = sys._MEIPASS
icon_path = path.join(base_path, 'Interface', 'icon.ico')
else:
icon_path = "Interface/icon.ico"
self.setWindowIcon(QtGui.QIcon(icon_path))
self.setIconSize(QtCore.QSize(100,100))
def start(self)-> None:
"""
Start the generation process.
"""
QMessageBox.information(self,"Generation has started","Please wait...")
self.GenerateButton(False)
generator = Generate(self.ui.spinBox.value(),self.ui.spinBox_2.value(),self.fileName[0])
self.output = generator()
WriteFile(self.fileName[0])(self.output)
QMessageBox.information(self,
"Generation Complete",
"The dictionary has been generated successfully.\nPlease check the directory of your .py file. There should be a txt file contains the same name.")
self.close()
def openFileSelectionDialog(self)-> None:
"""
Open the file selection dialog to select the Python file to generate the dictionary.
"""
self.fileName = (
QFileDialog.getOpenFileName(self,self.tr("Open Python File"), "/", self.tr("Python Files (*.py)")))
if self.fileName[0]:
self.GenerateButton(True)
self.ui.pushButton.setText(f"File Selected: {self.fileName[0]}")
if __name__ == "__main__":
multiprocessing.freeze_support()
parser = argparse.ArgumentParser(description="Generate a dictionary for OI problems.")
group = parser.add_mutually_exclusive_group()
group.add_argument("-n","--normal",default=True,help="Normal mode")
group.add_argument("-p","--package",help="Package Installation mode, the str belongs to the package name, spilt by ','",type=str)
args = parser.parse_args()
if args.package:
PackageManager()(args.package.split(','))
elif args.normal:
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec())
else:
print("Invalid arguments")