/[ascend]/branches/adrian/pygtk/loading.py
ViewVC logotype

Contents of /branches/adrian/pygtk/loading.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2944 - (show annotations) (download) (as text)
Thu Jun 4 20:28:52 2015 UTC (7 years ago) by adrian
File MIME type: text/x-python
File size: 4162 byte(s)
Added testing gtksourceview
1 import sys
2 import config
3 import os.path
4
5 global have_gtk
6 have_gtk = False
7
8 if not sys.executable.endswith("pythonw.exe"):
9 print "PYTHON PATH =",sys.path
10
11 try:
12 import gi
13 gi.require_version('Gtk', '3.0')
14 from gi.repository import Gtk
15 have_gtk = True
16 except Exception,e:
17
18 if sys.platform=="win32":
19 try:
20 from ctypes import c_int, WINFUNCTYPE, windll
21 from ctypes.wintypes import HWND, LPCSTR, UINT
22 prototype = WINFUNCTYPE(c_int, HWND, LPCSTR, LPCSTR, UINT)
23 paramflags = (1, "hwnd", 0), (1, "text", "Hi"), (1, "caption", None), (1, "flags", 0)
24 MessageBox = prototype(("MessageBoxA", windll.user32), paramflags)
25 MessageBox(text="""ASCEND could not load PyGI. Probably this is because
26 either PyGI, PyCairo, PyGObject or GTK3+ are not installed on your
27 system. Please try re-installing ASCEND to rectify the problem.""")
28 except:
29 pass
30 else:
31 print "PyGI COULD NOT BE LOADED (is it installed? do you have X-Windows running?) (%s)" % str(e)
32
33 sys.exit("FATAL ERROR: PyGI not available, unable to start ASCEND.")
34
35 global _messages
36 _messages = []
37
38 def get_messages():
39 return _messages
40
41 def load_matplotlib(throw=False,alert=False):
42 print_status("Loading python matplotlib")
43 try:
44 import matplotlib
45 # Added a new backend backend_gtk3. File bundle exists in PYTHONPATH
46 matplotlib.use('module://backend_gtk3')
47 try:
48 print_status("Trying python numpy")
49 import numpy
50 print_status("","Using python module numpy")
51 except ImportError:
52 print_status("","FAILED to load Python module 'numpy'")
53 import pylab
54
55
56 except ImportError,e:
57 print_status("","FAILED TO LOAD MATPLOTLIB")
58 if alert or throw:
59 _d = Gtk.MessageDialog(None,Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT
60 ,Gtk.MessageType.ERROR,Gtk.ButtonsType.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)
61 )
62 _d.run()
63 _d.destroy()
64 while Gtk.events_pending():
65 Gtk.main_iteration(False)
66 if throw:
67 raise RuntimeError("Failed to load plotting library 'matplotlib'. (%s)" % str(e))
68
69
70 class LoadingWindow:
71 def __init__(self):
72 self.is_loading = False
73 self.set_assets_dir(config.PYGTK_ASSETS)
74
75 def set_assets_dir(self, d):
76 self.assetsdir = d
77 self.splashfile = os.path.join(self.assetsdir,'ascend-loading.png')
78
79 def create_window(self):
80 if have_gtk:
81 if os.path.exists(self.splashfile):
82 _w = Gtk.Window(Gtk.WindowType.TOPLEVEL)
83 _w.set_decorated(False)
84 _w.set_position(Gtk.WindowPosition.CENTER)
85 _a = Gtk.Alignment.new(0.5,0.5,0,0)
86 _a.set_padding(4,4,4,4)
87 _w.add(_a)
88 _a.show()
89 _v = Gtk.VBox()
90 _a.add(_v)
91 _v.show()
92 _i = Gtk.Image()
93 self.image = _i
94 _i.set_pixel_size(3)
95 _i.set_from_file(self.splashfile)
96 _v.add(_i)
97 _i.show()
98 _l = Gtk.Label(label="Loading ASCEND...")
99 _l.set_justify(Gtk.Justification.CENTER)
100 _v.add(_l)
101 _l.show()
102 _w.show()
103 self.window = _w
104 self.label = _l
105 self.is_loading = True
106 while Gtk.events_pending():
107 Gtk.main_iteration()
108 else:
109 pass
110 #do nothing, don't know where splash file is yet
111 else:
112 print "DON'T HAVE GTK!"
113 sys.exit(1)
114
115 def print_status(self,status,msg=None):
116 if self.is_loading:
117 if not sys.executable.endswith("pythonw.exe"):
118 print status
119 self.label.set_text(status)
120 if msg is not None:
121 try:
122 sys.stderr.write(msg+"\n")
123 except IOError:
124 pass
125 _messages.append(msg)
126 while Gtk.events_pending():
127 Gtk.main_iteration()
128 else:
129 try:
130 sys.stderr.write("\r \r")
131 if msg!=None:
132 sys.stderr.write(msg+"\n")
133 _messages.append(msg)
134 sys.stderr.write(status+"...\r")
135 sys.stderr.flush()
136 except IOError:
137 pass
138
139 def complete(self):
140 if self.is_loading:
141 self.window.destroy()
142 self.is_loading = False
143
144 global w
145
146 def print_status(status,msg=None):
147 w.print_status(status,msg)
148
149 def complete():
150 w.complete()
151
152 def create_window(assetsdir=config.PYGTK_ASSETS):
153 w.set_assets_dir(assetsdir)
154 w.create_window()
155
156 w = LoadingWindow()
157 create_window()

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