When importing non-UTF8 text, allow the user to select an encoding to use.
[rox-edit/bju.git] / findrox.py
blob6cb009ff5010213f7705f9546a2ba7a9303b6dbc
1 # Most of the common code needed by ROX applications is in ROX-Lib2.
2 # Except this code, which is needed to find ROX-Lib2 in the first place!
4 # Just make sure you import findrox before importing anything inside
5 # ROX-Lib2...
7 import os, sys
8 from os.path import exists
9 import string
11 try:
12 path = os.environ['LIBDIRPATH']
13 paths = string.split(path, ':')
14 except KeyError:
15 paths = [ os.environ['HOME'] + '/lib', '/usr/local/lib', '/usr/lib' ]
17 paths = map(lambda p: os.path.join(p, 'ROX-Lib2'), paths)
18 for p in paths:
19 if exists(p):
20 sys.path.append(os.path.join(p, 'python'))
21 break
22 else:
23 err = "This program needs ROX-Lib2 to run.\n" + \
24 "I tried all of these places:\n\n" + \
25 string.join(paths, '\n') + '\n\n' + \
26 "ROX-Lib2 is available from:\nhttp://rox.sourceforge.net"
27 try:
28 sys.stderr.write('*** ' + err + '\n')
29 except:
30 pass
31 try:
32 import gtk2 as g
33 except:
34 import gtk
35 win = gtk.GtkDialog()
36 message = gtk.GtkLabel(err +
37 '\n\nAlso, pygtk2 needs to be present')
38 win.set_title('Missing ROX-Lib2')
39 win.set_position(gtk.WIN_POS_CENTER)
40 message.set_padding(20, 20)
41 win.vbox.pack_start(message)
43 ok = gtk.GtkButton("OK")
44 ok.set_flags(gtk.CAN_DEFAULT)
45 win.action_area.pack_start(ok)
46 ok.connect('clicked', gtk.mainquit)
47 ok.grab_default()
49 win.connect('destroy', gtk.mainquit)
50 win.show_all()
51 gtk.mainloop()
52 else:
53 box = g.MessageDialog(None, g.MESSAGE_ERROR, 0,
54 g.BUTTONS_OK, err)
55 box.set_title('Missing ROX-Lib2')
56 box.set_position(g.WIN_POS_CENTER)
57 box.set_default_response(g.RESPONSE_OK)
58 box.run()
59 sys.exit(1)