Skip to content

Commit

Permalink
gui_master can load command line arguments of analysis files
Browse files Browse the repository at this point in the history
  • Loading branch information
rgerum committed Dec 29, 2023
1 parent 7745417 commit 3f66fb4
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 12 deletions.
26 changes: 14 additions & 12 deletions saenopy/gui/common/plot_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ def __init__(self, parent=None):
with QtShortCuts.QVBoxLayout(self) as main_layout0:
main_layout0.setContentsMargins(0, 0, 0, 0)
with QtShortCuts.QHBoxLayout() as main_layout00:
self.button_save = QtShortCuts.QPushButton(None, "save", self.save)
self.button_load = QtShortCuts.QPushButton(None, "load", self.load)
self.button_save = QtShortCuts.QPushButton(None, "save", lambda x: self.save())
self.button_load = QtShortCuts.QPushButton(None, "load", lambda x: self.load())
main_layout00.addStretch()
with QtShortCuts.QHBoxLayout() as main_layout:
with QtShortCuts.QVBoxLayout() as layout:
Expand Down Expand Up @@ -132,24 +132,26 @@ def __init__(self, parent=None):
self.addGroup()
self.current_plot_func = self.run2

def save(self):
new_path = QtWidgets.QFileDialog.getSaveFileName(None, "Save Session", os.getcwd(), "JSON File (*.json)")
if new_path:
if not new_path.endswith(".json"):
new_path += ".json"
def save(self, filename=None):
if filename is None:
filename = QtWidgets.QFileDialog.getSaveFileName(None, "Save Session", os.getcwd(), "JSON File (*.json)")
if filename:
if not filename.endswith(".json"):
filename += ".json"
list_new = []
for item in self.list.data:
list_new.append({"name": item[0], "selected": item[1], "color": item[3], "paths": []})
for item2 in item[2]:
list_new[-1]["paths"].append({"path": item2[0], "selected": item[1]})

with open(new_path, "w") as fp:
with open(filename, "w") as fp:
json.dump(list_new, fp, indent=2)

def load(self):
new_path = QtWidgets.QFileDialog.getOpenFileName(None, "Load Session", os.getcwd(), "JSON File (*.json)")
if new_path:
with open(new_path, "r") as fp:
def load(self, filename=None):
if filename is None:
filename = QtWidgets.QFileDialog.getOpenFileName(None, "Load Session", os.getcwd(), "JSON File (*.json)")
if filename:
with open(filename, "r") as fp:
list_new = json.load(fp)
self.list.clear()
self.list.setData([[i["name"], i["selected"], [], i["color"]] for i in list_new])
Expand Down
25 changes: 25 additions & 0 deletions saenopy/gui/gui_master.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import sys
import traceback

Expand Down Expand Up @@ -114,6 +115,30 @@ def timer():

for file in sys.argv[1:]:
print(file)
if file.endswith(".json"):
try:
with open(file, "r") as fp:
data = json.load(fp)
filename = data[0]["paths"][0]["path"]
if filename.endswith(".saenopy"):
self.setTab(2)
self.solver.tabs.setCurrentIndex(1)
self.solver.plotting_window.load(file)
elif filename.endswith("saenopy2D"):
self.setTab(5)
self.pytfm2d.tabs.setCurrentIndex(1)
self.pytfm2d.plotting_window.load(file)
elif filename.endswith(".saenopySpheroid"):
self.setTab(3)
self.spheroid.tabs.setCurrentIndex(1)
self.spheroid.plotting_window.load(file)
elif filename.endswith(".saenopyOrientation"):
self.setTab(4)
self.orientation.tabs.setCurrentIndex(1)
self.orientation.plotting_window.load(file)
continue
except:
continue
if file.endswith(".py"):
self.setTab(6)
elif file.endswith(".saenopy"):
Expand Down

0 comments on commit 3f66fb4

Please sign in to comment.