Changed 'Dismiss' to 'Close' (Chris Shaffer).
[rox-lib.git] / python / rox / filer.py
blob9feebd718c06b7ae141b65cf394fe39ddb763482
1 """An easy way to get ROX-Filer to do things."""
3 # Note: do a double-fork in case it's an old version of the filer
4 # and doesn't automatically background itself.
5 def _spawn(argv):
6 """Run a new process and forget about it."""
7 from os import fork, _exit, execvp, waitpid
8 child = fork()
9 if child == 0:
10 # We are the child
11 child = fork()
12 if child == 0:
13 # Grandchild
14 try:
15 execvp(argv[0], argv)
16 except:
17 pass
18 print "Warning: exec('%s') failed!" % argv[0]
19 _exit(1)
20 elif child == -1:
21 print "Error: fork() failed!"
22 _exit(1)
23 elif child == -1:
24 print "Error: fork() failed!"
25 waitpid(child, 0)
27 def open_dir(dir):
28 "Open 'dir' in a new filer window."
29 _spawn(('rox', '-d', dir))
31 def examine(file):
32 """'file' may have changed (maybe you just created it, for example). Update
33 any filer views of it."""
34 _spawn(('rox', '-x', file))
36 def show_file(file):
37 """Open a directory and draw the user's attention to this file. Useful for
38 'Up' toolbar buttons that show where a file is saved."""
39 _spawn(('rox', '-s', file))