Attachment 'PanelControls.py'

Download

   1 # PanelControls.py
   2 
   3 import wx
   4 import AddSpacer        as asp  # A more intelligent BoxSizer spacer.
   5 import PanelControls    as pc
   6 
   7 #------------------------------------------------------------------------------
   8 
   9 class CheckListBoxPanel( wx.Panel ) :
  10     """ 
  11     A Multiple-Controls Class in BoxSizers demo.
  12     
  13     The panel is arbitrarily designed to be slightly larger than the
  14     usual minimum panel size that just holds its controls. 
  15     """
  16     
  17     def __init__( self, parent, caption_txt, bgColor, items_list ) :
  18     
  19         wx.Panel.__init__( self, parent=parent, id=-1 )
  20         self.BackgroundColour = bgColor
  21         
  22         #-----
  23     
  24         Caption_stTxt = wx.StaticText( self, -1, caption_txt )
  25         Caption_stTxt.BackgroundColour = ( 'wHIte' )
  26         
  27         checkListBox = wx.CheckListBox(self, -1, size=(-1, 100), choices=items_list)
  28         #checkListBox.SetSelection(0)       # use is arbitrary
  29         
  30         #----
  31         
  32         # Use a single sizer to position the controls.
  33         pnl_vertSizer = wx.BoxSizer( wx.VERTICAL )
  34         
  35         asp.AddSpacer( pnl_vertSizer, 10 )     # 1-D vertical spacer.
  36         
  37         alignFlag = wx.ALIGN_CENTRE
  38         padFlags = wx.LEFT | wx.RIGHT       # Pad to space from panel's L & R edges.
  39         
  40         pnl_vertSizer.Add( Caption_stTxt, flag=alignFlag | padFlags, border=10 )
  41         
  42         asp.AddSpacer( pnl_vertSizer, 4 )
  43         
  44         pnl_vertSizer.Add( checkListBox,  flag=alignFlag | padFlags, border=10 )
  45                                 
  46         asp.AddSpacer( pnl_vertSizer, 10 )     # 1-D vertical spacer.
  47         
  48         #-----
  49         
  50         self.SetSizer( pnl_vertSizer )    # Invoke the sizer.
  51         self.Layout()
  52         
  53     #end __init__
  54     
  55 #end CheckListBoxPanel class
  56 
  57 #------------------------------------------------------------------------------
  58 
  59 class RadioBoxPanel( wx.Panel ) :
  60     """ 
  61     A Multiple-Controls Class in BoxSizers demo.
  62     
  63     The panel is arbitrarily designed to be slightly larger than the
  64     usual minimum panel size that just holds its controls. 
  65     """
  66     
  67     def __init__( self, parent, caption_txt, choices_list, bgColor ) :
  68     
  69         wx.Panel.__init__( self, parent=parent, id=-1 )
  70         self.BackgroundColour = bgColor
  71         
  72         #-----
  73         
  74         self.Caption_stTxt = wx.StaticText( self, -1, caption_txt )
  75         self.Caption_stTxt.BackgroundColour = ( 'wHIte' )
  76         stTxtSize = self.Caption_stTxt.GetSize()
  77         
  78         self.radBox = wx.RadioBox( self, -1, 'RadioBox A', 
  79                                      choices=choices_list, 
  80                                      majorDimension=4, 
  81                                      style=wx.RA_SPECIFY_ROWS )
  82         #----
  83         
  84         # Use a single sizer to position the controls.
  85         pnl_vertSizer = wx.BoxSizer( wx.VERTICAL )
  86         
  87         asp.AddSpacer( pnl_vertSizer, (0, 10) )     # a rectangular spacer.
  88         
  89         alignFlag = wx.ALIGN_CENTRE
  90         padFlags = wx.LEFT | wx.RIGHT       # Pad to space from panel's L & R edges.
  91         
  92         pnl_vertSizer.Add( self.Caption_stTxt, 
  93                            flag=alignFlag | padFlags, 
  94                            border=10 )              # Pad the minor axis, only.
  95         
  96         asp.AddSpacer( pnl_vertSizer, 4, 0 )   # a rectangular spacer.
  97         
  98         pnl_vertSizer.Add( self.radBox, 
  99                            flag=alignFlag | padFlags, 
 100                            border=10 )              # Pad the minor axis, only.
 101         
 102         asp.AddSpacer( pnl_vertSizer, 10 )     # 1-D vertical spacer.
 103         
 104         #-----
 105         
 106         self.SetSizer( pnl_vertSizer )    # Invoke the sizer.
 107         self.Layout()
 108         
 109     #end __init__
 110     
 111     #------------------------
 112     
 113     def GetControls( self ) :
 114         return self.Caption_stTxt, self.radBox
 115         
 116 #end RadioBoxPanel class
 117 
 118 #------------------------------------------------------------------------------
 119 
 120 class TxtCtrlPanel( wx.Panel ) :
 121     """ 
 122     A Multiple-Controls Class in BoxSizers demo.
 123     
 124     The panel is arbitrarily designed to be slightly larger than the
 125     usual minimum panel size that just holds its controls. 
 126     """
 127     
 128     def __init__( self, parent, caption_txt, bgColor, txtCtl_list ) :
 129     
 130         wx.Panel.__init__( self, parent=parent, id=-1 )
 131         self.BackgroundColour = bgColor
 132         
 133         #-----
 134     
 135         self.Caption_stTxt = wx.StaticText( self, -1, caption_txt )
 136         self.Caption_stTxt.BackgroundColour = ( 'wHIte' )
 137         stTxtSize = self.Caption_stTxt.GetSize()
 138         
 139         txtCtrl_size = (200, 150)
 140         self.pnl_txtCtrl = wx.TextCtrl( self, -1, 
 141                                         style=wx.TE_MULTILINE, 
 142                                         size=txtCtrl_size )
 143         self.pnl_txtCtrl.SetInsertionPoint( 0 )
 144         for aLine in txtCtl_list :
 145             self.pnl_txtCtrl.WriteText( aLine + '\n' )
 146         # An often-used "trick" that deselects all the text:
 147         wx.CallAfter( self.pnl_txtCtrl.SetInsertionPoint, 0 )
 148         
 149         #----
 150         
 151         # Use a single sizer to position the controls.
 152         self.pnl_vertSizer = wx.BoxSizer( wx.VERTICAL )
 153         
 154         asp.AddSpacer( self.pnl_vertSizer, 10 )     # 1-D vertical spacer.
 155         
 156         alignFlag = wx.ALIGN_CENTRE
 157         padFlags = wx.LEFT | wx.RIGHT       # Pad to space from panel's L & R edges.
 158         
 159         self.pnl_vertSizer.Add( self.Caption_stTxt, 
 160                                 flag=alignFlag | padFlags, 
 161                                 border=10 )              # Pad the minor axis, only.
 162         
 163         asp.AddSpacer( self.pnl_vertSizer, 4 )
 164         
 165         self.pnl_vertSizer.Add( self.pnl_txtCtrl, 
 166                                 flag=alignFlag | padFlags, 
 167                                 border=10 )              # Pad the minor axis, only.
 168         
 169         asp.AddSpacer( self.pnl_vertSizer, 10 )    # 1-D vertical spacer.
 170         
 171         #-----
 172         
 173         self.SetSizer( self.pnl_vertSizer )    # Invoke the sizer.
 174         self.Layout()
 175         
 176     #end __init__
 177     
 178     #------------------------
 179     
 180     def GetControls( self ) :
 181         return self.Caption_stTxt, self.pnl_txtCtrl
 182         
 183 #end TxtCtrlPanel class
 184 
 185 #------------------------------------------------------------------------------
 186 
 187 class TextButtonRadioPanel( wx.Panel ) :
 188     """ 
 189     A Multiple-Controls Class in BoxSizers demo.
 190     
 191     The panel is arbitrarily designed to be slightly larger than the
 192     usual minimum panel size that just holds its controls. 
 193     """
 194     
 195     def __init__( self, parent, txtCtl_list, radBtn_list, bgColor ) :
 196     
 197         wx.Panel.__init__( self, parent, -1 )
 198         self.BackgroundColour = (220, 250, 220)     # Green
 199         
 200         txtBtnRadPnl_stTxt = wx.StaticText( self, -1, ' TextButtonRadioPanel ' )
 201         
 202         #-----
 203         
 204         # Create all the page's controls either individually or using classes.
 205         
 206         txtCtrlPanel = TxtCtrlPanel( self, 'TextCtrlPanel Caption',
 207                                      bgColor=(220, 220, 255), 
 208                                      txtCtl_list=txtCtl_list )
 209         
 210         radBoxPanel = RadioBoxPanel( self, 
 211                                      caption_txt='RadioBoxPanel Caption', 
 212                                      choices_list=radBtn_list, 
 213                                      bgColor=bgColor )
 214         
 215         btn = wx.Button( self, -1, 'Launch Missiles' )
 216         
 217         #-----  Create the sizers and add the controls to it.
 218         
 219         pnlCtrls_horzSizer = wx.BoxSizer( wx.HORIZONTAL )
 220         
 221         asp.AddSpacer( pnlCtrls_horzSizer, 10 )
 222         pnlCtrls_horzSizer.Add( txtCtrlPanel, flag=wx.CENTER )
 223         asp.AddSpacer( pnlCtrls_horzSizer, 10 )
 224         pnlCtrls_horzSizer.Add( radBoxPanel, flag=wx.CENTER )
 225         asp.AddSpacer( pnlCtrls_horzSizer, 10 )
 226         
 227         
 228         pnlCtrls_vertSizer = wx.BoxSizer( wx.VERTICAL )
 229         
 230         pnlCtrls_vertSizer.Add( txtBtnRadPnl_stTxt, flag=wx.ALIGN_LEFT )
 231         
 232         asp.AddSpacer( pnlCtrls_vertSizer, 10 )
 233         pnlCtrls_vertSizer.Add( pnlCtrls_horzSizer, flag=wx.CENTRE )    #Add sizer to sizer
 234         asp.AddSpacer( pnlCtrls_vertSizer, 10 )
 235         pnlCtrls_vertSizer.Add( btn, flag=wx.CENTRE )
 236         asp.AddSpacer( pnlCtrls_vertSizer, 10 )
 237         
 238         self.SetSizer( pnlCtrls_vertSizer )
 239         
 240     #end __init__
 241         
 242 #end TextButtonRadioPanel class
 243 
 244 #------------------------------------------------------------------------------
 245 
 246 class ComboBoxPanel( wx.Panel ) :
 247     """ 
 248     A Multiple-Controls Class in BoxSizers demo.
 249     
 250     The panel is arbitrarily designed to be slightly larger than the
 251     usual minimum panel size that just holds its controls. 
 252     """
 253     
 254     def __init__( self, parent, bgColor, cmbBx_list ) :
 255     
 256         wx.Panel.__init__( self, parent=parent, id=-1 )
 257         self.BackgroundColour = bgColor
 258         
 259         #-----
 260     
 261         comboCaption_stTxt = wx.StaticText( self, -1, 'ComboBoxPanel Caption' )
 262         comboCaption_stTxt.BackgroundColour = ( 'wHIte' )
 263         
 264         comboBox = wx.ComboBox( self,
 265                                 value='DefaultValue', 
 266                                 size=(160, -1), 
 267                                 choices=cmbBx_list,
 268                                 style=wx.CB_DROPDOWN
 269                                 #| wx.TE_PROCESS_ENTER
 270                                 #| wx.CB_SORT
 271                               )
 272         #-----
 273         
 274         pnl_vertSizer = wx.BoxSizer( wx.VERTICAL )
 275         
 276         asp.AddSpacer( pnl_vertSizer, 10 )
 277         
 278         alignFlag = wx.ALIGN_CENTRE
 279         padFlags = wx.LEFT | wx.RIGHT       # Pad to space from panel's L & R edges.
 280         
 281         pnl_vertSizer.Add( comboCaption_stTxt, 
 282                            flag=alignFlag | padFlags, 
 283                            border=10 )              # Pad the minor axis, only.
 284                            
 285         asp.AddSpacer( pnl_vertSizer, 4 )
 286         
 287         pnl_vertSizer.Add( comboBox, 
 288                            flag=alignFlag | padFlags, 
 289                            border=10 )              # Pad the minor axis, only.
 290         
 291         asp.AddSpacer( pnl_vertSizer, 10 )    # 1-D vertical spacer.
 292         
 293         self.SetSizer( pnl_vertSizer )    # Invoke the sizer.
 294         
 295     #end __init
 296     
 297 #end ComboBoxPanel class
 298 
 299 #------------------------------------------------------------------------------
 300 
 301 class SpinControlPanel( wx.Panel ) :
 302     """ 
 303     A Multiple-Controls Class in BoxSizers demo.
 304     
 305     The panel is arbitrarily designed to be slightly larger than the
 306     usual minimum panel size that just holds its controls. 
 307     """
 308     
 309     def __init__( self, parent, bgColor ) :
 310     
 311         wx.Panel.__init__( self, parent=parent, id=-1 )
 312         self.BackgroundColour = bgColor
 313         
 314         #-----
 315     
 316         spinCaption_stTxt = wx.StaticText( self, -1, 'SpinControlPanel Caption' )
 317         spinCaption_stTxt.BackgroundColour = ( 'wHIte' )
 318         
 319         spinCtrl = wx.SpinCtrl( self, size=(70, -1) )
 320         spinCtrl.SetRange( 1, 100 )
 321         spinCtrl.SetValue( 5 )
 322         
 323         #-----
 324         
 325         pnl_vertSizer = wx.BoxSizer( wx.VERTICAL )
 326         
 327         asp.AddSpacer( pnl_vertSizer, 10 )     # 1-D vertical spacer
 328         
 329         alignFlag = wx.ALIGN_CENTRE
 330         padFlags = wx.LEFT | wx.RIGHT       # Pad to space from panel's L & R edges.
 331         
 332         pnl_vertSizer.Add( spinCaption_stTxt, 
 333                            flag=alignFlag | padFlags, 
 334                            border=10 )              # Pad the minor axis, only.
 335                            
 336         asp.AddSpacer( pnl_vertSizer, 4 )     # 1-D vertical spacer for the major axis.
 337         
 338         pnl_vertSizer.Add( spinCtrl, 
 339                            flag=alignFlag | padFlags, 
 340                            border=10 )              # Pad the minor axis, only.
 341         
 342         # The first 2-D spacer already set the panel's width.
 343         asp.AddSpacer( pnl_vertSizer, 10 )    # 1-D vertical spacer.
 344         
 345         self.SetSizer( pnl_vertSizer )    # Invoke the sizer.
 346         
 347     #end __init
 348     
 349 #end SpinControlPanel class
 350 
 351 #------------------------------------------------------------------------------
 352 
 353 class SliderPanel( wx.Panel ) :
 354     """ 
 355     A Multiple-Controls Class in BoxSizers demo.
 356     
 357     The panel is arbitrarily designed to be slightly larger than the
 358     usual minimum panel size that just holds its controls. 
 359     """
 360     
 361     def __init__( self, parent, bgColor ) :
 362     
 363         wx.Panel.__init__( self, parent=parent, id=-1 )
 364         self.BackgroundColour = bgColor
 365         
 366         #-----
 367     
 368         sliderCaption_stTxt = wx.StaticText( self, -1, 'SliderPanel Caption' )
 369         sliderCaption_stTxt.BackgroundColour = ( 'wHIte' )
 370         
 371         sliderStyle = wx.SL_AUTOTICKS | wx.SL_HORIZONTAL | wx.SL_LABELS
 372         sliderCtrl = wx.Slider( self, -1, 50, 0, 100, wx.DefaultPosition, 
 373                                 size=(250, -1),
 374                                 style=sliderStyle
 375                               )
 376         sliderCtrl.SetTickFreq( 2, pos=1 )
 377         
 378         #-----
 379         
 380         pnl_vertSizer = wx.BoxSizer( wx.VERTICAL )
 381         
 382         asp.AddSpacer( pnl_vertSizer, 10 )     # 1-D vertical spacer.
 383         
 384         alignFlag = wx.ALIGN_CENTRE
 385         padFlags = wx.LEFT | wx.RIGHT       # Pad to space from panel's L & R edges.
 386         
 387         pnl_vertSizer.Add( sliderCaption_stTxt, 
 388                            flag=alignFlag | padFlags, 
 389                            border=10 )              # Pad the minor axis, only.
 390         
 391         asp.AddSpacer( pnl_vertSizer, 4 )     # 1-D vertical spacer.
 392         
 393         pnl_vertSizer.Add( sliderCtrl, 
 394                            flag=alignFlag | padFlags, 
 395                            border=10 )              # Pad the minor axis, only.
 396         
 397         # The first 2-D spacer already set the panel's width.
 398         asp.AddSpacer( pnl_vertSizer, 10 )    # 1-D vertical spacer.
 399         
 400         self.SetSizer( pnl_vertSizer )      # Invoke the sizer.
 401         
 402     #end __init
 403     
 404 #end SliderPanel class
 405 
 406 #------------------------------------------------------------------------------
 407 
 408 class ComboSpinSliderPanel( wx.Panel ) :
 409     """ 
 410     A Multiple-Controls Class in BoxSizers demo.
 411     
 412     The panel is arbitrarily designed to be slightly larger than the
 413     usual minimum panel size that just holds its controls. 
 414     """
 415     
 416     def __init__( self, parent, bgColor, cmbBx_list ) :
 417     
 418         wx.Panel.__init__( self, parent=parent, id=-1 )
 419         self.BackgroundColour = bgColor
 420         
 421         #-----
 422     
 423         pnlLabel_stTxt = wx.StaticText( self, -1, ' ComboSpinSliderPanel ' )
 424         
 425         comboBoxPanel = ComboBoxPanel( self, 
 426                                         (250, 150, 150),        # pale orange
 427                                         cmbBx_list=cmbBx_list )
 428         
 429         spinCtrlPanel = SpinControlPanel( self, bgColor=(255, 250, 220) )   # light beige
 430         
 431         sliderPanel = SliderPanel( self, bgColor=(225, 255, 235) )
 432         
 433         #-----
 434         
 435         pnl_vertSizer = wx.BoxSizer( wx.VERTICAL )
 436         pnl_vertSizer.Add( (400, 5) )
 437         
 438         
 439         comboSpin_horzSizer = wx.BoxSizer( wx.HORIZONTAL )
 440         asp.AddSpacer( comboSpin_horzSizer, 10 )
 441         comboSpin_horzSizer.Add( comboBoxPanel, flag=wx.CENTRE )
 442         asp.AddSpacer( comboSpin_horzSizer, 10 )
 443         comboSpin_horzSizer.Add( spinCtrlPanel, flag=wx.ALIGN_CENTER )
 444         asp.AddSpacer( comboSpin_horzSizer, 10 )
 445         
 446         
 447         pnl_vertSizer = wx.BoxSizer( wx.VERTICAL )
 448         pnl_vertSizer.Add( pnlLabel_stTxt, flag=wx.ALIGN_LEFT )
 449         asp.AddSpacer( pnl_vertSizer, 10 )
 450         pnl_vertSizer.Add( comboSpin_horzSizer, flag=wx.CENTRE )
 451         asp.AddSpacer( pnl_vertSizer, 10 )
 452         
 453         
 454         slider_horzSizer = wx.BoxSizer( wx.HORIZONTAL )
 455         asp.AddSpacer( slider_horzSizer, 10 )
 456         slider_horzSizer.Add( sliderPanel, flag=wx.CENTER )
 457         asp.AddSpacer( slider_horzSizer, 10 )
 458         
 459         
 460         pnl_vertSizer.Add( slider_horzSizer, flag=wx.CENTER )
 461         
 462         asp.AddSpacer( pnl_vertSizer, 10 )
 463         
 464         #-----
 465         
 466         self.SetSizer( pnl_vertSizer )    # Invoke the sizer.
 467         self.Layout()
 468         
 469     #end __init__
 470     
 471 #end ComboSpinSliderPanel class
 472 
 473 #------------------------------------------------------------------------------
 474 
 475 class ComboSpinSliderCheckPanel( wx.Panel ) :
 476     """
 477     A Multiple-Controls Class in BoxSizers demo.
 478     
 479     The panel is arbitrarily designed to be slightly larger than the
 480     usual minimum panel size that just holds its controls. 
 481     """
 482     
 483     def __init__( self, parent, coSpSl_list, chkBox_list, bgColor ) :
 484     
 485         wx.Panel.__init__( self, parent, -1 )
 486         self.BackgroundColour = (255, 180, 100)       # medium orange
 487         
 488         #-----
 489         
 490         # Create all the page's controls either individually or using classes.
 491         
 492         coSpSlChPnl_stTxt = wx.StaticText( self, -1, ' ComboSpinSliderCheckPanel ' )
 493         
 494         comboSpinSlider_pnl = pc.ComboSpinSliderPanel( self, 
 495                                                        (210, 210, 230), 
 496                                                        coSpSl_list )
 497         
 498         chkLstBoxPanel = pc.CheckListBoxPanel( self, 'CheckListBoxPanel Caption',
 499                                                 #bgColor=(210, 230, 210), 
 500                                                 bgColor=(150, 230, 150), 
 501                                                 items_list=chkBox_list )
 502         
 503         #-----  Create the sizers and add the controls to it.
 504         
 505         pnlCtrls_horzSizer = wx.BoxSizer( wx.HORIZONTAL )
 506         
 507         asp.AddSpacer( pnlCtrls_horzSizer, 10 )
 508         pnlCtrls_horzSizer.Add( comboSpinSlider_pnl, flag=wx.CENTER )
 509         asp.AddSpacer( pnlCtrls_horzSizer, 10 )
 510         pnlCtrls_horzSizer.Add( chkLstBoxPanel, flag=wx.CENTER )
 511         asp.AddSpacer( pnlCtrls_horzSizer, 10 )
 512         
 513         
 514         pnl_vertSizer = wx.BoxSizer( wx.VERTICAL )
 515         
 516         pnl_vertSizer.Add( coSpSlChPnl_stTxt,  flag=wx.LEFT )
 517         asp.AddSpacer( pnl_vertSizer, 10 )
 518         pnl_vertSizer.Add( pnlCtrls_horzSizer, flag=wx.CENTER )
 519         asp.AddSpacer( pnl_vertSizer, 10 )
 520         
 521         self.SetSizer( pnl_vertSizer )
 522         self.Layout()
 523         
 524     #end __init__
 525         
 526 #end ComboSpinSliderCheckPanel class

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2010-10-18 04:58:55, 2.5 KB) [[attachment:AddSpacer.py]]
  • [get | view] (2010-11-14 22:48:20, 28.1 KB) [[attachment:MultipleControlsPanels_Demo.png]]
  • [get | view] (2010-10-18 04:59:19, 3.7 KB) [[attachment:MultipleControlsPanels_Demo.py]]
  • [get | view] (2010-11-14 22:48:31, 18.7 KB) [[attachment:PanelControls.py]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.

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