source: sasview/sansguiframe/src/sans/guiframe/aboutbox.py @ 3bc6090

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 3bc6090 was 3bc6090, checked in by Jae Cho <jhjcho@…>, 13 years ago

uses build number and date for build sansview in welcome and about

  • Property mode set to 100644
File size: 11.0 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
26try:
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
37except:
38    # Didn't find local config, load the default
39    import config
40
41def 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
54class 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_nsf = wx.BitmapButton(self, -1,
107                                                 wx.NullBitmap)
108        self.bitmap_button_danse = wx.BitmapButton(self, -1, wx.NullBitmap)
109        self.bitmap_button_msu = wx.BitmapButton(self, -1, wx.NullBitmap)
110        self.static_line_3 = wx.StaticLine(self, -1)
111        self.button_OK = wx.Button(self, wx.ID_OK, "OK")
112
113        self.__set_properties()
114        self.__do_layout()
115
116        self.Bind(wx.EVT_BUTTON, self.onNsfLogo, self.bitmap_button_nsf)
117        self.Bind(wx.EVT_BUTTON, self.onDanseLogo, self.bitmap_button_danse)
118        self.Bind(wx.EVT_BUTTON, self.onUTLogo, self.bitmap_button_msu)
119        # end wxGlade
120        # fill in acknowledgements
121        #self.text_ctrl_acknowledgement.SetValue(__acknowledgement__)
122        # randomly shuffle authors' names
123        random.shuffle(config._authors)
124        strLabel = ", ".join(config._authors)
125       
126        # display version and svn revison numbers
127        verwords = config.__version__.split('.')
128        version = '.'.join(verwords[:-1])
129        revision = verwords[-1]
130        try:
131            build_num = str(config.__build__)
132        except:
133            build_num = str(config.__version__)
134        self.label_author.SetLabel(strLabel)
135        self.label_version.SetLabel(config.__version__)#(version)
136        self.label_svnrevision.SetLabel(build_num)
137       
138        # set bitmaps for logo buttons
139        image = file_dir + "/images/nsf_logo.png"
140        if os.path.isfile(config._nsf_logo):
141            image = config._nsf_logo
142        logo = wx.Bitmap(image)       
143        self.bitmap_button_nsf.SetBitmapLabel(logo)
144
145        image = file_dir + "/images/danse_logo.png"
146        if os.path.isfile(config._danse_logo):
147            image = config._danse_logo
148        logo = wx.Bitmap(image)
149        self.bitmap_button_danse.SetBitmapLabel(logo)
150       
151        image = file_dir + "/images/utlogo.gif"
152        if os.path.isfile(config._inst_logo):
153            image = config._inst_logo
154        logo = wx.Bitmap(image)
155        self.bitmap_button_msu.SetBitmapLabel(logo)
156       
157        # resize dialog window to fit version number nicely
158        if wx.VERSION >= (2, 7, 2, 0):
159            size = [self.GetEffectiveMinSize()[0], self.GetSize()[1]]
160        else:
161            size = [self.GetBestFittingSize()[0], self.GetSize()[1]]
162        self.Fit()
163       
164    def __set_properties(self):
165        """
166        """
167        # begin wxGlade: DialogAbout.__set_properties
168        self.SetTitle("About")
169        self.SetSize((600, 595))
170        self.label_title.SetFont(wx.Font(26, wx.DEFAULT, wx.NORMAL,
171                                         wx.BOLD, 0, ""))
172        self.label_version.SetFont(wx.Font(26, wx.DEFAULT, wx.NORMAL,
173                                           wx.NORMAL, 0, ""))
174        self.hyperlink_paper.Enable(True)
175        self.bitmap_button_nsf.SetSize(self.bitmap_button_nsf.GetBestSize())
176        self.bitmap_button_danse.SetSize(self.bitmap_button_danse.GetBestSize())
177        self.bitmap_button_msu.SetSize(self.bitmap_button_msu.GetBestSize())
178        # end wxGlade
179
180    def __do_layout(self):
181        """
182        """
183        # begin wxGlade: DialogAbout.__do_layout
184        sizer_main = wx.BoxSizer(wx.VERTICAL)
185        sizer_button = wx.BoxSizer(wx.HORIZONTAL)
186        sizer_logos = wx.BoxSizer(wx.HORIZONTAL)
187        sizer_header = wx.BoxSizer(wx.HORIZONTAL)
188        sizer_titles = wx.BoxSizer(wx.VERTICAL)
189        sizer_build = wx.BoxSizer(wx.HORIZONTAL)
190        sizer_title = wx.BoxSizer(wx.HORIZONTAL)
191        sizer_header.Add(self.bitmap_logo, 0, wx.EXPAND, 0)
192        sizer_title.Add(self.label_title, 0,
193                        wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 10)
194        sizer_title.Add((20, 20), 0, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
195        sizer_title.Add(self.label_version, 0,
196                        wx.RIGHT|wx.ALIGN_BOTTOM|wx.ADJUST_MINSIZE, 10)
197        sizer_titles.Add(sizer_title, 0, wx.EXPAND, 0)
198        sizer_build.Add(self.label_build, 0,
199                        wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10)
200        sizer_build.Add(self.label_svnrevision, 0, wx.ADJUST_MINSIZE, 0)
201        sizer_titles.Add(sizer_build, 0, wx.TOP|wx.EXPAND, 5)
202        sizer_titles.Add(self.label_copyright, 0,
203                         wx.LEFT|wx.RIGHT|wx.TOP|wx.ADJUST_MINSIZE, 10)
204        sizer_titles.Add(self.label_author, 0,
205                         wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10)
206        sizer_titles.Add(self.hyperlink, 0, wx.LEFT|wx.RIGHT, 10)
207        sizer_titles.Add((20, 20), 0, wx.ADJUST_MINSIZE, 0)
208        sizer_titles.Add(self.hyperlink_license, 0, wx.LEFT|wx.RIGHT, 10)
209        sizer_titles.Add(self.hyperlink_paper, 0, wx.LEFT|wx.RIGHT, 10)
210        sizer_titles.Add((20, 20), 0, wx.ADJUST_MINSIZE, 0)
211        sizer_titles.Add(self.hyperlink_download, 0, wx.LEFT|wx.RIGHT, 10)
212        sizer_header.Add(sizer_titles, 0, wx.EXPAND, 0)
213        sizer_main.Add(sizer_header, 0, wx.BOTTOM|wx.EXPAND, 3)
214        sizer_main.Add(self.static_line_1, 0, wx.EXPAND, 0)
215        sizer_main.Add(self.label_acknowledgement, 0,
216                       wx.LEFT|wx.TOP|wx.BOTTOM|wx.ADJUST_MINSIZE, 7)
217        sizer_main.Add(self.static_line_2, 0, wx.EXPAND, 0)
218        sizer_logos.Add(self.bitmap_button_nsf, 0, wx.LEFT|wx.ADJUST_MINSIZE, 2)
219        sizer_logos.Add(self.bitmap_button_danse, 0,
220                        wx.LEFT|wx.ADJUST_MINSIZE, 2)
221        sizer_logos.Add(self.bitmap_button_msu, 0, wx.LEFT|wx.ADJUST_MINSIZE, 2)
222        sizer_logos.Add((50, 50), 0, wx.ADJUST_MINSIZE, 0)
223        sizer_main.Add(sizer_logos, 0, wx.EXPAND, 0)
224        sizer_main.Add(self.static_line_3, 0, wx.EXPAND, 0)
225        sizer_button.Add((20, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
226        sizer_button.Add(self.button_OK, 0, wx.RIGHT|wx.ADJUST_MINSIZE, 10)
227        sizer_main.Add(sizer_button, 0, wx.EXPAND, 0)
228        self.SetAutoLayout(True)
229        self.SetSizer(sizer_main)
230        self.Layout()
231        self.Centre()
232        # end wxGlade
233
234    def onNsfLogo(self, event): 
235        """
236        """
237        # wxGlade: DialogAbout.<event_handler>
238        launchBrowser(config._nsf_url)
239        event.Skip()
240
241    def onDanseLogo(self, event):
242        """
243        """
244        # wxGlade: DialogAbout.<event_handler>
245        launchBrowser(config._danse_url)
246        event.Skip()
247
248    def onUTLogo(self, event):
249        """
250        """ 
251        # wxGlade: DialogAbout.<event_handler>
252        launchBrowser(config._inst_url)
253        event.Skip()
254
255# end of class DialogAbout
256
257##### testing code ############################################################
258class MyApp(wx.App):
259    """
260    """
261    def OnInit(self):
262        """
263        """
264        wx.InitAllImageHandlers()
265        dialog = DialogAbout(None, -1, "")
266        self.SetTopWindow(dialog)
267        dialog.ShowModal()
268        dialog.Destroy()
269        return 1
270
271# end of class MyApp
272
273if __name__ == "__main__":
274    app = MyApp(0)
275    app.MainLoop()
276   
277##### end of testing code #####################################################   
Note: See TracBrowser for help on using the repository browser.