summary refs log tree commit diff stats
path: root/ranger/data/apps.py
blob: 8a50604d8ec6185bd3dca4bc33b1802b19c1e1eb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# ===================================================================
# This is the configuration file for file type detection and application
# handling.  It's all in python; lines beginning with # are comments.
#
# Scroll down for a few examples.
# ===================================================================
# This system is based on things called MODES and FLAGS.  You can read
# in the man page about them.  To remind you, here's a list of all flags.
# An uppercase flag inverts previous flags of the same name.
#     s   Silent mode.  Output will be discarded.
#     d   Detach the process.  (Run in background)
#     p   Redirect output to the pager
#     w   Wait for an Enter-press when the process is done
#     c   Run the current file only, instead of the selection
#
# To implement flags in this file, you could do this:
#     context.flags += "d"
# Another example:
#     context.flags += "Dw"
#
# To implement modes in this file, you can do something like:
#     if context.mode == 1:
#         <run in one way>
#     elif context.mode == 2:
#         <run in another way>
# ===================================================================
# The methods are called with a "context" object which provides some
# attributes that transfer information.  Relevant attributes are:
#
# mode -- a number, mainly used in determining the action in app_xyz()
# flags -- a string with flags which change the way programs are run
# files -- a list containing files, mainly used in app_xyz
# filepaths -- a list of the paths of each file
# file -- an arbitrary file from that list (or None)
# fm -- the filemanager instance
# popen_kws -- keyword arguments which are directly passed to Popen
# ===================================================================
# The return value of the functions should be either:
# 1. A reference to another app, like:
#     return self.app_editor(context)
#
# 2. A call to the "either" method, which uses the first program that
# is installed on your system.  If none are installed, None is returned.
#     return self.either(context, "libreoffice", "soffice", "ooffice")
#
# 3. A tuple of arguments that should be run.
#     return "mplayer", "-fs", context.file.path
# If you use lists instead of strings, they will be flattened:
#     args = ["-fs", "-shuf"]
#     return "mplayer", args, context.filepaths
# "context.filepaths" can, and will often be abbreviated with just "context":
#     return "mplayer", context
#
# 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
from ranger.api.apps import *

#
# Here, the class "CustomApplications" is defined as a subclass of the default
# application handler class.  It is located at ranger/defaults/apps.py and
# contains a whole lot of definitions.  The reason why we don't put them here
# is that when you update, this file doesn't change.
class CustomApplications(DefaultApps):
	# By default, this just inherits all methods from DefaultApps
	pass

#	def app_kaffeine(self, context):
#		return 'kaffeine', context
#
#	def app_feh_fullscreen_by_default(self, context):
#		return 'feh', '-F', context
#
#	# app_default is the function that is always called to determine which
#	# application to run, unless you specify one manually with :open_with
#	def app_default(self, context):
#		f = context.file #shortcut
#		if f.video or f.audio:
#			return self.app_kaffeine(context)
#
#		if f.image and context.mode == 0:
#			return self.app_feh_fullscreen_by_default(context)
#
#		return DefaultApps.app_default(self, context)
#
#	# You could write this to use an entirely different program to open files:
#	def app_default(self, context):
#		return "mimeopen", context


## 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
##
## 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', deps=['X'], flags='d')