How to create a customized settings dialog (Phoenix)

Keywords : Dialog, Setting, ListBox, FourWaySplitter, Scrolledpanel, StaticBoxSizer, StaticBox.


Demonstrating :

Tested py3.x, wx4.x and Win10.

Are you ready to use some samples ? ;)

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


Settings dialog

img_sample_one.png

ICON file : icon_wxWidgets.ico

   1 # sample_one.py
   2 
   3 import sys
   4 import os
   5 import wx
   6 import wx.lib.agw.fourwaysplitter as FWS
   7 import wx.lib.scrolledpanel as scrolled
   8 
   9 # class MyGeneralPane
  10 # class MyInterfacePane
  11 # class MySourcePane
  12 # class MyLanguagePane
  13 # class MyControlPane
  14 # class MySplitterPanel
  15 # class MySettingDialog
  16 # class MyFrame
  17 # class MyApp
  18 
  19 #---------------------------------------------------------------------------
  20 
  21 class MyGeneralPane(wx.Panel):
  22     """
  23     ...
  24     """
  25     def __init__(self, parent):
  26         wx.Panel.__init__(self, parent,
  27                           style=wx.BORDER_THEME |
  28                                 wx.TAB_TRAVERSAL)
  29 
  30         #------------
  31 
  32 
  33         labels = 'One Two Three Four Five Six Seven Eight Nine Ten Eleven Twelve Thirteen Fourteen Firteen'.split()
  34 
  35         #------------
  36 
  37         # Font, size and style.
  38         font = self.GetFont().GetPointSize()
  39         font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)
  40         font.SetWeight(wx.BOLD)
  41 
  42         #------------
  43 
  44         sizer = wx.BoxSizer(wx.VERTICAL)
  45         self.SetSizer(sizer)
  46 
  47         #------------
  48 
  49         sbox = wx.StaticBox(self, -1, " General : ")
  50         sbox.SetForegroundColour("#0068c6")
  51         sbox.SetFont(font)
  52 
  53         ssizer = wx.StaticBoxSizer(sbox, wx.VERTICAL)
  54         sizer.Add(ssizer, 1, wx.EXPAND | wx.ALL, 10)
  55 
  56         #------------
  57 
  58         spanel = scrolled.ScrolledPanel(self, -1)
  59         ssizer.Add(spanel, 1, wx.EXPAND)
  60 
  61         #------------
  62 
  63         spsizer = wx.BoxSizer(wx.VERTICAL)
  64         spanel.SetSizer(spsizer)
  65         for label in labels:
  66             self.chkbx = wx.CheckBox(spanel,
  67                                       label=label,
  68                                       size=(-1,-1))
  69             spsizer.Add(self.chkbx, flag=wx.ALL, border=10)
  70 
  71             self.Bind(wx.EVT_CHECKBOX, self.OnPass, self.chkbx)
  72 
  73         #------------
  74 
  75         spanel.SetupScrolling(scroll_x=False,
  76                               scroll_y=True,
  77                               rate_y=10,
  78                               scrollToTop=True)
  79 
  80         #------------
  81 
  82         sizer.Layout()
  83 
  84     #-----------------------------------------------------------------------
  85 
  86     def OnPass(self, event):
  87         """
  88         Just grouping the empty event handlers together.
  89         """
  90 
  91         print("Hello 1 !")
  92 
  93         pass
  94 
  95 #---------------------------------------------------------------------------
  96 
  97 class MyInterfacePane(wx.Panel):
  98     """
  99     ...
 100     """
 101     def __init__(self, parent):
 102         wx.Panel.__init__(self, parent,
 103                           style=wx.BORDER_THEME |
 104                                 wx.TAB_TRAVERSAL)
 105 
 106         #------------
 107 
 108         labels = 'One Two Three Four Five Six Seven Eight Nine Ten Eleven Twelve Thirteen Fourteen Firteen'.split()
 109 
 110         #------------
 111 
 112         # Font, size and style.
 113         font = self.GetFont().GetPointSize()
 114         font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)
 115         font.SetWeight(wx.BOLD)
 116 
 117         #------------
 118 
 119         sizer = wx.BoxSizer(wx.VERTICAL)
 120         self.SetSizer(sizer)
 121 
 122         #------------
 123 
 124         sbox = wx.StaticBox(self, -1, " User interface : ")
 125         sbox.SetForegroundColour("#0068c6")
 126         sbox.SetFont(font)
 127 
 128         ssizer = wx.StaticBoxSizer(sbox, wx.VERTICAL)
 129         sizer.Add(ssizer, 1, wx.EXPAND | wx.ALL, 10)
 130 
 131         #------------
 132 
 133         spanel = scrolled.ScrolledPanel(self, -1)
 134         ssizer.Add(spanel, 1, wx.EXPAND)
 135 
 136         #------------
 137 
 138         spsizer = wx.BoxSizer(wx.VERTICAL)
 139         spanel.SetSizer(spsizer)
 140         for label in labels:
 141             self.btn = wx.Button(spanel,
 142                             label=label,
 143                             size=(-1,50))
 144             spsizer.Add(self.btn, flag=wx.ALL, border=2)
 145 
 146             self.Bind(wx.EVT_BUTTON, self.OnPass, self.btn)
 147 
 148         #------------
 149 
 150         spanel.SetupScrolling(scroll_x=False,
 151                               scroll_y=True,
 152                               rate_y=10,
 153                               scrollToTop=False)
 154 
 155         #------------
 156 
 157         sizer.Layout()
 158 
 159     #-----------------------------------------------------------------------
 160 
 161     def OnPass(self, event):
 162         """
 163         Just grouping the empty event handlers together.
 164         """
 165 
 166         print("Hello 2 !")
 167 
 168         pass
 169 
 170 #---------------------------------------------------------------------------
 171 
 172 class MySourcePane(wx.Panel):
 173     """
 174     ...
 175     """
 176     def __init__(self, parent):
 177         wx.Panel.__init__(self, parent,
 178                           style=wx.BORDER_THEME |
 179                                 wx.TAB_TRAVERSAL)
 180 
 181         #------------
 182 
 183         labels = 'One Two Three Four Five Six Seven Eight Nine Ten Eleven Twelve Thirteen Fourteen Firteen'.split()
 184 
 185         #------------
 186 
 187         # Font, size and style.
 188         font = self.GetFont().GetPointSize()
 189         font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)
 190         font.SetWeight(wx.BOLD)
 191 
 192         #------------
 193 
 194         sizer = wx.BoxSizer(wx.VERTICAL)
 195         self.SetSizer(sizer)
 196 
 197         #------------
 198 
 199         sbox = wx.StaticBox(self, -1, " Path : ")
 200         sbox.SetForegroundColour("#0068c6")
 201         sbox.SetFont(font)
 202 
 203         ssizer = wx.StaticBoxSizer(sbox, wx.VERTICAL)
 204         sizer.Add(ssizer, 1, wx.EXPAND | wx.ALL, 10)
 205 
 206         #------------
 207 
 208         spanel = scrolled.ScrolledPanel(self, -1)
 209         ssizer.Add(spanel, 1, wx.EXPAND)
 210 
 211         #------------
 212 
 213         spsizer = wx.BoxSizer(wx.VERTICAL)
 214         spanel.SetSizer(spsizer)
 215         for label in labels:
 216             self.chkbx = wx.CheckBox(spanel,
 217                                       label=label,
 218                                       size=(-1,-1))
 219             spsizer.Add(self.chkbx, flag=wx.ALL, border=10)
 220 
 221             self.Bind(wx.EVT_CHECKBOX, self.OnPass, self.chkbx)
 222 
 223         #------------
 224 
 225         spanel.SetupScrolling(scroll_x=False,
 226                               scroll_y=True,
 227                               rate_y=10,
 228                               scrollToTop=False)
 229 
 230         #------------
 231 
 232         sizer.Layout()
 233 
 234     #-----------------------------------------------------------------------
 235 
 236     def OnPass(self, event):
 237         """
 238         Just grouping the empty event handlers together.
 239         """
 240 
 241         print("Hello 3 !")
 242 
 243         pass
 244 
 245 #---------------------------------------------------------------------------
 246 
 247 class MyLanguagePane(wx.Panel):
 248     """
 249     ...
 250     """
 251     def __init__(self, parent):
 252         wx.Panel.__init__(self, parent,
 253                           style=wx.BORDER_THEME |
 254                                 wx.TAB_TRAVERSAL)
 255 
 256         #------------
 257 
 258         labels = 'One Two Three Four Five Six Seven Eight Nine Ten Eleven Twelve Thirteen Fourteen Firteen'.split()
 259 
 260         #------------
 261 
 262         # Font, size and style.
 263         font = self.GetFont().GetPointSize()
 264         font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)
 265         font.SetWeight(wx.BOLD)
 266 
 267         #------------
 268 
 269         sizer = wx.BoxSizer(orient=wx.VERTICAL)
 270         self.SetSizer(sizer)
 271 
 272         #------------
 273 
 274         sbox = wx.StaticBox(self, -1, " Language : ")
 275         sbox.SetForegroundColour("#0068c6")
 276         sbox.SetFont(font)
 277 
 278         ssizer = wx.StaticBoxSizer(sbox, orient=wx.VERTICAL)
 279         sizer.Add(ssizer, 1, wx.EXPAND | wx.ALL, 10)
 280 
 281         #------------
 282 
 283         spanel = scrolled.ScrolledPanel(self, -1)
 284         ssizer.Add(spanel, 1, wx.EXPAND)
 285 
 286         #------------
 287 
 288         spsizer = wx.BoxSizer(wx.VERTICAL)
 289         spanel.SetSizer(spsizer)
 290         for label in labels:
 291             self.btn = wx.Button(spanel,
 292                             label=label,
 293                             size=(-1,50))
 294             spsizer.Add(self.btn, flag=wx.ALL, border=2)
 295 
 296             self.Bind(wx.EVT_BUTTON, self.OnPass, self.btn)
 297 
 298         #------------
 299 
 300         spanel.SetupScrolling(scroll_x=False,
 301                               scroll_y=True,
 302                               rate_y=10,
 303                               scrollToTop=False)
 304 
 305         #------------
 306 
 307         sizer.Layout()
 308 
 309     #-----------------------------------------------------------------------
 310 
 311     def OnPass(self, event):
 312         """
 313         Just grouping the empty event handlers together.
 314         """
 315 
 316         print("Hello 4 !")
 317 
 318         pass
 319 
 320 #---------------------------------------------------------------------------
 321 
 322 class MyControlPane(wx.Panel):
 323     """
 324     ...
 325     """
 326     def __init__(self, parent):
 327         wx.Panel.__init__(self, parent)
 328 
 329         #------------
 330 
 331         # Font, size and style.
 332         font = self.GetFont().GetPointSize()
 333         font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)
 334         font.SetWeight(wx.BOLD)
 335 
 336         #------------
 337 
 338         statictxt = wx.StaticText(self, -1, "Category :")
 339         statictxt.SetForegroundColour("#be3a3a")
 340         statictxt.SetFont(font)
 341 
 342         #------------
 343 
 344         sampleList = ["General",
 345                       "User interface",
 346                       "Path",
 347                       "Language"]
 348 
 349         combo = wx.ListBox(self,
 350                            -1,
 351                            (-1, -1),
 352                            (200, 1600),
 353                            sampleList,
 354                            style=wx.LB_ALWAYS_SB |
 355                                  wx.LB_SINGLE)
 356         combo.SetSelection(0)
 357         combo.SetForegroundColour("white")
 358         combo.SetBackgroundColour("gray")
 359 
 360         #------------
 361 
 362         sizer = wx.BoxSizer(wx.VERTICAL)
 363         sizer.Add(statictxt, 0, wx.TOP, 7)
 364         sizer.Add(combo, 1, wx.EXPAND | wx.TOP, 2)
 365 
 366         border = wx.BoxSizer()
 367         border.Add(sizer, 1, wx.EXPAND | wx.ALL, 9)
 368         self.SetSizer(border)
 369 
 370         #------------
 371 
 372         # Simplified init method.
 373         self.BindEvents()
 374 
 375     #-----------------------------------------------------------------------
 376 
 377     def BindEvents(self):
 378         """
 379         ...
 380         """
 381 
 382         self.Bind(wx.EVT_LISTBOX, self.OnExpandWindow)
 383 
 384 
 385     def OnExpandWindow(self, event):
 386         """
 387         ...
 388         """
 389 
 390         self.GetParent().ExpandWindow(event.GetSelection())
 391 
 392 #---------------------------------------------------------------------------
 393 
 394 class MySplitterPanel(wx.Panel):
 395     """
 396     ...
 397     """
 398     def __init__(self, parent):
 399         wx.Panel.__init__(self, parent, -1)
 400 
 401         #------------
 402 
 403         cp = MyControlPane(self)
 404         splitter = FWS.FourWaySplitter(self)
 405         self.splitter = splitter
 406         self.splitter.SetExpanded(0)
 407 
 408         #------------
 409 
 410         sizer = wx.BoxSizer(wx.HORIZONTAL)
 411 
 412         sizer.Add(cp)
 413         sizer.Add(splitter, 1, wx.EXPAND | wx.ALL, 10)
 414 
 415         self.SetSizer(sizer)
 416 
 417         #------------
 418 
 419         pane1 = MyGeneralPane(splitter)
 420         splitter.AppendWindow(pane1)
 421 
 422         pane2 = MyInterfacePane(splitter)
 423         splitter.AppendWindow(pane2)
 424 
 425         pane3 = MySourcePane(splitter)
 426         splitter.AppendWindow(pane3)
 427 
 428         pane4 = MyLanguagePane(splitter)
 429         splitter.AppendWindow(pane4)
 430 
 431     #-----------------------------------------------------------------------
 432 
 433     def ExpandWindow(self, selection):
 434         """
 435         ...
 436         """
 437 
 438         self.splitter.SetExpanded(selection)
 439 
 440 #---------------------------------------------------------------------------
 441 
 442 class MySettingDialog(wx.Dialog):
 443     """
 444     ...
 445     """
 446     def __init__(self, parent, title,
 447                  pos=wx.DefaultPosition,
 448                  size=wx.DefaultSize):
 449         wx.Dialog.__init__(self,
 450                            parent,
 451                            -1,
 452                            title,
 453                            pos=(-1, -1),
 454                            size=(640, 526),
 455                            style=wx.DEFAULT_FRAME_STYLE)
 456 
 457         #------------
 458 
 459         # Attributes.
 460         self.parent = parent
 461 
 462         #------------
 463 
 464         # Simplified init method.
 465         self.SetProperties()
 466         self.CreateCtrls()
 467         self.DoLayout()
 468 
 469         #------------
 470 
 471         self.CenterOnScreen(wx.BOTH)
 472         print("\nDisplay the settings dialog")
 473 
 474         #------------
 475 
 476         self.ShowModal()
 477         self.Destroy()
 478 
 479     #-----------------------------------------------------------------------
 480 
 481     def SetProperties(self):
 482         """
 483         ...
 484         """
 485 
 486         frameicon = wx.Icon("icon_wxWidgets.ico")
 487         self.SetIcon(frameicon)
 488 
 489         self.SetMinSize((640, 526))
 490 
 491 
 492     def CreateCtrls(self):
 493         """
 494         ...
 495         """
 496 
 497         self.panel = MySplitterPanel(self)
 498 
 499         self.btnSizer = self.CreateButtonSizer(wx.OK | wx.CANCEL)
 500 
 501 
 502     def DoLayout(self):
 503         """
 504         ...
 505         """
 506 
 507         mainSizer = wx.BoxSizer(wx.HORIZONTAL)
 508         ctrlSizer = wx.BoxSizer(wx.VERTICAL)
 509 
 510         ctrlSizer.Add(self.panel, 1, wx.EXPAND)
 511         ctrlSizer.Add(self.btnSizer, 0, wx.EXPAND |
 512                       wx.RIGHT, 5)
 513 
 514         mainSizer.Add(ctrlSizer, 1, wx.EXPAND |
 515                       wx.BOTTOM, 10)
 516 
 517         self.SetSizer(mainSizer)
 518         mainSizer.Layout()
 519 
 520 #---------------------------------------------------------------------------
 521 
 522 class MyFrame(wx.Frame):
 523     """
 524     ...
 525     """
 526     def __init__(self):
 527         super(MyFrame, self).__init__(None,
 528                                       -1,
 529                                       title="")
 530 
 531         #------------
 532 
 533         # Return application name.
 534         self.app_name = wx.GetApp().GetAppName()
 535 
 536         #------------
 537 
 538         # Simplified init method.
 539         self.SetProperties()
 540         self.CreateCtrls()
 541         self.BindEvents()
 542         self.DoLayout()
 543 
 544         #------------
 545 
 546         self.CenterOnScreen()
 547 
 548     #-----------------------------------------------------------------------
 549 
 550     def SetProperties(self):
 551         """
 552         ...
 553         """
 554 
 555         self.SetTitle(self.app_name)
 556 
 557         #------------
 558 
 559         frameicon = wx.Icon("icon_wxWidgets.ico")
 560         self.SetIcon(frameicon)
 561 
 562 
 563     def CreateCtrls(self):
 564         """
 565         ...
 566         """
 567 
 568         # Create a panel.
 569         self.panel = wx.Panel(self, -1)
 570 
 571         #------------
 572 
 573         # Add some buttons.
 574         self.btnDlg = wx.Button(self.panel,
 575                                 -1,
 576                                 "&Show settings dialog")
 577 
 578         self.btnClose = wx.Button(self.panel,
 579                                   -1,
 580                                   "&Close")
 581 
 582 
 583     def BindEvents(self):
 584         """
 585         Bind some events to an events handler.
 586         """
 587 
 588         # Bind the close event to an event handler.
 589         self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
 590 
 591         # Bind the buttons event to an event handler.
 592         self.Bind(wx.EVT_BUTTON, self.OnSetting, self.btnDlg)
 593         self.Bind(wx.EVT_BUTTON, self.OnCloseMe, self.btnClose)
 594 
 595 
 596     def DoLayout(self):
 597         """
 598         ...
 599         """
 600 
 601         # MainSizer is the top-level one that manages everything.
 602         mainSizer = wx.BoxSizer(wx.VERTICAL)
 603 
 604         # wx.BoxSizer(window, proportion, flag, border)
 605         # wx.BoxSizer(sizer, proportion, flag, border)
 606         mainSizer.Add(self.btnDlg, 1, wx.EXPAND | wx.ALL, 10)
 607         mainSizer.Add(self.btnClose, 1, wx.EXPAND | wx.ALL, 10)
 608 
 609         # Finally, tell the panel to use the sizer for layout.
 610         self.panel.SetAutoLayout(True)
 611         self.panel.SetSizer(mainSizer)
 612 
 613         mainSizer.Fit(self.panel)
 614 
 615     #-----------------------------------------------------------------------
 616 
 617     def OnCloseMe(self, event):
 618         """
 619         ...
 620         """
 621 
 622         self.Close(True)
 623 
 624 
 625     def OnSetting(self, event):
 626         """
 627         ...
 628         """
 629 
 630         settingDlg = MySettingDialog(self,
 631                                      title="Settings dialog")
 632                                      #pos=(-1, -1),
 633                                      #size=(500, 300))
 634 
 635     def OnCloseWindow(self, event):
 636         """
 637         ...
 638         """
 639 
 640         self.Destroy()
 641 
 642 #---------------------------------------------------------------------------
 643 
 644 class MyApp(wx.App):
 645     """
 646     ...
 647     """
 648     def OnInit(self):
 649 
 650         #------------
 651 
 652         self.SetAppName("Main frame")
 653 
 654         #------------
 655 
 656         self.installDir = os.path.split(os.path.abspath(sys.argv[0]))[0]
 657 
 658         #------------
 659 
 660         frame = MyFrame()
 661         self.SetTopWindow(frame)
 662         frame.Show(True)
 663 
 664         return True
 665 
 666     #-----------------------------------------------------------------------
 667 
 668     def GetInstallDir(self):
 669         """
 670         Returns the installation directory for my application.
 671         """
 672 
 673         return self.installDir
 674 
 675 #---------------------------------------------------------------------------
 676 
 677 def main():
 678     app = MyApp(False)
 679     app.MainLoop()
 680 
 681 #---------------------------------------------------------------------------
 682 
 683 if __name__ == "__main__" :
 684     main()


Download source

source.zip


Additional Information

Link :

- - - - -

https://wiki.wxpython.org/TitleIndex

https://docs.wxpython.org/


Thanks to

Robin Dunn, Andrea Gavana, the wxPython community...


About this page

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

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


Comments

- blah, blah, blah....

How to create a customized settings dialog (Phoenix) (last edited 2020-12-13 17:07:34 by Ecco)

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