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