7 import  wx
.lib
.masked             
as  masked
 
   8 import  wx
.lib
.scrolledpanel      
as  scroll
 
  13     Centralized routines common to demo pages, to remove repetition. 
  15     def labelGeneralTable(self
, sizer
): 
  16         description 
= wx
.StaticText( self
, -1, "Description", ) 
  17         mask        
= wx
.StaticText( self
, -1, "Mask Value" ) 
  18         formatcode  
= wx
.StaticText( self
, -1, "Format" ) 
  19         regex       
= wx
.StaticText( self
, -1, "Regexp Validator(opt.)" ) 
  20         ctrl        
= wx
.StaticText( self
, -1, "Masked TextCtrl" ) 
  22         description
.SetFont( wx
.Font(9, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD
)) 
  23         mask
.SetFont( wx
.Font(9, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD
)) 
  24         formatcode
.SetFont( wx
.Font(9, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD
) ) 
  25         regex
.SetFont( wx
.Font(9, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD
)) 
  26         ctrl
.SetFont( wx
.Font(9, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD
)) 
  28         sizer
.Add(description
) 
  35     def layoutGeneralTable(self
, controls
, sizer
): 
  36         for control 
in controls
: 
  37             sizer
.Add( wx
.StaticText( self
, -1, control
[0]) ) 
  38             sizer
.Add( wx
.StaticText( self
, -1, control
[1]) ) 
  39             sizer
.Add( wx
.StaticText( self
, -1, control
[3]) ) 
  40             sizer
.Add( wx
.StaticText( self
, -1, control
[4]) ) 
  42             if control 
in controls
: 
  43                 newControl  
= masked
.TextCtrl( self
, -1, "", 
  45                                                 excludeChars 
= control
[2], 
  46                                                 formatcodes  
= control
[3], 
  48                                                 validRegex   
= control
[4], 
  49                                                 validRange   
= control
[5], 
  51                                                 choiceRequired 
= True, 
  52                                                 defaultValue 
= control
[7], 
  55             self
.editList
.append(newControl
) 
  59     def changeControlParams(self
, event
, parameter
, checked_value
, notchecked_value
): 
  60         if event
.IsChecked(): value 
= checked_value
 
  61         else:               value 
= notchecked_value
 
  63         kwargs 
= {parameter: value}
 
  65         for control 
in self
.editList
: 
  66             control
.SetCtrlParameters(**kwargs
) 
  73 #---------------------------------------------------------------------------- 
  74 class demoPage1(scroll
.ScrolledPanel
, demoMixin
): 
  75     def __init__(self
, parent
, log
): 
  76         scroll
.ScrolledPanel
.__init
__(self
, parent
, -1) 
  77         self
.sizer 
= wx
.BoxSizer( wx
.VERTICAL 
) 
  80         label 
= wx
.StaticText( self
, -1, """\ 
  81 Here are some basic masked TextCtrls to give you an idea of what you can do 
  82 with this control.  Note that all controls have been auto-sized by including 'F' in 
  85 Try entering nonsensical or partial values in validated fields to see what happens. 
  86 Note that the State and Last Name fields are list-limited (valid last names are: 
  87 Smith, Jones, Williams).  Signs on numbers can be toggled with the minus key. 
  89         label
.SetForegroundColour( "Blue" ) 
  90         header 
= wx
.BoxSizer( wx
.HORIZONTAL 
) 
  91         header
.Add( label
, 0, flag
=wx
.ALIGN_LEFT|wx
.ALL
, border 
= 5 ) 
  93         highlight 
= wx
.CheckBox( self
, -1, "Highlight Empty" ) 
  94         disallow 
=  wx
.CheckBox( self
, -1, "Disallow Empty" ) 
  95         showFill 
= wx
.CheckBox( self
, -1, "change fillChar" ) 
  97         vbox 
= wx
.BoxSizer( wx
.VERTICAL 
) 
  98         vbox
.Add( highlight
, 0, wx
.ALIGN_LEFT|wx
.ALL
, 5 ) 
  99         vbox
.Add( disallow
, 0, wx
.ALIGN_LEFT|wx
.ALL
, 5 ) 
 100         vbox
.Add( showFill
, 0, wx
.ALIGN_LEFT|wx
.ALL
, 5 ) 
 102         header
.Add(vbox
, 0, flag
=wx
.ALIGN_LEFT|wx
.ALL
, border
=5 ) 
 104         self
.Bind(wx
.EVT_CHECKBOX
, self
.onHighlightEmpty
, id=highlight
.GetId()) 
 105         self
.Bind(wx
.EVT_CHECKBOX
, self
.onDisallowEmpty
, id=disallow
.GetId()) 
 106         self
.Bind(wx
.EVT_CHECKBOX
, self
.onShowFill
, id=showFill
.GetId()) 
 108         grid 
= wx
.FlexGridSizer( 0, 5, vgap
=10, hgap
=10 ) 
 109         self
.labelGeneralTable(grid
) 
 111         # The following list is of the controls for the demo. Feel free to play around with 
 114         #description        mask                    excl format     regexp                              range,list,initial 
 115        ("Phone No",         "(###) ###-#### x:###", "", 'F^-',     "^\(\d{3}\) \d{3}-\d{4}",           '','',''), 
 116        ("Social Sec#",      "###-##-####",          "", 'F',        "\d{3}-\d{2}-\d{4}",                '','',''), 
 117        ("Full Name",        "C{14}",                "", 'F_',       '^[A-Z][a-zA-Z]+ [A-Z][a-zA-Z]+',   '','',''), 
 118        ("Last Name Only",   "C{14}",                "", 'F {list}', '^[A-Z][a-zA-Z]+',                  '',('Smith','Jones','Williams'),''), 
 119        ("Zip plus 4",       "#{5}-#{4}",            "", 'F',        "\d{5}-(\s{4}|\d{4})",              '','',''), 
 120        ("Customer No",      "\CAA-###",             "", 'F!',       "C[A-Z]{2}-\d{3}",                  '','',''), 
 121        ("Invoice Total",    "#{9}.##",              "", 'F-_,',     "",                                 '','',''), 
 122        ("Integer",          "#{9}",                 "", 'F-_',      "",                                 '','',''), 
 125         self
.layoutGeneralTable(controls
, grid
) 
 126         self
.sizer
.Add( header
, 0, flag
=wx
.ALIGN_LEFT|wx
.ALL
, border
=5 ) 
 127         self
.sizer
.Add( grid
, 0, flag
= wx
.ALIGN_LEFT|wx
.LEFT
, border
=5 ) 
 128         self
.SetSizer(self
.sizer
) 
 129         self
.SetupScrolling() 
 130         self
.SetAutoLayout(1) 
 133     def onDisallowEmpty( self
, event 
): 
 134         """ Set emptyInvalid parameter on/off """ 
 135         self
.changeControlParams( event
, "emptyInvalid", True, False ) 
 137     def onHighlightEmpty( self
, event 
): 
 138         """ Highlight empty values""" 
 139         self
.changeControlParams( event
, "emptyBackgroundColour", "Blue", "White" ) 
 141     def onShowFill( self
, event 
): 
 142         """ Set fillChar parameter to '?' or ' ' """ 
 143         self
.changeControlParams( event
, "fillChar", '?', ' ' ) 
 146 class demoPage2(scroll
.ScrolledPanel
, demoMixin
): 
 147     def __init__( self
, parent
, log 
): 
 149         scroll
.ScrolledPanel
.__init
__( self
, parent
, -1 ) 
 150         self
.sizer 
= wx
.BoxSizer( wx
.VERTICAL 
) 
 152         label 
= wx
.StaticText( self
, -1, """\ 
 153 All these controls have been created by passing a single parameter, the autoformat code, 
 154 and use the factory class masked.Ctrl with its default controlType. 
 155 The masked package contains an internal dictionary of types and formats (autoformats). 
 156 Many of these already do complicated validation; To see some examples, try 
 157 29 Feb 2002 vs. 2004 for the date formats, or email address validation. 
 160         label
.SetForegroundColour( "Blue" ) 
 161         self
.sizer
.Add( label
, 0, wx
.ALIGN_LEFT|wx
.ALL
, 5 ) 
 163         description 
= wx
.StaticText( self
, -1, "Description") 
 164         autofmt     
= wx
.StaticText( self
, -1, "AutoFormat Code") 
 165         ctrl        
= wx
.StaticText( self
, -1, "Masked Ctrl") 
 167         description
.SetFont( wx
.Font( 9, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD 
) ) 
 168         autofmt
.SetFont( wx
.Font( 9, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD 
) ) 
 169         ctrl
.SetFont( wx
.Font( 9, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD 
) ) 
 171         grid 
= wx
.FlexGridSizer( 0, 3, vgap
=10, hgap
=5 ) 
 172         grid
.Add( description
, 0, wx
.ALIGN_LEFT 
) 
 173         grid
.Add( autofmt
,     0, wx
.ALIGN_LEFT 
) 
 174         grid
.Add( ctrl
,        0, wx
.ALIGN_LEFT 
) 
 176         for autoformat
, desc 
in masked
.autoformats
: 
 177             grid
.Add( wx
.StaticText( self
, -1, desc
), 0, wx
.ALIGN_LEFT 
) 
 178             grid
.Add( wx
.StaticText( self
, -1, autoformat
), 0, wx
.ALIGN_LEFT 
) 
 179             grid
.Add( masked
.Ctrl( self
, -1, "", 
 180                                     autoformat       
= autoformat
, 
 185         self
.sizer
.Add( grid
, 0, wx
.ALIGN_LEFT|wx
.ALL
, border
=5 ) 
 186         self
.SetSizer( self
.sizer 
) 
 187         self
.SetAutoLayout( 1 ) 
 188         self
.SetupScrolling() 
 191 class demoPage3(scroll
.ScrolledPanel
, demoMixin
): 
 192     def __init__(self
, parent
, log
): 
 194         scroll
.ScrolledPanel
.__init
__(self
, parent
, -1) 
 195         self
.sizer 
= wx
.BoxSizer( wx
.VERTICAL 
) 
 198         label 
= wx
.StaticText( self
, -1, """\ 
 199 Here masked TextCtrls that have default values.  The states 
 200 control has a list of valid values, and the unsigned integer 
 201 has a legal range specified. 
 203         label
.SetForegroundColour( "Blue" ) 
 204         requireValid 
=  wx
.CheckBox( self
, -1, "Require Valid Value" ) 
 205         self
.Bind(wx
.EVT_CHECKBOX
, self
.onRequireValid
, id=requireValid
.GetId()) 
 207         header 
= wx
.BoxSizer( wx
.HORIZONTAL 
) 
 208         header
.Add( label
, 0, flag
=wx
.ALIGN_LEFT|wx
.ALL
, border 
= 5) 
 210         header
.Add( requireValid
, 0, flag
=wx
.ALIGN_LEFT|wx
.ALL
, border
=10 ) 
 212         grid 
= wx
.FlexGridSizer( 0, 5, vgap
=10, hgap
=10 ) 
 213         self
.labelGeneralTable( grid 
) 
 216         #description        mask                    excl format     regexp                              range,list,initial 
 217        ("U.S. State (2 char)",      "AA",            "", 'F!_',       "[A-Z]{2}",                         '', masked
.states
, masked
.states
[0]), 
 218        ("Integer (signed)",         "#{6}",          "", 'F-_',       "",                                 '','', ' 0    '), 
 219        ("Integer (unsigned)\n(1-399)","######",      "", 'F_',        "",                                 (1,399),'', '1     '), 
 220        ("Float (signed)",           "#{6}.#{9}",     "", 'F-_R',      "",                                 '','', '000000.000000000'), 
 221        ("Date (MDY) + Time",        "##/##/#### ##:##:## AM",  'BCDEFGHIJKLMNOQRSTUVWXYZ','DF!',"",          '','', wx
.DateTime_Now().Format("%m/%d/%Y %I:%M:%S %p")), 
 223         self
.layoutGeneralTable( controls
, grid 
) 
 225         self
.sizer
.Add( header
, 0, flag
=wx
.ALIGN_LEFT|wx
.ALL
, border
=5 ) 
 226         self
.sizer
.Add( grid
, 0, flag
=wx
.ALIGN_LEFT|wx
.ALL
, border
=5 ) 
 228         self
.SetSizer( self
.sizer 
) 
 229         self
.SetAutoLayout( 1 ) 
 230         self
.SetupScrolling() 
 232     def onRequireValid( self
, event 
): 
 233         """ Set validRequired parameter on/off """ 
 234         self
.changeControlParams( event
, "validRequired", True, False ) 
 237 class demoPage4(scroll
.ScrolledPanel
, demoMixin
): 
 238     def __init__( self
, parent
, log 
): 
 240         scroll
.ScrolledPanel
.__init
__( self
, parent
, -1 ) 
 241         self
.sizer 
= wx
.BoxSizer( wx
.VERTICAL 
) 
 243         label 
= wx
.StaticText( self
, -1, """\ 
 244 These controls have field-specific choice lists and allow autocompletion. 
 246 Down arrow or Page Down in an uncompleted field with an auto-completable field will attempt 
 247 to auto-complete a field if it has a choice list. 
 248 Page Down and Shift-Down arrow will also auto-complete, or cycle through the complete list. 
 249 Page Up and Shift-Up arrow will similarly cycle backwards through the list. 
 252         label
.SetForegroundColour( "Blue" ) 
 253         self
.sizer
.Add( label
, 0, wx
.ALIGN_LEFT|wx
.ALL
, 5 ) 
 255         description  
= wx
.StaticText( self
, -1, "Description" ) 
 256         autofmt      
= wx
.StaticText( self
, -1, "AutoFormat Code" ) 
 257         fields       
= wx
.StaticText( self
, -1, "Field Objects" ) 
 258         ctrl         
= wx
.StaticText( self
, -1, "Masked TextCtrl" ) 
 260         description
.SetFont( wx
.Font( 9, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD 
) ) 
 261         autofmt
.SetFont( wx
.Font( 9, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD 
) ) 
 262         fields
.SetFont( wx
.Font( 9, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD 
) ) 
 263         ctrl
.SetFont( wx
.Font( 9, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD 
) ) 
 265         grid 
= wx
.FlexGridSizer( 0, 4, vgap
=10, hgap
=10 ) 
 266         grid
.Add( description
, 0, wx
.ALIGN_LEFT 
) 
 267         grid
.Add( autofmt
,     0, wx
.ALIGN_LEFT 
) 
 268         grid
.Add( fields
,      0, wx
.ALIGN_LEFT 
) 
 269         grid
.Add( ctrl
,        0, wx
.ALIGN_LEFT 
) 
 271         autoformat 
= "USPHONEFULLEXT" 
 272         fieldsDict 
= {0: masked.Field(choices=["617","781","508","978","413"], choiceRequired=True)}
 
 277           choiceRequired=True)}""" 
 278         grid
.Add( wx
.StaticText( self
, -1, "Restricted Area Code"), 0, wx
.ALIGN_LEFT 
) 
 279         grid
.Add( wx
.StaticText( self
, -1, autoformat
), 0, wx
.ALIGN_LEFT 
) 
 280         grid
.Add( wx
.StaticText( self
, -1, fieldsLabel
), 0, wx
.ALIGN_LEFT 
) 
 281         grid
.Add( masked
.TextCtrl( self
, -1, "", 
 282                                     autoformat       
= autoformat
, 
 288         autoformat 
= "EXPDATEMMYY" 
 289         fieldsDict 
= {1: masked.Field(choices=["03", "04", "05"], choiceRequired=True)}
 
 293           choiceRequired=True)}""" 
 294         exp 
=  masked
.TextCtrl( self
, -1, "", 
 295                                  autoformat       
= autoformat
, 
 300         grid
.Add( wx
.StaticText( self
, -1, "Restricted Expiration"), 0, wx
.ALIGN_LEFT 
) 
 301         grid
.Add( wx
.StaticText( self
, -1, autoformat
), 0, wx
.ALIGN_LEFT 
) 
 302         grid
.Add( wx
.StaticText( self
, -1, fieldsLabel
), 0, wx
.ALIGN_LEFT 
) 
 303         grid
.Add( exp
, 0, wx
.ALIGN_LEFT 
) 
 305         fieldsDict 
= {0: masked
.Field(choices
=["02134","02155"], choiceRequired
=True), 
 306                       1: masked
.Field(choices
=["1234", "5678"],  choiceRequired
=False)} 
 308 {0: Field(choices=["02134","02155"], 
 309           choiceRequired=True), 
 310  1: Field(choices=["1234", "5678"], 
 311           choiceRequired=False)}""" 
 312         autoformat 
= "USZIPPLUS4" 
 313         zip =  masked
.TextCtrl( self
, -1, "", 
 314                                  autoformat       
= autoformat
, 
 319         grid
.Add( wx
.StaticText( self
, -1, "Restricted Zip + 4"), 0, wx
.ALIGN_LEFT 
) 
 320         grid
.Add( wx
.StaticText( self
, -1, autoformat
), 0, wx
.ALIGN_LEFT 
) 
 321         grid
.Add( wx
.StaticText( self
, -1, fieldsLabel
), 0, wx
.ALIGN_LEFT 
) 
 322         grid
.Add( zip, 0, wx
.ALIGN_LEFT 
) 
 324         self
.sizer
.Add( grid
, 0, wx
.ALIGN_LEFT|wx
.ALL
, border
=5 ) 
 325         self
.SetSizer( self
.sizer 
) 
 326         self
.SetAutoLayout(1) 
 327         self
.SetupScrolling() 
 330 class demoPage5(scroll
.ScrolledPanel
, demoMixin
): 
 331     def __init__( self
, parent
, log 
): 
 333         scroll
.ScrolledPanel
.__init
__( self
, parent
, -1 ) 
 334         self
.sizer 
= wx
.BoxSizer( wx
.VERTICAL 
) 
 337         labelMaskedCombos 
= wx
.StaticText( self
, -1, """\ 
 338 These are some examples of masked.ComboBox:""") 
 339         labelMaskedCombos
.SetForegroundColour( "Blue" ) 
 342         label_statecode 
= wx
.StaticText( self
, -1, """\ 
 343 A state selector; only 
 344 "legal" values can be 
 346         statecode 
= masked
.ComboBox( self
, -1, masked
.states
[0], 
 347                                   choices 
= masked
.states
, 
 348                                   autoformat
="USSTATE") 
 350         label_statename 
= wx
.StaticText( self
, -1, """\ 
 351 A state name selector, 
 352 with auto-select:""") 
 354         # Create this one using factory function: 
 355         statename 
= masked
.Ctrl( self
, -1, masked
.state_names
[0], 
 356                                   controlType 
= masked
.controlTypes
.COMBO
, 
 357                                   choices 
= masked
.state_names
, 
 358                                   autoformat
="USSTATENAME", 
 360         statename
.SetCtrlParameters(formatcodes 
= 'F!V_') 
 363         numerators 
= [ str(i
) for i 
in range(1, 4) ] 
 364         denominators 
= [ string
.ljust(str(i
), 2) for i 
in [2,3,4,5,8,16,32,64] ] 
 365         fieldsDict 
= {0: masked
.Field(choices
=numerators
, choiceRequired
=False), 
 366                       1: masked
.Field(choices
=denominators
, choiceRequired
=True)} 
 369             for d 
in denominators
: 
 371                     choices
.append( '%s/%s' % (n
,d
) ) 
 374         label_fraction 
= wx
.StaticText( self
, -1, """\ 
 375 A masked ComboBox for fraction selection. 
 376 Choices for each side of the fraction can 
 377 be selected with PageUp/Down:""") 
 379         fraction 
= masked
.Ctrl( self
, -1, "", 
 380                                  controlType 
= masked
.controlTypes
.COMBO
, 
 382                                  choiceRequired 
= True, 
 385                                  validRegex 
= "^\d\/\d\d?", 
 386                                  fields 
= fieldsDict 
) 
 389         label_code 
= wx
.StaticText( self
, -1, """\ 
 390 A masked ComboBox to validate 
 391 text from a list of numeric codes:""") 
 393         choices 
= ["91", "136", "305", "4579"] 
 394         code 
= masked
.ComboBox( self
, -1, choices
[0], 
 396                                  choiceRequired 
= True, 
 400         label_selector 
= wx
.StaticText( self
, -1, """\ 
 403         self
.list_selector 
= wx
.ComboBox(self
, -1, '', choices 
= ['list1', 'list2', 'list3']) 
 404         self
.dynamicbox 
= masked
.Ctrl( self
, -1, '    ', 
 405                                       controlType 
= masked
.controlTypes
.COMBO
, 
 408                                       # these are to give dropdown some initial height, 
 409                                       # as base control apparently only sets that size 
 410                                       # during initial construction <sigh>: 
 411                                       choices 
= ['', '1', '2', '3', '4', '5'] ) 
 413         self
.dynamicbox
.Clear()   # get rid of initial choices used to size the dropdown 
 416         labelIpAddrs 
= wx
.StaticText( self
, -1, """\ 
 417 Here are some examples of IpAddrCtrl, a control derived from masked.TextCtrl:""") 
 418         labelIpAddrs
.SetForegroundColour( "Blue" ) 
 421         label_ipaddr1 
= wx
.StaticText( self
, -1, "An empty control:") 
 422         ipaddr1 
= masked
.IpAddrCtrl( self
, -1, style 
= wx
.TE_PROCESS_TAB 
) 
 425         label_ipaddr2 
= wx
.StaticText( self
, -1, "A restricted mask:") 
 426         ipaddr2 
= masked
.IpAddrCtrl( self
, -1, mask
=" 10.  1.109.###" ) 
 429         label_ipaddr3 
= wx
.StaticText( self
, -1, """\ 
 430 A control with restricted legal values: 
 431 10. (1|2) . (129..255) . (0..255)""") 
 432         ipaddr3 
= masked
.Ctrl( self
, -1, 
 433                                 controlType 
= masked
.controlTypes
.IPADDR
, 
 434                                 mask
=" 10.  #.###.###") 
 435         ipaddr3
.SetFieldParameters(0, validRegex
="1|2",validRequired
=False )   # requires entry to match or not allowed 
 437         # This allows any value in penultimate field, but colors anything outside of the range invalid: 
 438         ipaddr3
.SetFieldParameters(1, validRange
=(129,255), validRequired
=False ) 
 442         labelNumerics 
= wx
.StaticText( self
, -1, """\ 
 443 Here are some useful configurations of a masked.TextCtrl for integer and floating point input that still treat 
 444 the control as a text control.  (For a true numeric control, check out the masked.NumCtrl class!)""") 
 445         labelNumerics
.SetForegroundColour( "Blue" ) 
 447         label_intctrl1 
= wx
.StaticText( self
, -1, """\ 
 448 An integer entry control with 
 449 shifting insert enabled:""") 
 450         self
.intctrl1 
= masked
.TextCtrl(self
, -1, name
='intctrl', mask
="#{9}", formatcodes 
= '_-,F>') 
 451         label_intctrl2 
= wx
.StaticText( self
, -1, """\ 
 452      Right-insert integer entry:""") 
 453         self
.intctrl2 
= masked
.TextCtrl(self
, -1, name
='intctrl', mask
="#{9}", formatcodes 
= '_-,Fr') 
 455         label_floatctrl 
= wx
.StaticText( self
, -1, """\ 
 456 A floating point entry control 
 457 with right-insert for ordinal:""") 
 458         self
.floatctrl 
= masked
.TextCtrl(self
, -1, name
='floatctrl', mask
="#{9}.#{2}", formatcodes
="F,_-R", useParensForNegatives
=False) 
 459         self
.floatctrl
.SetFieldParameters(0, formatcodes
='r<', validRequired
=True)  # right-insert, require explicit cursor movement to change fields 
 460         self
.floatctrl
.SetFieldParameters(1, defaultValue
='00')                     # don't allow blank fraction 
 462         label_numselect 
= wx
.StaticText( self
, -1, """\ 
 463 <= Programmatically set the value 
 464      of the float entry ctrl:""") 
 465         numselect 
= wx
.ComboBox(self
, -1, choices 
= [ '', '111', '222.22', '-3', '54321.666666666', '-1353.978', 
 466                                                      '1234567', '-1234567', '123456789', '-123456789.1', 
 467                                                      '1234567890.', '-1234567890.1' ]) 
 469         parens_check 
= wx
.CheckBox(self
, -1, "Use () to indicate negatives in above controls") 
 473         gridCombos 
= wx
.FlexGridSizer( 0, 4, vgap
=10, hgap 
= 10 ) 
 474         gridCombos
.Add( label_statecode
, 0, wx
.ALIGN_LEFT 
) 
 475         gridCombos
.Add( statecode
, 0, wx
.ALIGN_LEFT 
) 
 476         gridCombos
.Add( label_fraction
, 0, wx
.ALIGN_LEFT 
) 
 477         gridCombos
.Add( fraction
, 0, wx
.ALIGN_LEFT 
) 
 478         gridCombos
.Add( label_statename
, 0, wx
.ALIGN_LEFT 
) 
 479         gridCombos
.Add( statename
, 0, wx
.ALIGN_LEFT 
) 
 480         gridCombos
.Add( label_code
, 0, wx
.ALIGN_LEFT 
) 
 481         gridCombos
.Add( code
, 0, wx
.ALIGN_LEFT 
) 
 482         gridCombos
.Add( label_selector
, 0, wx
.ALIGN_LEFT
) 
 483         hbox 
= wx
.BoxSizer( wx
.HORIZONTAL 
) 
 484         hbox
.Add( self
.list_selector
, 0, wx
.ALIGN_LEFT 
) 
 485         hbox
.Add(wx
.StaticText(self
, -1, ' => '), 0, wx
.ALIGN_LEFT
) 
 486         hbox
.Add( self
.dynamicbox
, 0, wx
.ALIGN_LEFT 
) 
 487         gridCombos
.Add( hbox
, 0, wx
.ALIGN_LEFT 
) 
 489         gridIpAddrs 
= wx
.FlexGridSizer( 0, 4, vgap
=10, hgap 
= 15 ) 
 490         gridIpAddrs
.Add( label_ipaddr1
, 0, wx
.ALIGN_LEFT 
) 
 491         gridIpAddrs
.Add( ipaddr1
, 0, wx
.ALIGN_LEFT 
) 
 492         gridIpAddrs
.Add( label_ipaddr2
, 0, wx
.ALIGN_LEFT 
) 
 493         gridIpAddrs
.Add( ipaddr2
, 0, wx
.ALIGN_LEFT 
) 
 494         gridIpAddrs
.Add( label_ipaddr3
, 0, wx
.ALIGN_LEFT 
) 
 495         gridIpAddrs
.Add( ipaddr3
, 0, wx
.ALIGN_LEFT 
) 
 497         gridNumerics 
= wx
.FlexGridSizer( 0, 4, vgap
=10, hgap 
= 10 ) 
 498         gridNumerics
.Add( label_intctrl1
, 0, wx
.ALIGN_LEFT 
) 
 499         gridNumerics
.Add( self
.intctrl1
, 0, wx
.ALIGN_LEFT 
) 
 500         gridNumerics
.Add( label_intctrl2
, 0, wx
.ALIGN_RIGHT 
) 
 501         gridNumerics
.Add( self
.intctrl2
, 0, wx
.ALIGN_LEFT 
) 
 502         gridNumerics
.Add( label_floatctrl
, 0, wx
.ALIGN_LEFT 
) 
 503         gridNumerics
.Add( self
.floatctrl
, 0, wx
.ALIGN_LEFT 
) 
 504         gridNumerics
.Add( label_numselect
, 0, wx
.ALIGN_RIGHT 
) 
 505         gridNumerics
.Add( numselect
, 0, wx
.ALIGN_LEFT 
) 
 507         self
.sizer
.Add( labelMaskedCombos
, 0, wx
.ALIGN_LEFT|wx
.ALL
, 5 ) 
 508         self
.sizer
.Add( gridCombos
, 0, wx
.ALIGN_LEFT|wx
.ALL
, border
=5 ) 
 509         self
.sizer
.Add( wx
.StaticLine(self
, -1), 0, wx
.EXPAND|wx
.TOP|wx
.BOTTOM
, border
=8 ) 
 510         self
.sizer
.Add( labelIpAddrs
, 0, wx
.ALIGN_LEFT|wx
.ALL
, 5 ) 
 511         self
.sizer
.Add( gridIpAddrs
, 0, wx
.ALIGN_LEFT|wx
.ALL
, border
=5 ) 
 512         self
.sizer
.Add( wx
.StaticLine(self
, -1), 0, wx
.EXPAND|wx
.TOP|wx
.BOTTOM
, border
=8 ) 
 513         self
.sizer
.Add( labelNumerics
, 0, wx
.ALIGN_LEFT|wx
.ALL
, 5 ) 
 514         self
.sizer
.Add( gridNumerics
, 0, wx
.ALIGN_LEFT|wx
.ALL
, border
=5 ) 
 515         self
.sizer
.Add( parens_check
, 0, wx
.ALIGN_LEFT|wx
.ALL
, 5 ) 
 517         self
.SetSizer( self
.sizer 
) 
 518         self
.SetAutoLayout(1) 
 519         self
.SetupScrolling() 
 521         self
.Bind(wx
.EVT_COMBOBOX
, self
.OnComboSelection
, id=fraction
.GetId()) 
 522         self
.Bind(wx
.EVT_COMBOBOX
, self
.OnComboSelection
, id=code
.GetId()) 
 523         self
.Bind(wx
.EVT_COMBOBOX
, self
.OnComboSelection
, id=statecode
.GetId()) 
 524         self
.Bind(wx
.EVT_COMBOBOX
, self
.OnComboSelection
, id=statename
.GetId()) 
 525         self
.Bind(wx
.EVT_TEXT
, self
.OnTextChange
, id=code
.GetId()) 
 526         self
.Bind(wx
.EVT_TEXT
, self
.OnTextChange
, id=statecode
.GetId()) 
 527         self
.Bind(wx
.EVT_TEXT
, self
.OnTextChange
, id=statename
.GetId()) 
 528         self
.Bind(wx
.EVT_COMBOBOX
, self
.OnListSelection
, id=self
.list_selector
.GetId()) 
 530         self
.Bind(wx
.EVT_TEXT
, self
.OnTextChange
, id=self
.intctrl1
.GetId()) 
 531         self
.Bind(wx
.EVT_TEXT
, self
.OnTextChange
, id=self
.intctrl2
.GetId()) 
 532         self
.Bind(wx
.EVT_TEXT
, self
.OnTextChange
, id=self
.floatctrl
.GetId()) 
 533         self
.Bind(wx
.EVT_COMBOBOX
, self
.OnNumberSelect
, id=numselect
.GetId()) 
 534         self
.Bind(wx
.EVT_CHECKBOX
, self
.OnParensCheck
, id=parens_check
.GetId()) 
 536         self
.Bind(wx
.EVT_TEXT
, self
.OnIpAddrChange
, id=ipaddr1
.GetId()) 
 537         self
.Bind(wx
.EVT_TEXT
, self
.OnIpAddrChange
, id=ipaddr2
.GetId()) 
 538         self
.Bind(wx
.EVT_TEXT
, self
.OnIpAddrChange
, id=ipaddr3
.GetId()) 
 543     def OnComboSelection( self
, event 
): 
 544         ctl 
= self
.FindWindowById( event
.GetId() ) 
 545         if not ctl
.IsValid(): 
 546             self
.log
.write('current value not a valid choice') 
 547         self
.log
.write('new value = %s' % ctl
.GetValue()) 
 549     def OnTextChange( self
, event 
): 
 550         ctl 
= self
.FindWindowById( event
.GetId() ) 
 552             self
.log
.write('new value = %s\n' % ctl
.GetValue() ) 
 554     def OnNumberSelect( self
, event 
): 
 555         value 
= event
.GetString() 
 556         # Format choice to fit into format for #{9}.#{2}, with sign position reserved: 
 557         # (ordinal + fraction == 11 + decimal point + sign == 13) 
 559             floattext 
= "%13.2f" % float(value
) 
 561             floattext 
= value   
# clear the value again 
 563             self
.floatctrl
.SetValue(floattext
) 
 565             type, value
, tb 
= sys
.exc_info() 
 566             for line 
in traceback
.format_exception_only(type, value
): 
 569     def OnParensCheck( self
, event 
): 
 570         self
.intctrl1
.SetCtrlParameters(useParensForNegatives
=event
.IsChecked()) 
 571         self
.intctrl2
.SetCtrlParameters(useParensForNegatives
=event
.IsChecked()) 
 572         self
.floatctrl
.SetCtrlParameters(useParensForNegatives
=event
.IsChecked()) 
 574     def OnIpAddrChange( self
, event 
): 
 575         ipaddr 
= self
.FindWindowById( event
.GetId() ) 
 577             self
.log
.write('new addr = %s\n' % ipaddr
.GetAddress() ) 
 579     def OnListSelection( self
, event 
): 
 580         list = self
.list_selector
.GetStringSelection() 
 583             choices 
= ['abc', 'defg', 'hi'] 
 585         elif list == 'list2': 
 586             choices 
= ['1', '2', '34', '567'] 
 590             choices 
= masked
.states
 
 593         self
.dynamicbox
.SetCtrlParameters( mask 
= mask
, 
 597                                            formatcodes
=formatcodes
) 
 598         self
.dynamicbox
.SetValue(choices
[0]) 
 600 # --------------------------------------------------------------------- 
 601 class TestMaskedTextCtrls(wx
.Notebook
): 
 602     def __init__(self
, parent
, id, log
): 
 603         wx
.Notebook
.__init
__(self
, parent
, id) 
 606         win 
= demoPage1(self
, log
) 
 607         self
.AddPage(win
, "General examples") 
 609         win 
= demoPage2(self
, log
) 
 610         self
.AddPage(win
, 'Auto-formatted controls') 
 612         win 
= demoPage3(self
, log
) 
 613         self
.AddPage(win
, "Using default values") 
 615         win 
= demoPage4(self
, log
) 
 616         self
.AddPage(win
, 'Using auto-complete fields') 
 618         win 
= demoPage5(self
, log
) 
 619         self
.AddPage(win
, 'Other masked controls') 
 622 #---------------------------------------------------------------------------- 
 624 def runTest(frame
, nb
, log
): 
 625     testWin 
= TestMaskedTextCtrls(nb
, -1, log
) 
 629     app 
= wx
.PySimpleApp() 
 630     frame 
= wx
.Frame(None, -1, "Test MaskedEditCtrls", size
=(640, 480)) 
 631     win 
= TestMaskedTextCtrls(frame
, -1, sys
.stdout
) 
 634 #---------------------------------------------------------------------------- 
 635 import wx
.lib
.masked
.maskededit 
as maskededit
 
 636 # strip out module header used for pydoc: 
 637 demodoc 
= '\n'.join(maskededit
.__doc
__.split('\n')[2:]) 
 644 if __name__ 
== "__main__": 
 647     run
.main(['', os
.path
.basename(sys
.argv
[0])] + sys
.argv
[1:])