-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.py
More file actions
85 lines (67 loc) · 2.65 KB
/
MainWindow.py
File metadata and controls
85 lines (67 loc) · 2.65 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
SETTINGS_PATH = r"~\Documents\Elemental Recycling\salvagEE\settings.ini"
# matplotlib setup
from matplotlib import use as mpl_backend
mpl_backend('QtAgg')
from PyQt6 import uic
from PyQt6.QtCore import QSettings
from PyQt6.QtWidgets import QMainWindow, QMessageBox, QPushButton, QWidget
from os import path
from SalvageWindow import SalvageWindow
class MainWindow(QMainWindow):
# Global Variables
_baseDir = ''
# Windows
mainWindow: QWidget
salvageWindow: SalvageWindow
# Controls
newSalvage_btn: QPushButton
def __init__(self, baseDir:str, *args, **kwargs):
super().__init__(*args, **kwargs)
self._baseDir = baseDir
uic.loadUi(path.join(self._baseDir, 'app.ui'), self)
self.mainWindow = self.centralWidget()
self.salvageWindow = SalvageWindow(self._baseDir)
self.newSalvage_btn.clicked.connect(self.onNewSalvage_clicked)
self.salvageWindow.canceled.connect(self.onSalvageWindow_canceled)
self.salvageWindow.saved.connect(self.onSalvageWindow_saved)
try:
self.loadConfig()
except Exception as e:
self.createPopupDialog('Warning', f'Failed to load settings. {e}')
def onNewSalvage_clicked(self):
self.mainWindow.setParent(None)
self.setCentralWidget(self.salvageWindow)
def onSalvageWindow_canceled(self):
self.salvageWindow.setParent(None)
self.setCentralWidget(self.mainWindow)
def onSalvageWindow_saved(self):
self.salvageWindow.setParent(None)
self.setCentralWidget(self.mainWindow)
def createPopupDialog(self, severity: str, message: str) -> bool:
d = QMessageBox(self)
d.setWindowTitle(severity)
d.setText(message)
if severity == 'Warning':
d.setStandardButtons(QMessageBox.StandardButton.Ok | QMessageBox.StandardButton.Cancel)
result = d.exec()
return result == QMessageBox.StandardButton.Ok
else:
d.exec()
return False
def saveConfig(self):
settings = QSettings(path.expanduser(SETTINGS_PATH), QSettings.Format.IniFormat)
def loadConfig(self):
settings = QSettings(path.expanduser(SETTINGS_PATH), QSettings.Format.IniFormat)
def closeEvent(self, event):
reply = QMessageBox.question(
self,
"Confirm Exit",
"Are you sure you want to quit?",
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No,
QMessageBox.StandardButton.No,
)
if reply == QMessageBox.StandardButton.Yes:
self.saveConfig()
event.accept()
else:
event.ignore()