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): |
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 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 |
raise RuntimeError("Failed to load plotting library 'matplotlib'. Details:"+str(e)) |
77 |
|
78 |
def create_window(): |
79 |
_w = gtk.Window(gtk.WINDOW_TOPLEVEL) |
80 |
_w.set_decorated(False) |
81 |
_w.set_position(gtk.WIN_POS_CENTER) |
82 |
_a = gtk.Alignment() |
83 |
_a.set_padding(4,4,4,4) |
84 |
_w.add(_a) |
85 |
_a.show() |
86 |
_v = gtk.VBox() |
87 |
_a.add(_v) |
88 |
_v.show() |
89 |
_i = gtk.Image() |
90 |
_i.set_pixel_size(3) |
91 |
_i.set_from_file(os.path.join(config.PYGTK_ASSETS,'ascend-loading.svg')) |
92 |
_v.add(_i) |
93 |
_i.show() |
94 |
_l = gtk.Label("Loading ASCEND...") |
95 |
_l.set_justify(gtk.JUSTIFY_CENTER) |
96 |
_v.add(_l) |
97 |
_l.show() |
98 |
_w.show() |
99 |
return _w, _l |
100 |
|
101 |
loadingwindow, loadinglabel = create_window() |
102 |
is_loading = True |
103 |
|