Skip to content

Commit

Permalink
gui: Remember the path to the input files
Browse files Browse the repository at this point in the history
When a user navigates to a directory to read the YML file,
then wants to open a geqdsk file, start in the same directory.
  • Loading branch information
bendudson committed Jul 5, 2024
1 parent d8e6be6 commit 6b1905d
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions hypnotoad/gui/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ def __init__(self):
super().__init__(None)
self.setupUi(self)

# Used in file dialogs
self._current_dir = "."

try:
self.menu_File.setToolTipsVisible(True)
self.menu_Mesh.setToolTipsVisible(True)
Expand Down Expand Up @@ -452,7 +455,7 @@ def select_options_file(self):
"""Choose a Hypnotoad options file to load"""

filename, _ = QFileDialog.getOpenFileName(
self, "Open options file", ".", filter=YAML_FILTER
self, "Open options file", self._current_dir, filter=YAML_FILTER
)

if (filename is None) or (filename == ""):
Expand All @@ -461,6 +464,9 @@ def select_options_file(self):
self.write("Could not find " + filename)
return

# Record the directory so user doesn't have to navigate again
self._current_dir = os.path.dirname(filename)

self.options_file_line_edit.setText(filename)
self.filename = filename
self.read_options()
Expand Down Expand Up @@ -506,7 +512,9 @@ def read_options(self):
def select_geqdsk_file(self):
"""Choose a "geqdsk" equilibrium file to open"""

filename, _ = QFileDialog.getOpenFileName(self, "Open geqdsk file", ".")
filename, _ = QFileDialog.getOpenFileName(
self, "Open geqdsk file", self._current_dir
)

if (filename is None) or (filename == ""):
return # Cancelled
Expand All @@ -517,6 +525,9 @@ def select_geqdsk_file(self):
)
return

# Record the directory so user doesn't have to navigate again
self._current_dir = os.path.dirname(filename)

self.geqdsk_file_line_edit.setText(filename)
self.geqdsk_file_line_edit.setStyleSheet("")

Expand Down Expand Up @@ -643,7 +654,7 @@ def write_grid(self):
filename, _ = QFileDialog.getSaveFileName(
self,
"Save grid to file",
self.gui_options["grid_file"],
os.path.join(self._current_dir, self.gui_options["grid_file"]),
filter=NETCDF_FILTER,
)

Expand Down

0 comments on commit 6b1905d

Please sign in to comment.