[41d466f] | 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() |
---|
[278cc25] | 30 | if(os.path.isfile("%s/%s.py" % (path, 'local_config'))) or \ |
---|
| 31 | (os.path.isfile("%s/%s.pyc" % (path, 'local_config'))): |
---|
[32c0841] | 32 | fObj, path, descr = imp.find_module('local_config', [path]) |
---|
| 33 | config = imp.load_module('local_config', fObj, path, descr) |
---|
[278cc25] | 34 | else: |
---|
| 35 | # Try simply importing local_config |
---|
| 36 | import local_config as config |
---|
[41d466f] | 37 | except: |
---|
[278cc25] | 38 | # Didn't find local config, load the default |
---|
[41d466f] | 39 | import config |
---|
| 40 | |
---|
| 41 | def launchBrowser(url): |
---|
[d955bf19] | 42 | """ |
---|
| 43 | Launches browser and opens specified url |
---|
[41d466f] | 44 | |
---|
| 45 | In some cases may require BROWSER environment variable to be set up. |
---|
| 46 | |
---|
[d955bf19] | 47 | :param url: URL to open |
---|
| 48 | |
---|
| 49 | """ |
---|
[41d466f] | 50 | import webbrowser |
---|
| 51 | webbrowser.open(url) |
---|
| 52 | |
---|
| 53 | |
---|
| 54 | class DialogAbout(wx.Dialog): |
---|
[d955bf19] | 55 | """ |
---|
| 56 | "About" Dialog |
---|
[41d466f] | 57 | |
---|
| 58 | Shows product name, current version, authors, and link to the product page. |
---|
| 59 | Current version is taken from version.py |
---|
[d955bf19] | 60 | |
---|
| 61 | """ |
---|
[41d466f] | 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 | |
---|
[32c0841] | 71 | # Mac doesn't display images with transparent background so well, |
---|
| 72 | # keep it for Windows |
---|
| 73 | image = file_dir + "/images/angles_flat.png" |
---|
[2bd9927] | 74 | |
---|
[41d466f] | 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") |
---|
[32c0841] | 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) |
---|
[41d466f] | 102 | self.static_line_1 = wx.StaticLine(self, -1) |
---|
[32c0841] | 103 | self.label_acknowledgement = wx.StaticText(self, -1, |
---|
| 104 | config._acknowledgement) |
---|
[41d466f] | 105 | self.static_line_2 = wx.StaticLine(self, -1) |
---|
[1452132] | 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) |
---|
[32c0841] | 109 | self.bitmap_button_nsf = wx.BitmapButton(self, -1, |
---|
| 110 | wx.NullBitmap) |
---|
[41d466f] | 111 | self.bitmap_button_danse = wx.BitmapButton(self, -1, wx.NullBitmap) |
---|
| 112 | self.bitmap_button_msu = wx.BitmapButton(self, -1, wx.NullBitmap) |
---|
| 113 | self.static_line_3 = wx.StaticLine(self, -1) |
---|
| 114 | self.button_OK = wx.Button(self, wx.ID_OK, "OK") |
---|
| 115 | |
---|
| 116 | self.__set_properties() |
---|
| 117 | self.__do_layout() |
---|
[1452132] | 118 | |
---|
| 119 | self.Bind(wx.EVT_BUTTON, self.onNistLogo, self.bitmap_button_nist) |
---|
| 120 | self.Bind(wx.EVT_BUTTON, self.onUmdLogo, self.bitmap_button_umd) |
---|
| 121 | self.Bind(wx.EVT_BUTTON, self.onSnsLogo, self.bitmap_button_sns) |
---|
[41d466f] | 122 | self.Bind(wx.EVT_BUTTON, self.onNsfLogo, self.bitmap_button_nsf) |
---|
| 123 | self.Bind(wx.EVT_BUTTON, self.onDanseLogo, self.bitmap_button_danse) |
---|
| 124 | self.Bind(wx.EVT_BUTTON, self.onUTLogo, self.bitmap_button_msu) |
---|
| 125 | # end wxGlade |
---|
| 126 | # fill in acknowledgements |
---|
[32c0841] | 127 | #self.text_ctrl_acknowledgement.SetValue(__acknowledgement__) |
---|
[41d466f] | 128 | # randomly shuffle authors' names |
---|
| 129 | random.shuffle(config._authors) |
---|
| 130 | strLabel = ", ".join(config._authors) |
---|
| 131 | |
---|
| 132 | # display version and svn revison numbers |
---|
| 133 | verwords = config.__version__.split('.') |
---|
| 134 | version = '.'.join(verwords[:-1]) |
---|
| 135 | revision = verwords[-1] |
---|
[3bc6090] | 136 | try: |
---|
| 137 | build_num = str(config.__build__) |
---|
| 138 | except: |
---|
| 139 | build_num = str(config.__version__) |
---|
[41d466f] | 140 | self.label_author.SetLabel(strLabel) |
---|
[1c97a3f] | 141 | self.label_version.SetLabel(config.__version__)#(version) |
---|
[3bc6090] | 142 | self.label_svnrevision.SetLabel(build_num) |
---|
[41d466f] | 143 | |
---|
| 144 | # set bitmaps for logo buttons |
---|
[1452132] | 145 | image = file_dir + "/images/nist_logo.png" |
---|
| 146 | if os.path.isfile(config._nist_logo): |
---|
| 147 | image = config._nist_logo |
---|
| 148 | logo = wx.Bitmap(image) |
---|
| 149 | self.bitmap_button_nist.SetBitmapLabel(logo) |
---|
| 150 | |
---|
| 151 | image = file_dir + "/images/umd_logo.png" |
---|
| 152 | if os.path.isfile(config._umd_logo): |
---|
| 153 | image = config._umd_logo |
---|
| 154 | logo = wx.Bitmap(image) |
---|
| 155 | self.bitmap_button_umd.SetBitmapLabel(logo) |
---|
| 156 | |
---|
| 157 | |
---|
| 158 | image = file_dir + "/images/sns_logo.png" |
---|
| 159 | if os.path.isfile(config._sns_logo): |
---|
| 160 | image = config._sns_logo |
---|
| 161 | logo = wx.Bitmap(image) |
---|
| 162 | self.bitmap_button_sns.SetBitmapLabel(logo) |
---|
| 163 | |
---|
[32c0841] | 164 | image = file_dir + "/images/nsf_logo.png" |
---|
[41d466f] | 165 | if os.path.isfile(config._nsf_logo): |
---|
| 166 | image = config._nsf_logo |
---|
| 167 | logo = wx.Bitmap(image) |
---|
| 168 | self.bitmap_button_nsf.SetBitmapLabel(logo) |
---|
| 169 | |
---|
[32c0841] | 170 | image = file_dir + "/images/danse_logo.png" |
---|
[41d466f] | 171 | if os.path.isfile(config._danse_logo): |
---|
| 172 | image = config._danse_logo |
---|
| 173 | logo = wx.Bitmap(image) |
---|
| 174 | self.bitmap_button_danse.SetBitmapLabel(logo) |
---|
| 175 | |
---|
[32c0841] | 176 | image = file_dir + "/images/utlogo.gif" |
---|
[41d466f] | 177 | if os.path.isfile(config._inst_logo): |
---|
| 178 | image = config._inst_logo |
---|
| 179 | logo = wx.Bitmap(image) |
---|
| 180 | self.bitmap_button_msu.SetBitmapLabel(logo) |
---|
| 181 | |
---|
| 182 | # resize dialog window to fit version number nicely |
---|
[32c0841] | 183 | if wx.VERSION >= (2, 7, 2, 0): |
---|
[41d466f] | 184 | size = [self.GetEffectiveMinSize()[0], self.GetSize()[1]] |
---|
| 185 | else: |
---|
| 186 | size = [self.GetBestFittingSize()[0], self.GetSize()[1]] |
---|
| 187 | self.Fit() |
---|
| 188 | |
---|
| 189 | def __set_properties(self): |
---|
[d955bf19] | 190 | """ |
---|
| 191 | """ |
---|
[41d466f] | 192 | # begin wxGlade: DialogAbout.__set_properties |
---|
| 193 | self.SetTitle("About") |
---|
| 194 | self.SetSize((600, 595)) |
---|
[32c0841] | 195 | self.label_title.SetFont(wx.Font(26, wx.DEFAULT, wx.NORMAL, |
---|
| 196 | wx.BOLD, 0, "")) |
---|
| 197 | self.label_version.SetFont(wx.Font(26, wx.DEFAULT, wx.NORMAL, |
---|
| 198 | wx.NORMAL, 0, "")) |
---|
[41d466f] | 199 | self.hyperlink_paper.Enable(True) |
---|
[1452132] | 200 | self.bitmap_button_nist.SetSize(self.bitmap_button_nist.GetBestSize()) |
---|
| 201 | self.bitmap_button_umd.SetSize(self.bitmap_button_umd.GetBestSize()) |
---|
| 202 | self.bitmap_button_sns.SetSize(self.bitmap_button_sns.GetBestSize()) |
---|
[41d466f] | 203 | self.bitmap_button_nsf.SetSize(self.bitmap_button_nsf.GetBestSize()) |
---|
| 204 | self.bitmap_button_danse.SetSize(self.bitmap_button_danse.GetBestSize()) |
---|
| 205 | self.bitmap_button_msu.SetSize(self.bitmap_button_msu.GetBestSize()) |
---|
| 206 | # end wxGlade |
---|
| 207 | |
---|
| 208 | def __do_layout(self): |
---|
[d955bf19] | 209 | """ |
---|
| 210 | """ |
---|
[41d466f] | 211 | # begin wxGlade: DialogAbout.__do_layout |
---|
| 212 | sizer_main = wx.BoxSizer(wx.VERTICAL) |
---|
| 213 | sizer_button = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 214 | sizer_logos = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 215 | sizer_header = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 216 | sizer_titles = wx.BoxSizer(wx.VERTICAL) |
---|
| 217 | sizer_build = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 218 | sizer_title = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 219 | sizer_header.Add(self.bitmap_logo, 0, wx.EXPAND, 0) |
---|
[32c0841] | 220 | sizer_title.Add(self.label_title, 0, |
---|
| 221 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
[41d466f] | 222 | sizer_title.Add((20, 20), 0, wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[32c0841] | 223 | sizer_title.Add(self.label_version, 0, |
---|
| 224 | wx.RIGHT|wx.ALIGN_BOTTOM|wx.ADJUST_MINSIZE, 10) |
---|
[41d466f] | 225 | sizer_titles.Add(sizer_title, 0, wx.EXPAND, 0) |
---|
[32c0841] | 226 | sizer_build.Add(self.label_build, 0, |
---|
| 227 | wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) |
---|
[41d466f] | 228 | sizer_build.Add(self.label_svnrevision, 0, wx.ADJUST_MINSIZE, 0) |
---|
| 229 | sizer_titles.Add(sizer_build, 0, wx.TOP|wx.EXPAND, 5) |
---|
[32c0841] | 230 | sizer_titles.Add(self.label_copyright, 0, |
---|
| 231 | wx.LEFT|wx.RIGHT|wx.TOP|wx.ADJUST_MINSIZE, 10) |
---|
| 232 | sizer_titles.Add(self.label_author, 0, |
---|
| 233 | wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) |
---|
[41d466f] | 234 | sizer_titles.Add(self.hyperlink, 0, wx.LEFT|wx.RIGHT, 10) |
---|
| 235 | sizer_titles.Add((20, 20), 0, wx.ADJUST_MINSIZE, 0) |
---|
| 236 | sizer_titles.Add(self.hyperlink_license, 0, wx.LEFT|wx.RIGHT, 10) |
---|
| 237 | sizer_titles.Add(self.hyperlink_paper, 0, wx.LEFT|wx.RIGHT, 10) |
---|
| 238 | sizer_titles.Add((20, 20), 0, wx.ADJUST_MINSIZE, 0) |
---|
| 239 | sizer_titles.Add(self.hyperlink_download, 0, wx.LEFT|wx.RIGHT, 10) |
---|
| 240 | sizer_header.Add(sizer_titles, 0, wx.EXPAND, 0) |
---|
| 241 | sizer_main.Add(sizer_header, 0, wx.BOTTOM|wx.EXPAND, 3) |
---|
| 242 | sizer_main.Add(self.static_line_1, 0, wx.EXPAND, 0) |
---|
[32c0841] | 243 | sizer_main.Add(self.label_acknowledgement, 0, |
---|
| 244 | wx.LEFT|wx.TOP|wx.BOTTOM|wx.ADJUST_MINSIZE, 7) |
---|
[41d466f] | 245 | sizer_main.Add(self.static_line_2, 0, wx.EXPAND, 0) |
---|
[1452132] | 246 | sizer_logos.Add(self.bitmap_button_nist, 0, wx.LEFT|wx.ADJUST_MINSIZE, 2) |
---|
| 247 | sizer_logos.Add(self.bitmap_button_umd, 0, wx.LEFT|wx.ADJUST_MINSIZE, 2) |
---|
| 248 | sizer_logos.Add(self.bitmap_button_sns, 0, wx.LEFT|wx.ADJUST_MINSIZE, 2) |
---|
[41d466f] | 249 | sizer_logos.Add(self.bitmap_button_nsf, 0, wx.LEFT|wx.ADJUST_MINSIZE, 2) |
---|
[32c0841] | 250 | sizer_logos.Add(self.bitmap_button_danse, 0, |
---|
| 251 | wx.LEFT|wx.ADJUST_MINSIZE, 2) |
---|
[41d466f] | 252 | sizer_logos.Add(self.bitmap_button_msu, 0, wx.LEFT|wx.ADJUST_MINSIZE, 2) |
---|
| 253 | sizer_logos.Add((50, 50), 0, wx.ADJUST_MINSIZE, 0) |
---|
| 254 | sizer_main.Add(sizer_logos, 0, wx.EXPAND, 0) |
---|
| 255 | sizer_main.Add(self.static_line_3, 0, wx.EXPAND, 0) |
---|
| 256 | sizer_button.Add((20, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[3c965fd] | 257 | sizer_button.Add(self.button_OK, 0, |
---|
| 258 | wx.RIGHT|wx.ADJUST_MINSIZE|wx.BOTTOM, 10) |
---|
[41d466f] | 259 | sizer_main.Add(sizer_button, 0, wx.EXPAND, 0) |
---|
| 260 | self.SetAutoLayout(True) |
---|
| 261 | self.SetSizer(sizer_main) |
---|
| 262 | self.Layout() |
---|
| 263 | self.Centre() |
---|
| 264 | # end wxGlade |
---|
| 265 | |
---|
[1452132] | 266 | def onNistLogo(self, event): |
---|
| 267 | """ |
---|
| 268 | """ |
---|
| 269 | # wxGlade: DialogAbout.<event_handler> |
---|
| 270 | launchBrowser(config._nist_url) |
---|
| 271 | event.Skip() |
---|
| 272 | |
---|
| 273 | def onUmdLogo(self, event): |
---|
| 274 | """ |
---|
| 275 | """ |
---|
| 276 | # wxGlade: DialogAbout.<event_handler> |
---|
| 277 | launchBrowser(config._umd_url) |
---|
| 278 | event.Skip() |
---|
| 279 | |
---|
| 280 | def onSnsLogo(self, event): |
---|
| 281 | """ |
---|
| 282 | """ |
---|
| 283 | # wxGlade: DialogAbout.<event_handler> |
---|
| 284 | launchBrowser(config._sns_url) |
---|
| 285 | event.Skip() |
---|
| 286 | |
---|
[d955bf19] | 287 | def onNsfLogo(self, event): |
---|
| 288 | """ |
---|
| 289 | """ |
---|
| 290 | # wxGlade: DialogAbout.<event_handler> |
---|
[41d466f] | 291 | launchBrowser(config._nsf_url) |
---|
| 292 | event.Skip() |
---|
| 293 | |
---|
[d955bf19] | 294 | def onDanseLogo(self, event): |
---|
| 295 | """ |
---|
| 296 | """ |
---|
| 297 | # wxGlade: DialogAbout.<event_handler> |
---|
[41d466f] | 298 | launchBrowser(config._danse_url) |
---|
| 299 | event.Skip() |
---|
| 300 | |
---|
[d955bf19] | 301 | def onUTLogo(self, event): |
---|
| 302 | """ |
---|
| 303 | """ |
---|
| 304 | # wxGlade: DialogAbout.<event_handler> |
---|
[41d466f] | 305 | launchBrowser(config._inst_url) |
---|
| 306 | event.Skip() |
---|
| 307 | |
---|
| 308 | # end of class DialogAbout |
---|
| 309 | |
---|
| 310 | ##### testing code ############################################################ |
---|
| 311 | class MyApp(wx.App): |
---|
[32c0841] | 312 | """ |
---|
| 313 | """ |
---|
[41d466f] | 314 | def OnInit(self): |
---|
[32c0841] | 315 | """ |
---|
| 316 | """ |
---|
[41d466f] | 317 | wx.InitAllImageHandlers() |
---|
| 318 | dialog = DialogAbout(None, -1, "") |
---|
| 319 | self.SetTopWindow(dialog) |
---|
| 320 | dialog.ShowModal() |
---|
| 321 | dialog.Destroy() |
---|
| 322 | return 1 |
---|
| 323 | |
---|
| 324 | # end of class MyApp |
---|
| 325 | |
---|
| 326 | if __name__ == "__main__": |
---|
| 327 | app = MyApp(0) |
---|
| 328 | app.MainLoop() |
---|
| 329 | |
---|
| 330 | ##### end of testing code ##################################################### |
---|