Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

Commit

Permalink
Merge branch 'ui' of /~https://github.com/isogeo/isogeo-2-office into ui
Browse files Browse the repository at this point in the history
  • Loading branch information
Guts committed Aug 27, 2019
2 parents 0de69b8 + cb77b01 commit 74eeb1f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
2 changes: 1 addition & 1 deletion IsogeoToOffice.py
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ def set_output_folder(self):
selected_folder = self.app_utils.open_FileNameDialog(
self,
file_type="folder",
from_dir=self.app_settings.value("settings/out_folder_path"),
from_dir=self.app_settings.value("settings/out_folder_path", app_outdir),
)
# test selected folder
if not path.exists(selected_folder):
Expand Down
41 changes: 26 additions & 15 deletions modules/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,31 +131,36 @@ def open_urls(self, li_url):
open_new_tab(url)
x += 1

def open_dir_file(self, target):
def open_dir_file(self, target: str):
"""Open a file or a directory in the explorer of the operating system.
:param str target: path of the folder or file to open
"""
target_dir = Path(target)
# check if the file or the directory exists
if not path.exists(target):
raise IOError("No such file: {0}".format(target))
if not target_dir.exists():
raise IOError("No such file/folder: {0}".format(target))

# check the read permission
if not access(target, R_OK):
raise IOError("Cannot access file: {0}".format(target))

# open the directory or the file according to the os
if opersys == "win32": # Windows
proc = startfile(path.realpath(target))
proc = startfile(target_dir.resolve())

elif opersys.startswith("linux"): # Linux:
proc = subprocess.Popen(
["xdg-open", target], stdout=subprocess.PIPE, stderr=subprocess.PIPE
["xdg-open", target_dir.resolve()],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)

elif opersys == "darwin": # Mac:
proc = subprocess.Popen(
["open", "--", target], stdout=subprocess.PIPE, stderr=subprocess.PIPE
["open", "--", target_dir.resolve()],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)

else:
Expand All @@ -176,13 +181,16 @@ def open_FileNameDialog(
:param str file_type: credentials | thumbnails | folder
:param str from_dir: path to the start directory. Default value: "downloads"
"""
if from_dir == "downloads":
# check the folder to open from
if from_dir.lower() == "downloads":
# get user download directory
start_dir = path.realpath(path.join(path.expanduser("~"), "Downloads"))
start_dir = Path.home() / "Downloads"
else:
start_dir = path.realpath(from_dir)
if not path.exists(start_dir):
start_dir = path.expanduser("~")
start_dir = Path(from_dir)
# check if folder exists
if not start_dir.exists():
start_dir = Path.home()

# set options
options = QFileDialog.Options()
# options |= QFileDialog.DontUseNativeDialog
Expand All @@ -197,7 +205,7 @@ def open_FileNameDialog(
return QFileDialog.getOpenFileName(
parent=None,
caption=dlg_title,
directory=start_dir,
directory=str(start_dir.resolve()),
filter=file_filters,
options=options,
)
Expand All @@ -209,23 +217,26 @@ def open_FileNameDialog(
return QFileDialog.getOpenFileName(
parent=None,
caption=dlg_title,
directory=start_dir,
directory=str(start_dir.resolve()),
filter=file_filters,
options=options,
)
elif file_type == "folder":
options |= QFileDialog.ShowDirsOnly
dlg_title = parent.tr("Select folder")
return QFileDialog.getExistingDirectory(
parent=None, caption=dlg_title, directory=start_dir, options=options
parent=None,
caption=dlg_title,
directory=str(start_dir.resolve()),
options=options,
)
else:
file_filters = "All Files (*)"
dlg_title = parent.tr("Pick a file")
return QFileDialog.getOpenFileName(
parent=None,
caption=dlg_title,
directory=start_dir,
directory=str(start_dir.resolve()),
filter=file_filters,
options=options,
)
Expand Down

0 comments on commit 74eeb1f

Please sign in to comment.