Skip to content

Commit 770729c

Browse files
Update Closing File (#53)
* Partially or completely closes #50. * Removed Signal usage, should be more robust. feels a bit slower, needs review on that. * - small modification enabling navigation to menu's on windows / linux you can now get to the file menu with ALT+F ... then with n to new / o to open ... --------- Co-authored-by: Frank T. Bergmann <frank.thomas.bergmann@gmail.com>
1 parent 05b6d99 commit 770729c

3 files changed

Lines changed: 13 additions & 18 deletions

File tree

src/petab_gui/controllers/mother_controller.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,6 @@ def setup_connections(self):
160160
self.model.sbml.something_changed.connect(
161161
self.unsaved_changes_change
162162
)
163-
# Closing event
164-
self.view.closing_signal.connect(
165-
self.maybe_close
166-
)
167163
# correctly update the visibility even when "x" is clicked in a dock
168164
self.view.measurement_dock.visibilityChanged.connect(
169165
lambda visible: self.actions["show_measurement"].setChecked(
@@ -189,22 +185,22 @@ def setup_actions(self):
189185
"""Setup actions for the main controller."""
190186
actions = {"close": QAction(
191187
qta.icon("mdi6.close"),
192-
"Close", self.view
188+
"&Close", self.view
193189
)}
194190
# Close
195191
actions["close"].setShortcut("Ctrl+Q")
196-
actions["close"].triggered.connect(self.maybe_close)
192+
actions["close"].triggered.connect(self.view.close)
197193
# New File
198194
actions["new"] = QAction(
199195
qta.icon("mdi6.file-document"),
200-
"New", self.view
196+
"&New", self.view
201197
)
202198
actions["new"].setShortcut("Ctrl+N")
203199
actions["new"].triggered.connect(self.new_file)
204200
# Open File
205201
actions["open"] = QAction(
206202
qta.icon("mdi6.folder-open"),
207-
"Open", self.view
203+
"&Open", self.view
208204
)
209205
actions["open"].setShortcut("Ctrl+O")
210206
actions["open"].triggered.connect(
@@ -222,7 +218,7 @@ def setup_actions(self):
222218
# Save
223219
actions["save"] = QAction(
224220
qta.icon("mdi6.content-save-all"),
225-
"Save", self.view
221+
"&Save", self.view
226222
)
227223
actions["save"].setShortcut("Ctrl+S")
228224
actions["save"].triggered.connect(self.save_model)
@@ -346,7 +342,7 @@ def save_model(self):
346342
options=options
347343
)
348344
if not file_name:
349-
return None
345+
return False
350346
if not file_name.endswith(".zip"):
351347
file_name += ".zip"
352348

@@ -370,6 +366,7 @@ def save_model(self):
370366
self.view, "Save Project",
371367
f"Project saved successfully to {file_name}"
372368
)
369+
return True
373370

374371
def open_find_replace_dialog(self):
375372
current_tab = self.view.tab_widget.currentIndex()
@@ -631,8 +628,8 @@ def maybe_close(self):
631628
QMessageBox.Save
632629
)
633630
if reply == QMessageBox.Save:
634-
self.save_model()
635-
self.view.allow_close = True
631+
saved = self.save_model()
632+
self.view.allow_close = saved
636633
elif reply == QMessageBox.Discard:
637634
self.view.allow_close = True
638635
else:

src/petab_gui/views/main_view.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111

1212
class MainWindow(QMainWindow):
13-
closing_signal = Signal()
14-
1513
def __init__(self):
1614
super().__init__()
1715

@@ -184,7 +182,7 @@ def set_docks_visible(self, index):
184182
def closeEvent(self, event):
185183
"""Override the closeEvent to emit a signal and let the controller handle it."""
186184
# Emit the signal to let the controller decide what to do
187-
self.closing_signal.emit()
185+
self.controller.maybe_close()
188186

189187
if self.allow_close:
190188
self.save_settings()

src/petab_gui/views/task_bar.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def menu_name(self):
3939
class FileMenu(BasicMenu):
4040
"""Class for the file menu."""
4141
def menu_name(self):
42-
return "File"
42+
return "&File"
4343

4444
def __init__(self, parent, actions):
4545
super().__init__(parent, actions)
@@ -58,7 +58,7 @@ class EditMenu(BasicMenu):
5858
# done in the next PR)
5959
"""Edit Menu of the TaskBar."""
6060
def menu_name(self):
61-
return "Edit"
61+
return "&Edit"
6262

6363
def __init__(self, parent, actions):
6464
super().__init__(parent, actions)
@@ -78,7 +78,7 @@ def __init__(self, parent, actions):
7878
class ViewMenu(BasicMenu):
7979
"""View Menu of the TaskBar."""
8080
def menu_name(self):
81-
return "View"
81+
return "&View"
8282

8383
def __init__(self, parent, actions):
8484
super().__init__(parent, actions)

0 commit comments

Comments
 (0)