Skip to content

Commit

Permalink
fixed problems with save dialog overloading
Browse files Browse the repository at this point in the history
  • Loading branch information
rgerum committed Dec 19, 2024
1 parent 8e0c6a4 commit ba8141d
Show file tree
Hide file tree
Showing 13 changed files with 19 additions and 35 deletions.
2 changes: 1 addition & 1 deletion saenopy/gui/code/gui_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def update_console(self, open_script):
self.console.setText(open_script.console)

def load(self):
new_path = QtWidgets.QFileDialog.getOpenFileName(None, "Open Script", os.getcwd(), "Python File (*.py)")
new_path = QtWidgets.QFileDialog.getOpenFileName(None, "Open Script", os.getcwd(), "Python File (*.py)")[0]
if new_path:
self.do_load(new_path)

Expand Down
2 changes: 1 addition & 1 deletion saenopy/gui/common/BatchEvaluateBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def generate_code(self):
return
except IndexError:
return
new_path = QtWidgets.QFileDialog.getSaveFileName(None, "Save Session as Script", os.getcwd(), "Python File (*.py)")
new_path = QtWidgets.QFileDialog.getSaveFileName(None, "Save Session as Script", os.getcwd(), "Python File (*.py)")[0]
if new_path:
# ensure filename ends in .py
if not new_path.endswith(".py"):
Expand Down
4 changes: 2 additions & 2 deletions saenopy/gui/common/PlottingWindowBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def __init__(self, parent=None, batch_evluate_instance=None):

def save(self, filename=None):
if filename is None:
filename = QtWidgets.QFileDialog.getSaveFileName(None, "Save Session", os.getcwd(), "JSON File (*.json)")
filename = QtWidgets.QFileDialog.getSaveFileName(None, "Save Session", os.getcwd(), "JSON File (*.json)")[0]
if filename:
if not filename.endswith(".json"):
filename += ".json"
Expand All @@ -179,7 +179,7 @@ def save(self, filename=None):

def load(self, filename=None):
if filename is None:
filename = QtWidgets.QFileDialog.getOpenFileName(None, "Load Session", os.getcwd(), "JSON File (*.json)")
filename = QtWidgets.QFileDialog.getOpenFileName(None, "Load Session", os.getcwd(), "JSON File (*.json)")[0]
if filename:
with open(filename, "r") as fp:
list_new = json.load(fp)
Expand Down
13 changes: 6 additions & 7 deletions saenopy/gui/common/QtShortCuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,6 @@ def value(self):


class QInputChoice(QInput):
valueChanged = QtCore.Signal(str)

def __init__(self, layout=None, name=None, value=None, values=None, value_names=None, reference_by_index=False, **kwargs):
# initialize the super widget
Expand Down Expand Up @@ -612,15 +611,15 @@ def _openDialog(self):
# open an new files
if not self.existing:
if "PYCHARM_HOSTED" in os.environ:
filename = QtWidgets.QFileDialog.getSaveFileName(None, self.dialog_title, self.last_folder, self.file_type, options=QtWidgets.QFileDialog.DontUseNativeDialog)
filename = QtWidgets.QFileDialog.getSaveFileName(None, self.dialog_title, self.last_folder, self.file_type, options=QtWidgets.QFileDialog.DontUseNativeDialog)[0]
else:
filename = QtWidgets.QFileDialog.getSaveFileName(None, self.dialog_title, self.last_folder, self.file_type)
filename = QtWidgets.QFileDialog.getSaveFileName(None, self.dialog_title, self.last_folder, self.file_type)[0]
# or choose an existing file
else:
if "PYCHARM_HOSTED" in os.environ:
filename = QtWidgets.QFileDialog.getOpenFileName(None, self.dialog_title, self.last_folder, self.file_type, options=QtWidgets.QFileDialog.DontUseNativeDialog)
filename = QtWidgets.QFileDialog.getOpenFileName(None, self.dialog_title, self.last_folder, self.file_type, options=QtWidgets.QFileDialog.DontUseNativeDialog)[0]
else:
filename = QtWidgets.QFileDialog.getOpenFileName(None, self.dialog_title, self.last_folder, self.file_type)
filename = QtWidgets.QFileDialog.getOpenFileName(None, self.dialog_title, self.last_folder, self.file_type)[0]

# get the string
if isinstance(filename, tuple): # Qt5
Expand Down Expand Up @@ -916,7 +915,7 @@ def AddQSaveFileChoose(layout, text, value=None, dialog_title="Choose File", fil
lineEdit.setEnabled(False)

def OpenDialog():
srcpath = QtWidgets.QFileDialog.getSaveFileName(None, dialog_title, os.getcwd(), file_type)
srcpath = QtWidgets.QFileDialog.getSaveFileName(None, dialog_title, os.getcwd(), file_type)[0]
if isinstance(srcpath, tuple):
srcpath = srcpath[0]
else:
Expand Down Expand Up @@ -949,7 +948,7 @@ def AddQOpenFileChoose(layout, text, value=None, dialog_title="Choose File", fil
lineEdit.setEnabled(False)

def OpenDialog():
srcpath = QtWidgets.QFileDialog.getOpenFileName(None, dialog_title, os.getcwd(), file_type)
srcpath = QtWidgets.QFileDialog.getOpenFileName(None, dialog_title, os.getcwd(), file_type)[0]
if isinstance(srcpath, tuple):
srcpath = srcpath[0]
else:
Expand Down
15 changes: 0 additions & 15 deletions saenopy/gui/common/gui_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,18 +590,3 @@ def set_result(self, result):
self.thread.quit()
self.worker.deleteLater()
self.finished.emit()


def wrap_string(func):
def call(*args, **kwargs):
new_path = func(*args, **kwargs)
if new_path:
if isinstance(new_path, tuple):
new_path = new_path[0]
else:
new_path = str(new_path)
return new_path
return call

QtWidgets.QFileDialog.getSaveFileName = wrap_string(QtWidgets.QFileDialog.getSaveFileName)
QtWidgets.QFileDialog.getOpenFileName = wrap_string(QtWidgets.QFileDialog.getOpenFileName)
2 changes: 1 addition & 1 deletion saenopy/gui/common/stack_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __init__(self, layout, name, partner=None, use_time=False):
layout.addWidget(self)

def export(self):
new_path = QtWidgets.QFileDialog.getSaveFileName(None, "Save Images", os.getcwd())
new_path = QtWidgets.QFileDialog.getSaveFileName(None, "Save Images", os.getcwd())[0]
# if we got one, set it
if new_path:
if isinstance(new_path, tuple):
Expand Down
2 changes: 1 addition & 1 deletion saenopy/gui/material_fit/gui_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def set(params, keys=keys):
self.canvas.draw()

def add_measurement(self):
new_path = QtWidgets.QFileDialog.getOpenFileName(None, "Load Measurement", os.getcwd(), "Text File (*.txt);; CSV File (*.csv)")
new_path = QtWidgets.QFileDialog.getOpenFileName(None, "Load Measurement", os.getcwd(), "Text File (*.txt);; CSV File (*.csv)")[0]
if new_path:
self.add_file(new_path)

Expand Down
2 changes: 1 addition & 1 deletion saenopy/gui/solver/modules/TabResultView.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def replot(self):
plotter.render()

def saveScreenshot(self):
new_path = QtWidgets.QFileDialog.getSaveFileName(self, "Save Image", os.getcwd(), "Image Files (*.jpg, *.png)")
new_path = QtWidgets.QFileDialog.getSaveFileName(self, "Save Image", os.getcwd(), "Image Files (*.jpg, *.png)")[0]
# if we got one, set it
if new_path:
imageio.imsave(new_path, self.plotter.image)
Expand Down
2 changes: 1 addition & 1 deletion saenopy/gui/solver/modules/TabStackDisplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def check_available(self, result: Result) -> bool:
def export(self):
if self.result is None:
return
new_path = QtWidgets.QFileDialog.getSaveFileName(None, "Save Images", os.getcwd())
new_path = QtWidgets.QFileDialog.getSaveFileName(None, "Save Images", os.getcwd())[0]
# if we got one, set it
if new_path:
new_path = new_path.strip(".gif").strip("_relaxed.tif").strip("_deformed.tif")
Expand Down
2 changes: 1 addition & 1 deletion saenopy/gui/solver/modules/VTK_Toolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def __init__(self, plotter: BasePlotter, update_display, scalbar_type="deformati
self.button.clicked.connect(lambda x: self.plotter.isometric_view())

def save():
new_path = QtWidgets.QFileDialog.getSaveFileName(None, "Save Images", os.getcwd())
new_path = QtWidgets.QFileDialog.getSaveFileName(None, "Save Images", os.getcwd())[0]
# if we got one, set it
if new_path:
print(new_path)
Expand Down
4 changes: 2 additions & 2 deletions saenopy/gui/solver/modules/exporter/Exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,15 +639,15 @@ def hide_stack_image(self):
self.z_slider.setEnabled(isActive)

def save_parameters(self):
new_path = QtWidgets.QFileDialog.getSaveFileName(None, "Save Parameters", os.getcwd(), "JSON File (*.json)")
new_path = QtWidgets.QFileDialog.getSaveFileName(None, "Save Parameters", os.getcwd(), "JSON File (*.json)")[0]
if new_path:
if not new_path.endswith(".json"):
new_path += ".json"
with open(new_path, "w") as fp:
json.dump(self.get_parameters(), fp, indent=2)

def load_parameters(self):
new_path = QtWidgets.QFileDialog.getOpenFileName(None, "Load Parameters", os.getcwd(), "JSON File (*.json)")
new_path = QtWidgets.QFileDialog.getOpenFileName(None, "Load Parameters", os.getcwd(), "JSON File (*.json)")[0]
if new_path:
try:
with open(new_path, "r") as fp:
Expand Down
2 changes: 1 addition & 1 deletion saenopy/gui/spheroid/modules/LookupTable.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ class SelectLookup(QtWidgets.QDialog):

def loadExisting(self):
last_folder = settings.value("batch", "batch/lookuptable_path")
filename = QtWidgets.QFileDialog.getOpenFileName(None, "Open Lookup Table", last_folder, "Numpy Lookup Table (*.npy);; Pickle Lookup Table (*.pkl)")
filename = QtWidgets.QFileDialog.getOpenFileName(None, "Open Lookup Table", last_folder, "Numpy Lookup Table (*.npy);; Pickle Lookup Table (*.pkl)")[0]
filename = filename[0] if isinstance(filename, tuple) else str(filename) if filename is not None else None

if filename == "":
Expand Down
2 changes: 1 addition & 1 deletion saenopy/gui/tfm2d/modules/BatchEvaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def tab_changed(x):

def generate_data(self):
new_path = QtWidgets.QFileDialog.getSaveFileName(None, "Save Data CSV", os.getcwd(),
"Comma Separated File (*.csv)")
"Comma Separated File (*.csv)")[0]
if not new_path:
return None
# ensure filename ends in .py
Expand Down

0 comments on commit ba8141d

Please sign in to comment.