source: sasview/src/sas/sasgui/guiframe/aboutbox.py

ESS_GUI
Last change on this file was b963b20, checked in by Paul Kienzle <pkienzle@…>, 7 years ago

pull config out of sas.sasgui so it can be used without reference to wx

  • Property mode set to 100644
File size: 17.4 KB
Line 
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
21import wx
22import wx.lib.hyperlink
23import random
24import os.path
25import os
26
27from sas import get_local_config
28config = get_local_config()
29
30def launchBrowser(url):
31    """
32    Launches browser and opens specified url
33
34    In some cases may require BROWSER environment variable to be set up.
35
36    :param url: URL to open
37
38    """
39    import webbrowser
40    webbrowser.open(url)
41
42
43class DialogAbout(wx.Dialog):
44    """
45    "About" Dialog
46
47    Shows product name, current version, authors, and link to the product page.
48    Current version is taken from version.py
49
50    """
51
52    def __init__(self, *args, **kwds):
53
54        # begin wxGlade: DialogAbout.__init__
55        kwds["style"] = wx.DEFAULT_DIALOG_STYLE
56        wx.Dialog.__init__(self, *args, **kwds)
57
58        file_dir = os.path.dirname(__file__)
59
60        # Mac doesn't display images with transparent background so well,
61        # keep it for Windows
62        image = file_dir + "/images/angles_flat.png"
63
64        if os.path.isfile(config._corner_image):
65            image = config._corner_image
66
67        if os.name == 'nt':
68            self.bitmap_logo = wx.StaticBitmap(self, -1, wx.Bitmap(image))
69        else:
70            self.bitmap_logo = wx.StaticBitmap(self, -1, wx.Bitmap(image))
71
72        self.label_title = wx.StaticText(self, -1, config.__appname__)
73        self.label_version = wx.StaticText(self, -1, "")
74        self.label_build = wx.StaticText(self, -1, "Build:")
75        self.label_svnrevision = wx.StaticText(self, -1, "")
76        self.label_copyright = wx.StaticText(self, -1, config._copyright)
77        self.label_author = wx.StaticText(self, -1, "authors")
78        self.hyperlink = wx.lib.hyperlink.HyperLinkCtrl(self, -1,
79                                                        config._homepage,
80                                                        URL=config._homepage)
81        #self.hyperlink_license = wx.lib.hyperlink.HyperLinkCtrl(self, -1,
82        #"Comments? Bugs? Requests?", URL=config._paper)
83        self.hyperlink_license = wx.StaticText(self, -1,
84                                               "Comments? Bugs? Requests?")
85        self.hyperlink_paper = wx.lib.hyperlink.HyperLinkCtrl(self, -1,
86                                                        "Send us a ticket",
87                                                        URL=config._license)
88        self.hyperlink_download = wx.lib.hyperlink.HyperLinkCtrl(self, -1,
89                                                "Get the latest version",
90                                                URL=config._download)
91        self.static_line_1 = wx.StaticLine(self, -1)
92        self.label_acknowledgement = wx.StaticText(self, -1,
93                                                   config._acknowledgement)
94        self.static_line_2 = wx.StaticLine(self, -1)
95        self.bitmap_button_nist = wx.BitmapButton(self, -1, wx.NullBitmap)
96        self.bitmap_button_umd = wx.BitmapButton(self, -1, wx.NullBitmap)
97        self.bitmap_button_ornl = wx.BitmapButton(self, -1, wx.NullBitmap)
98        #self.bitmap_button_sns = wx.BitmapButton(self, -1, wx.NullBitmap)
99        #self.bitmap_button_nsf = wx.BitmapButton(self, -1,
100        #                                         wx.NullBitmap)
101        #self.bitmap_button_danse = wx.BitmapButton(self, -1, wx.NullBitmap)
102        self.bitmap_button_msu = wx.BitmapButton(self, -1, wx.NullBitmap)
103
104        self.bitmap_button_isis = wx.BitmapButton(self, -1, wx.NullBitmap)
105        self.bitmap_button_ess = wx.BitmapButton(self, -1, wx.NullBitmap)
106        self.bitmap_button_ill = wx.BitmapButton(self, -1, wx.NullBitmap)
107        self.bitmap_button_ansto = wx.BitmapButton(self, -1, wx.NullBitmap)
108        self.bitmap_button_tudelft = wx.BitmapButton(self, -1, wx.NullBitmap)
109        self.bitmap_button_dls = wx.BitmapButton(self, -1, wx.NullBitmap)
110
111        self.static_line_3 = wx.StaticLine(self, -1)
112        self.button_OK = wx.Button(self, wx.ID_OK, "OK")
113
114        self.__set_properties()
115        self.__do_layout()
116
117        self.Bind(wx.EVT_BUTTON, self.onNistLogo, self.bitmap_button_nist)
118        self.Bind(wx.EVT_BUTTON, self.onUmdLogo, self.bitmap_button_umd)
119        #self.Bind(wx.EVT_BUTTON, self.onSnsLogo, self.bitmap_button_sns)
120        self.Bind(wx.EVT_BUTTON, self.onOrnlLogo, self.bitmap_button_ornl)
121        #self.Bind(wx.EVT_BUTTON, self.onNsfLogo, self.bitmap_button_nsf)
122        #self.Bind(wx.EVT_BUTTON, self.onDanseLogo, self.bitmap_button_danse)
123        self.Bind(wx.EVT_BUTTON, self.onUTLogo, self.bitmap_button_msu)
124        self.Bind(wx.EVT_BUTTON, self.onIsisLogo, self.bitmap_button_isis)
125        self.Bind(wx.EVT_BUTTON, self.onEssLogo, self.bitmap_button_ess)
126        self.Bind(wx.EVT_BUTTON, self.onIllLogo, self.bitmap_button_ill)
127        self.Bind(wx.EVT_BUTTON, self.onAnstoLogo, self.bitmap_button_ansto)
128        self.Bind(wx.EVT_BUTTON, self.onTudelftLogo, self.bitmap_button_tudelft)
129        self.Bind(wx.EVT_BUTTON, self.onDlsLogo, self.bitmap_button_dls)
130        # end wxGlade
131        # fill in acknowledgements
132        #self.text_ctrl_acknowledgement.SetValue(__acknowledgement__)
133        # randomly shuffle authors' names
134        random.shuffle(config._authors)
135        strLabel = ", ".join(config._authors)
136
137        # display version and svn revison numbers
138        verwords = config.__version__.split('.')
139        version = '.'.join(verwords[:-1])
140        revision = verwords[-1]
141        try:
142            build_num = str(config.__build__)
143        except:
144            build_num = str(config.__version__)
145        self.label_author.SetLabel(strLabel)
146        self.label_version.SetLabel(config.__version__)#(version)
147        self.label_svnrevision.SetLabel(build_num)
148
149        # set bitmaps for logo buttons
150        image = file_dir + "/images/nist_logo.png"
151        if os.path.isfile(config._nist_logo):
152            image = config._nist_logo
153        logo = wx.Bitmap(image)
154        self.bitmap_button_nist.SetBitmapLabel(logo)
155
156        image = file_dir + "/images/umd_logo.png"
157        if os.path.isfile(config._umd_logo):
158            image = config._umd_logo
159        logo = wx.Bitmap(image)
160        self.bitmap_button_umd.SetBitmapLabel(logo)
161
162        image = file_dir + "/images/ornl_logo.png"
163        if os.path.isfile(config._ornl_logo):
164            image = config._ornl_logo
165        logo = wx.Bitmap(image)
166        self.bitmap_button_ornl.SetBitmapLabel(logo)
167
168        """
169        image = file_dir + "/images/sns_logo.png"
170        if os.path.isfile(config._sns_logo):
171            image = config._sns_logo
172        logo = wx.Bitmap(image)
173        self.bitmap_button_sns.SetBitmapLabel(logo)
174
175        image = file_dir + "/images/nsf_logo.png"
176        if os.path.isfile(config._nsf_logo):
177            image = config._nsf_logo
178        logo = wx.Bitmap(image)
179        self.bitmap_button_nsf.SetBitmapLabel(logo)
180
181        image = file_dir + "/images/danse_logo.png"
182        if os.path.isfile(config._danse_logo):
183            image = config._danse_logo
184        logo = wx.Bitmap(image)
185        self.bitmap_button_danse.SetBitmapLabel(logo)
186        """
187        image = file_dir + "/images/utlogo.png"
188        if os.path.isfile(config._inst_logo):
189            image = config._inst_logo
190        logo = wx.Bitmap(image)
191        self.bitmap_button_msu.SetBitmapLabel(logo)
192
193        image = file_dir + "/images/isis_logo.png"
194        if os.path.isfile(config._isis_logo):
195            image = config._isis_logo
196        logo = wx.Bitmap(image)
197        self.bitmap_button_isis.SetBitmapLabel(logo)
198
199        image = file_dir + "/images/ess_logo.png"
200        if os.path.isfile(config._ess_logo):
201            image = config._ess_logo
202        logo = wx.Bitmap(image)
203        self.bitmap_button_ess.SetBitmapLabel(logo)
204
205        image = file_dir + "/images/ill_logo.png"
206        if os.path.isfile(config._ill_logo):
207            image = config._ill_logo
208        logo = wx.Bitmap(image)
209        self.bitmap_button_ill.SetBitmapLabel(logo)
210
211        image = file_dir + "/images/ansto_logo.png"
212        if os.path.isfile(config._ansto_logo):
213            image = config._ansto_logo
214        logo = wx.Bitmap(image)
215        self.bitmap_button_ansto.SetBitmapLabel(logo)
216
217        image = file_dir + "/images/tudelft_logo.png"
218        if os.path.isfile(config._tudelft_logo):
219            image = config._tudelft_logo
220        logo = wx.Bitmap(image)
221        self.bitmap_button_tudelft.SetBitmapLabel(logo)
222
223        image = file_dir + "/images/dls_logo.png"
224        if os.path.isfile(config._dls_logo):
225            image = config._dls_logo
226        logo = wx.Bitmap(image)
227        self.bitmap_button_dls.SetBitmapLabel(logo)
228
229        # resize dialog window to fit version number nicely
230        if wx.VERSION >= (2, 7, 2, 0):
231            size = [self.GetEffectiveMinSize()[0], self.GetSize()[1]]
232        else:
233            size = [self.GetBestFittingSize()[0], self.GetSize()[1]]
234        self.Fit()
235
236    def __set_properties(self):
237        """
238        """
239        # begin wxGlade: DialogAbout.__set_properties
240        self.SetTitle("About")
241        self.SetSize((600, 595))
242        self.label_title.SetFont(wx.Font(26, wx.DEFAULT, wx.NORMAL,
243                                         wx.BOLD, 0, ""))
244        self.label_version.SetFont(wx.Font(26, wx.DEFAULT, wx.NORMAL,
245                                           wx.NORMAL, 0, ""))
246        self.hyperlink_paper.Enable(True)
247        self.bitmap_button_nist.SetSize(self.bitmap_button_nist.GetBestSize())
248        self.bitmap_button_umd.SetSize(self.bitmap_button_umd.GetBestSize())
249        self.bitmap_button_ornl.SetSize(self.bitmap_button_ornl.GetBestSize())
250        #self.bitmap_button_sns.SetSize(self.bitmap_button_sns.GetBestSize())
251        #self.bitmap_button_nsf.SetSize(self.bitmap_button_nsf.GetBestSize())
252        #self.bitmap_button_danse.SetSize(self.bitmap_button_danse.GetBestSize())
253        self.bitmap_button_msu.SetSize(self.bitmap_button_msu.GetBestSize())
254        self.bitmap_button_isis.SetSize(self.bitmap_button_isis.GetBestSize())
255        self.bitmap_button_ess.SetSize(self.bitmap_button_ess.GetBestSize())
256        self.bitmap_button_ill.SetSize(self.bitmap_button_ill.GetBestSize())
257        self.bitmap_button_ansto.SetSize(self.bitmap_button_ansto.GetBestSize())
258        self.bitmap_button_tudelft.SetSize(self.bitmap_button_tudelft.GetBestSize())
259        self.bitmap_button_dls.SetSize(self.bitmap_button_dls.GetBestSize())
260        # end wxGlade
261
262    def __do_layout(self):
263        """
264        """
265        # begin wxGlade: DialogAbout.__do_layout
266        sizer_main = wx.BoxSizer(wx.VERTICAL)
267        sizer_button = wx.BoxSizer(wx.HORIZONTAL)
268        sizer_logos = wx.BoxSizer(wx.HORIZONTAL)
269        sizer_header = wx.BoxSizer(wx.HORIZONTAL)
270        sizer_titles = wx.BoxSizer(wx.VERTICAL)
271        sizer_build = wx.BoxSizer(wx.HORIZONTAL)
272        sizer_title = wx.BoxSizer(wx.HORIZONTAL)
273        sizer_header.Add(self.bitmap_logo, 0, wx.EXPAND, 0)
274        sizer_title.Add(self.label_title, 0,
275                        wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 10)
276        sizer_title.Add((20, 20), 0, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
277        sizer_title.Add(self.label_version, 0,
278                        wx.RIGHT|wx.ALIGN_BOTTOM|wx.ADJUST_MINSIZE, 10)
279        sizer_titles.Add(sizer_title, 0, wx.EXPAND, 0)
280        sizer_build.Add(self.label_build, 0,
281                        wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10)
282        sizer_build.Add(self.label_svnrevision, 0, wx.ADJUST_MINSIZE, 0)
283        sizer_titles.Add(sizer_build, 0, wx.TOP|wx.EXPAND, 5)
284        sizer_titles.Add(self.label_copyright, 0,
285                         wx.LEFT|wx.RIGHT|wx.TOP|wx.ADJUST_MINSIZE, 10)
286        sizer_titles.Add(self.label_author, 0,
287                         wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10)
288        sizer_titles.Add(self.hyperlink, 0, wx.LEFT|wx.RIGHT, 10)
289        sizer_titles.Add((20, 20), 0, wx.ADJUST_MINSIZE, 0)
290        sizer_titles.Add(self.hyperlink_license, 0, wx.LEFT|wx.RIGHT, 10)
291        sizer_titles.Add(self.hyperlink_paper, 0, wx.LEFT|wx.RIGHT, 10)
292        sizer_titles.Add((20, 20), 0, wx.ADJUST_MINSIZE, 0)
293        sizer_titles.Add(self.hyperlink_download, 0, wx.LEFT|wx.RIGHT, 10)
294        sizer_header.Add(sizer_titles, 0, wx.EXPAND, 0)
295        sizer_main.Add(sizer_header, 0, wx.BOTTOM|wx.EXPAND, 3)
296        sizer_main.Add(self.static_line_1, 0, wx.EXPAND, 0)
297        sizer_main.Add(self.label_acknowledgement, 0,
298                       wx.LEFT|wx.TOP|wx.BOTTOM|wx.ADJUST_MINSIZE, 7)
299        sizer_main.Add(self.static_line_2, 0, wx.EXPAND, 0)
300
301        sizer_logos.Add(self.bitmap_button_msu, 0,
302                        wx.LEFT|wx.ADJUST_MINSIZE, 2)
303        #sizer_logos.Add(self.bitmap_button_danse, 0,
304        #                wx.LEFT|wx.ADJUST_MINSIZE, 2)
305        #sizer_logos.Add(self.bitmap_button_nsf, 0,
306        #                wx.LEFT|wx.ADJUST_MINSIZE, 2)
307        sizer_logos.Add(self.bitmap_button_umd, 0,
308                        wx.LEFT|wx.ADJUST_MINSIZE, 2)
309        sizer_logos.Add(self.bitmap_button_nist, 0,
310                        wx.LEFT|wx.ADJUST_MINSIZE, 2)
311        #sizer_logos.Add(self.bitmap_button_sns, 0,
312        #                wx.LEFT|wx.ADJUST_MINSIZE, 2)
313        sizer_logos.Add(self.bitmap_button_ornl, 0,
314                        wx.LEFT|wx.ADJUST_MINSIZE, 2)
315        sizer_logos.Add(self.bitmap_button_isis, 0,
316                        wx.LEFT|wx.ADJUST_MINSIZE, 2)
317        sizer_logos.Add(self.bitmap_button_ess, 0,
318                        wx.LEFT|wx.ADJUST_MINSIZE, 2)
319        sizer_logos.Add(self.bitmap_button_ill, 0,
320                        wx.LEFT|wx.ADJUST_MINSIZE, 2)
321        sizer_logos.Add(self.bitmap_button_ansto, 0,
322                        wx.LEFT|wx.ADJUST_MINSIZE, 2)
323        sizer_logos.Add(self.bitmap_button_tudelft, 0,
324                        wx.LEFT|wx.ADJUST_MINSIZE, 2)
325        sizer_logos.Add(self.bitmap_button_dls, 0,
326                        wx.LEFT|wx.ADJUST_MINSIZE, 2)
327
328        sizer_logos.Add((10, 50), 0, wx.ADJUST_MINSIZE, 0)
329        sizer_main.Add(sizer_logos, 0, wx.EXPAND, 0)
330        sizer_main.Add(self.static_line_3, 0, wx.EXPAND, 0)
331        sizer_button.Add((20, 40), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
332        sizer_button.Add(self.button_OK, 0,
333                         wx.RIGHT|wx.ADJUST_MINSIZE|wx.CENTER, 10)
334        sizer_main.Add(sizer_button, 0, wx.EXPAND, 0)
335        self.SetAutoLayout(True)
336        self.SetSizer(sizer_main)
337        self.Layout()
338        self.Centre()
339        # end wxGlade
340
341    def onNistLogo(self, event):
342        """
343        """
344        # wxGlade: DialogAbout.<event_handler>
345        launchBrowser(config._nist_url)
346        event.Skip()
347
348    def onUmdLogo(self, event):
349        """
350        """
351        # wxGlade: DialogAbout.<event_handler>
352        launchBrowser(config._umd_url)
353        event.Skip()
354
355    def onOrnlLogo(self, event):
356        """
357        """
358        # wxGlade: DialogAbout.<event_handler>
359        launchBrowser(config._ornl_url)
360        event.Skip()
361
362    def onSnsLogo(self, event):
363        """
364        """
365        # wxGlade: DialogAbout.<event_handler>
366        launchBrowser(config._sns_url)
367        event.Skip()
368
369    def onNsfLogo(self, event):
370        """
371        """
372        # wxGlade: DialogAbout.<event_handler>
373        launchBrowser(config._nsf_url)
374        event.Skip()
375
376    def onDanseLogo(self, event):
377        """
378        """
379        # wxGlade: DialogAbout.<event_handler>
380        launchBrowser(config._danse_url)
381        event.Skip()
382
383    def onUTLogo(self, event):
384        """
385        """
386        # wxGlade: DialogAbout.<event_handler>
387        launchBrowser(config._inst_url)
388        event.Skip()
389
390    def onIsisLogo(self, event):
391        """
392        """
393        # wxGlade: DialogAbout.<event_handler>
394        launchBrowser(config._isis_url)
395        event.Skip()
396
397    def onEssLogo(self, event):
398        """
399        """
400        # wxGlade: DialogAbout.<event_handler>
401        launchBrowser(config._ess_url)
402        event.Skip()
403
404    def onIllLogo(self, event):
405        """
406        """
407        # wxGlade: DialogAbout.<event_handler>
408        launchBrowser(config._ill_url)
409        event.Skip()
410
411    def onAnstoLogo(self, event):
412        """
413        """
414        # wxGlade: DialogAbout.<event_handler>
415        launchBrowser(config._ansto_url)
416        event.Skip()
417
418    def onTudelftLogo(self, event):
419        """
420        """
421        # wxGlade: DialogAbout.<event_handler>
422        launchBrowser(config._tudelft_url)
423        event.Skip()
424
425    def onDlsLogo(self, event):
426        """
427        """
428        # wxGlade: DialogAbout.<event_handler>
429        launchBrowser(config._dls_url)
430        event.Skip()
431
432# end of class DialogAbout
433
434##### testing code ############################################################
435class MyApp(wx.App):
436    """
437    """
438    def OnInit(self):
439        """
440        """
441        wx.InitAllImageHandlers()
442        dialog = DialogAbout(None, -1, "")
443        self.SetTopWindow(dialog)
444        dialog.ShowModal()
445        dialog.Destroy()
446        return 1
447
448# end of class MyApp
449
450if __name__ == "__main__":
451    app = MyApp(0)
452    app.MainLoop()
453
454##### end of testing code #####################################################
Note: See TracBrowser for help on using the repository browser.