Attachment 'DUAL_CONTROL_CLASS_3.PY'

Download

#!/usr/bin/python

# DUAL_CONTROL_CLASS_3.PY

"""
Demonstrate dual sizers.
"""

import wx
import AddLinearSpacer as als

#------------------------------------------------------------------------------

class TxtCtrlPanel( wx.Panel ) :
    """ A 2-control class with a sizer """
    
    def __init__( self, parent, caption_txt ) :
    
        wx.Panel.__init__( self, parent=parent, id=-1 )
        
        #-----
    
        self.ctrlsPanelCaption_1_stTxt = wx.StaticText( self, -1, caption_txt )
        self.ctrlsPanelCaption_1_stTxt.BackgroundColour = ( 'wHIte' )
        
        self.ctrlsPanel_1_txtCtrl = wx.TextCtrl( self, -1, style=wx.TE_MULTILINE, size=(200, 150) )
        
        #-----
        
        # Use a single page level sizer to position all controls 
        #   and controls classes' instantiations.
        self.panel_vertSizer = wx.BoxSizer( wx.VERTICAL )
        
        self.panel_vertSizer.Add( self.ctrlsPanelCaption_1_stTxt, proportion=0, flag=wx.CENTER )
        
        als.AddLinearSpacer( self.panel_vertSizer, 2 )
        
        self.panel_vertSizer.Add( self.ctrlsPanel_1_txtCtrl,  proportion=0, flag=wx.ALIGN_CENTRE )
        
        #-----
        
        self.SetSizer( self.panel_vertSizer )    # Invoke the sizer.
        self.Fit()  # Make "self" (the panel) shrink to the minimum size required by the controls.
        
    #end __init__
    
    #------------------------
    
    def GetControls( self ) :
        return self.ctrlsPanelCaption_1_stTxt, self.ctrlsPanel_1_txtCtrl
        
    def LayoutAgain( self ) :
        self.panel_vertSizer.Layout()

    
#end TxtCtrlPanel class

#------------------------------------------------------------------------------

class MainFrame( wx.Frame ) :
    """ A 2-control class with a BoxSizer demo """
        
    #-----  Configure the Frame.
        
    def __init__( self, parent ) :
        
        wx.Frame.__init__ ( self, parent, -1, title='DUAL_CONTROL_CLASS_3.PY', 
                            size=(600, 400), style=wx.DEFAULT_FRAME_STYLE )
        self.Position = (100, 0)
        
        # A panel is needed for tab-traversal and platform background color capabilities.
        # The first control instantiated in a Frame automatically expands 
        #   to the Frame's client size.  This is unique to Frames.
        frm_pnl = wx.Panel( self )
        frm_pnl.BackgroundColour = (250, 250, 150)         # yellow
        
        #-----  Create the controls
        
        # Create all the page's controls either individually or using classes.
        
        ctrlsPanel_1 = TxtCtrlPanel( frm_pnl, 'My TextCtrl Caption #1' )
        stTxt_1, txtCtl_1 = ctrlsPanel_1.GetControls()  # Retrieve the control objects.
        
        ctrlsPanel_2 = TxtCtrlPanel( frm_pnl, 'My TextCtrl Caption #2' )
        stTxt_2, txtCtl_2 = ctrlsPanel_2.GetControls()
        
        # Change the original caption after being created.
        stTxt_2.Label = 'Caption Redefined After Panel Class Instantiation'
        ctrlsPanel_2.LayoutAgain()
        
        #-----  Create the sizers and add the controls to it.
        
        panelCtrls_horzSizer = wx.BoxSizer( wx.HORIZONTAL )
        
        als.AddLinearSpacer( panelCtrls_horzSizer, 35 )
        panelCtrls_horzSizer.Add( ctrlsPanel_1 )
        als.AddLinearSpacer( panelCtrls_horzSizer, 15 )
        panelCtrls_horzSizer.Add( ctrlsPanel_2 )
        als.AddLinearSpacer( panelCtrls_horzSizer, 35 )
        
        frmPnl_vertSizer = wx.BoxSizer( wx.VERTICAL )
        
        frmPnl_vertSizer.AddStretchSpacer( prop=1 )
        
        frmPnl_vertSizer.Add( panelCtrls_horzSizer, flag=wx.CENTRE )    # synonym
        
        frmPnl_vertSizer.AddStretchSpacer( prop=1 )
        
        #----- Invoke the sizer via its container.
        
        # "There can be only one.", Duncan MacLeod from the clan MacLeod.
        # That is, a container can have no or exactly 1 top level sizer.
        # Sizer nesting can effectively be infinitely done.
        frm_pnl.SetSizer( frmPnl_vertSizer )
        frm_pnl.Layout()
        
    #end __init__

#end MainFrame class

#==============================================================================

if __name__ == '__main__' :

    app = wx.PySimpleApp( redirect=False )
    appFrame = MainFrame( None ).Show()
    app.MainLoop()

#end if

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-03 00:02:35, 0.8 KB) [[attachment:AddLinearSpacer.PY]]
  • [get | view] (2010-09-27 21:22:43, 0.6 KB) [[attachment:AddLinearSpacer.py]]
  • [get | view] (2010-10-03 00:07:55, 15.1 KB) [[attachment:DUAL_CONTROL_CLASS_1.PNG]]
  • [get | view] (2010-10-03 16:43:05, 2.9 KB) [[attachment:DUAL_CONTROL_CLASS_1.PY]]
  • [get | view] (2010-10-03 00:08:04, 17.3 KB) [[attachment:DUAL_CONTROL_CLASS_2.PNG]]
  • [get | view] (2010-10-03 16:42:58, 4.3 KB) [[attachment:DUAL_CONTROL_CLASS_2.PY]]
  • [get | view] (2010-10-03 00:08:11, 18.1 KB) [[attachment:DUAL_CONTROL_CLASS_3.PNG]]
  • [get | view] (2010-10-03 16:43:16, 4.4 KB) [[attachment:DUAL_CONTROL_CLASS_3.PY]]
  • [get | view] (2010-10-03 16:13:27, 21.6 KB) [[attachment:DUAL_CONTROL_CLASS_4.PNG]]
  • [get | view] (2010-10-03 16:44:24, 5.3 KB) [[attachment:DUAL_CONTROL_CLASS_4.PY]]
  • [get | view] (2010-09-30 16:11:37, 42.7 KB) [[attachment:DUAL_SIZER_SKETCH.PNG]]
  • [get | view] (2010-09-30 17:37:50, 6.5 KB) [[attachment:DUAL_SIZER_SKETCH_ANNO.PNG]]
  • [get | view] (2010-09-30 17:46:56, 13.6 KB) [[attachment:DUAL_SIZER_SKETCH_EXPLODED.PNG]]
  • [get | view] (2010-09-28 18:55:07, 4.2 KB) [[attachment:LIGHTBULB.64x64.PNG]]
 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.