Closing the Window ("X") also queries on modifications.
This commit is contained in:
parent
f4f4c5d14a
commit
8ebc5ce033
1 changed files with 18 additions and 13 deletions
31
src/main.py
31
src/main.py
|
@ -190,7 +190,6 @@ class MainWindow(QMainWindow):
|
|||
self.load_ui()
|
||||
self.init_ui()
|
||||
self.set_defaults()
|
||||
self.create_actions()
|
||||
self.create_menu(language, uom_length, uom_mass)
|
||||
self.connect_signals()
|
||||
self.create_toolbar()
|
||||
|
@ -294,17 +293,6 @@ class MainWindow(QMainWindow):
|
|||
|
||||
layoutGb.addWidget(self.ui.tableStuff)
|
||||
|
||||
def create_actions(self):
|
||||
global APP_INI_FILE
|
||||
|
||||
self.ui.actionNew.triggered.connect(self.file_new)
|
||||
self.ui.actionOpen.triggered.connect(self.file_open)
|
||||
self.ui.actionSave.triggered.connect(self.file_save)
|
||||
self.ui.actionExport.triggered.connect(self.file_export)
|
||||
self.ui.actionAbout_Qt.triggered.connect(QApplication.aboutQt)
|
||||
self.ui.actionAbout.triggered.connect(lambda: show_about(APP_INI_FILE, self.opened_file))
|
||||
self.ui.actionQuit.triggered.connect(self.quit_app)
|
||||
|
||||
def create_menu(self, language=None, uom_length=None, uom_mass=None):
|
||||
menuMain = self.menuBar()
|
||||
menuFile = menuMain.addMenu(QCoreApplication.translate("main", "&File"))
|
||||
|
@ -409,12 +397,28 @@ class MainWindow(QMainWindow):
|
|||
self.is_modified = False
|
||||
|
||||
def connect_signals(self):
|
||||
global APP_INI_FILE
|
||||
|
||||
tblGarage = self.ui.tableGarage
|
||||
tblStuff = self.ui.tableStuff
|
||||
|
||||
tblGarage.itemChanged.connect(self.on_garage_changed)
|
||||
tblStuff.itemChanged.connect(self.on_stuff_changed)
|
||||
|
||||
self.ui.actionNew.triggered.connect(self.file_new)
|
||||
self.ui.actionOpen.triggered.connect(self.file_open)
|
||||
self.ui.actionSave.triggered.connect(self.file_save)
|
||||
self.ui.actionExport.triggered.connect(self.file_export)
|
||||
self.ui.actionAbout_Qt.triggered.connect(QApplication.aboutQt)
|
||||
self.ui.actionAbout.triggered.connect(lambda: show_about(APP_INI_FILE, self.opened_file))
|
||||
self.ui.actionQuit.triggered.connect(self.quit_app)
|
||||
|
||||
def closeEvent(self, event):
|
||||
if self.quit_app():
|
||||
event.accept()
|
||||
else:
|
||||
event.ignore()
|
||||
|
||||
def init_ui(self):
|
||||
tblGarage = self.ui.tableGarage
|
||||
tblStuff = self.ui.tableStuff
|
||||
|
@ -442,7 +446,7 @@ class MainWindow(QMainWindow):
|
|||
self.ui.efVol_Free.setStyleSheet("")
|
||||
self.is_modified = False
|
||||
|
||||
def quit_app(self):
|
||||
def quit_app(self) -> bool:
|
||||
if self.is_modified:
|
||||
msg = QCoreApplication.translate("main", TXT_UNSAVED_CHANGES)
|
||||
reply = QMessageBox.question(self, QCoreApplication.translate("main", "Quit"), msg, \
|
||||
|
@ -450,6 +454,7 @@ class MainWindow(QMainWindow):
|
|||
if reply == QMessageBox.No:
|
||||
return False
|
||||
QApplication.quit()
|
||||
return False
|
||||
|
||||
def file_new(self):
|
||||
if self.is_modified:
|
||||
|
|
Loading…
Reference in a new issue