Ensure icon in /tmp is removed on exit.
[AddApp.git] / AddApp / AppRun
blob9a607dda16b7dadb0d893020085be51676042eb8
1 #!/usr/bin/env python
2 import os, sys
3 import findrox; findrox.version(1, 9, 6)
4 import rox
5 from rox import g, processes, saving
6 from cStringIO import StringIO
8 def try_interface(uri):
9 errors = StringIO()
10 launcher = processes.PipeThroughCommand(
11 ["0launch", "-d", "--", uri],
12 None, errors)
13 try:
14 launcher.wait()
15 except processes.ChildError, ex:
16 if '(256)' not in str(ex):
17 rox.alert(str(ex))
18 except:
19 rox.report_exception()
20 else:
21 return True
22 return False
24 if len(sys.argv) == 1:
25 # By default, create a launcher for ourselves
26 uri = 'http://rox.sourceforge.net/2005/interfaces/AddApp'
27 if not try_interface(uri):
28 sys.exit(1)
29 elif sys.argv[1] == '--prompt':
30 from chooser import Chooser
31 m = Chooser()
32 while True:
33 m.show()
34 resp = m.run()
35 if resp != g.RESPONSE_OK:
36 sys.exit(1)
37 m.hide()
38 uri = m.uri.get_text()
39 if try_interface(uri):
40 break
41 m.destroy()
42 elif len(sys.argv) == 2:
43 uri = sys.argv[1]
44 if not try_interface(uri):
45 sys.exit(1)
46 elif len(sys.argv) == 3 and sys.argv[1] == '--show-help':
47 import help
48 help.show_help(sys.argv[2])
49 sys.exit(0)
50 else:
51 rox.alert("Multiple arguments to AddApp (%s)!" % `sys.argv[1:]`)
52 sys.exit(1)
54 from launcher import AppLauncher
55 try:
56 launcher = AppLauncher(uri)
57 box = saving.SaveBox(launcher, os.path.basename(uri), 'inode/directory')
59 box.show()
60 g.gdk.flush()
61 launcher.get_icon()
62 if launcher.icon:
63 image = g.Image()
64 icon_pixbuf = g.gdk.pixbuf_new_from_file(launcher.icon.name)
65 image.set_from_pixbuf(icon_pixbuf)
66 box.set_type('inode/directory', image)
67 rox.mainloop()
68 launcher.delete_icon()
69 except:
70 rox.report_exception()