1 | #!/usr/bin/env python |
---|
2 | ######################################################################## |
---|
3 | # |
---|
4 | # PDFgui by DANSE Diffraction group |
---|
5 | # Simon J. L. Billinge |
---|
6 | # (c) 2006 trustees of the Michigan State University. |
---|
7 | # All rights reserved. |
---|
8 | # |
---|
9 | # File coded by: Dmitriy Bryndin |
---|
10 | # |
---|
11 | # See AUTHORS.txt for a list of people who contributed. |
---|
12 | # See LICENSE.txt for license information. |
---|
13 | # |
---|
14 | # Modified by U. Tennessee for DANSE/SANS |
---|
15 | ######################################################################## |
---|
16 | |
---|
17 | # version |
---|
18 | __id__ = "$Id: aboutdialog.py 1193 2007-05-03 17:29:59Z dmitriy $" |
---|
19 | __revision__ = "$Revision: 1193 $" |
---|
20 | |
---|
21 | import wx |
---|
22 | import wx.lib.hyperlink |
---|
23 | import random |
---|
24 | import os.path |
---|
25 | import os |
---|
26 | try: |
---|
27 | # Try to find a local config |
---|
28 | import imp |
---|
29 | path = os.getcwd() |
---|
30 | if(os.path.isfile("%s/%s.py" % (path, 'local_config'))) or \ |
---|
31 | (os.path.isfile("%s/%s.pyc" % (path, 'local_config'))): |
---|
32 | fObj, path, descr = imp.find_module('local_config', [path]) |
---|
33 | config = imp.load_module('local_config', fObj, path, descr) |
---|
34 | else: |
---|
35 | # Try simply importing local_config |
---|
36 | import local_config as config |
---|
37 | except: |
---|
38 | # Didn't find local config, load the default |
---|
39 | import config |
---|
40 | |
---|
41 | def launchBrowser(url): |
---|
42 | """ |
---|
43 | Launches browser and opens specified url |
---|
44 | |
---|
45 | In some cases may require BROWSER environment variable to be set up. |
---|
46 | |
---|
47 | :param url: URL to open |
---|
48 | |
---|
49 | """ |
---|
50 | import webbrowser |
---|
51 | webbrowser.open(url) |
---|
52 | |
---|
53 | |
---|
54 | class DialogAbout(wx.Dialog): |
---|
55 | """ |
---|
56 | "About" Dialog |
---|
57 | |
---|
58 | Shows product name, current version, authors, and link to the product page. |
---|
59 | Current version is taken from version.py |
---|
60 | |
---|
61 | """ |
---|
62 | |
---|
63 | def __init__(self, *args, **kwds): |
---|
64 | |
---|
65 | # begin wxGlade: DialogAbout.__init__ |
---|
66 | kwds["style"] = wx.DEFAULT_DIALOG_STYLE |
---|
67 | wx.Dialog.__init__(self, *args, **kwds) |
---|
68 | |
---|
69 | file_dir = os.path.dirname(__file__) |
---|
70 | |
---|
71 | # Mac doesn't display images with transparent background so well, |
---|
72 | # keep it for Windows |
---|
73 | image = file_dir + "/images/angles_flat.png" |
---|
74 | |
---|
75 | if os.path.isfile(config._corner_image): |
---|
76 | image = config._corner_image |
---|
77 | |
---|
78 | if os.name == 'nt': |
---|
79 | self.bitmap_logo = wx.StaticBitmap(self, -1, wx.Bitmap(image)) |
---|
80 | else: |
---|
81 | self.bitmap_logo = wx.StaticBitmap(self, -1, wx.Bitmap(image)) |
---|
82 | |
---|
83 | self.label_title = wx.StaticText(self, -1, config.__appname__) |
---|
84 | self.label_version = wx.StaticText(self, -1, "") |
---|
85 | self.label_build = wx.StaticText(self, -1, "Build:") |
---|
86 | self.label_svnrevision = wx.StaticText(self, -1, "") |
---|
87 | self.label_copyright = wx.StaticText(self, -1, config._copyright) |
---|
88 | self.label_author = wx.StaticText(self, -1, "authors") |
---|
89 | self.hyperlink = wx.lib.hyperlink.HyperLinkCtrl(self, -1, |
---|
90 | config._homepage, |
---|
91 | URL=config._homepage) |
---|
92 | #self.hyperlink_license = wx.lib.hyperlink.HyperLinkCtrl(self, -1, |
---|
93 | #"Comments? Bugs? Requests?", URL=config._paper) |
---|
94 | self.hyperlink_license = wx.StaticText(self, -1, |
---|
95 | "Comments? Bugs? Requests?") |
---|
96 | self.hyperlink_paper = wx.lib.hyperlink.HyperLinkCtrl(self, -1, |
---|
97 | "Send us a ticket", |
---|
98 | URL=config._license) |
---|
99 | self.hyperlink_download = wx.lib.hyperlink.HyperLinkCtrl(self, -1, |
---|
100 | "Get the latest version", |
---|
101 | URL=config._download) |
---|
102 | self.static_line_1 = wx.StaticLine(self, -1) |
---|
103 | self.label_acknowledgement = wx.StaticText(self, -1, |
---|
104 | config._acknowledgement) |
---|
105 | self.static_line_2 = wx.StaticLine(self, -1) |
---|
106 | self.bitmap_button_nist = wx.BitmapButton(self, -1, wx.NullBitmap) |
---|
107 | self.bitmap_button_umd = wx.BitmapButton(self, -1, wx.NullBitmap) |
---|
108 | self.bitmap_button_sns = wx.BitmapButton(self, -1, wx.NullBitmap) |
---|
109 | #self.bitmap_button_nsf = wx.BitmapButton(self, -1, |
---|
110 | # wx.NullBitmap) |
---|
111 | #self.bitmap_button_danse = wx.BitmapButton(self, -1, wx.NullBitmap) |
---|
112 | self.bitmap_button_msu = wx.BitmapButton(self, -1, wx.NullBitmap) |
---|
113 | |
---|
114 | self.bitmap_button_isis = wx.BitmapButton(self, -1, wx.NullBitmap) |
---|
115 | self.bitmap_button_ess = wx.BitmapButton(self, -1, wx.NullBitmap) |
---|
116 | self.bitmap_button_ill = wx.BitmapButton(self, -1, wx.NullBitmap) |
---|
117 | |
---|
118 | self.static_line_3 = wx.StaticLine(self, -1) |
---|
119 | self.button_OK = wx.Button(self, wx.ID_OK, "OK") |
---|
120 | |
---|
121 | self.__set_properties() |
---|
122 | self.__do_layout() |
---|
123 | |
---|
124 | self.Bind(wx.EVT_BUTTON, self.onNistLogo, self.bitmap_button_nist) |
---|
125 | self.Bind(wx.EVT_BUTTON, self.onUmdLogo, self.bitmap_button_umd) |
---|
126 | self.Bind(wx.EVT_BUTTON, self.onSnsLogo, self.bitmap_button_sns) |
---|
127 | #self.Bind(wx.EVT_BUTTON, self.onNsfLogo, self.bitmap_button_nsf) |
---|
128 | #self.Bind(wx.EVT_BUTTON, self.onDanseLogo, self.bitmap_button_danse) |
---|
129 | self.Bind(wx.EVT_BUTTON, self.onUTLogo, self.bitmap_button_msu) |
---|
130 | self.Bind(wx.EVT_BUTTON, self.onIsisLogo, self.bitmap_button_isis) |
---|
131 | self.Bind(wx.EVT_BUTTON, self.onEssLogo, self.bitmap_button_ess) |
---|
132 | self.Bind(wx.EVT_BUTTON, self.onIllLogo, self.bitmap_button_ill) |
---|
133 | # end wxGlade |
---|
134 | # fill in acknowledgements |
---|
135 | #self.text_ctrl_acknowledgement.SetValue(__acknowledgement__) |
---|
136 | # randomly shuffle authors' names |
---|
137 | random.shuffle(config._authors) |
---|
138 | strLabel = ", ".join(config._authors) |
---|
139 | |
---|
140 | # display version and svn revison numbers |
---|
141 | verwords = config.__version__.split('.') |
---|
142 | version = '.'.join(verwords[:-1]) |
---|
143 | revision = verwords[-1] |
---|
144 | try: |
---|
145 | build_num = str(config.__build__) |
---|
146 | except: |
---|
147 | build_num = str(config.__version__) |
---|
148 | self.label_author.SetLabel(strLabel) |
---|
149 | self.label_version.SetLabel(config.__version__)#(version) |
---|
150 | self.label_svnrevision.SetLabel(build_num) |
---|
151 | |
---|
152 | # set bitmaps for logo buttons |
---|
153 | image = file_dir + "/images/nist_logo.png" |
---|
154 | if os.path.isfile(config._nist_logo): |
---|
155 | image = config._nist_logo |
---|
156 | logo = wx.Bitmap(image) |
---|
157 | self.bitmap_button_nist.SetBitmapLabel(logo) |
---|
158 | |
---|
159 | image = file_dir + "/images/umd_logo.png" |
---|
160 | if os.path.isfile(config._umd_logo): |
---|
161 | image = config._umd_logo |
---|
162 | logo = wx.Bitmap(image) |
---|
163 | self.bitmap_button_umd.SetBitmapLabel(logo) |
---|
164 | |
---|
165 | |
---|
166 | image = file_dir + "/images/sns_logo.png" |
---|
167 | if os.path.isfile(config._sns_logo): |
---|
168 | image = config._sns_logo |
---|
169 | logo = wx.Bitmap(image) |
---|
170 | self.bitmap_button_sns.SetBitmapLabel(logo) |
---|
171 | |
---|
172 | """ |
---|
173 | image = file_dir + "/images/nsf_logo.png" |
---|
174 | if os.path.isfile(config._nsf_logo): |
---|
175 | image = config._nsf_logo |
---|
176 | logo = wx.Bitmap(image) |
---|
177 | self.bitmap_button_nsf.SetBitmapLabel(logo) |
---|
178 | |
---|
179 | image = file_dir + "/images/danse_logo.png" |
---|
180 | if os.path.isfile(config._danse_logo): |
---|
181 | image = config._danse_logo |
---|
182 | logo = wx.Bitmap(image) |
---|
183 | self.bitmap_button_danse.SetBitmapLabel(logo) |
---|
184 | """ |
---|
185 | image = file_dir + "/images/utlogo.gif" |
---|
186 | if os.path.isfile(config._inst_logo): |
---|
187 | image = config._inst_logo |
---|
188 | logo = wx.Bitmap(image) |
---|
189 | self.bitmap_button_msu.SetBitmapLabel(logo) |
---|
190 | |
---|
191 | image = file_dir + "/images/isis_logo.png" |
---|
192 | if os.path.isfile(config._isis_logo): |
---|
193 | image = config._isis_logo |
---|
194 | logo = wx.Bitmap(image) |
---|
195 | self.bitmap_button_isis.SetBitmapLabel(logo) |
---|
196 | |
---|
197 | image = file_dir + "/images/ess_logo.png" |
---|
198 | if os.path.isfile(config._ess_logo): |
---|
199 | image = config._ess_logo |
---|
200 | logo = wx.Bitmap(image) |
---|
201 | self.bitmap_button_ess.SetBitmapLabel(logo) |
---|
202 | |
---|
203 | image = file_dir + "/images/ill_logo.png" |
---|
204 | if os.path.isfile(config._ill_logo): |
---|
205 | image = config._ill_logo |
---|
206 | logo = wx.Bitmap(image) |
---|
207 | self.bitmap_button_ill.SetBitmapLabel(logo) |
---|
208 | |
---|
209 | # resize dialog window to fit version number nicely |
---|
210 | if wx.VERSION >= (2, 7, 2, 0): |
---|
211 | size = [self.GetEffectiveMinSize()[0], self.GetSize()[1]] |
---|
212 | else: |
---|
213 | size = [self.GetBestFittingSize()[0], self.GetSize()[1]] |
---|
214 | self.Fit() |
---|
215 | |
---|
216 | def __set_properties(self): |
---|
217 | """ |
---|
218 | """ |
---|
219 | # begin wxGlade: DialogAbout.__set_properties |
---|
220 | self.SetTitle("About") |
---|
221 | self.SetSize((600, 595)) |
---|
222 | self.label_title.SetFont(wx.Font(26, wx.DEFAULT, wx.NORMAL, |
---|
223 | wx.BOLD, 0, "")) |
---|
224 | self.label_version.SetFont(wx.Font(26, wx.DEFAULT, wx.NORMAL, |
---|
225 | wx.NORMAL, 0, "")) |
---|
226 | self.hyperlink_paper.Enable(True) |
---|
227 | self.bitmap_button_nist.SetSize(self.bitmap_button_nist.GetBestSize()) |
---|
228 | self.bitmap_button_umd.SetSize(self.bitmap_button_umd.GetBestSize()) |
---|
229 | self.bitmap_button_sns.SetSize(self.bitmap_button_sns.GetBestSize()) |
---|
230 | #self.bitmap_button_nsf.SetSize(self.bitmap_button_nsf.GetBestSize()) |
---|
231 | #self.bitmap_button_danse.SetSize(self.bitmap_button_danse.GetBestSize()) |
---|
232 | self.bitmap_button_msu.SetSize(self.bitmap_button_msu.GetBestSize()) |
---|
233 | self.bitmap_button_isis.SetSize(self.bitmap_button_isis.GetBestSize()) |
---|
234 | self.bitmap_button_ess.SetSize(self.bitmap_button_ess.GetBestSize()) |
---|
235 | self.bitmap_button_ill.SetSize(self.bitmap_button_ill.GetBestSize()) |
---|
236 | # end wxGlade |
---|
237 | |
---|
238 | def __do_layout(self): |
---|
239 | """ |
---|
240 | """ |
---|
241 | # begin wxGlade: DialogAbout.__do_layout |
---|
242 | sizer_main = wx.BoxSizer(wx.VERTICAL) |
---|
243 | sizer_button = wx.BoxSizer(wx.HORIZONTAL) |
---|
244 | sizer_logos = wx.BoxSizer(wx.HORIZONTAL) |
---|
245 | sizer_header = wx.BoxSizer(wx.HORIZONTAL) |
---|
246 | sizer_titles = wx.BoxSizer(wx.VERTICAL) |
---|
247 | sizer_build = wx.BoxSizer(wx.HORIZONTAL) |
---|
248 | sizer_title = wx.BoxSizer(wx.HORIZONTAL) |
---|
249 | sizer_header.Add(self.bitmap_logo, 0, wx.EXPAND, 0) |
---|
250 | sizer_title.Add(self.label_title, 0, |
---|
251 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
252 | sizer_title.Add((20, 20), 0, wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
253 | sizer_title.Add(self.label_version, 0, |
---|
254 | wx.RIGHT|wx.ALIGN_BOTTOM|wx.ADJUST_MINSIZE, 10) |
---|
255 | sizer_titles.Add(sizer_title, 0, wx.EXPAND, 0) |
---|
256 | sizer_build.Add(self.label_build, 0, |
---|
257 | wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) |
---|
258 | sizer_build.Add(self.label_svnrevision, 0, wx.ADJUST_MINSIZE, 0) |
---|
259 | sizer_titles.Add(sizer_build, 0, wx.TOP|wx.EXPAND, 5) |
---|
260 | sizer_titles.Add(self.label_copyright, 0, |
---|
261 | wx.LEFT|wx.RIGHT|wx.TOP|wx.ADJUST_MINSIZE, 10) |
---|
262 | sizer_titles.Add(self.label_author, 0, |
---|
263 | wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) |
---|
264 | sizer_titles.Add(self.hyperlink, 0, wx.LEFT|wx.RIGHT, 10) |
---|
265 | sizer_titles.Add((20, 20), 0, wx.ADJUST_MINSIZE, 0) |
---|
266 | sizer_titles.Add(self.hyperlink_license, 0, wx.LEFT|wx.RIGHT, 10) |
---|
267 | sizer_titles.Add(self.hyperlink_paper, 0, wx.LEFT|wx.RIGHT, 10) |
---|
268 | sizer_titles.Add((20, 20), 0, wx.ADJUST_MINSIZE, 0) |
---|
269 | sizer_titles.Add(self.hyperlink_download, 0, wx.LEFT|wx.RIGHT, 10) |
---|
270 | sizer_header.Add(sizer_titles, 0, wx.EXPAND, 0) |
---|
271 | sizer_main.Add(sizer_header, 0, wx.BOTTOM|wx.EXPAND, 3) |
---|
272 | sizer_main.Add(self.static_line_1, 0, wx.EXPAND, 0) |
---|
273 | sizer_main.Add(self.label_acknowledgement, 0, |
---|
274 | wx.LEFT|wx.TOP|wx.BOTTOM|wx.ADJUST_MINSIZE, 7) |
---|
275 | sizer_main.Add(self.static_line_2, 0, wx.EXPAND, 0) |
---|
276 | |
---|
277 | sizer_logos.Add(self.bitmap_button_msu, 0, |
---|
278 | wx.LEFT|wx.ADJUST_MINSIZE, 2) |
---|
279 | #sizer_logos.Add(self.bitmap_button_danse, 0, |
---|
280 | # wx.LEFT|wx.ADJUST_MINSIZE, 2) |
---|
281 | #sizer_logos.Add(self.bitmap_button_nsf, 0, |
---|
282 | # wx.LEFT|wx.ADJUST_MINSIZE, 2) |
---|
283 | sizer_logos.Add(self.bitmap_button_umd, 0, |
---|
284 | wx.LEFT|wx.ADJUST_MINSIZE, 2) |
---|
285 | sizer_logos.Add(self.bitmap_button_nist, 0, |
---|
286 | wx.LEFT|wx.ADJUST_MINSIZE, 2) |
---|
287 | sizer_logos.Add(self.bitmap_button_sns, 0, |
---|
288 | wx.LEFT|wx.ADJUST_MINSIZE, 2) |
---|
289 | sizer_logos.Add(self.bitmap_button_isis, 0, |
---|
290 | wx.LEFT|wx.ADJUST_MINSIZE, 2) |
---|
291 | sizer_logos.Add(self.bitmap_button_ess, 0, |
---|
292 | wx.LEFT|wx.ADJUST_MINSIZE, 2) |
---|
293 | sizer_logos.Add(self.bitmap_button_ill, 0, |
---|
294 | wx.LEFT|wx.ADJUST_MINSIZE, 2) |
---|
295 | |
---|
296 | sizer_logos.Add((10, 50), 0, wx.ADJUST_MINSIZE, 0) |
---|
297 | sizer_main.Add(sizer_logos, 0, wx.EXPAND, 0) |
---|
298 | sizer_main.Add(self.static_line_3, 0, wx.EXPAND, 0) |
---|
299 | sizer_button.Add((20, 40), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
300 | sizer_button.Add(self.button_OK, 0, |
---|
301 | wx.RIGHT|wx.ADJUST_MINSIZE|wx.CENTER, 10) |
---|
302 | sizer_main.Add(sizer_button, 0, wx.EXPAND, 0) |
---|
303 | self.SetAutoLayout(True) |
---|
304 | self.SetSizer(sizer_main) |
---|
305 | self.Layout() |
---|
306 | self.Centre() |
---|
307 | # end wxGlade |
---|
308 | |
---|
309 | def onNistLogo(self, event): |
---|
310 | """ |
---|
311 | """ |
---|
312 | # wxGlade: DialogAbout.<event_handler> |
---|
313 | launchBrowser(config._nist_url) |
---|
314 | event.Skip() |
---|
315 | |
---|
316 | def onUmdLogo(self, event): |
---|
317 | """ |
---|
318 | """ |
---|
319 | # wxGlade: DialogAbout.<event_handler> |
---|
320 | launchBrowser(config._umd_url) |
---|
321 | event.Skip() |
---|
322 | |
---|
323 | def onSnsLogo(self, event): |
---|
324 | """ |
---|
325 | """ |
---|
326 | # wxGlade: DialogAbout.<event_handler> |
---|
327 | launchBrowser(config._sns_url) |
---|
328 | event.Skip() |
---|
329 | |
---|
330 | def onNsfLogo(self, event): |
---|
331 | """ |
---|
332 | """ |
---|
333 | # wxGlade: DialogAbout.<event_handler> |
---|
334 | launchBrowser(config._nsf_url) |
---|
335 | event.Skip() |
---|
336 | |
---|
337 | def onDanseLogo(self, event): |
---|
338 | """ |
---|
339 | """ |
---|
340 | # wxGlade: DialogAbout.<event_handler> |
---|
341 | launchBrowser(config._danse_url) |
---|
342 | event.Skip() |
---|
343 | |
---|
344 | def onUTLogo(self, event): |
---|
345 | """ |
---|
346 | """ |
---|
347 | # wxGlade: DialogAbout.<event_handler> |
---|
348 | launchBrowser(config._inst_url) |
---|
349 | event.Skip() |
---|
350 | |
---|
351 | def onIsisLogo(self, event): |
---|
352 | """ |
---|
353 | """ |
---|
354 | # wxGlade: DialogAbout.<event_handler> |
---|
355 | launchBrowser(config._isis_url) |
---|
356 | event.Skip() |
---|
357 | |
---|
358 | def onEssLogo(self, event): |
---|
359 | """ |
---|
360 | """ |
---|
361 | # wxGlade: DialogAbout.<event_handler> |
---|
362 | launchBrowser(config._ess_url) |
---|
363 | event.Skip() |
---|
364 | |
---|
365 | def onIllLogo(self, event): |
---|
366 | """ |
---|
367 | """ |
---|
368 | # wxGlade: DialogAbout.<event_handler> |
---|
369 | launchBrowser(config._ill_url) |
---|
370 | event.Skip() |
---|
371 | |
---|
372 | # end of class DialogAbout |
---|
373 | |
---|
374 | ##### testing code ############################################################ |
---|
375 | class MyApp(wx.App): |
---|
376 | """ |
---|
377 | """ |
---|
378 | def OnInit(self): |
---|
379 | """ |
---|
380 | """ |
---|
381 | wx.InitAllImageHandlers() |
---|
382 | dialog = DialogAbout(None, -1, "") |
---|
383 | self.SetTopWindow(dialog) |
---|
384 | dialog.ShowModal() |
---|
385 | dialog.Destroy() |
---|
386 | return 1 |
---|
387 | |
---|
388 | # end of class MyApp |
---|
389 | |
---|
390 | if __name__ == "__main__": |
---|
391 | app = MyApp(0) |
---|
392 | app.MainLoop() |
---|
393 | |
---|
394 | ##### end of testing code ##################################################### |
---|