<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/python

# DUAL_CONTROL_CLASS_2.PY

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 """
        
    def __init__( self ) :
        
        #-----  Configure the Frame.
        
        wx.Frame.__init__ ( self, None, title='DUAL_CONTROL_CLASS_2.PY', 
                            size=(600, 300), 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()
        
        # Let's change the original caption "after the fact".
        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 )
        
        als.AddLinearSpacer( frmPnl_vertSizer, 35 )
        frmPnl_vertSizer.Add( panelCtrls_horzSizer )
        
        als.AddLinearSpacer( frmPnl_vertSizer, 35 )
        
        #-----  Create the sizer and add the controls to it.
        
        # "There can be only one.", Duncan MacLeod from the clan MacLeod.
        # That is, a page can have exactly 1 or none top level sizer.
        # Sizer nesting can effectively have infinite levels.
        frm_pnl.SetSizer( frmPnl_vertSizer )
        frm_pnl.Fit()
        
    #end __init__

#end MainFrame class

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

if __name__ == '__main__' :

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

#end if
</pre></body></html>