Closing the Window ("X") also queries on modifications.

This commit is contained in:
Paul S 2021-07-13 11:27:37 +02:00
parent f4f4c5d14a
commit 8ebc5ce033

View file

@ -190,7 +190,6 @@ class MainWindow(QMainWindow):
self.load_ui() self.load_ui()
self.init_ui() self.init_ui()
self.set_defaults() self.set_defaults()
self.create_actions()
self.create_menu(language, uom_length, uom_mass) self.create_menu(language, uom_length, uom_mass)
self.connect_signals() self.connect_signals()
self.create_toolbar() self.create_toolbar()
@ -294,17 +293,6 @@ class MainWindow(QMainWindow):
layoutGb.addWidget(self.ui.tableStuff) 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): def create_menu(self, language=None, uom_length=None, uom_mass=None):
menuMain = self.menuBar() menuMain = self.menuBar()
menuFile = menuMain.addMenu(QCoreApplication.translate("main", "&File")) menuFile = menuMain.addMenu(QCoreApplication.translate("main", "&File"))
@ -409,12 +397,28 @@ class MainWindow(QMainWindow):
self.is_modified = False self.is_modified = False
def connect_signals(self): def connect_signals(self):
global APP_INI_FILE
tblGarage = self.ui.tableGarage tblGarage = self.ui.tableGarage
tblStuff = self.ui.tableStuff tblStuff = self.ui.tableStuff
tblGarage.itemChanged.connect(self.on_garage_changed) tblGarage.itemChanged.connect(self.on_garage_changed)
tblStuff.itemChanged.connect(self.on_stuff_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): def init_ui(self):
tblGarage = self.ui.tableGarage tblGarage = self.ui.tableGarage
tblStuff = self.ui.tableStuff tblStuff = self.ui.tableStuff
@ -442,7 +446,7 @@ class MainWindow(QMainWindow):
self.ui.efVol_Free.setStyleSheet("") self.ui.efVol_Free.setStyleSheet("")
self.is_modified = False self.is_modified = False
def quit_app(self): def quit_app(self) -> bool:
if self.is_modified: if self.is_modified:
msg = QCoreApplication.translate("main", TXT_UNSAVED_CHANGES) msg = QCoreApplication.translate("main", TXT_UNSAVED_CHANGES)
reply = QMessageBox.question(self, QCoreApplication.translate("main", "Quit"), msg, \ reply = QMessageBox.question(self, QCoreApplication.translate("main", "Quit"), msg, \
@ -450,6 +454,7 @@ class MainWindow(QMainWindow):
if reply == QMessageBox.No: if reply == QMessageBox.No:
return False return False
QApplication.quit() QApplication.quit()
return False
def file_new(self): def file_new(self):
if self.is_modified: if self.is_modified: