summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2010-04-27 03:33:24 +0200
committerhut <hut@lavabit.com>2010-04-27 03:33:24 +0200
commit4db79381d4874318c76c605cf990c630c9d70115 (patch)
tree7e15fc295a69672b3b06828694953b375612f38a
parent2e631f441dc2cc89cbdf8744ee31b98112b2395d (diff)
parentbea16f4e5d56edb1dcfa3e19c8e1fbc2cde587a3 (diff)
downloadranger-4db79381d4874318c76c605cf990c630c9d70115.tar.gz
Merge branch 'generic'
-rw-r--r--ranger/api/apps.py24
-rw-r--r--ranger/defaults/apps.py81
2 files changed, 41 insertions, 64 deletions
diff --git a/ranger/api/apps.py b/ranger/api/apps.py
index 90162e0b..d2e9ac4f 100644
--- a/ranger/api/apps.py
+++ b/ranger/api/apps.py
@@ -76,7 +76,7 @@ class Applications(FileManagerAware):
 				application_handler = getattr(self, 'app_' + app)
 			except AttributeError:
 				if app in get_executables():
-					return tup(app, *context)
+					return _generic_app(app, context)
 				continue
 			if self._meets_dependencies(application_handler):
 				return application_handler(context)
@@ -99,7 +99,7 @@ class Applications(FileManagerAware):
 			handler = getattr(self, 'app_' + app)
 		except AttributeError:
 			if app in get_executables():
-				return tup(app, *context)  # generic app
+				return _generic_app(app, context)
 			handler = self.app_default
 		return handler(context)
 
@@ -116,6 +116,13 @@ class Applications(FileManagerAware):
 			result |= set(m[4:] for m in cls.__dict__ if m.startswith('app_'))
 		return sorted(result)
 
+	@classmethod
+	def generic(cls, *args, **keywords):
+		flags = 'flags' in keywords and keywords['flags'] or ""
+		for name in args:
+			assert isinstance(name, str)
+			setattr(cls, "app_" + name, _generic_wrapper(name, flags=flags))
+
 
 def tup(*args):
 	"""
@@ -134,3 +141,16 @@ def depends_on(*args):
 		fnc.dependencies = args
 		return fnc
 	return decorator
+
+
+def _generic_app(name, context, flags=''):
+	"""Use this function when no other information is given"""
+	context.flags += flags
+	return tup(name, *context)
+
+
+def _generic_wrapper(name, flags=''):
+	"""Wraps _generic_app into a method for Applications"""
+	assert isinstance(name, str)
+	return depends_on(name)(lambda self, context:
+			_generic_app(name, context, flags))
diff --git a/ranger/defaults/apps.py b/ranger/defaults/apps.py
index 6c09298a..4dd3bde5 100644
--- a/ranger/defaults/apps.py
+++ b/ranger/defaults/apps.py
@@ -92,13 +92,10 @@ class CustomApplications(Applications):
 
 
 	# ----------------------------------------- application definitions
+	# Note: Trivial applications are defined at the bottom
 	def app_pager(self, c):
 		return tup('less', *c)
 
-	@depends_on('vim')
-	def app_vim(self, c):
-		return tup('vim', *c)
-
 	def app_editor(self, c):
 		try:
 			default_editor = os.environ['EDITOR']
@@ -135,16 +132,6 @@ class CustomApplications(Applications):
 		else:
 			return tup('mplayer', *c)
 
-	@depends_on("eog")
-	def app_eye_of_gnome(self, c):
-		c.flags += 'd'
-		return tup('eog', *c)
-
-	@depends_on('mirage')
-	def app_mirage(self, c):
-		c.flags += 'd'
-		return tup('mirage', *c)
-
 	@depends_on('feh')
 	def app_feh(self, c):
 		arg = {1: '--bg-scale', 2: '--bg-tile', 3: '--bg-center'}
@@ -171,10 +158,6 @@ class CustomApplications(Applications):
 		except:
 			return tup('feh', *c)
 
-	@depends_on("gimp")
-	def app_gimp(self, c):
-		return tup('gimp', *c)
-
 	@depends_on('aunpack')
 	def app_aunpack(self, c):
 		if c.mode is 0:
@@ -182,15 +165,6 @@ class CustomApplications(Applications):
 			return tup('aunpack', '-l', c.file.path)
 		return tup('aunpack', c.file.path)
 
-	@depends_on('fceux')
-	def app_fceux(self, c):
-		return tup('fceux', *c)
-
-	@depends_on('apvlv')
-	def app_apvlv(self, c):
-		c.flags += 'd'
-		return tup('apvlv', *c)
-
 	@depends_on('make')
 	def app_make(self, c):
 		if c.mode is 0:
@@ -200,25 +174,6 @@ class CustomApplications(Applications):
 		if c.mode is 2:
 			return tup("make", "clear")
 
-	@depends_on('elinks')
-	def app_elinks(self, c):
-		c.flags += 'D'
-		return tup('elinks', *c)
-
-	@depends_on('opera')
-	def app_opera(self, c):
-		c.flags += 'd'
-		return tup('opera', *c)
-
-	@depends_on('firefox')
-	def app_firefox(self, c):
-		c.flags += 'd'
-		return tup("firefox", *c)
-
-	@depends_on('javac')
-	def app_javac(self, c):
-		return tup("javac", *c)
-
 	@depends_on('java')
 	def app_java(self, c):
 		def strip_extensions(file):
@@ -228,22 +183,6 @@ class CustomApplications(Applications):
 		files_without_extensions = map(strip_extensions, c.files)
 		return tup("java", files_without_extensions)
 
-	@depends_on('zsnes')
-	def app_zsnes(self, c):
-		return tup("zsnes", c.file.path)
-
-	@depends_on('evince')
-	def app_evince(self, c):
-		return tup("evince", *c)
-
-	@depends_on('zathura')
-	def app_zathura(self, c):
-		return tup("zathura", *c)
-
-	@depends_on('wine')
-	def app_wine(self, c):
-		return tup("wine", c.file.path)
-
 	@depends_on('totem')
 	def app_totem(self, c):
 		if c.mode is 0:
@@ -251,6 +190,24 @@ class CustomApplications(Applications):
 		if c.mode is 1:
 			return tup("totem", "--fullscreen", *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, c):
+#        return tup("vim", *c.files)
+# 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')
+
+# By setting flags='d', this programs will not block ranger's terminal:
+CustomApplications.generic('opera', 'firefox', 'apvlv', 'evince',
+		'zathura', 'gimp', 'mirage', 'eog', flags='d')
+
+# What filetypes are recognized as scripts for interpreted languages?
+# This regular expression is used in app_default()
 INTERPRETED_LANGUAGES = re.compile(r'''
 	^(text|application)/x-(
 		haskell|perl|python|ruby|sh
teral.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 */
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: module ranger.gui.widgets.taskview</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head><body bgcolor="#f0f0f8">

<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial">&nbsp;<br><big><big><strong><a href="ranger.html"><font color="#ffffff">ranger</font></a>.<a href="ranger.gui.html"><font color="#ffffff">gui</font></a>.<a href="ranger.gui.widgets.html"><font color="#ffffff">widgets</font></a>.taskview</strong></big></big></font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/hut/work/ranger/ranger/gui/widgets/taskview.py">/home/hut/work/ranger/ranger/gui/widgets/taskview.py</a></font></td></tr></table>
    <p><tt>The&nbsp;<a href="#TaskView">TaskView</a>&nbsp;allows&nbsp;you&nbsp;to&nbsp;modify&nbsp;what&nbsp;the&nbsp;loader&nbsp;is&nbsp;doing.</tt></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#aa55cc">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr>
    
<tr><td bgcolor="#aa55cc"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="curses.html">curses</a><br>
</td><td width="25%" valign=top></td><td width="25%" valign=top></td><td width="25%" valign=top></td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ee77aa">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr>
    
<tr><td bgcolor="#ee77aa"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><dl>
<dt><font face="helvetica, arial"><a href="ranger.ext.accumulator.html#Accumulator">ranger.ext.accumulator.Accumulator</a>(<a href="builtins.html#object">builtins.object</a>)
</font></dt><dd>
<dl>
<dt><font face="helvetica, arial"><a href="ranger.gui.widgets.taskview.html#TaskView">TaskView</a>(<a href="ranger.gui.widgets.html#Widget">ranger.gui.widgets.Widget</a>, <a href="ranger.ext.accumulator.html#Accumulator">ranger.ext.accumulator.Accumulator</a>)
</font></dt></dl>
</dd>
<dt><font face="helvetica, arial"><a href="ranger.gui.widgets.html#Widget">ranger.gui.widgets.Widget</a>(<a href="ranger.gui.displayable.html#Displayable">ranger.gui.displayable.Displayable</a>)
</font></dt><dd>
<dl>
<dt><font face="helvetica, arial"><a href="ranger.gui.widgets.taskview.html#TaskView">TaskView</a>(<a href="ranger.gui.widgets.html#Widget">ranger.gui.widgets.Widget</a>, <a href="ranger.ext.accumulator.html#Accumulator">ranger.ext.accumulator.Accumulator</a>)
</font></dt></dl>
</dd>
</dl>
 <p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#000000" face="helvetica, arial"><a name="TaskView">class <strong>TaskView</strong></a>(<a href="ranger.gui.widgets.html#Widget">ranger.gui.widgets.Widget</a>, <a href="ranger.ext.accumulator.html#Accumulator">ranger.ext.accumulator.Accumulator</a>)</font></td></tr>
    
<tr><td bgcolor="#ffc8d8"><tt>&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><dl><dt>Method resolution order:</dt>
<dd><a href="ranger.gui.widgets.taskview.html#TaskView">TaskView</a></dd>
<dd><a href="ranger.gui.widgets.html#Widget">ranger.gui.widgets.Widget</a></dd>
<dd><a href="ranger.gui.displayable.html#Displayable">ranger.gui.displayable.Displayable</a></dd>
<dd><a href="ranger.shared.html#EnvironmentAware">ranger.shared.EnvironmentAware</a></dd>
<dd><a href="ranger.shared.html#FileManagerAware">ranger.shared.FileManagerAware</a></dd>
<dd><a href="ranger.shared.html#Awareness">ranger.shared.Awareness</a></dd>
<dd><a href="ranger.gui.curses_shortcuts.html#CursesShortcuts">ranger.gui.curses_shortcuts.CursesShortcuts</a></dd>
<dd><a href="ranger.shared.settings.html#SettingsAware">ranger.shared.settings.SettingsAware</a></dd>
<dd><a href="ranger.ext.accumulator.html#Accumulator">ranger.ext.accumulator.Accumulator</a></dd>
<dd><a href="builtins.html#object">builtins.object</a></dd>
</dl>
<hr>
Methods defined here:<br>
<dl><dt><a name="TaskView-__init__"><strong>__init__</strong></a>(self, win)</dt></dl>

<dl><dt><a name="TaskView-draw"><strong>draw</strong></a>(self)</dt></dl>

<dl><dt><a name="TaskView-get_list"><strong>get_list</strong></a>(self)</dt></dl>

<dl><dt><a name="TaskView-press"><strong>press</strong></a>(self, key)</dt></dl>

<dl><dt><a name="TaskView-task_move"><strong>task_move</strong></a>(self, absolute, i<font color="#909090">=None</font>)</dt></dl>

<dl><dt><a name="TaskView-task_remove"><strong>task_remove</strong></a>(self, i<font color="#909090">=None</font>)</dt></dl>

<hr>
Data and other attributes defined here:<br>
<dl><dt><strong>old_lst</strong> = None</dl>

<hr>
Methods inherited from <a href="ranger.gui.displayable.html#Displayable">ranger.gui.displayable.Displayable</a>:<br>
<dl><dt><a name="TaskView-__contains__"><strong>__contains__</strong></a>(self, item)</dt><dd><tt>Is&nbsp;item&nbsp;inside&nbsp;the&nbsp;boundaries?<br>
item&nbsp;can&nbsp;be&nbsp;an&nbsp;iterable&nbsp;like&nbsp;[y,&nbsp;x]&nbsp;or&nbsp;an&nbsp;object&nbsp;with&nbsp;x&nbsp;and&nbsp;y&nbsp;methods.</tt></dd></dl>

<dl><dt><a name="TaskView-__nonzero__"><strong>__nonzero__</strong></a>(self)</dt><dd><tt>Always&nbsp;True</tt></dd></dl>

<dl><dt><a name="TaskView-__str__"><strong>__str__</strong></a>(self)</dt></dl>

<dl><dt><a name="TaskView-click"><strong>click</strong></a>(self, event)</dt><dd><tt>Called&nbsp;when&nbsp;a&nbsp;mouse&nbsp;key&nbsp;is&nbsp;pressed&nbsp;and&nbsp;self.<strong>focused</strong>&nbsp;is&nbsp;True.<br>
Override&nbsp;this!</tt></dd></dl>

<dl><dt><a name="TaskView-contains_point"><strong>contains_point</strong></a>(self, y, x)</dt><dd><tt>Test&nbsp;whether&nbsp;the&nbsp;point&nbsp;(with&nbsp;absolute&nbsp;coordinates)&nbsp;lies<br>
within&nbsp;the&nbsp;boundaries&nbsp;of&nbsp;this&nbsp;object.</tt></dd></dl>

<dl><dt><a name="TaskView-destroy"><strong>destroy</strong></a>(self)</dt><dd><tt>Called&nbsp;when&nbsp;the&nbsp;object&nbsp;is&nbsp;destroyed.<br>
Override&nbsp;this!</tt></dd></dl>

<dl><dt><a name="TaskView-finalize"><strong>finalize</strong></a>(self)</dt><dd><tt>Called&nbsp;after&nbsp;every&nbsp;displayable&nbsp;is&nbsp;done&nbsp;drawing.<br>
Override&nbsp;this!</tt></dd></dl>

<dl><dt><a name="TaskView-poke"><strong>poke</strong></a>(self)</dt><dd><tt>Called&nbsp;before&nbsp;drawing,&nbsp;even&nbsp;if&nbsp;invisible</tt></dd></dl>

<dl><dt><a name="TaskView-resize"><strong>resize</strong></a>(self, y, x, hei<font color="#909090">=None</font>, wid<font color="#909090">=None</font>)</dt><dd><tt>Resize&nbsp;the&nbsp;widget</tt></dd></dl>

<hr>
Data and other attributes inherited from <a href="ranger.shared.html#EnvironmentAware">ranger.shared.EnvironmentAware</a>:<br>
<dl><dt><strong>env</strong> = None</dl>

<hr>
Data and other attributes inherited from <a href="ranger.shared.html#FileManagerAware">ranger.shared.FileManagerAware</a>:<br>
<dl><dt><strong>fm</strong> = None</dl>

<hr>
Data descriptors inherited from <a href="ranger.shared.html#Awareness">ranger.shared.Awareness</a>:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dd>
</dl>
<dl><dt><strong>__weakref__</strong></dt>
<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</tt></dd>
</dl>
<hr>
Methods inherited from <a href="ranger.gui.curses_shortcuts.html#CursesShortcuts">ranger.gui.curses_shortcuts.CursesShortcuts</a>:<br>
<dl><dt><a name="TaskView-addnstr"><strong>addnstr</strong></a>(self, *args)</dt></dl>

<dl><dt><a name="TaskView-addstr"><strong>addstr</strong></a>(self, *args)</dt></dl>

<dl><dt><a name="TaskView-color"><strong>color</strong></a>(self, keylist<font color="#909090">=None</font>, *keys)</dt><dd><tt>Change&nbsp;the&nbsp;colors&nbsp;from&nbsp;now&nbsp;on.</tt></dd></dl>

<dl><dt><a name="TaskView-color_at"><strong>color_at</strong></a>(self, y, x, wid, keylist<font color="#909090">=None</font>, *keys)</dt><dd><tt>Change&nbsp;the&nbsp;colors&nbsp;at&nbsp;the&nbsp;specified&nbsp;position</tt></dd></dl>

<dl><dt><a name="TaskView-color_reset"><strong>color_reset</strong></a>(self)</dt><dd><tt>Change&nbsp;the&nbsp;colors&nbsp;to&nbsp;the&nbsp;default&nbsp;colors</tt></dd></dl>

<hr>
Data and other attributes inherited from <a href="ranger.shared.settings.html#SettingsAware">ranger.shared.settings.SettingsAware</a>:<br>
<dl><dt><strong>settings</strong> = &lt;ranger.ext.openstruct.OpenStruct object at 0x7f28d0aa5bd0&gt;</dl>

<hr>
Methods inherited from <a href="ranger.ext.accumulator.html#Accumulator">ranger.ext.accumulator.Accumulator</a>:<br>
<dl><dt><a name="TaskView-correct_pointer"><strong>correct_pointer</strong></a>(self)</dt></dl>

<dl><dt><a name="TaskView-get_height"><strong>get_height</strong></a>(self)</dt><dd><tt>OVERRIDE&nbsp;THIS</tt></dd></dl>

<dl><dt><a name="TaskView-move"><strong>move</strong></a>(self, relative<font color="#909090">=0</font>, absolute<font color="#909090">=None</font>, pages<font color="#909090">=None</font>, narg<font color="#909090">=None</font>)</dt></dl>

<dl><dt><a name="TaskView-move_to_obj"><strong>move_to_obj</strong></a>(self, arg, attr<font color="#909090">=None</font>)</dt></dl>

<dl><dt><a name="TaskView-pointer_is_synced"><strong>pointer_is_synced</strong></a>(self)</dt></dl>

<dl><dt><a name="TaskView-sync_index"><strong>sync_index</strong></a>(self, **kw)</dt></dl>

</td></tr></table></td></tr></table>
</body></html>