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.You are not allowed to attach a file to this page.