Browse Source

Add quit button

Maarten van den Berg 6 years ago
parent
commit
b01ba65522
1 changed files with 19 additions and 0 deletions
  1. 19 0
      piket_client/gui.py

+ 19 - 0
piket_client/gui.py

13
     QGridLayout,
13
     QGridLayout,
14
     QInputDialog,
14
     QInputDialog,
15
     QMainWindow,
15
     QMainWindow,
16
+    QMessageBox,
16
     QPushButton,
17
     QPushButton,
17
     QSizePolicy,
18
     QSizePolicy,
18
     QToolBar,
19
     QToolBar,
175
         )
176
         )
176
         self.toolbar.addAction(self.load_icon("undo.svg"), "Oeps")
177
         self.toolbar.addAction(self.load_icon("undo.svg"), "Oeps")
177
 
178
 
179
+        self.toolbar.addAction(
180
+            self.load_icon("quit.svg"), "Afsluiten", self.confirm_quit
181
+        )
182
+
178
         self.toolbar.addWidget(self.create_spacer())
183
         self.toolbar.addWidget(self.create_spacer())
179
 
184
 
180
         # Right
185
         # Right
263
 
268
 
264
             self.main_widget.init_ui()
269
             self.main_widget.init_ui()
265
 
270
 
271
+    def confirm_quit(self) -> None:
272
+        """ Ask for confirmation that the user wishes to quit, then do so. """
273
+        ok = QMessageBox.warning(
274
+            self,
275
+            "Wil je echt afsluiten?",
276
+            "Bevestig dat je wilt afsluiten.",
277
+            QMessageBox.Yes,
278
+            QMessageBox.Cancel,
279
+        )
280
+
281
+        if ok == QMessageBox.Yes:
282
+            LOG.warning("Shutdown by user.")
283
+            QApplication.instance().quit()
284
+
266
     @staticmethod
285
     @staticmethod
267
     def create_spacer() -> QWidget:
286
     def create_spacer() -> QWidget:
268
         """ Return an empty QWidget that automatically expands. """
287
         """ Return an empty QWidget that automatically expands. """