source: sasview/guiframe/aboutbox.py @ 6e5eb55

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 6e5eb55 was 12aa9b5, checked in by Gervaise Alina <gervyh@…>, 16 years ago

class and method commented

  • Property mode set to 100644
File size: 10.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    '''Launches browser and opens specified url
43   
44    In some cases may require BROWSER environment variable to be set up.
45   
46    @param url: URL to open
47    '''
48    import webbrowser
49    webbrowser.open(url)
50
51
52class DialogAbout(wx.Dialog):
53    '''"About" Dialog
54   
55    Shows product name, current version, authors, and link to the product page.
56    Current version is taken from version.py
57    '''
58   
59    def __init__(self, *args, **kwds):
60
61        # begin wxGlade: DialogAbout.__init__
62        kwds["style"] = wx.DEFAULT_DIALOG_STYLE
63        wx.Dialog.__init__(self, *args, **kwds)
64       
65        file_dir = os.path.dirname(__file__)
66       
67        # Mac doesn't display images with transparent background so well, keep it for Windows
68        image = file_dir+"/images/angles_flat.png"
69       
70        if os.path.isfile(config._corner_image):
71            image = config._corner_image
72
73        if os.name == 'nt':
74            self.bitmap_logo = wx.StaticBitmap(self, -1, wx.Bitmap(image))
75        else:
76            self.bitmap_logo = wx.StaticBitmap(self, -1, wx.Bitmap(image))
77       
78        self.label_title = wx.StaticText(self, -1, config.__appname__)
79        self.label_version = wx.StaticText(self, -1, "")
80        self.label_build = wx.StaticText(self, -1, "Build:")
81        self.label_svnrevision = wx.StaticText(self, -1, "")
82        self.label_copyright = wx.StaticText(self, -1, config._copyright)
83        self.label_author = wx.StaticText(self, -1, "authors")
84        self.hyperlink = wx.lib.hyperlink.HyperLinkCtrl(self, -1, config._homepage, URL=config._homepage)
85        #self.hyperlink_license = wx.lib.hyperlink.HyperLinkCtrl(self, -1, "Comments? Bugs? Requests?", URL=config._paper)
86        self.hyperlink_license = wx.StaticText(self, -1, "Comments? Bugs? Requests?")
87        self.hyperlink_paper = wx.lib.hyperlink.HyperLinkCtrl(self, -1, "Send us a ticket", URL=config._license)
88        self.hyperlink_download = wx.lib.hyperlink.HyperLinkCtrl(self, -1, "Get the latest version", URL=config._download)
89        self.static_line_1 = wx.StaticLine(self, -1)
90        self.label_acknowledgement = wx.StaticText(self, -1, config._acknowledgement)
91        self.static_line_2 = wx.StaticLine(self, -1)
92        self.bitmap_button_nsf = wx.BitmapButton(self, -1, wx.NullBitmap)
93        self.bitmap_button_danse = wx.BitmapButton(self, -1, wx.NullBitmap)
94        self.bitmap_button_msu = wx.BitmapButton(self, -1, wx.NullBitmap)
95        self.static_line_3 = wx.StaticLine(self, -1)
96        self.button_OK = wx.Button(self, wx.ID_OK, "OK")
97
98        self.__set_properties()
99        self.__do_layout()
100
101        self.Bind(wx.EVT_BUTTON, self.onNsfLogo, self.bitmap_button_nsf)
102        self.Bind(wx.EVT_BUTTON, self.onDanseLogo, self.bitmap_button_danse)
103        self.Bind(wx.EVT_BUTTON, self.onUTLogo, self.bitmap_button_msu)
104        # end wxGlade
105       
106        # fill in acknowledgements
107#       self.text_ctrl_acknowledgement.SetValue(__acknowledgement__)
108
109        # randomly shuffle authors' names
110        random.shuffle(config._authors)
111        strLabel = ", ".join(config._authors)
112       
113        # display version and svn revison numbers
114        verwords = config.__version__.split('.')
115        version = '.'.join(verwords[:-1])
116        revision = verwords[-1]
117       
118        self.label_author.SetLabel(strLabel)
119        self.label_version.SetLabel(version)
120        self.label_svnrevision.SetLabel(config.__version__)
121       
122        # set bitmaps for logo buttons
123        image = file_dir+"/images/nsf_logo.png"
124        if os.path.isfile(config._nsf_logo):
125            image = config._nsf_logo
126        logo = wx.Bitmap(image)       
127        self.bitmap_button_nsf.SetBitmapLabel(logo)
128
129        image = file_dir+"/images/danse_logo.png"
130        if os.path.isfile(config._danse_logo):
131            image = config._danse_logo
132        logo = wx.Bitmap(image)
133        self.bitmap_button_danse.SetBitmapLabel(logo)
134       
135        image = file_dir+"/images/utlogo.gif"
136        if os.path.isfile(config._inst_logo):
137            image = config._inst_logo
138        logo = wx.Bitmap(image)
139        self.bitmap_button_msu.SetBitmapLabel(logo)
140       
141        # resize dialog window to fit version number nicely
142        if wx.VERSION >= (2,7,2,0):
143            size = [self.GetEffectiveMinSize()[0], self.GetSize()[1]]
144        else:
145            size = [self.GetBestFittingSize()[0], self.GetSize()[1]]
146
147        self.Fit()
148       
149
150    def __set_properties(self):
151        # begin wxGlade: DialogAbout.__set_properties
152        self.SetTitle("About")
153        self.SetSize((600, 595))
154        self.label_title.SetFont(wx.Font(26, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))
155        self.label_version.SetFont(wx.Font(26, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, ""))
156     
157        self.hyperlink_paper.Enable(True)
158       
159        self.bitmap_button_nsf.SetSize(self.bitmap_button_nsf.GetBestSize())
160        self.bitmap_button_danse.SetSize(self.bitmap_button_danse.GetBestSize())
161        self.bitmap_button_msu.SetSize(self.bitmap_button_msu.GetBestSize())
162        # end wxGlade
163
164    def __do_layout(self):
165        # begin wxGlade: DialogAbout.__do_layout
166        sizer_main = wx.BoxSizer(wx.VERTICAL)
167        sizer_button = wx.BoxSizer(wx.HORIZONTAL)
168        sizer_logos = wx.BoxSizer(wx.HORIZONTAL)
169        sizer_header = wx.BoxSizer(wx.HORIZONTAL)
170        sizer_titles = wx.BoxSizer(wx.VERTICAL)
171        sizer_build = wx.BoxSizer(wx.HORIZONTAL)
172        sizer_title = wx.BoxSizer(wx.HORIZONTAL)
173        sizer_header.Add(self.bitmap_logo, 0, wx.EXPAND, 0)
174        sizer_title.Add(self.label_title, 0, wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 10)
175        sizer_title.Add((20, 20), 0, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
176        sizer_title.Add(self.label_version, 0, wx.RIGHT|wx.ALIGN_BOTTOM|wx.ADJUST_MINSIZE, 10)
177        sizer_titles.Add(sizer_title, 0, wx.EXPAND, 0)
178        sizer_build.Add(self.label_build, 0, wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10)
179        sizer_build.Add(self.label_svnrevision, 0, wx.ADJUST_MINSIZE, 0)
180        sizer_titles.Add(sizer_build, 0, wx.TOP|wx.EXPAND, 5)
181        sizer_titles.Add(self.label_copyright, 0, wx.LEFT|wx.RIGHT|wx.TOP|wx.ADJUST_MINSIZE, 10)
182        sizer_titles.Add(self.label_author, 0, wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10)
183        sizer_titles.Add(self.hyperlink, 0, wx.LEFT|wx.RIGHT, 10)
184        sizer_titles.Add((20, 20), 0, wx.ADJUST_MINSIZE, 0)
185        sizer_titles.Add(self.hyperlink_license, 0, wx.LEFT|wx.RIGHT, 10)
186        sizer_titles.Add(self.hyperlink_paper, 0, wx.LEFT|wx.RIGHT, 10)
187        sizer_titles.Add((20, 20), 0, wx.ADJUST_MINSIZE, 0)
188        sizer_titles.Add(self.hyperlink_download, 0, wx.LEFT|wx.RIGHT, 10)
189        sizer_header.Add(sizer_titles, 0, wx.EXPAND, 0)
190        sizer_main.Add(sizer_header, 0, wx.BOTTOM|wx.EXPAND, 3)
191        sizer_main.Add(self.static_line_1, 0, wx.EXPAND, 0)
192        sizer_main.Add(self.label_acknowledgement, 0, wx.LEFT|wx.TOP|wx.BOTTOM|wx.ADJUST_MINSIZE, 7)
193        sizer_main.Add(self.static_line_2, 0, wx.EXPAND, 0)
194        sizer_logos.Add(self.bitmap_button_nsf, 0, wx.LEFT|wx.ADJUST_MINSIZE, 2)
195        sizer_logos.Add(self.bitmap_button_danse, 0, wx.LEFT|wx.ADJUST_MINSIZE, 2)
196        sizer_logos.Add(self.bitmap_button_msu, 0, wx.LEFT|wx.ADJUST_MINSIZE, 2)
197        sizer_logos.Add((50, 50), 0, wx.ADJUST_MINSIZE, 0)
198        sizer_main.Add(sizer_logos, 0, wx.EXPAND, 0)
199        sizer_main.Add(self.static_line_3, 0, wx.EXPAND, 0)
200        sizer_button.Add((20, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
201        sizer_button.Add(self.button_OK, 0, wx.RIGHT|wx.ADJUST_MINSIZE, 10)
202        sizer_main.Add(sizer_button, 0, wx.EXPAND, 0)
203        self.SetAutoLayout(True)
204        self.SetSizer(sizer_main)
205        self.Layout()
206        self.Centre()
207        # end wxGlade
208
209    def onNsfLogo(self, event): # wxGlade: DialogAbout.<event_handler>
210        launchBrowser(config._nsf_url)
211        event.Skip()
212
213    def onDanseLogo(self, event): # wxGlade: DialogAbout.<event_handler>
214        launchBrowser(config._danse_url)
215        event.Skip()
216
217    def onUTLogo(self, event): # wxGlade: DialogAbout.<event_handler>
218        launchBrowser(config._inst_url)
219        event.Skip()
220
221# end of class DialogAbout
222
223##### testing code ############################################################
224class MyApp(wx.App):
225    def OnInit(self):
226        wx.InitAllImageHandlers()
227        dialog = DialogAbout(None, -1, "")
228        self.SetTopWindow(dialog)
229        dialog.ShowModal()
230        dialog.Destroy()
231        return 1
232
233# end of class MyApp
234
235if __name__ == "__main__":
236    app = MyApp(0)
237    app.MainLoop()
238   
239##### end of testing code #####################################################   
Note: See TracBrowser for help on using the repository browser.