summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2011-10-09 05:11:56 +0200
committerhut <hut@lavabit.com>2011-10-09 05:59:10 +0200
commit710b0bb77fef315bb023a32e244e0da663cfb532 (patch)
tree6c48c8f611e1c3dc21d4d668bcb8e544e299fbae
parentbf331bb90d56bc3278f0f11be42c66d6c1ad5ad1 (diff)
downloadranger-710b0bb77fef315bb023a32e244e0da663cfb532.tar.gz
api.apps: added test whether X runs or not.
-rw-r--r--ranger/api/apps.py14
-rw-r--r--ranger/defaults/apps.py27
2 files changed, 28 insertions, 13 deletions
diff --git a/ranger/api/apps.py b/ranger/api/apps.py
index f1fcba62..62632df2 100644
--- a/ranger/api/apps.py
+++ b/ranger/api/apps.py
@@ -63,6 +63,10 @@ class Applications(FileManagerAware):
 			return True
 
 		for dep in deps:
+			if dep == 'X':
+				if 'DISPLAY' not in os.environ or not os.environ['DISPLAY']:
+					return False
+				continue
 			if hasattr(dep, 'dependencies') \
 			and not self._meets_dependencies(dep):
 				return False
@@ -132,10 +136,13 @@ class Applications(FileManagerAware):
 	@classmethod
 	def generic(cls, *args, **keywords):
 		flags = 'flags' in keywords and keywords['flags'] or ""
+		deps = 'deps' in keywords and keywords['deps'] or ()
 		for name in args:
 			assert isinstance(name, str)
 			if not hasattr(cls, "app_" + name):
-				setattr(cls, "app_" + name, _generic_wrapper(name, flags=flags))
+				fnc = _generic_wrapper(name, flags=flags)
+				fnc = depends_on(*deps)(fnc)
+				setattr(cls, "app_" + name, fnc)
 
 
 def tup(*args):
@@ -152,7 +159,10 @@ def tup(*args):
 def depends_on(*args):
 	args = tuple(flatten(args))
 	def decorator(fnc):
-		fnc.dependencies = args
+		try:
+			fnc.dependencies += args
+		except:
+			fnc.dependencies  = args
 		return fnc
 	return decorator
 
diff --git a/ranger/defaults/apps.py b/ranger/defaults/apps.py
index 10f0b3cf..802dca91 100644
--- a/ranger/defaults/apps.py
+++ b/ranger/defaults/apps.py
@@ -123,7 +123,8 @@ class CustomApplications(Applications):
 		args[0] += '2'
 		return args
 
-	@depends_on('feh')
+	# A dependence on "X" means: this programs requires a running X server!
+	@depends_on('feh', 'X')
 	def app_set_bg_with_feh(self, c):
 		c.flags += 'd'
 		arg = {11: '--bg-scale', 12: '--bg-tile', 13: '--bg-center',
@@ -132,7 +133,7 @@ class CustomApplications(Applications):
 			return 'feh', arg[c.mode], c.file.path
 		return 'feh', arg[11], c.file.path
 
-	@depends_on('feh')
+	@depends_on('feh', 'X')
 	def app_feh(self, c):
 		c.flags += 'd'
 		if c.mode is 0 and len(c.files) is 1: # view all files in the cwd
@@ -140,7 +141,7 @@ class CustomApplications(Applications):
 			return 'feh', '--start-at', c.file.basename, images
 		return 'feh', c
 
-	@depends_on('sxiv')
+	@depends_on('sxiv', 'X')
 	def app_sxiv(self, c):
 		c.flags = 'd' + c.flags
 		if len(c.files) is 1:
@@ -159,7 +160,7 @@ class CustomApplications(Applications):
 			return 'aunpack', '-l', c.file.path
 		return 'aunpack', c.file.path
 
-	@depends_on('file-roller')
+	@depends_on('file-roller', 'X')
 	def app_file_roller(self, c):
 		c.flags += 'd'
 		return 'file-roller', c.file.path
@@ -182,7 +183,7 @@ class CustomApplications(Applications):
 		files_without_extensions = map(strip_extensions, c.files)
 		return "java", files_without_extensions
 
-	@depends_on('totem')
+	@depends_on('totem', 'X')
 	def app_totem(self, c):
 		if c.mode is 0:
 			return "totem", c
@@ -198,20 +199,24 @@ class CustomApplications(Applications):
 			# aka "Open with..."
 			return "mimeopen", "--ask", c
 
+
 # Often a programs invocation is trivial.  For example:
 #    vim test.py readme.txt [...]
+#
 # This could be implemented like:
 #    @depends_on("vim")
 #    def app_vim(self, context):
 #        return "vim", context
-# Instead of creating such a generic function for each program, just add
-# its name here and it will be automatically done for you.
-CustomApplications.generic('vim', 'fceux', 'elinks', 'wine',
-		'zsnes', 'javac')
+#
+# But this is redundant and ranger does this automatically.  However, sometimes
+# you want to change some properties like flags or dependencies.  Add programs
+# that should only run in X this way here:
+CustomApplications.generic('fceux', 'wine', 'zsnes', deps=['X'])
 
-# By setting flags='d', this programs will not block ranger's terminal:
+# Add those which should only run in X AND should be detached/forked here:
 CustomApplications.generic('opera', 'firefox', 'apvlv', 'evince',
-		'zathura', 'gimp', 'mirage', 'eog', flags='d')
+		'zathura', 'gimp', 'mirage', 'eog', 'jumanji',
+			flags='d', deps=['X'])
 
 # What filetypes are recognized as scripts for interpreted languages?
 # This regular expression is used in app_default()