/[ascend]/trunk/pygtk/loading.py
ViewVC logotype

Contents of /trunk/pygtk/loading.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1464 - (show annotations) (download) (as text)
Sun Jun 3 04:09:36 2007 UTC (12 years, 8 months ago) by jpye
File MIME type: text/x-python
File size: 2693 byte(s)
Added 'alert' option to 'loading' module.
Added start menu shortcut to Model Library
Bumped version to 0.9.5.111.
Fixed loading of fourbarplot.py example when matplotlib not available.
1 import sys
2 import config
3 import os.path
4
5 try:
6 import pygtk
7 pygtk.require('2.0')
8 import gtk
9 is_loading = True
10 except:
11 print "PyGTK COULD NOT BE LOADED (is it installed? do you have X-Windows running?)"
12 is_loading = False
13
14 _messages = []
15
16 def get_messages():
17 return _messages
18
19 def print_status(status,msg=None):
20 if is_loading:
21 print status
22 loadinglabel.set_text(status)
23 if msg is not None:
24 sys.stderr.write(msg+"\n")
25 _messages.append(msg)
26 while gtk.events_pending():
27 gtk.main_iteration(False)
28 else:
29 sys.stderr.write("\r \r")
30 if msg!=None:
31 sys.stderr.write(msg+"\n")
32 _messages.append(msg)
33 sys.stderr.write(status+"...\r")
34 sys.stderr.flush()
35
36 def complete():
37 loadingwindow.destroy()
38 _is_loading = False
39
40 def load_matplotlib(throw=False,alert=False):
41 print_status("Loading python matplotlib")
42 try:
43 import matplotlib
44 matplotlib.use('GTKAgg')
45
46 try:
47 print_status("Trying python numpy")
48 import numpy
49 matplotlib.rcParams['numerix'] = 'numpy'
50 print_status("","Using python module numpy")
51 except ImportError:
52 try:
53 print_status("Trying python numarray")
54 import numarray
55 matplotlib.rcParams['numerix'] = 'numarray'
56 print_status("","Using python module numarray")
57 except ImportError:
58 try:
59 print_status("Trying python Numeric")
60 import Numeric
61 matplotlib.rcParams['numerix'] = 'Numeric'
62 print_status("","Using python module Numeric")
63 except ImportError:
64 print_status("","FAILED TO LOAD A NUMERIC MODULE FOR PYTHON")
65
66 except ImportError,e:
67 print_status("","FAILED TO LOAD MATPLOTLIB")
68 if alert or throw:
69 _d = gtk.MessageDialog(None,gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT
70 ,gtk.MESSAGE_ERROR,gtk.BUTTONS_CLOSE,"Plotting functions are not available unless you have 'matplotlib' installed.\n\nSee http://matplotlib.sf.net/\n\nFailed to load matplotlib (%s)" % str(e)
71 )
72 _d.run()
73 _d.destroy()
74 while gtk.events_pending():
75 gtk.main_iteration(False)
76 if throw:
77 raise RuntimeError("Failed to load plotting library 'matplotlib'. (%s)" % str(e))
78
79 def create_window():
80 _w = gtk.Window(gtk.WINDOW_TOPLEVEL)
81 _w.set_decorated(False)
82 _w.set_position(gtk.WIN_POS_CENTER)
83 _a = gtk.Alignment()
84 _a.set_padding(4,4,4,4)
85 _w.add(_a)
86 _a.show()
87 _v = gtk.VBox()
88 _a.add(_v)
89 _v.show()
90 _i = gtk.Image()
91 _i.set_pixel_size(3)
92 _i.set_from_file(os.path.join(config.PYGTK_ASSETS,'ascend-loading.svg'))
93 _v.add(_i)
94 _i.show()
95 _l = gtk.Label("Loading ASCEND...")
96 _l.set_justify(gtk.JUSTIFY_CENTER)
97 _v.add(_l)
98 _l.show()
99 _w.show()
100 return _w, _l
101
102 loadingwindow, loadinglabel = create_window()
103 is_loading = True
104

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22