Skip to content

Commit

Permalink
Remember previous directories for chrono data and saved graph files
Browse files Browse the repository at this point in the history
Use graph title as default filename
  • Loading branch information
mncoppola committed Mar 22, 2021
1 parent 37bb30b commit 8b9bff9
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions ChronoPlotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@ def __init__(self):

self.dir_autofill_shown = False

self.prev_data_dir = None
self.prev_save_dir = ""

self.initUI()

def initUI(self):
Expand Down Expand Up @@ -755,7 +758,9 @@ def enumerate_LR_dir(self, path):
return None

def dirDialog(self):
path = QFileDialog.getExistingDirectory(None, "Select directory")
print("Previous directory: %s" % self.prev_data_dir)
path = QFileDialog.getExistingDirectory(None, "Select directory", self.prev_data_dir)
self.prev_data_dir = path
print("Selected directory: %s" % path)

if path == "":
Expand Down Expand Up @@ -1193,9 +1198,20 @@ def showGraph(self, save_without_showing=False):
plt.xticks(range(len(xticks)), xticks)

if save_without_showing:

# Use the graph title as the default filename, or just "graph.png" if empty
if graph_title == "":
file_name = "graph"
else:
file_name = graph_title
save_path = os.path.join(self.prev_save_dir, "%s.png" % file_name)
print("graph_title: '%s'" % graph_title)
print("file_name: '%s'" % file_name)
print("save_path: '%s'" % save_path)
filters = "PNG image (*.png);;SVG image (*.svg);;PDF file (*.pdf)"
path = QFileDialog().getSaveFileName(self, "Save graph as image", "graph.png", filters)[0]
path = QFileDialog().getSaveFileName(self, "Save graph as image", save_path, filters)[0]
print("User selected save path '%s'" % path)
self.prev_save_dir = os.path.dirname(path)

# User canceled file dialog
if path == "":
Expand Down

0 comments on commit 8b9bff9

Please sign in to comment.