1 """splash.py: Display PyRAF splash screen
2
3 $Id: splash.py 1463 2011-06-24 22:58:30Z stsci_embray $
4
5 R. White, 2001 Dec 15
6 """
7
8 from __future__ import division
9
10 import os, sys, Tkinter
11 from stsci.tools.irafglobals import IrafPkg
12 import wutil
13
14 logo = "pyraflogo_rgb_web.gif"
15
17
18 """Base class for splash screen
19
20 Subclass and override createWidgets().
21 In constructor of main window/application call
22 - S = SplashScreen(main=self) (if caller is Toplevel)
23 - S = SplashScreen(main=self.master) (if caller is Frame)
24 - S.Destroy() after you are done creating your widgets etc.
25
26 Based closely on news posting by Alexander Schliep, 07 Apr 1999
27 """
28
29 - def __init__(self, master=None, borderwidth=4, relief=Tkinter.RAISED, **kw):
30 Tkinter.Toplevel.__init__(self, master, relief=relief,
31 borderwidth=borderwidth, **kw)
32 if self.master.master != None:
33 self.master.master.withdraw()
34 self.master.withdraw()
35 self.overrideredirect(1)
36 self.createWidgets()
37 self.after_idle(self.centerOnScreen)
38 self.update()
39
41 self.update_idletasks()
42 xmax = self.winfo_screenwidth()
43 ymax = self.winfo_screenheight()
44 x0 = (xmax - self.winfo_reqwidth()) // 2
45 y0 = (ymax - self.winfo_reqheight()) // 2
46 self.geometry("+%d+%d" % (x0, y0))
47
51
53 self.master.update()
54 self.master.deiconify()
55 self.withdraw()
56
57
59
60 """PyRAF splash screen
61
62 Contains an image and one or more text lines underneath. The number
63 of lines is determined by the value of the text argument, which may be
64 a string (for a single line or, with embedded newlines, multiple lines)
65 or a list of strings. The text line(s) can be changed using the write()
66 method.
67 """
68
69 - def __init__(self, filename=logo, text=None, textcolor="blue", **kw):
96
124
126 """Set text string"""
127 if self.text is None:
128 return
129 if isinstance(s, type('')):
130 s = s.split("\n")
131 s = s[:len(self.text)]
132 for i in range(len(s)):
133 if s[i] is not None:
134 self.canvas.itemconfigure(self.text[i], text=s[i])
135 self.update_idletasks()
136
138 """Set 'pirate' kill cursor on button down"""
139 self['cursor'] = 'pirate'
140
142 if event:
143
144
145 if event.x<0 or event.x>=self.winfo_width() or \
146 event.y<0 or event.y>=self.winfo_height():
147 self['cursor'] = self.defaultCursor
148 return
149 self.destroy()
150
151 self.text = None
152 self.update_idletasks()
153
154 if self.__termWin:
155 wutil.setFocusTo(self.__termWin)
156
158
159 """PyRAF splash screen that also acts as IRAF task execution monitor
160
161 Usually start this by calling the splash() function in this module.
162 """
163
164 - def __init__(self, label="PyRAF Execution Monitor", **kw):
170
172 if task is None:
173
174 try:
175 self.stack.pop()
176 msg = self.stack[-1]
177 except IndexError:
178 msg = ""
179 else:
180 name = task.getName()
181 if name != 'cl':
182 if isinstance(task, IrafPkg):
183 msg = "Loading %s" % name
184 else:
185 msg = "Running %s" % name
186 else:
187
188 try:
189 msg = "cl %s" % os.path.basename(sys.stdin.name)
190 except AttributeError:
191 msg = "cl <pipe>"
192 self.stack.append(msg)
193 self.write(msg)
194
201
202 -def splash(label="PyRAF Execution Monitor", background="LightYellow", **kw):
203 """Display the PyRAF splash screen
204
205 Silently does nothing if Tkinter is not usable.
206 """
207 if wutil.hasGraphics:
208 try:
209 return IrafMonitorSplash(label, background=background, **kw)
210 except Tkinter.TclError:
211 pass
212 return None
213
214
215 if __name__ == "__main__":
216 import time
217 s = PyrafSplash()
218 print "Sleeping 2 seconds..."
219 time.sleep(2)
220