How to create a customized about box dialog (Phoenix)
Keywords : About, Dialog, Description, Copyright, Application's name, Application's version, Main developper, Website url, Licence text, Multiple developpers, Translator, Email, Icon.
Contents
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
1 # sample_one.py
2
3 import os
4 import wx
5
6 # class DlgAbout
7 # class MainFrame
8 # class MyApp
9
10 #-------------------------------------------------------------------------------
11
12 class DlgAbout(wx.Dialog):
13 def __init__(self, parent):
14 wx.Dialog.__init__(self, parent, title=wx.GetStockLabel(wx.ID_ABOUT, wx.STOCK_NOFLAGS))
15
16 self._createInterface()
17
18 self.CenterOnParent()
19
20 def _createInterface(self):
21
22 sTitle = 'AboutBoxDlg (v1.0.0)'
23 sVersion = wx.version()
24 pos = sVersion.find(' wxWidgets')
25 if pos != -1:
26 sVersion = sVersion[:pos]
27 sMsg = 'Made with wxPython ' + sVersion + '\nBased on ' + wx.GetLibraryVersionInfo().VersionString
28 szrMain = wx.BoxSizer(wx.VERTICAL)
29
30 szrTop = wx.BoxSizer(wx.HORIZONTAL)
31
32 bmpCtrl = wx.StaticBitmap(self, wx.ID_ANY, wx.Bitmap('bitmaps/wxWidgets.png', wx.BITMAP_TYPE_PNG))
33 szrTop.Add(bmpCtrl, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5)
34
35 szrRight = wx.BoxSizer(wx.VERTICAL)
36
37 label = wx.StaticText(self, wx.ID_STATIC, sTitle)
38 fntTitle = label.GetFont()
39 fntTitle.MakeLarger()
40 fntTitle.MakeBold()
41 label.SetFont(fntTitle)
42 szrRight.Add(label, 0, wx.ALL|wx.ALIGN_CENTER, 5)
43
44 label = wx.StaticText(self, wx.ID_STATIC, 'Copyright (c) X.P. 2018')
45 szrRight.Add(label, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ALIGN_CENTER, 5)
46
47 label = wx.StaticText(self, wx.ID_STATIC, 'wxWidgets Application')
48 szrRight.Add(label, 0, wx.LEFT|wx.RIGHT|wx.TOP|wx.ALIGN_CENTER, 5)
49
50 label = wx.StaticText(self, wx.ID_STATIC, sMsg, style=wx.ST_NO_AUTORESIZE|wx.ALIGN_CENTER)
51 szrRight.Add(label, 0, wx.ALL|wx.EXPAND, 5)
52
53 szrTop.Add(szrRight, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5)
54
55 szrMain.Add(szrTop, 0, wx.ALL, 5)
56
57 btnSzr = self.CreateSeparatedButtonSizer(wx.CLOSE)
58 szrMain.Add(btnSzr, 0, wx.ALL|wx.EXPAND, 5)
59
60 self.SetSizer(szrMain)
61
62 szrMain.SetSizeHints(self)
63
64 #-------------------------------------------------------------------------------
65
66 class MainFrame(wx.Frame):
67 def __init__(self):
68 wx.Frame.__init__(self, None, title=wx.GetApp().GetAppName())
69 self.SetIcon(wx.Icon('icons/wxwin.ico'))
70
71 self._createControls()
72
73 self._connectControls()
74
75 def _createControls(self):
76 # A Statusbar in the bottom of the window
77 self.CreateStatusBar(1)
78 sMsg = 'wxPython ' + wx.version()
79 self.SetStatusText(sMsg)
80
81 # Add a panel to the frame (needed under Windows to have a nice background)
82 wx.Panel(self, wx.ID_ANY)
83
84 # Create the menu bar
85 menuBar = wx.MenuBar()
86 # File menu
87 menuFile = wx.Menu()
88 menuFile.Append(wx.ID_EXIT)
89 menuBar.Append(menuFile, wx.GetStockLabel(wx.ID_FILE))
90 # Help menu
91 menuHelp = wx.Menu()
92 menuHelp.Append(wx.ID_ABOUT)
93 menuBar.Append(menuHelp, wx.GetStockLabel(wx.ID_HELP))
94 # Assigne the menubar
95 self.SetMenuBar(menuBar)
96
97 # On OS X, delete the created menus
98 # as the About and Exit items are handled by the OS specific menu
99 if wx.GetOsDescription()[:8] == 'Mac OS X':
100 menuBar.Remove(1)
101 del menuHelp
102 menuBar.Remove(0)
103 del menuFile
104
105 def _connectControls(self):
106 self.Bind(wx.EVT_MENU, self._onMenuExitClicked, id=wx.ID_EXIT)
107 self.Bind(wx.EVT_MENU, self._onMenuAboutClicked, id=wx.ID_ABOUT)
108
109 def _onMenuExitClicked(self, evt):
110 self.Close()
111
112 def _onMenuAboutClicked(self, evt):
113 dlg = DlgAbout(self)
114 dlg.ShowModal()
115
116 #-------------------------------------------------------------------------------
117
118 class MyApp(wx.App):
119 def OnInit(self):
120 print('Running wxPython ' + wx.version())
121 # Set Current directory to the one containing this file
122 os.chdir(os.path.dirname(os.path.abspath(__file__)))
123
124 self.SetAppName('AboutBoxDlg')
125
126 # Create the main window
127 frm = MainFrame()
128 self.SetTopWindow(frm)
129
130 frm.Show()
131 return True
132
133 #-------------------------------------------------------------------------------
134
135 if __name__ == '__main__':
136 app = MyApp()
137 app.MainLoop()
Second example
1 # sample_two.py
2
3 import wx
4 try:
5 from agw import hyperlink as hl
6 except ImportError:
7 # If it's not there locally, try the wxPython lib.
8 import wx.lib.agw.hyperlink as hl
9
10 # class MyAboutDlg
11 # class MyFrame
12 # class MyApp
13
14 #-------------------------------------------------------------------------------
15
16 class MyAboutDlg(wx.Dialog):
17 """
18 ...
19 """
20 def __init__(self,
21 parent,
22 title,
23 icon1=None,
24 icon2=None,
25 short_name=None,
26 long_name=None,
27 version=None,
28 description=None,
29 urls=None,
30 licence=None,
31 developers=[]):
32 wx.Dialog.__init__(self, parent, title=title)
33
34 self.icon1 = icon1
35 self.icon2 = icon2
36 self.short_name = short_name
37 self.long_name = long_name
38 self.version = version
39 self.version = version
40 self.description = description
41 self.urls = urls
42 self.licence = licence
43 self.developers = developers
44
45 #------------
46
47 # Simplified init method.
48 self.Build()
49
50 #------------
51
52 self.CenterOnParent()
53
54 #---------------------------------------------------------------------------
55
56 def Build(self):
57 """
58 ...
59 """
60
61 # Build the header.
62 header = wx.BoxSizer(wx.HORIZONTAL)
63
64 if self.icon1:
65 header.Add(wx.StaticBitmap(self, bitmap=self.icon1), 0)
66 else:
67 header.Add((64, 64))
68 header.Add((20, 1), 1)
69
70 if self.short_name:
71 label = wx.StaticText(self, label=self.short_name)
72 of = label.GetFont()
73 font = wx.Font(int(of.GetPointSize() * 2), of.GetFamily(), wx.NORMAL, wx.FONTWEIGHT_BOLD)
74 label.SetFont(font)
75 header.Add(label, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5)
76 else:
77 header.Add((1, 1), 1)
78 header.Add((20, 1), 1)
79
80 if self.icon2:
81 header.Add(wx.StaticBitmap(self, bitmap=self.icon2), 0)
82 else:
83 header.Add((64, 64))
84 width = header.MinSize[0]
85
86 #------------
87
88 # Now the rest.
89 mainSizer = wx.BoxSizer(wx.VERTICAL)
90 mainSizer.Add(header, 0, wx.ALIGN_CENTER|wx.ALL, 5)
91
92 #------------
93
94 if self.long_name:
95 label = wx.StaticText(self, label=self.long_name)
96 # label.SetForegroundColour("gray")
97 of = label.GetFont()
98 font = wx.Font(int(of.GetPointSize() * 1.5), of.GetFamily(), wx.NORMAL, wx.NORMAL)
99 label.SetFont(font)
100 mainSizer.Add(label, 0, wx.TOP|wx.RIGHT|wx.LEFT|wx.ALIGN_CENTER, 5)
101 width = max(width, label.Size[0])
102
103 #------------
104
105 if self.version:
106 label = wx.StaticText(self, label="Version : " + self.version)
107 label.SetForegroundColour("red")
108 # of = label.GetFont()
109 # font = wx.Font(int(of.GetPointSize() * 1.5), of.GetFamily(), wx.NORMAL, wx.NORMAL)
110 # label.SetFont(font)
111 mainSizer.Add(label, 0, wx.BOTTOM|wx.ALIGN_CENTER, 5)
112
113 #------------
114
115 if self.description:
116 label = wx.StaticText(self, label=self.description)
117 # label.SetForegroundColour("gray")
118 # of = label.GetFont()
119 # font = wx.Font(int(of.GetPointSize() * 1.5), of.GetFamily(), wx.NORMAL, wx.NORMAL)
120 # label.SetFont(font)
121 label.Wrap(max(250, int(0.9*width)))
122 mainSizer.Add(label, 0, wx.ALL|wx.ALIGN_CENTER, 5)
123
124 #------------
125
126 if self.licence:
127 label = wx.StaticText(self, label="License :")
128 # label.SetForegroundColour("gray")
129 of = label.GetFont()
130 font = wx.Font(of.GetPointSize(), of.GetFamily(), wx.NORMAL, wx.BOLD)
131 label.SetFont(font)
132 mainSizer.Add(label, 0, wx.ALL|wx.ALIGN_LEFT, 5)
133 label = wx.StaticText(self, label=self.licence)
134 label.SetForegroundColour("gray")
135 label.Wrap(max(250, int(0.9*width)))
136 mainSizer.Add(label, 0, wx.ALL|wx.ALIGN_CENTER, 2)
137
138 #------------
139
140 if self.developers:
141 label = wx.StaticText(self, label="Developed by :")
142 # label.SetForegroundColour("gray")
143 of = label.GetFont()
144 font = wx.Font(of.GetPointSize(), of.GetFamily(), wx.NORMAL, wx.BOLD)
145 label.SetFont(font)
146 mainSizer.Add(label, 0, wx.ALL|wx.ALIGN_LEFT, 5)
147
148 for developer in self.developers:
149 label = wx.StaticText(self, label=" " + developer)
150 label.SetForegroundColour("gray")
151 mainSizer.Add(label, 0, wx.ALL|wx.ALIGN_LEFT, 0)
152
153 #------------
154
155 if self.urls:
156 label = wx.StaticText(self, label="For more information :")
157 # label.SetForegroundColour("gray")
158 of = label.GetFont()
159 font = wx.Font(of.GetPointSize(), of.GetFamily(), wx.NORMAL, wx.BOLD)
160 label.SetFont(font)
161 mainSizer.Add(label, 0, wx.ALL|wx.ALIGN_LEFT, 5)
162 for url in self.urls:
163 link = hl.HyperLinkCtrl(self, wx.ID_ANY,
164 label=url,
165 URL=url)
166 mainSizer.Add(link, 0, wx.ALL|wx.ALIGN_CENTER, 2)
167
168 #------------
169
170 mainSizer.Add((1, 5), 1)
171 mainSizer.Add(wx.Button(self, id=wx.ID_OK, label="&Dismiss"), 0, wx.ALL|wx.ALIGN_RIGHT,5)
172 spaceSizer = wx.BoxSizer(wx.VERTICAL)
173 spaceSizer.Add(mainSizer, 0, wx.ALL, 10)
174 self.SetSizerAndFit(spaceSizer)
175
176 #-------------------------------------------------------------------------------
177
178 class MyFrame(wx.Frame):
179 """
180 ...
181 """
182 def __init__(self):
183 super(MyFrame, self).__init__(None,
184 -1,
185 title="")
186
187 #------------
188
189 # Return application name.
190 self.app_name = wx.GetApp().GetAppName()
191
192 #------------
193
194 # Simplified init method.
195 self.SetProperties()
196 self.CreateCtrls()
197 self.BindEvents()
198 self.DoLayout()
199
200 #------------
201
202 self.CenterOnScreen()
203
204 #-----------------------------------------------------------------------
205
206 def SetProperties(self):
207 """
208 ...
209 """
210
211 self.SetTitle(self.app_name)
212
213 #------------
214
215 frameicon = wx.Icon("icon_wxWidgets.ico")
216 self.SetIcon(frameicon)
217
218
219 def CreateCtrls(self):
220 """
221 ...
222 """
223
224 # Create a panel.
225 self.panel = wx.Panel(self, -1)
226
227 #------------
228
229 # Add some buttons.
230 self.btnDlg = wx.Button(self.panel,
231 -1,
232 "&Show customized about dialog")
233
234 self.btnClose = wx.Button(self.panel,
235 -1,
236 "&Close")
237
238
239 def BindEvents(self):
240 """
241 Bind some events to an events handler.
242 """
243
244 # Bind the close event to an event handler.
245 self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
246
247 # Bind the buttons event to an event handler.
248 self.Bind(wx.EVT_BUTTON, self.OnAboutDlg, self.btnDlg)
249 self.Bind(wx.EVT_BUTTON, self.OnCloseMe, self.btnClose)
250
251
252 def DoLayout(self):
253 """
254 ...
255 """
256
257 # mainSizer is the top-level one that manages everything.
258 mainSizer = wx.BoxSizer(wx.VERTICAL)
259
260 # wx.BoxSizer(window, proportion, flag, border)
261 # wx.BoxSizer(sizer, proportion, flag, border)
262 mainSizer.Add(self.btnDlg, 1, wx.EXPAND | wx.ALL, 10)
263 mainSizer.Add(self.btnClose, 1, wx.EXPAND | wx.ALL, 10)
264
265 # Finally, tell the panel to use the sizer for layout.
266 self.panel.SetAutoLayout(True)
267 self.panel.SetSizer(mainSizer)
268
269 mainSizer.Fit(self.panel)
270
271 #-----------------------------------------------------------------------
272
273 def OnCloseMe(self, event):
274 """
275 ...
276 """
277
278 self.Close(True)
279
280
281 def OnAboutDlg(self, event):
282 """
283 ...
284 """
285
286 aboutDlg = MyAboutDlg(self,
287 title="Customized about dialog",
288 icon1=wx.Bitmap("Images/wxWidgets.png"),
289 icon2=wx.Bitmap("Images/wxPython.png"),
290 short_name='Acronym',
291 long_name='A longer name for the program',
292 version = "1.2.3",
293 description="A description of the program. This could be a pretty long bit of text. How shall I know how long to make it ? How will it fit in ?",
294 urls = ["http://www.some.website.org/", "mailto:someone@somwewhere.com"],
295 licence="This is a short description of the license used for the program.",
296 developers = ["A developer", "Another developer"])
297
298 aboutDlg.ShowModal()
299
300
301 def OnCloseWindow(self, event):
302 """
303 ...
304 """
305
306 self.Destroy()
307
308 #-------------------------------------------------------------------------------
309
310 class MyApp(wx.App):
311 """
312 ...
313 """
314 def OnInit(self):
315
316 #------------
317
318 self.locale = wx.Locale(wx.LANGUAGE_ENGLISH)
319
320 #------------
321
322 self.SetAppName("Main frame")
323
324 #------------
325
326 frame = MyFrame()
327 self.SetTopWindow(frame)
328 frame.Show(True)
329
330 return True
331
332 #---------------------------------------------------------------------------
333
334 def main():
335 app = MyApp(False)
336 app.MainLoop()
337
338 #---------------------------------------------------------------------------
339
340 if __name__ == "__main__" :
341 main()
Third example
1 # sample_three.py
2
3 # Copyright (C) 2007-2008 www.stani.be
4 #
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see http://www.gnu.org/licenses/
17
18 # Generated by wxGlade 0.4.1cvs on Thu Jun 7 21:24:31 2007
19 # from /home/stani/sync/python/convert/trunk/about.wxg
20
21 # Auto generated so no pep 8.
22
23 # Updated for Python 3 and wxPython Phoenix by Ecco.
24
25 import sys
26 import wx
27 import random
28 import wx.lib.agw.hyperlink as hl
29 import wx.lib.dialogs
30
31 _ = wx.GetTranslation
32
33 # def create_credits
34 # class MyTransparentBitmap
35 # class WxgAboutDialog
36 # class WxgCreditsDialog
37 # class MyCreditsDialog
38 # class MyDialog
39 # class MyApp
40
41 #---------------------------------------------------------------------------
42
43 def create_credits(*args):
44 """
45 ...
46 """
47
48 result = {}
49 for arg in args:
50 result[arg] = [{
51 'name':'%s %d' % (arg, x),
52 'email':'info@%s%d.com' % (arg, x)}
53 for x in range(random.randint(1, 9))]
54
55 return result
56
57 #---------------------------------------------------------------------------
58
59 if sys.platform.startswith('win'):
60 class MyTransparentBitmap(wx.Panel):
61 def __init__(self, parent, id, bitmap=wx.NullBitmap, *args, **keyw):
62 super(MyTransparentBitmap, self).__init__(parent, id, *args, **keyw)
63
64 self.SetBitmap(bitmap)
65
66 self.Bind(wx.EVT_PAINT, self.OnPaint)
67
68 #-------------------------------------------------------------------
69
70 def SetBitmap(self, bitmap):
71 """
72 ...
73 """
74
75 self._bitmap = bitmap
76
77 size = self._bitmap.GetSize()
78 self.SetSize(size)
79 self.SetMinSize(size)
80
81 self.GetParent().Layout()
82
83
84 def OnPaint(self, evt):
85 """
86 ...
87 """
88
89 dc = wx.PaintDC(self)
90 dc.SetBackground(wx.Brush(self.GetParent().GetBackgroundColour()))
91 dc.Clear()
92 dc.DrawBitmap(self._bitmap, 0, 0, True)
93
94 else:
95 MyTransparentBitmap = wx.StaticBitmap
96
97 #---------------------------------------------------------------------------
98
99 class WxgAboutDialog(wx.Dialog):
100 def __init__(self, *args, **kwds):
101 kwds["style"] = wx.DEFAULT_DIALOG_STYLE
102 wx.Dialog.__init__(self, *args, **kwds)
103
104 self.logo = MyTransparentBitmap(self, -1, wx.NullBitmap)
105
106 self.title = wx.StaticText(self, -1,
107 _("Program Version"),
108 style=wx.ALIGN_CENTRE)
109
110 self.description = wx.StaticText(self, -1, _("Description"))
111
112 self.website = hl.HyperLinkCtrl(self, -1,
113 label = "http://www.stani.be",
114 URL = "http://www.stani.be")
115
116 self.credits = wx.Button(self, -1, _("C&redits"))
117 self.license = wx.Button(self, -1, _("&License"))
118 self.close = wx.Button(self, wx.ID_CLOSE, _("&Close"))
119
120 #------------
121
122 # Simplified init method.
123 self.__set_properties()
124 self.__do_layout()
125
126 #------------
127
128 self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
129 self.Bind(wx.EVT_BUTTON, self.OnCredits, self.credits)
130 self.Bind(wx.EVT_BUTTON, self.OnLicense, self.license)
131 self.Bind(wx.EVT_BUTTON, self.OnClose, id=wx.ID_CLOSE)
132
133 #-----------------------------------------------------------------------
134
135 def __set_properties(self):
136 """
137 ...
138 """
139
140 self.SetTitle(_("About"))
141 self.license.SetDefault()
142
143
144 def __do_layout(self):
145 """
146 ...
147 """
148
149 sizer_7 = wx.BoxSizer(wx.VERTICAL)
150 sizer_9 = wx.BoxSizer(wx.HORIZONTAL)
151
152 #------------
153
154 sizer_7.Add(self.logo, 1, wx.ALIGN_CENTER_HORIZONTAL, 0)
155 sizer_7.Add(self.title, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL, 4)
156 sizer_7.Add(self.description, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL, 4)
157 sizer_7.Add(self.website, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL, 4)
158 sizer_9.Add(self.credits, 0, wx.ALL|wx.EXPAND, 4)
159 sizer_9.Add(self.license, 0, wx.ALL|wx.EXPAND, 3)
160 sizer_9.Add(self.close, 0, wx.ALL|wx.EXPAND, 4)
161 sizer_7.Add(sizer_9, 0, wx.TOP|wx.ALIGN_CENTER_HORIZONTAL, 10)
162
163 #------------
164
165 self.SetSizer(sizer_7)
166 sizer_7.Fit(self)
167 self.Layout()
168
169
170 def OnCredits(self, event):
171 """
172 ...
173 """
174
175 print("Event handler `OnCredits' not implemented !")
176 event.Skip()
177
178
179 def OnLicense(self, event):
180 """
181 ...
182 """
183
184 print("Event handler `OnLicense' not implemented !")
185 event.Skip()
186
187
188 def OnClose(self, event):
189 """
190 ...
191 """
192
193 print("Event handler `OnClose' not implemented !")
194 event.Skip()
195
196
197 def OnCloseWindow(self, event):
198 """
199 ...
200 """
201
202 self.Destroy()
203
204 #---------------------------------------------------------------------------
205
206 class WxgCreditsDialog(wx.Dialog):
207 def __init__(self, *args, **kwds):
208 kwds["style"] = wx.DEFAULT_DIALOG_STYLE
209 wx.Dialog.__init__(self, *args, **kwds)
210
211 self.notebook = wx.Notebook(self, -1, style=0)
212
213 #------------
214
215 self.notebook_pane_6 = wx.Panel(self.notebook, -1)
216 self.notebook_1_pane_5 = wx.Panel(self.notebook, -1)
217 self.notebook_1_pane_4 = wx.Panel(self.notebook, -1)
218 self.notebook_1_pane_3 = wx.Panel(self.notebook, -1)
219 self.notebook_1_pane_2 = wx.Panel(self.notebook, -1)
220 self.notebook_1_pane_1 = wx.Panel(self.notebook, -1)
221
222 #------------
223
224 self.credits_code = wx.TextCtrl(self.notebook_1_pane_1, -1, "",
225 style=wx.TE_MULTILINE|wx.TE_READONLY|wx.HSCROLL)
226 self.credits_documentation = wx.TextCtrl(self.notebook_1_pane_2, -1, "",
227 style=wx.TE_MULTILINE|wx.TE_READONLY|wx.HSCROLL)
228 self.credits_translation = wx.TextCtrl(self.notebook_1_pane_3, -1, "",
229 style=wx.TE_MULTILINE|wx.TE_READONLY|wx.HSCROLL)
230 self.credits_graphics = wx.TextCtrl(self.notebook_1_pane_4, -1, "",
231 style=wx.TE_MULTILINE|wx.TE_READONLY|wx.HSCROLL)
232 self.credits_libraries = wx.TextCtrl(self.notebook_1_pane_5, -1, "",
233 style=wx.TE_MULTILINE|wx.TE_READONLY|wx.HSCROLL)
234 self.credits_sponsors = wx.TextCtrl(self.notebook_pane_6, -1, "",
235 style=wx.TE_MULTILINE|wx.TE_READONLY|wx.HSCROLL)
236
237 self.close = wx.Button(self, wx.ID_CLOSE, _("&Close"))
238
239 #------------
240
241 # Simplified init method.
242 self.__set_properties()
243 self.__do_layout()
244
245 #------------
246
247 self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
248 self.Bind(wx.EVT_BUTTON, self.OnClose, id=wx.ID_CLOSE)
249
250 #-----------------------------------------------------------------------
251
252 def __set_properties(self):
253 """
254 ...
255 """
256
257 self.SetTitle(_("Credits"))
258
259
260 def __do_layout(self):
261 """
262 ...
263 """
264
265 sizer_100 = wx.BoxSizer(wx.VERTICAL)
266 sizer_1 = wx.BoxSizer(wx.HORIZONTAL)
267 sizer_11_copy_3 = wx.BoxSizer(wx.HORIZONTAL)
268 sizer_11_copy_2 = wx.BoxSizer(wx.HORIZONTAL)
269 sizer_11_copy_1 = wx.BoxSizer(wx.HORIZONTAL)
270 sizer_11_copy = wx.BoxSizer(wx.HORIZONTAL)
271 sizer_11 = wx.BoxSizer(wx.HORIZONTAL)
272
273 #------------
274
275 sizer_11.Add(self.credits_code, 1, wx.EXPAND, 0)
276 self.notebook_1_pane_1.SetSizer(sizer_11)
277
278 sizer_11_copy.Add(self.credits_documentation, 1, wx.EXPAND, 0)
279 self.notebook_1_pane_2.SetSizer(sizer_11_copy)
280
281 sizer_11_copy_1.Add(self.credits_translation, 1, wx.EXPAND, 0)
282 self.notebook_1_pane_3.SetSizer(sizer_11_copy_1)
283
284 sizer_11_copy_2.Add(self.credits_graphics, 1, wx.EXPAND, 0)
285 self.notebook_1_pane_4.SetSizer(sizer_11_copy_2)
286
287 sizer_11_copy_3.Add(self.credits_libraries, 1, wx.EXPAND, 0)
288 self.notebook_1_pane_5.SetSizer(sizer_11_copy_3)
289
290 sizer_1.Add(self.credits_sponsors, 1, wx.EXPAND, 0)
291 self.notebook_pane_6.SetSizer(sizer_1)
292
293 #------------
294
295 self.notebook.AddPage(self.notebook_1_pane_1, _("Code"))
296 self.notebook.AddPage(self.notebook_1_pane_2, _("Documentation"))
297 self.notebook.AddPage(self.notebook_1_pane_3, _("Translation"))
298 self.notebook.AddPage(self.notebook_1_pane_4, _("Artwork"))
299 self.notebook.AddPage(self.notebook_1_pane_5, _("Libraries"))
300 self.notebook.AddPage(self.notebook_pane_6, _("Sponsors"))
301
302 #------------
303
304 sizer_100.Add(self.notebook, 1, wx.EXPAND, 0)
305 sizer_100.Add(self.close, 0, wx.ALL|wx.ALIGN_RIGHT, 4)
306
307 #------------
308
309 self.SetSizer(sizer_100)
310 sizer_100.Fit(self)
311 self.Layout()
312
313
314 def OnClose(self, event):
315 """
316 ...
317 """
318
319 print("Event handler `OnClose' not implemented !")
320 event.Skip()
321
322
323 def OnCloseWindow(self, event):
324 """
325 ...
326 """
327
328 self.Destroy()
329
330 #---------------------------------------------------------------------------
331
332 class MyCreditsDialog(WxgCreditsDialog):
333 """
334 Credit dialog.
335 """
336 def __init__(self,parent,credits):
337 """Shows a dialog with the credits of a project.
338 :param parent: parent control of dialog (mostly app frame)
339 :type parent: wx.Window
340 :param credits: people by category
341 :type credits: dictionary
342 """
343 super(MyCreditsDialog, self).__init__(parent, -1)
344
345 #------------
346
347 for attr, all in credits.items():
348 ctrl = getattr(self, 'credits_%s' %attr)
349 ctrl.SetValue('\n'.join([' - '.join(x.values()) for x in all]))
350
351 #------------
352
353 w, h = parent.GetSize()
354 self.SetSize((int(2*w), int(h/1.5)))
355
356 #------------
357
358 self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
359
360 #-----------------------------------------------------------------------
361
362 def OnClose(self,event):
363 """
364 ...
365 """
366
367 self.EndModal(wx.ID_CLOSE)
368
369
370 def OnCloseWindow(self, event):
371 """
372 ...
373 """
374
375 self.Destroy()
376
377 #---------------------------------------------------------------------------
378
379 class MyDialog(WxgAboutDialog):
380 def __init__(self, parent, title, logo, description,
381 website, credits, license):
382 super(MyDialog,self).__init__(parent, -1)
383
384 #------------
385
386 self.SetIcon(wx.Icon("wxwin.ico"))
387
388 self.SetBackgroundColour(self.GetBackgroundColour())
389
390 #------------
391
392 # Title.
393 self.title.SetLabel(title)
394 title_font = self.title.GetFont()
395 title_font.SetPointSize(title_font.GetPointSize()*3)
396 self.title.SetFont(title_font)
397
398 # Logo.
399 self.logo.SetBitmap(logo)
400
401 # Description.
402 self.description.SetLabel(description.replace("&", "&&"))
403
404 # Website.
405 self.website.SetLabel(website)
406 self.website.SetURL(website)
407
408 # Save other parameters.
409 self.credits = credits
410 self.license = license
411
412 # Layout.
413 self.GetSizer().Fit(self)
414 self.Layout()
415
416 #------------
417
418 self.Bind(wx.EVT_CLOSE, self.OnClose)
419
420 #-----------------------------------------------------------------------
421
422 def OnCredits(self,event):
423 """
424 ...
425 """
426
427 dlg = MyCreditsDialog(self, self.credits)
428 dlg.ShowModal()
429 dlg.Destroy()
430
431
432 def OnLicense(self,event):
433 """
434 ...
435 """
436
437 dlg = wx.lib.dialogs.ScrolledMessageDialog(self,
438 self.license,
439 _("License"))
440 dlg.ShowModal()
441
442
443 def OnClose(self,event):
444 """
445 ...
446 """
447
448 self.Destroy()
449
450 #---------------------------------------------------------------------------
451
452 class MyApp(wx.App):
453 def OnInit(self):
454
455 #------------
456
457 logo = wx.ArtProvider.GetBitmap(wx.ART_INFORMATION, wx.ART_OTHER, (128, 128))
458
459 credits = create_credits('code', 'documentation', 'translation',
460 'libraries', 'graphics')
461
462 aboutDialog = MyDialog(None,
463 'My app.', logo,
464 'Description', 'Website',
465 credits, 'License (latest GPL)')
466 self.SetTopWindow(aboutDialog)
467 aboutDialog.Show(True)
468
469 return True
470
471 #---------------------------------------------------------------------------
472
473 def main():
474 app = MyApp(redirect=False)
475 app.MainLoop()
476
477 #---------------------------------------------------------------------------
478
479 if __name__ == "__main__" :
480 main()
Download source
Additional Information
Link :
- - - - -
https://wiki.wxpython.org/TitleIndex
Thanks to
Xaviou (sample_one.py coding), Chris Barker (sample_two.py coding), stani.be (sample_three.py coding), the wxPython community...
About this page
Date(d/m/y) Person (bot) Comments :
5/08/19 - Ecco (Created page for wxPython Phoenix).
Comments
- blah, blah, blah....