
# PanelControls.py

import wx
import AddSpacer        as asp  # A more intelligent BoxSizer spacer.
import PanelControls    as pc

#------------------------------------------------------------------------------

class CheckListBoxPanel( wx.Panel ) :
    """ 
    A Multiple-Controls Class in BoxSizers demo.
    
    The panel is arbitrarily designed to be slightly larger than the
    usual minimum panel size that just holds its controls. 
    """
    
    def __init__( self, parent, caption_txt, bgColor, items_list ) :
    
        wx.Panel.__init__( self, parent=parent, id=-1 )
        self.BackgroundColour = bgColor
        
        #-----
    
        Caption_stTxt = wx.StaticText( self, -1, caption_txt )
        Caption_stTxt.BackgroundColour = ( 'wHIte' )
        
        checkListBox = wx.CheckListBox(self, -1, size=(-1, 100), choices=items_list)
        #checkListBox.SetSelection(0)       # use is arbitrary
        
        #----
        
        # Use a single sizer to position the controls.
        pnl_vertSizer = wx.BoxSizer( wx.VERTICAL )
        
        asp.AddSpacer( pnl_vertSizer, 10 )     # 1-D vertical spacer.
        
        alignFlag = wx.ALIGN_CENTRE
        padFlags = wx.LEFT | wx.RIGHT       # Pad to space from panel's L & R edges.
        
        pnl_vertSizer.Add( Caption_stTxt, flag=alignFlag | padFlags, border=10 )
        
        asp.AddSpacer( pnl_vertSizer, 4 )
        
        pnl_vertSizer.Add( checkListBox,  flag=alignFlag | padFlags, border=10 )
                                
        asp.AddSpacer( pnl_vertSizer, 10 )     # 1-D vertical spacer.
        
        #-----
        
        self.SetSizer( pnl_vertSizer )    # Invoke the sizer.
        self.Layout()
        
    #end __init__
    
#end CheckListBoxPanel class

#------------------------------------------------------------------------------

class RadioBoxPanel( wx.Panel ) :
    """ 
    A Multiple-Controls Class in BoxSizers demo.
    
    The panel is arbitrarily designed to be slightly larger than the
    usual minimum panel size that just holds its controls. 
    """
    
    def __init__( self, parent, caption_txt, choices_list, bgColor ) :
    
        wx.Panel.__init__( self, parent=parent, id=-1 )
        self.BackgroundColour = bgColor
        
        #-----
        
        self.Caption_stTxt = wx.StaticText( self, -1, caption_txt )
        self.Caption_stTxt.BackgroundColour = ( 'wHIte' )
        stTxtSize = self.Caption_stTxt.GetSize()
        
        self.radBox = wx.RadioBox( self, -1, 'RadioBox A', 
                                     choices=choices_list, 
                                     majorDimension=4, 
                                     style=wx.RA_SPECIFY_ROWS )
        #----
        
        # Use a single sizer to position the controls.
        pnl_vertSizer = wx.BoxSizer( wx.VERTICAL )
        
        asp.AddSpacer( pnl_vertSizer, (0, 10) )     # a rectangular spacer.
        
        alignFlag = wx.ALIGN_CENTRE
        padFlags = wx.LEFT | wx.RIGHT       # Pad to space from panel's L & R edges.
        
        pnl_vertSizer.Add( self.Caption_stTxt, 
                           flag=alignFlag | padFlags, 
                           border=10 )              # Pad the minor axis, only.
        
        asp.AddSpacer( pnl_vertSizer, 4, 0 )   # a rectangular spacer.
        
        pnl_vertSizer.Add( self.radBox, 
                           flag=alignFlag | padFlags, 
                           border=10 )              # Pad the minor axis, only.
        
        asp.AddSpacer( pnl_vertSizer, 10 )     # 1-D vertical spacer.
        
        #-----
        
        self.SetSizer( pnl_vertSizer )    # Invoke the sizer.
        self.Layout()
        
    #end __init__
    
    #------------------------
    
    def GetControls( self ) :
        return self.Caption_stTxt, self.radBox
        
#end RadioBoxPanel class

#------------------------------------------------------------------------------

class TxtCtrlPanel( wx.Panel ) :
    """ 
    A Multiple-Controls Class in BoxSizers demo.
    
    The panel is arbitrarily designed to be slightly larger than the
    usual minimum panel size that just holds its controls. 
    """
    
    def __init__( self, parent, caption_txt, bgColor, txtCtl_list ) :
    
        wx.Panel.__init__( self, parent=parent, id=-1 )
        self.BackgroundColour = bgColor
        
        #-----
    
        self.Caption_stTxt = wx.StaticText( self, -1, caption_txt )
        self.Caption_stTxt.BackgroundColour = ( 'wHIte' )
        stTxtSize = self.Caption_stTxt.GetSize()
        
        txtCtrl_size = (200, 150)
        self.pnl_txtCtrl = wx.TextCtrl( self, -1, 
                                        style=wx.TE_MULTILINE, 
                                        size=txtCtrl_size )
        self.pnl_txtCtrl.SetInsertionPoint( 0 )
        for aLine in txtCtl_list :
            self.pnl_txtCtrl.WriteText( aLine + '\n' )
        # An often-used "trick" that deselects all the text:
        wx.CallAfter( self.pnl_txtCtrl.SetInsertionPoint, 0 )
        
        #----
        
        # Use a single sizer to position the controls.
        self.pnl_vertSizer = wx.BoxSizer( wx.VERTICAL )
        
        asp.AddSpacer( self.pnl_vertSizer, 10 )     # 1-D vertical spacer.
        
        alignFlag = wx.ALIGN_CENTRE
        padFlags = wx.LEFT | wx.RIGHT       # Pad to space from panel's L & R edges.
        
        self.pnl_vertSizer.Add( self.Caption_stTxt, 
                                flag=alignFlag | padFlags, 
                                border=10 )              # Pad the minor axis, only.
        
        asp.AddSpacer( self.pnl_vertSizer, 4 )
        
        self.pnl_vertSizer.Add( self.pnl_txtCtrl, 
                                flag=alignFlag | padFlags, 
                                border=10 )              # Pad the minor axis, only.
        
        asp.AddSpacer( self.pnl_vertSizer, 10 )    # 1-D vertical spacer.
        
        #-----
        
        self.SetSizer( self.pnl_vertSizer )    # Invoke the sizer.
        self.Layout()
        
    #end __init__
    
    #------------------------
    
    def GetControls( self ) :
        return self.Caption_stTxt, self.pnl_txtCtrl
        
#end TxtCtrlPanel class

#------------------------------------------------------------------------------

class TextButtonRadioPanel( wx.Panel ) :
    """ 
    A Multiple-Controls Class in BoxSizers demo.
    
    The panel is arbitrarily designed to be slightly larger than the
    usual minimum panel size that just holds its controls. 
    """
    
    def __init__( self, parent, txtCtl_list, radBtn_list, bgColor ) :
    
        wx.Panel.__init__( self, parent, -1 )
        self.BackgroundColour = (220, 250, 220)     # Green
        
        txtBtnRadPnl_stTxt = wx.StaticText( self, -1, ' TextButtonRadioPanel ' )
        
        #-----
        
        # Create all the page's controls either individually or using classes.
        
        txtCtrlPanel = TxtCtrlPanel( self, 'TextCtrlPanel Caption',
                                     bgColor=(220, 220, 255), 
                                     txtCtl_list=txtCtl_list )
        
        radBoxPanel = RadioBoxPanel( self, 
                                     caption_txt='RadioBoxPanel Caption', 
                                     choices_list=radBtn_list, 
                                     bgColor=bgColor )
        
        btn = wx.Button( self, -1, 'Launch Missiles' )
        
        #-----  Create the sizers and add the controls to it.
        
        pnlCtrls_horzSizer = wx.BoxSizer( wx.HORIZONTAL )
        
        asp.AddSpacer( pnlCtrls_horzSizer, 10 )
        pnlCtrls_horzSizer.Add( txtCtrlPanel, flag=wx.CENTER )
        asp.AddSpacer( pnlCtrls_horzSizer, 10 )
        pnlCtrls_horzSizer.Add( radBoxPanel, flag=wx.CENTER )
        asp.AddSpacer( pnlCtrls_horzSizer, 10 )
        
        
        pnlCtrls_vertSizer = wx.BoxSizer( wx.VERTICAL )
        
        pnlCtrls_vertSizer.Add( txtBtnRadPnl_stTxt, flag=wx.ALIGN_LEFT )
        
        asp.AddSpacer( pnlCtrls_vertSizer, 10 )
        pnlCtrls_vertSizer.Add( pnlCtrls_horzSizer, flag=wx.CENTRE )    #Add sizer to sizer
        asp.AddSpacer( pnlCtrls_vertSizer, 10 )
        pnlCtrls_vertSizer.Add( btn, flag=wx.CENTRE )
        asp.AddSpacer( pnlCtrls_vertSizer, 10 )
        
        self.SetSizer( pnlCtrls_vertSizer )
        
    #end __init__
        
#end TextButtonRadioPanel class

#------------------------------------------------------------------------------

class ComboBoxPanel( wx.Panel ) :
    """ 
    A Multiple-Controls Class in BoxSizers demo.
    
    The panel is arbitrarily designed to be slightly larger than the
    usual minimum panel size that just holds its controls. 
    """
    
    def __init__( self, parent, bgColor, cmbBx_list ) :
    
        wx.Panel.__init__( self, parent=parent, id=-1 )
        self.BackgroundColour = bgColor
        
        #-----
    
        comboCaption_stTxt = wx.StaticText( self, -1, 'ComboBoxPanel Caption' )
        comboCaption_stTxt.BackgroundColour = ( 'wHIte' )
        
        comboBox = wx.ComboBox( self,
                                value='DefaultValue', 
                                size=(160, -1), 
                                choices=cmbBx_list,
                                style=wx.CB_DROPDOWN
                                #| wx.TE_PROCESS_ENTER
                                #| wx.CB_SORT
                              )
        #-----
        
        pnl_vertSizer = wx.BoxSizer( wx.VERTICAL )
        
        asp.AddSpacer( pnl_vertSizer, 10 )
        
        alignFlag = wx.ALIGN_CENTRE
        padFlags = wx.LEFT | wx.RIGHT       # Pad to space from panel's L & R edges.
        
        pnl_vertSizer.Add( comboCaption_stTxt, 
                           flag=alignFlag | padFlags, 
                           border=10 )              # Pad the minor axis, only.
                           
        asp.AddSpacer( pnl_vertSizer, 4 )
        
        pnl_vertSizer.Add( comboBox, 
                           flag=alignFlag | padFlags, 
                           border=10 )              # Pad the minor axis, only.
        
        asp.AddSpacer( pnl_vertSizer, 10 )    # 1-D vertical spacer.
        
        self.SetSizer( pnl_vertSizer )    # Invoke the sizer.
        
    #end __init
    
#end ComboBoxPanel class

#------------------------------------------------------------------------------

class SpinControlPanel( wx.Panel ) :
    """ 
    A Multiple-Controls Class in BoxSizers demo.
    
    The panel is arbitrarily designed to be slightly larger than the
    usual minimum panel size that just holds its controls. 
    """
    
    def __init__( self, parent, bgColor ) :
    
        wx.Panel.__init__( self, parent=parent, id=-1 )
        self.BackgroundColour = bgColor
        
        #-----
    
        spinCaption_stTxt = wx.StaticText( self, -1, 'SpinControlPanel Caption' )
        spinCaption_stTxt.BackgroundColour = ( 'wHIte' )
        
        spinCtrl = wx.SpinCtrl( self, size=(70, -1) )
        spinCtrl.SetRange( 1, 100 )
        spinCtrl.SetValue( 5 )
        
        #-----
        
        pnl_vertSizer = wx.BoxSizer( wx.VERTICAL )
        
        asp.AddSpacer( pnl_vertSizer, 10 )     # 1-D vertical spacer
        
        alignFlag = wx.ALIGN_CENTRE
        padFlags = wx.LEFT | wx.RIGHT       # Pad to space from panel's L & R edges.
        
        pnl_vertSizer.Add( spinCaption_stTxt, 
                           flag=alignFlag | padFlags, 
                           border=10 )              # Pad the minor axis, only.
                           
        asp.AddSpacer( pnl_vertSizer, 4 )     # 1-D vertical spacer for the major axis.
        
        pnl_vertSizer.Add( spinCtrl, 
                           flag=alignFlag | padFlags, 
                           border=10 )              # Pad the minor axis, only.
        
        # The first 2-D spacer already set the panel's width.
        asp.AddSpacer( pnl_vertSizer, 10 )    # 1-D vertical spacer.
        
        self.SetSizer( pnl_vertSizer )    # Invoke the sizer.
        
    #end __init
    
#end SpinControlPanel class

#------------------------------------------------------------------------------

class SliderPanel( wx.Panel ) :
    """ 
    A Multiple-Controls Class in BoxSizers demo.
    
    The panel is arbitrarily designed to be slightly larger than the
    usual minimum panel size that just holds its controls. 
    """
    
    def __init__( self, parent, bgColor ) :
    
        wx.Panel.__init__( self, parent=parent, id=-1 )
        self.BackgroundColour = bgColor
        
        #-----
    
        sliderCaption_stTxt = wx.StaticText( self, -1, 'SliderPanel Caption' )
        sliderCaption_stTxt.BackgroundColour = ( 'wHIte' )
        
        sliderStyle = wx.SL_AUTOTICKS | wx.SL_HORIZONTAL | wx.SL_LABELS
        sliderCtrl = wx.Slider( self, -1, 50, 0, 100, wx.DefaultPosition, 
                                size=(250, -1),
                                style=sliderStyle
                              )
        sliderCtrl.SetTickFreq( 2, pos=1 )
        
        #-----
        
        pnl_vertSizer = wx.BoxSizer( wx.VERTICAL )
        
        asp.AddSpacer( pnl_vertSizer, 10 )     # 1-D vertical spacer.
        
        alignFlag = wx.ALIGN_CENTRE
        padFlags = wx.LEFT | wx.RIGHT       # Pad to space from panel's L & R edges.
        
        pnl_vertSizer.Add( sliderCaption_stTxt, 
                           flag=alignFlag | padFlags, 
                           border=10 )              # Pad the minor axis, only.
        
        asp.AddSpacer( pnl_vertSizer, 4 )     # 1-D vertical spacer.
        
        pnl_vertSizer.Add( sliderCtrl, 
                           flag=alignFlag | padFlags, 
                           border=10 )              # Pad the minor axis, only.
        
        # The first 2-D spacer already set the panel's width.
        asp.AddSpacer( pnl_vertSizer, 10 )    # 1-D vertical spacer.
        
        self.SetSizer( pnl_vertSizer )      # Invoke the sizer.
        
    #end __init
    
#end SliderPanel class

#------------------------------------------------------------------------------

class ComboSpinSliderPanel( wx.Panel ) :
    """ 
    A Multiple-Controls Class in BoxSizers demo.
    
    The panel is arbitrarily designed to be slightly larger than the
    usual minimum panel size that just holds its controls. 
    """
    
    def __init__( self, parent, bgColor, cmbBx_list ) :
    
        wx.Panel.__init__( self, parent=parent, id=-1 )
        self.BackgroundColour = bgColor
        
        #-----
    
        pnlLabel_stTxt = wx.StaticText( self, -1, ' ComboSpinSliderPanel ' )
        
        comboBoxPanel = ComboBoxPanel( self, 
                                        (250, 150, 150),        # pale orange
                                        cmbBx_list=cmbBx_list )
        
        spinCtrlPanel = SpinControlPanel( self, bgColor=(255, 250, 220) )   # light beige
        
        sliderPanel = SliderPanel( self, bgColor=(225, 255, 235) )
        
        #-----
        
        pnl_vertSizer = wx.BoxSizer( wx.VERTICAL )
        pnl_vertSizer.Add( (400, 5) )
        
        
        comboSpin_horzSizer = wx.BoxSizer( wx.HORIZONTAL )
        asp.AddSpacer( comboSpin_horzSizer, 10 )
        comboSpin_horzSizer.Add( comboBoxPanel, flag=wx.CENTRE )
        asp.AddSpacer( comboSpin_horzSizer, 10 )
        comboSpin_horzSizer.Add( spinCtrlPanel, flag=wx.ALIGN_CENTER )
        asp.AddSpacer( comboSpin_horzSizer, 10 )
        
        
        pnl_vertSizer = wx.BoxSizer( wx.VERTICAL )
        pnl_vertSizer.Add( pnlLabel_stTxt, flag=wx.ALIGN_LEFT )
        asp.AddSpacer( pnl_vertSizer, 10 )
        pnl_vertSizer.Add( comboSpin_horzSizer, flag=wx.CENTRE )
        asp.AddSpacer( pnl_vertSizer, 10 )
        
        
        slider_horzSizer = wx.BoxSizer( wx.HORIZONTAL )
        asp.AddSpacer( slider_horzSizer, 10 )
        slider_horzSizer.Add( sliderPanel, flag=wx.CENTER )
        asp.AddSpacer( slider_horzSizer, 10 )
        
        
        pnl_vertSizer.Add( slider_horzSizer, flag=wx.CENTER )
        
        asp.AddSpacer( pnl_vertSizer, 10 )
        
        #-----
        
        self.SetSizer( pnl_vertSizer )    # Invoke the sizer.
        self.Layout()
        
    #end __init__
    
#end ComboSpinSliderPanel class

#------------------------------------------------------------------------------

class ComboSpinSliderCheckPanel( wx.Panel ) :
    """
    A Multiple-Controls Class in BoxSizers demo.
    
    The panel is arbitrarily designed to be slightly larger than the
    usual minimum panel size that just holds its controls. 
    """
    
    def __init__( self, parent, coSpSl_list, chkBox_list, bgColor ) :
    
        wx.Panel.__init__( self, parent, -1 )
        self.BackgroundColour = (255, 180, 100)       # medium orange
        
        #-----
        
        # Create all the page's controls either individually or using classes.
        
        coSpSlChPnl_stTxt = wx.StaticText( self, -1, ' ComboSpinSliderCheckPanel ' )
        
        comboSpinSlider_pnl = pc.ComboSpinSliderPanel( self, 
                                                       (210, 210, 230), 
                                                       coSpSl_list )
        
        chkLstBoxPanel = pc.CheckListBoxPanel( self, 'CheckListBoxPanel Caption',
                                                #bgColor=(210, 230, 210), 
                                                bgColor=(150, 230, 150), 
                                                items_list=chkBox_list )
        
        #-----  Create the sizers and add the controls to it.
        
        pnlCtrls_horzSizer = wx.BoxSizer( wx.HORIZONTAL )
        
        asp.AddSpacer( pnlCtrls_horzSizer, 10 )
        pnlCtrls_horzSizer.Add( comboSpinSlider_pnl, flag=wx.CENTER )
        asp.AddSpacer( pnlCtrls_horzSizer, 10 )
        pnlCtrls_horzSizer.Add( chkLstBoxPanel, flag=wx.CENTER )
        asp.AddSpacer( pnlCtrls_horzSizer, 10 )
        
        
        pnl_vertSizer = wx.BoxSizer( wx.VERTICAL )
        
        pnl_vertSizer.Add( coSpSlChPnl_stTxt,  flag=wx.LEFT )
        asp.AddSpacer( pnl_vertSizer, 10 )
        pnl_vertSizer.Add( pnlCtrls_horzSizer, flag=wx.CENTER )
        asp.AddSpacer( pnl_vertSizer, 10 )
        
        self.SetSizer( pnl_vertSizer )
        self.Layout()
        
    #end __init__
        
#end ComboSpinSliderCheckPanel class

