fix and generalize
[hband-tools.git] / icewm / icewm-menu-recently-used
blob41bd1c15b29e5a2e02c21bd75de93a1cb804e12b
1 #!/usr/bin/env python2
3 import os
4 import sys
5 import re
6 import gtk
8 def esc(s):
9         return s.replace('\\', '\\\\').replace('"', '\\"')
11 def iconpath_for_mime(mime):
12         BASE = "/usr/share/rox/ROX/MIME"
13         (main, sub) = mime.split('/')
14         path = os.path.join(BASE, main+'-'+sub+'.png')
15         if not os.path.exists(path):
16                 path = os.path.join(BASE, main+'-x-generic.png')
17         return path
20 opt_fullpath = any(flag in sys.argv for flag in ['-f', '--fullpath-label'])
22 dirs = {}
24 while True:
25         item = sys.stdin.readline()
26         if item == '': break
27         
28         item = item.rstrip('\n')
29         mime_type, filepath = item.split('\t', 1)
30         filepath = filepath.rstrip(os.path.sep)
31         
32         if os.path.exists(filepath):
33                 if opt_fullpath:
34                         label = filepath
35                 else:
36                         label = os.path.basename(filepath)
37                 
38                 iconpath = iconpath_for_mime(mime_type)
39                 
40                 # this method seems sparsely supported by applications
41                 # they register their commands wrong.
42                 #
43                 #app = item.last_application()
44                 #(cmd, _, _) = item.get_application_info(app)
45                 #command_str = "%s %s" % (cmd, filepath)
46                 
47                 cmd = "mimeopen-gui"
48                 
49                 print "prog \"%s\" \"%s\" %s %s" % (esc(label), esc(iconpath), cmd, esc(filepath))