[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'))): |
---|
| 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 |
---|
[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 | |
---|
| 71 | # Mac doesn't display images with transparent background so well, keep it for Windows |
---|
| 72 | image = file_dir+"/images/angles_flat.png" |
---|
[2bd9927] | 73 | |
---|
[41d466f] | 74 | if os.path.isfile(config._corner_image): |
---|
| 75 | image = config._corner_image |
---|
| 76 | |
---|
| 77 | if os.name == 'nt': |
---|
| 78 | self.bitmap_logo = wx.StaticBitmap(self, -1, wx.Bitmap(image)) |
---|
| 79 | else: |
---|
| 80 | self.bitmap_logo = wx.StaticBitmap(self, -1, wx.Bitmap(image)) |
---|
| 81 | |
---|
| 82 | self.label_title = wx.StaticText(self, -1, config.__appname__) |
---|
| 83 | self.label_version = wx.StaticText(self, -1, "") |
---|
| 84 | self.label_build = wx.StaticText(self, -1, "Build:") |
---|
| 85 | self.label_svnrevision = wx.StaticText(self, -1, "") |
---|
| 86 | self.label_copyright = wx.StaticText(self, -1, config._copyright) |
---|
| 87 | self.label_author = wx.StaticText(self, -1, "authors") |
---|
| 88 | self.hyperlink = wx.lib.hyperlink.HyperLinkCtrl(self, -1, config._homepage, URL=config._homepage) |
---|
| 89 | #self.hyperlink_license = wx.lib.hyperlink.HyperLinkCtrl(self, -1, "Comments? Bugs? Requests?", URL=config._paper) |
---|
| 90 | self.hyperlink_license = wx.StaticText(self, -1, "Comments? Bugs? Requests?") |
---|
| 91 | self.hyperlink_paper = wx.lib.hyperlink.HyperLinkCtrl(self, -1, "Send us a ticket", URL=config._license) |
---|
| 92 | self.hyperlink_download = wx.lib.hyperlink.HyperLinkCtrl(self, -1, "Get the latest version", URL=config._download) |
---|
| 93 | self.static_line_1 = wx.StaticLine(self, -1) |
---|
| 94 | self.label_acknowledgement = wx.StaticText(self, -1, config._acknowledgement) |
---|
| 95 | self.static_line_2 = wx.StaticLine(self, -1) |
---|
| 96 | self.bitmap_button_nsf = wx.BitmapButton(self, -1, wx.NullBitmap) |
---|
| 97 | self.bitmap_button_danse = wx.BitmapButton(self, -1, wx.NullBitmap) |
---|
| 98 | self.bitmap_button_msu = wx.BitmapButton(self, -1, wx.NullBitmap) |
---|
| 99 | self.static_line_3 = wx.StaticLine(self, -1) |
---|
| 100 | self.button_OK = wx.Button(self, wx.ID_OK, "OK") |
---|
| 101 | |
---|
| 102 | self.__set_properties() |
---|
| 103 | self.__do_layout() |
---|
| 104 | |
---|
| 105 | self.Bind(wx.EVT_BUTTON, self.onNsfLogo, self.bitmap_button_nsf) |
---|
| 106 | self.Bind(wx.EVT_BUTTON, self.onDanseLogo, self.bitmap_button_danse) |
---|
| 107 | self.Bind(wx.EVT_BUTTON, self.onUTLogo, self.bitmap_button_msu) |
---|
| 108 | # end wxGlade |
---|
| 109 | |
---|
| 110 | # fill in acknowledgements |
---|
| 111 | # self.text_ctrl_acknowledgement.SetValue(__acknowledgement__) |
---|
| 112 | |
---|
| 113 | # randomly shuffle authors' names |
---|
| 114 | random.shuffle(config._authors) |
---|
| 115 | strLabel = ", ".join(config._authors) |
---|
| 116 | |
---|
| 117 | # display version and svn revison numbers |
---|
| 118 | verwords = config.__version__.split('.') |
---|
| 119 | version = '.'.join(verwords[:-1]) |
---|
| 120 | revision = verwords[-1] |
---|
| 121 | |
---|
| 122 | self.label_author.SetLabel(strLabel) |
---|
[1c97a3f] | 123 | self.label_version.SetLabel(config.__version__)#(version) |
---|
[41d466f] | 124 | self.label_svnrevision.SetLabel(config.__version__) |
---|
| 125 | |
---|
| 126 | # set bitmaps for logo buttons |
---|
| 127 | image = file_dir+"/images/nsf_logo.png" |
---|
| 128 | if os.path.isfile(config._nsf_logo): |
---|
| 129 | image = config._nsf_logo |
---|
| 130 | logo = wx.Bitmap(image) |
---|
| 131 | self.bitmap_button_nsf.SetBitmapLabel(logo) |
---|
| 132 | |
---|
| 133 | image = file_dir+"/images/danse_logo.png" |
---|
| 134 | if os.path.isfile(config._danse_logo): |
---|
| 135 | image = config._danse_logo |
---|
| 136 | logo = wx.Bitmap(image) |
---|
| 137 | self.bitmap_button_danse.SetBitmapLabel(logo) |
---|
| 138 | |
---|
| 139 | image = file_dir+"/images/utlogo.gif" |
---|
| 140 | if os.path.isfile(config._inst_logo): |
---|
| 141 | image = config._inst_logo |
---|
| 142 | logo = wx.Bitmap(image) |
---|
| 143 | self.bitmap_button_msu.SetBitmapLabel(logo) |
---|
| 144 | |
---|
| 145 | # resize dialog window to fit version number nicely |
---|
| 146 | if wx.VERSION >= (2,7,2,0): |
---|
| 147 | size = [self.GetEffectiveMinSize()[0], self.GetSize()[1]] |
---|
| 148 | else: |
---|
| 149 | size = [self.GetBestFittingSize()[0], self.GetSize()[1]] |
---|
| 150 | |
---|
| 151 | self.Fit() |
---|
| 152 | |
---|
| 153 | def __set_properties(self): |
---|
[d955bf19] | 154 | """ |
---|
| 155 | """ |
---|
[41d466f] | 156 | # begin wxGlade: DialogAbout.__set_properties |
---|
| 157 | self.SetTitle("About") |
---|
| 158 | self.SetSize((600, 595)) |
---|
| 159 | self.label_title.SetFont(wx.Font(26, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, "")) |
---|
| 160 | self.label_version.SetFont(wx.Font(26, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, "")) |
---|
[12aa9b5] | 161 | |
---|
[41d466f] | 162 | self.hyperlink_paper.Enable(True) |
---|
[12aa9b5] | 163 | |
---|
[41d466f] | 164 | self.bitmap_button_nsf.SetSize(self.bitmap_button_nsf.GetBestSize()) |
---|
| 165 | self.bitmap_button_danse.SetSize(self.bitmap_button_danse.GetBestSize()) |
---|
| 166 | self.bitmap_button_msu.SetSize(self.bitmap_button_msu.GetBestSize()) |
---|
| 167 | # end wxGlade |
---|
| 168 | |
---|
| 169 | def __do_layout(self): |
---|
[d955bf19] | 170 | """ |
---|
| 171 | """ |
---|
[41d466f] | 172 | # begin wxGlade: DialogAbout.__do_layout |
---|
| 173 | sizer_main = wx.BoxSizer(wx.VERTICAL) |
---|
| 174 | sizer_button = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 175 | sizer_logos = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 176 | sizer_header = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 177 | sizer_titles = wx.BoxSizer(wx.VERTICAL) |
---|
| 178 | sizer_build = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 179 | sizer_title = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 180 | sizer_header.Add(self.bitmap_logo, 0, wx.EXPAND, 0) |
---|
| 181 | sizer_title.Add(self.label_title, 0, wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
| 182 | sizer_title.Add((20, 20), 0, wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 183 | sizer_title.Add(self.label_version, 0, wx.RIGHT|wx.ALIGN_BOTTOM|wx.ADJUST_MINSIZE, 10) |
---|
| 184 | sizer_titles.Add(sizer_title, 0, wx.EXPAND, 0) |
---|
| 185 | sizer_build.Add(self.label_build, 0, wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) |
---|
| 186 | sizer_build.Add(self.label_svnrevision, 0, wx.ADJUST_MINSIZE, 0) |
---|
| 187 | sizer_titles.Add(sizer_build, 0, wx.TOP|wx.EXPAND, 5) |
---|
| 188 | sizer_titles.Add(self.label_copyright, 0, wx.LEFT|wx.RIGHT|wx.TOP|wx.ADJUST_MINSIZE, 10) |
---|
| 189 | sizer_titles.Add(self.label_author, 0, wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) |
---|
| 190 | sizer_titles.Add(self.hyperlink, 0, wx.LEFT|wx.RIGHT, 10) |
---|
| 191 | sizer_titles.Add((20, 20), 0, wx.ADJUST_MINSIZE, 0) |
---|
| 192 | sizer_titles.Add(self.hyperlink_license, 0, wx.LEFT|wx.RIGHT, 10) |
---|
| 193 | sizer_titles.Add(self.hyperlink_paper, 0, wx.LEFT|wx.RIGHT, 10) |
---|
| 194 | sizer_titles.Add((20, 20), 0, wx.ADJUST_MINSIZE, 0) |
---|
| 195 | sizer_titles.Add(self.hyperlink_download, 0, wx.LEFT|wx.RIGHT, 10) |
---|
| 196 | sizer_header.Add(sizer_titles, 0, wx.EXPAND, 0) |
---|
| 197 | sizer_main.Add(sizer_header, 0, wx.BOTTOM|wx.EXPAND, 3) |
---|
| 198 | sizer_main.Add(self.static_line_1, 0, wx.EXPAND, 0) |
---|
| 199 | sizer_main.Add(self.label_acknowledgement, 0, wx.LEFT|wx.TOP|wx.BOTTOM|wx.ADJUST_MINSIZE, 7) |
---|
| 200 | sizer_main.Add(self.static_line_2, 0, wx.EXPAND, 0) |
---|
| 201 | sizer_logos.Add(self.bitmap_button_nsf, 0, wx.LEFT|wx.ADJUST_MINSIZE, 2) |
---|
| 202 | sizer_logos.Add(self.bitmap_button_danse, 0, wx.LEFT|wx.ADJUST_MINSIZE, 2) |
---|
| 203 | sizer_logos.Add(self.bitmap_button_msu, 0, wx.LEFT|wx.ADJUST_MINSIZE, 2) |
---|
| 204 | sizer_logos.Add((50, 50), 0, wx.ADJUST_MINSIZE, 0) |
---|
| 205 | sizer_main.Add(sizer_logos, 0, wx.EXPAND, 0) |
---|
| 206 | sizer_main.Add(self.static_line_3, 0, wx.EXPAND, 0) |
---|
| 207 | sizer_button.Add((20, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 208 | sizer_button.Add(self.button_OK, 0, wx.RIGHT|wx.ADJUST_MINSIZE, 10) |
---|
| 209 | sizer_main.Add(sizer_button, 0, wx.EXPAND, 0) |
---|
| 210 | self.SetAutoLayout(True) |
---|
| 211 | self.SetSizer(sizer_main) |
---|
| 212 | self.Layout() |
---|
| 213 | self.Centre() |
---|
| 214 | # end wxGlade |
---|
| 215 | |
---|
[d955bf19] | 216 | def onNsfLogo(self, event): |
---|
| 217 | """ |
---|
| 218 | """ |
---|
| 219 | # wxGlade: DialogAbout.<event_handler> |
---|
[41d466f] | 220 | launchBrowser(config._nsf_url) |
---|
| 221 | event.Skip() |
---|
| 222 | |
---|
[d955bf19] | 223 | def onDanseLogo(self, event): |
---|
| 224 | """ |
---|
| 225 | """ |
---|
| 226 | # wxGlade: DialogAbout.<event_handler> |
---|
[41d466f] | 227 | launchBrowser(config._danse_url) |
---|
| 228 | event.Skip() |
---|
| 229 | |
---|
[d955bf19] | 230 | def onUTLogo(self, event): |
---|
| 231 | """ |
---|
| 232 | """ |
---|
| 233 | # wxGlade: DialogAbout.<event_handler> |
---|
[41d466f] | 234 | launchBrowser(config._inst_url) |
---|
| 235 | event.Skip() |
---|
| 236 | |
---|
| 237 | # end of class DialogAbout |
---|
| 238 | |
---|
| 239 | ##### testing code ############################################################ |
---|
| 240 | class MyApp(wx.App): |
---|
| 241 | def OnInit(self): |
---|
| 242 | wx.InitAllImageHandlers() |
---|
| 243 | dialog = DialogAbout(None, -1, "") |
---|
| 244 | self.SetTopWindow(dialog) |
---|
| 245 | dialog.ShowModal() |
---|
| 246 | dialog.Destroy() |
---|
| 247 | return 1 |
---|
| 248 | |
---|
| 249 | # end of class MyApp |
---|
| 250 | |
---|
| 251 | if __name__ == "__main__": |
---|
| 252 | app = MyApp(0) |
---|
| 253 | app.MainLoop() |
---|
| 254 | |
---|
| 255 | ##### end of testing code ##################################################### |
---|