Skip to content

Commit 55f02a0

Browse files
Merge pull request #133 from computational-cell-analytics/130_fix_file_dialogs
130_fix_file_dialogs
2 parents ad98e4e + d2e12b1 commit 55f02a0

File tree

1 file changed

+9
-19
lines changed

1 file changed

+9
-19
lines changed

micro_sam/sam_annotator/gui_utils.py

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -47,36 +47,26 @@ def _overwrite():
4747

4848
@magicgui.magicgui(call_button="Create new file", labels=False)
4949
def _create():
50-
msg_box.close()
5150
# unfortunately there exists no dialog to create a directory so we have
5251
# to use "create new file" dialog with some adjustments.
5352
dialog = QtWidgets.QFileDialog(None)
5453
dialog.setFileMode(QtWidgets.QFileDialog.AnyFile)
5554
dialog.setOption(QtWidgets.QFileDialog.ShowDirsOnly)
5655
dialog.setNameFilter("Archives (*.zarr)")
57-
try_cnt = 0
58-
while os.path.splitext(new_path["value"])[1] != ".zarr":
59-
if try_cnt > 3:
60-
new_path["value"] = file_path
61-
return
62-
dialog.exec_()
63-
res = dialog.selectedFiles()
64-
new_path["value"] = res[0] if len(res) > 0 else ""
65-
try_cnt += 1
56+
dialog.exec_()
57+
res = dialog.selectedFiles()
58+
new_path["value"] = res[0] if len(res) > 0 else ""
59+
if os.path.splitext(new_path["value"])[1] != ".zarr":
60+
new_path["value"] += ".zarr"
6661
os.makedirs(new_path["value"])
62+
msg_box.close()
6763

6864
@magicgui.magicgui(call_button="Select different file", labels=False)
6965
def _select():
66+
new_path["value"] = QtWidgets.QFileDialog.getExistingDirectory(
67+
None, "Open a folder", os.path.split(file_path)[0], QtWidgets.QFileDialog.ShowDirsOnly
68+
)
7069
msg_box.close()
71-
try_cnt = 0
72-
while not os.path.exists(new_path["value"]):
73-
if try_cnt > 3:
74-
new_path["value"] = file_path
75-
return
76-
new_path["value"] = QtWidgets.QFileDialog.getExistingDirectory(
77-
None, "Open a folder", os.path.split(file_path)[0], QtWidgets.QFileDialog.ShowDirsOnly
78-
)
79-
try_cnt += 1
8070

8171
msg_box = Container(widgets=[_select, _ignore, _overwrite, _create], layout='horizontal', labels=False)
8272
msg_box.root_native_widget.setWindowTitle("The input data does not match the embeddings file")

0 commit comments

Comments
 (0)