summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--ranger/data/apps.py20
1 files changed, 16 insertions, 4 deletions
diff --git a/ranger/data/apps.py b/ranger/data/apps.py
index c9958e1e..8a50604d 100644
--- a/ranger/data/apps.py
+++ b/ranger/data/apps.py
@@ -54,6 +54,15 @@
 # 4. "None" to indicate that no action was found.
 #     return None
 # ===================================================================
+# When using the "either" method, ranger determines which program to
+# pick by looking at its dependencies.  You can set dependencies by
+# adding the decorator "depends_on":
+#     @depends_on("vim")
+#     def app_vim(self, context):
+#         ....
+# There is a special keyword which you can use as a dependence: "X"
+# This ensures that the program will only run when X is running.
+# ===================================================================
 
 # Import the basics
 from ranger.defaults.apps import CustomApplications as DefaultApps
@@ -93,13 +102,16 @@ class CustomApplications(DefaultApps):
 
 ## 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('zsnes', 'javac')
+##
+## But this is redundant and ranger does this automatically.  However, sometimes
+## you want to change some properties like flags or dependencies.  This can be
+## done with the generic() classmethod.
+#CustomApplications.generic('zsnes', 'wine', deps=['X'])
 
 ## By setting flags='d', this programs will not block ranger's terminal:
-#CustomApplications.generic('gimp', 'evince', flags='d')
+#CustomApplications.generic('gimp', 'evince', deps=['X'], flags='d')
ff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
if __name__ == '__main__': from __init__ import init; init()

from unittest import TestCase, main

class Test(TestCase):
	def test_wrapper(self):
		from ranger.keyapi import Wrapper

		class dummyfm(object):
			def move(relative):
				return "I move down by {0}".format(relative)

		class commandarg(object):
			def __init__(self):
				self.fm = dummyfm
				self.n = None

		arg = commandarg()

		do = Wrapper('fm')
		command = do.move(relative=4)

		self.assertEqual(command(arg), 'I move down by 4')

if __name__ == '__main__': main()