How to show an about dialog info (Phoenix)

Keywords : About, Dialog, Description, Copyright, Application's name, Application's version, Main developper, Website url, Licence text, Multiple developpers, Translator, Email, Icon.


Demonstrating :

Tested py3.x, wx4.x and Win10.

Are you ready to use some samples ? ;)

Test, modify, correct, complete, improve and share your discoveries ! (!)


First example

img_sample_one.png

   1 # sample_one.py
   2 
   3 import os
   4 import wx
   5 import wx.adv
   6 
   7 # class Options
   8 # class Details
   9 # class MyFrame
  10 # class MyApp
  11 
  12 sLicence = '''This application is provided "as is" without any licence
  13 
  14 Everyone is free to copy, modify, sell, and do anything with it.
  15 
  16 This application and its source code is provided as a small
  17 sample to show the use of wxWidgets standard about box.'''
  18 
  19 aTranslators = ['Xaviou (en = app default)', 'Nobody Else (no translations support)']
  20 
  21 #---------------------------------------------------------------------------
  22 
  23 class Options:
  24     MINIMAL = 0
  25     MAXIMAL = 1
  26     CUSTOM = 2
  27 
  28     COUNT = 3
  29 
  30 #---------------------------------------------------------------------------
  31 
  32 class Details:
  33     APP_NAME = 0
  34     APP_VERSION = 1
  35     APP_DESCRIPTION = 2
  36     COPYRIGHT = 3
  37     ICON = 4
  38     LICENCE = 5
  39     DEVELOPPER = 6
  40     DEVELOPPERS = 7
  41     WEBSITE = 8
  42     TRANSLATORS = 9
  43 
  44     COUNT = 10
  45 
  46 iCheckedBoxes = [
  47     Details.APP_NAME,
  48     Details.APP_VERSION,
  49     Details.APP_DESCRIPTION,
  50     Details.COPYRIGHT,
  51     Details.ICON
  52 ]
  53 
  54 #---------------------------------------------------------------------------
  55 
  56 class MyFrame(wx.Frame):
  57     def __init__(self):
  58         wx.Frame.__init__(self, None, title=wx.GetApp().GetAppName())
  59         self.SetIcon(wx.Icon('icons/wxwin.ico'))
  60 
  61         self._optInfos = [0] * Options.COUNT
  62         self._chkInfos = [0] * Details.COUNT
  63 
  64         self._createControls()
  65 
  66         self._connectControls()
  67 
  68         self._updateInterface()
  69 
  70     def _createControls(self):
  71         # A Statusbar in the bottom of the window
  72         self.CreateStatusBar(1)
  73         sMsg = 'wxPython ' + wx.version()
  74         self.SetStatusText(sMsg)
  75 
  76         # Add a panel to the frame (needed under Windows to have a nice background)
  77         pnl = wx.Panel(self, wx.ID_ANY)
  78 
  79         szrMain = wx.BoxSizer(wx.VERTICAL)
  80         stbSzr = wx.StaticBoxSizer(wx.VERTICAL, pnl, 'Informations to show in the "About" box:')
  81 
  82         self._optInfos[Options.MINIMAL] = wx.RadioButton(pnl, wx.ID_ANY, 'Application\'s name only (minimal "About" box)', style=wx.RB_GROUP)
  83         stbSzr.Add(self._optInfos[Options.MINIMAL], 0, wx.ALL, 5)
  84 
  85         self._optInfos[Options.MAXIMAL] = wx.RadioButton(pnl, wx.ID_ANY, 'All available informations')
  86         stbSzr.Add(self._optInfos[Options.MAXIMAL], 0, wx.LEFT|wx.RIGHT|wx.BOTTOM, 5)
  87 
  88         self._optInfos[Options.CUSTOM] = wx.RadioButton(pnl, wx.ID_ANY, 'Let me select the informations I want to see')
  89         stbSzr.Add(self._optInfos[Options.CUSTOM], 0, wx.LEFT|wx.RIGHT, 5)
  90 
  91         lnSzr = wx.BoxSizer(wx.HORIZONTAL)
  92         lnSzr.AddSpacer(10)
  93 
  94         flxSzr = wx.FlexGridSizer(2, 5, 5)
  95 
  96         self._chkInfos[Details.APP_NAME] = wx.CheckBox(pnl, wx.ID_ANY, 'Application\'s name')
  97         self._chkInfos[Details.APP_NAME].Disable()
  98         flxSzr.Add(self._chkInfos[Details.APP_NAME])
  99 
 100         self._chkInfos[Details.APP_VERSION] = wx.CheckBox(pnl, wx.ID_ANY, 'Application\'s version')
 101         flxSzr.Add(self._chkInfos[Details.APP_VERSION])
 102 
 103         self._chkInfos[Details.APP_DESCRIPTION] = wx.CheckBox(pnl, wx.ID_ANY, 'Description')
 104         flxSzr.Add(self._chkInfos[Details.APP_DESCRIPTION])
 105 
 106         self._chkInfos[Details.COPYRIGHT] = wx.CheckBox(pnl, wx.ID_ANY, 'Copyright')
 107         flxSzr.Add(self._chkInfos[Details.COPYRIGHT])
 108 
 109         self._chkInfos[Details.ICON] = wx.CheckBox(pnl, wx.ID_ANY, 'Icon')
 110         flxSzr.Add(self._chkInfos[Details.ICON])
 111 
 112         self._chkInfos[Details.LICENCE] = wx.CheckBox(pnl, wx.ID_ANY, 'Licence text')
 113         flxSzr.Add(self._chkInfos[Details.LICENCE])
 114 
 115         self._chkInfos[Details.DEVELOPPER] = wx.CheckBox(pnl, wx.ID_ANY, 'Main developper')
 116         flxSzr.Add(self._chkInfos[Details.DEVELOPPER])
 117 
 118         self._chkInfos[Details.DEVELOPPERS] = wx.CheckBox(pnl, wx.ID_ANY, 'Multiple developpers')
 119         flxSzr.Add(self._chkInfos[Details.DEVELOPPERS])
 120 
 121         self._chkInfos[Details.WEBSITE] = wx.CheckBox(pnl, wx.ID_ANY, 'Website url')
 122         flxSzr.Add(self._chkInfos[Details.WEBSITE])
 123 
 124         self._chkInfos[Details.TRANSLATORS] = wx.CheckBox(pnl, wx.ID_ANY, 'Translators')
 125         flxSzr.Add(self._chkInfos[Details.TRANSLATORS])
 126 
 127         lnSzr.Add(flxSzr, 0, wx.ALL, 0)
 128 
 129         stbSzr.Add(lnSzr, 0, wx.ALL, 5)
 130 
 131         szrMain.Add(stbSzr, 1, wx.ALL|wx.EXPAND, 5)
 132 
 133         pnl.SetSizer(szrMain)
 134 
 135         # At startup, select the "All available infos" option
 136         self._optInfos[Options.MAXIMAL].SetValue(True)
 137         # Check the wxCheckBoxes depending on the defined array (see on top of this file)
 138         for i in iCheckedBoxes:
 139             self._chkInfos[i].SetValue(True)
 140 
 141         # Create the menu bar
 142         menuBar = wx.MenuBar()
 143         # File menu
 144         menuFile = wx.Menu()
 145         menuFile.Append(wx.ID_EXIT)
 146         menuBar.Append(menuFile, wx.GetStockLabel(wx.ID_FILE))
 147         # Help menu
 148         menuHelp = wx.Menu()
 149         menuHelp.Append(wx.ID_ABOUT)
 150         menuBar.Append(menuHelp, wx.GetStockLabel(wx.ID_HELP))
 151         # Assigne the menubar
 152         self.SetMenuBar(menuBar)
 153 
 154         # On OS X, delete the created menus
 155         # as the About and Exit items are handled by the OS specific menu
 156         if wx.GetOsDescription()[:8] == 'Mac OS X':
 157             menuBar.Remove(1)
 158             del menuHelp
 159             menuBar.Remove(0)
 160             del menuFile
 161 
 162         # Adjust window size
 163         szrMain.SetSizeHints(self)
 164 
 165     def _connectControls(self):
 166         self.Bind(wx.EVT_MENU, self._onMenuExitClicked, id=wx.ID_EXIT)
 167         self.Bind(wx.EVT_MENU, self._onMenuAboutClicked, id=wx.ID_ABOUT)
 168         self.Bind(wx.EVT_RADIOBUTTON, self._onOptInfosClicked)
 169 
 170     def _updateInterface(self):
 171         # Checkboxes are only shown if the "custom" option is selected
 172         bShow = self._optInfos[Options.CUSTOM].GetValue()
 173         for chk in self._chkInfos:
 174             chk.Show(bShow)
 175 
 176     def _onMenuExitClicked(self, evt):
 177         self.Close()
 178 
 179     def _onMenuAboutClicked(self, evt):
 180         # Get the index of the selected option
 181         iOpt = Options.MAXIMAL
 182         for i in range(Options.COUNT):
 183             if self._optInfos[i].GetValue():
 184                 iOpt = i
 185                 break
 186         info = wx.adv.AboutDialogInfo()
 187 
 188         for i in range(Details.COUNT):
 189             if (i == Details.APP_NAME or iOpt == Options.MAXIMAL or
 190                 (iOpt == Options.CUSTOM and self._chkInfos[i].GetValue())):
 191 
 192                 if i == Details.APP_NAME:
 193                     info.SetName('AboutBoxWx')
 194                 elif i == Details.APP_VERSION:
 195                     info.SetVersion('1.0.0')
 196                 elif i == Details.APP_DESCRIPTION:
 197                     info.SetDescription('wxWidgets provided AboutBox')
 198                 elif i == Details.COPYRIGHT:
 199                     info.SetCopyright('Copyright (c) X.P. 2018')
 200                 elif i == Details.ICON:
 201                     info.SetIcon(wx.Icon('icons/wxWidgets.png', wx.BITMAP_TYPE_PNG))
 202                 elif i == Details.LICENCE:
 203                     info.SetLicence(sLicence)
 204                 elif i == Details.DEVELOPPER:
 205                     info.AddDeveloper('X.P. AKA Xaviou')
 206                 elif i == Details.DEVELOPPERS:
 207                     info.AddDeveloper('An unknown developper')
 208                     info.AddDeveloper('Another unknown developper')
 209                 elif i == Details.WEBSITE:
 210                     info.SetWebSite('https://wxstuff.xaviou.fr', 'X@v\'s wxStuff website')
 211                 elif i == Details.TRANSLATORS:
 212                     info.SetTranslators(aTranslators)
 213 
 214         wx.adv.AboutBox(info)
 215 
 216     def _onOptInfosClicked(self, evt):
 217         self._updateInterface()
 218 
 219 #---------------------------------------------------------------------------
 220 
 221 class MyApp(wx.App):
 222     def OnInit(self):
 223         print('Running wxPython ' + wx.version())
 224         # Set Current directory to the one containing this file
 225         os.chdir(os.path.dirname(os.path.abspath(__file__)))
 226 
 227         self.locale = wx.Locale(wx.LANGUAGE_ENGLISH)
 228 
 229         self.SetAppName('AboutBoxWx')
 230 
 231         # Create the main window
 232         frm = MyFrame()
 233         self.SetTopWindow(frm)
 234 
 235         frm.Show()
 236         return True
 237 
 238 #---------------------------------------------------------------------------
 239 
 240 if __name__ == '__main__':
 241     app = MyApp()
 242     app.MainLoop()


Download source

source.zip


Additional Information

Link :

- - - - -

https://wiki.wxpython.org/TitleIndex

https://docs.wxpython.org/


Thanks to

Xaviou (sample_one.py coding), the wxPython community...


About this page

Date(d/m/y) Person (bot) Comments :

28/10/19 - Ecco (Created page for wxPython Phoenix).


Comments

- blah, blah, blah....

How to show an about dialog info (Phoenix) (last edited 2020-12-13 17:27:48 by Ecco)

NOTE: To edit pages in this wiki you must be a member of the TrustedEditorsGroup.