Skip to content

Commit d1cf8a1

Browse files
authored
Use configurable default path for file dialogs (#184)
1 parent 1859f21 commit d1cf8a1

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

src/window.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
from src.figure_editor import StlMovePanel
4343
from src.qt_utils import ClickableLineEdit, LineEdit
4444
from src.settings_widget import SettingsWidget
45+
import os
4546
import os.path as path
4647
import logging
4748

@@ -854,16 +855,34 @@ def save_dialog(
854855
self,
855856
caption,
856857
format="STL (*.stl *.STL);;Gcode (*.gcode)",
857-
directory="/home/l1va/Downloads/5axes_3d_printer/test",
858-
): # TODO: fix path
858+
directory="",
859+
):
860+
base_dir = getattr(sett(), "project_path", "") or os.getcwd()
861+
if not base_dir or not path.isdir(base_dir):
862+
base_dir = path.expanduser("~")
863+
864+
if directory:
865+
directory = directory if path.isabs(directory) else path.join(base_dir, directory)
866+
else:
867+
directory = base_dir
868+
859869
return QFileDialog.getSaveFileName(None, caption, directory, format)[0]
860870

861871
def open_dialog(
862872
self,
863873
caption,
864874
format="STL (*.stl *.STL);;Gcode (*.gcode)",
865-
directory="/home/l1va/Downloads/5axes_3d_printer/test",
866-
): # TODO: fix path
875+
directory="",
876+
):
877+
base_dir = getattr(sett(), "project_path", "") or os.getcwd()
878+
if not base_dir or not path.isdir(base_dir):
879+
base_dir = path.expanduser("~")
880+
881+
if directory:
882+
directory = directory if path.isabs(directory) else path.join(base_dir, directory)
883+
else:
884+
directory = base_dir
885+
867886
return QFileDialog.getOpenFileName(None, caption, directory, format)[0]
868887

869888
def load_stl(self, stl_actor):

0 commit comments

Comments
 (0)