aboutsummaryrefslogtreecommitdiffstats
path: root/lvc/openfiles.py
diff options
context:
space:
mode:
authorJesús Eduardo <heckyel@hyperbola.info>2017-09-11 17:47:17 -0500
committerJesús Eduardo <heckyel@hyperbola.info>2017-09-11 17:47:17 -0500
commit14738704ede6dfa6ac79f362a9c1f7f40f470cdc (patch)
tree31c83bdd188ae7b64d7169974d6f066ccfe95367 /lvc/openfiles.py
parenteb1896583afbbb622cadcde1a24e17173f61904f (diff)
downloadlibrevideoconverter-14738704ede6dfa6ac79f362a9c1f7f40f470cdc.tar.lz
librevideoconverter-14738704ede6dfa6ac79f362a9c1f7f40f470cdc.tar.xz
librevideoconverter-14738704ede6dfa6ac79f362a9c1f7f40f470cdc.zip
rename mvc at lvc
Diffstat (limited to 'lvc/openfiles.py')
-rw-r--r--lvc/openfiles.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/lvc/openfiles.py b/lvc/openfiles.py
new file mode 100644
index 0000000..ef6710a
--- /dev/null
+++ b/lvc/openfiles.py
@@ -0,0 +1,46 @@
+"""openfiles.py -- open files/folders."""
+
+import logging
+import os
+import subprocess
+import sys
+
+
+# To open paths we use an OS-specific command. The approach is from:
+# http://stackoverflow.com/questions/6631299/python-opening-a-folder-in-explorer-nautilus-mac-thingie
+
+def check_kde():
+ return os.environ.get("KDE_FULL_SESSION", None) != None
+
+def _open_path_osx(path):
+ subprocess.call(['open', '--', path])
+
+def _open_path_kde(path):
+ subprocess.call(["kfmclient", "exec", "file://" + path]) # kfmclient is part of konqueror
+
+def _open_path_gnome(path):
+ subprocess.call(["gnome-open",'--'. path])
+
+def _open_path_windows(path):
+ subprocess.call(['explorer', path])
+
+def _open_path(path):
+ if sys.platform == 'darwin':
+ _open_path_osx(path)
+ elif sys.platform == 'linux2':
+ if check_kde():
+ _open_path_kde(path)
+ else:
+ _open_path_gnome(path)
+ elif sys.platform == 'win32':
+ _open_path_windows(path)
+ else:
+ logging.warn("unknown platform: %s", sys.platform)
+
+def reveal_folder(path):
+ """Show a folder in the desktop shell (finder/explorer/nautilous, etc)."""
+ logging.info("reveal_folder: %s", path)
+ if os.path.isdir(path):
+ _open_path(path)
+ else:
+ _open_path(os.path.dirname(path))