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

Contents of /trunk/pygtk/loading.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2203 - (show annotations) (download) (as text)
Fri May 21 04:29:59 2010 UTC (14 years ago) by jpye
File MIME type: text/x-python
File size: 4349 byte(s)
USe PNG image for splash, instead of SVG.
Change installer to use Tcl 8.5.8.2.
Fix URL for Tcl/Tk download.
1 import sys
2 import config
3 import os.path
4
5 global have_gtk
6 have_gtk = False
7
8 print "PYTHON PATH =",sys.path
9
10 try:
11 import pygtk
12 pygtk.require('2.0')
13 import gtk
14 have_gtk = True
15 except Exception,e:
16
17 if sys.platform=="win32":
18 try:
19 from ctypes import c_int, WINFUNCTYPE, windll
20 from ctypes.wintypes import HWND, LPCSTR, UINT
21 prototype = WINFUNCTYPE(c_int, HWND, LPCSTR, LPCSTR, UINT)
22 paramflags = (1, "hwnd", 0), (1, "text", "Hi"), (1, "caption", None), (1, "flags", 0)
23 MessageBox = prototype(("MessageBoxA", windll.user32), paramflags)
24 MessageBox(text="""ASCEND could not load PyGTK. Probably this is because
25 either PyGTK, PyCairo, PyGObject or GTK+ are not installed on your
26 system. Please try re-installing ASCEND to rectify the problem.""")
27 except:
28 pass
29 else:
30 print "PyGTK COULD NOT BE LOADED (is it installed? do you have X-Windows running?) (%s)" % str(e)
31
32 sys.exit("FATAL ERROR: PyGTK not available, unable to start ASCEND.")
33
34 global _messages
35 _messages = []
36
37 def get_messages():
38 return _messages
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 import pylab
66
67
68 except ImportError,e:
69 print_status("","FAILED TO LOAD MATPLOTLIB")
70 if alert or throw:
71 _d = gtk.MessageDialog(None,gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT
72 ,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)
73 )
74 _d.run()
75 _d.destroy()
76 while gtk.events_pending():
77 gtk.main_iteration(False)
78 if throw:
79 raise RuntimeError("Failed to load plotting library 'matplotlib'. (%s)" % str(e))
80
81
82 class LoadingWindow:
83 def __init__(self):
84 self.is_loading = False
85 self.set_assets_dir(config.PYGTK_ASSETS)
86
87 def set_assets_dir(self, d):
88 self.assetsdir = d
89 self.splashfile = os.path.join(self.assetsdir,'ascend-loading.png')
90
91 def create_window(self):
92 if have_gtk:
93 if os.path.exists(self.splashfile):
94 _w = gtk.Window(gtk.WINDOW_TOPLEVEL)
95 _w.set_decorated(False)
96 _w.set_position(gtk.WIN_POS_CENTER)
97 _a = gtk.Alignment()
98 _a.set_padding(4,4,4,4)
99 _w.add(_a)
100 _a.show()
101 _v = gtk.VBox()
102 _a.add(_v)
103 _v.show()
104 _i = gtk.Image()
105 self.image = _i
106 _i.set_pixel_size(3)
107 _i.set_from_file(self.splashfile)
108 _v.add(_i)
109 _i.show()
110 _l = gtk.Label("Loading ASCEND...")
111 _l.set_justify(gtk.JUSTIFY_CENTER)
112 _v.add(_l)
113 _l.show()
114 _w.show()
115 self.window = _w
116 self.label = _l
117 self.is_loading = True
118 while gtk.events_pending():
119 gtk.main_iteration(False)
120 else:
121 pass
122 #do nothing, don't know where splash file is yet
123 else:
124 print "DON'T HAVE GTK!"
125 sys.exit(1)
126
127 def print_status(self,status,msg=None):
128 if self.is_loading:
129 print status
130 self.label.set_text(status)
131 if msg is not None:
132 try:
133 sys.stderr.write(msg+"\n")
134 except IOError:
135 pass
136 _messages.append(msg)
137 while gtk.events_pending():
138 gtk.main_iteration(False)
139 else:
140 try:
141 sys.stderr.write("\r \r")
142 if msg!=None:
143 sys.stderr.write(msg+"\n")
144 _messages.append(msg)
145 sys.stderr.write(status+"...\r")
146 sys.stderr.flush()
147 except IOError:
148 pass
149
150 def complete(self):
151 if self.is_loading:
152 self.window.destroy()
153 self.is_loading = False
154
155 global w
156
157 def print_status(status,msg=None):
158 w.print_status(status,msg)
159
160 def complete():
161 w.complete()
162
163 def create_window(assetsdir=config.PYGTK_ASSETS):
164 w.set_assets_dir(assetsdir)
165 w.create_window()
166
167 w = LoadingWindow()
168 create_window()

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