1 # 11/23/2003 - Jeff Grimmett (grimmtooth@softhome.net)
3 # o Updated for wx namespace
5 # 11/26/2003 - Jeff Grimmett (grimmtooth@softhome.net)
7 # o the three libraries below all have not been hit by the
10 # 12/09/2003 - Jeff Grimmett (grimmtooth@softhome.net)
12 # o A few changes to correct my own mistakes earlier :-).
14 # 12/20/2003 - Jeff Grimmett (grimmtooth@softhome.net)
16 # o wxMaskedTextCtrl -> MaskedTextCtrl
17 # o wxMaskedComboBox -> MaskedComboBox
18 # o wxIpAddrCtrl -> IpAddrCtrl
19 # o wxMaskedNumCtrl -> MaskedNumCtrl
20 # o wxTimeCtrl -> TimeCtrl
21 # o wxScrolledPanel -> ScrolledPanel
29 import wx
.lib
.maskededit
as med
30 import wx
.lib
.maskedctrl
as mctl
31 import wx
.lib
.scrolledpanel
as scroll
36 Centralized routines common to demo pages, to remove repetition.
38 def labelGeneralTable(self
, sizer
):
39 description
= wx
.StaticText( self
, -1, "Description", )
40 mask
= wx
.StaticText( self
, -1, "Mask Value" )
41 formatcode
= wx
.StaticText( self
, -1, "Format" )
42 regex
= wx
.StaticText( self
, -1, "Regexp Validator(opt.)" )
43 ctrl
= wx
.StaticText( self
, -1, "MaskedTextCtrl" )
45 description
.SetFont( wx
.Font(9, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD
))
46 mask
.SetFont( wx
.Font(9, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD
))
47 formatcode
.SetFont( wx
.Font(9, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD
) )
48 regex
.SetFont( wx
.Font(9, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD
))
49 ctrl
.SetFont( wx
.Font(9, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD
))
51 sizer
.Add(description
)
58 def layoutGeneralTable(self
, controls
, sizer
):
59 for control
in controls
:
60 sizer
.Add( wx
.StaticText( self
, -1, control
[0]) )
61 sizer
.Add( wx
.StaticText( self
, -1, control
[1]) )
62 sizer
.Add( wx
.StaticText( self
, -1, control
[3]) )
63 sizer
.Add( wx
.StaticText( self
, -1, control
[4]) )
65 if control
in controls
:
66 newControl
= med
.MaskedTextCtrl( self
, -1, "",
68 excludeChars
= control
[2],
69 formatcodes
= control
[3],
71 validRegex
= control
[4],
72 validRange
= control
[5],
74 choiceRequired
= True,
75 defaultValue
= control
[7],
78 self
.editList
.append(newControl
)
82 def changeControlParams(self
, event
, parameter
, checked_value
, notchecked_value
):
83 if event
.IsChecked(): value
= checked_value
84 else: value
= notchecked_value
86 kwargs
= {parameter: value}
88 for control
in self
.editList
:
89 control
.SetCtrlParameters(**kwargs
)
96 #----------------------------------------------------------------------------
97 class demoPage1(scroll
.ScrolledPanel
, demoMixin
):
98 def __init__(self
, parent
, log
):
99 scroll
.ScrolledPanel
.__init
__(self
, parent
, -1)
100 self
.sizer
= wx
.BoxSizer( wx
.VERTICAL
)
103 label
= wx
.StaticText( self
, -1, """\
104 Here are some basic MaskedTextCtrls to give you an idea of what you can do
105 with this control. Note that all controls have been auto-sized by including 'F' in
108 Try entering nonsensical or partial values in validated fields to see what happens.
109 Note that the State and Last Name fields are list-limited (valid last names are:
110 Smith, Jones, Williams). Signs on numbers can be toggled with the minus key.
112 label
.SetForegroundColour( "Blue" )
113 header
= wx
.BoxSizer( wx
.HORIZONTAL
)
114 header
.Add( label
, 0, flag
=wx
.ALIGN_LEFT|wx
.ALL
, border
= 5 )
116 highlight
= wx
.CheckBox( self
, -1, "Highlight Empty" )
117 disallow
= wx
.CheckBox( self
, -1, "Disallow Empty" )
118 showFill
= wx
.CheckBox( self
, -1, "change fillChar" )
120 vbox
= wx
.BoxSizer( wx
.VERTICAL
)
121 vbox
.Add( highlight
, 0, wx
.ALIGN_LEFT|wx
.ALL
, 5 )
122 vbox
.Add( disallow
, 0, wx
.ALIGN_LEFT|wx
.ALL
, 5 )
123 vbox
.Add( showFill
, 0, wx
.ALIGN_LEFT|wx
.ALL
, 5 )
125 header
.Add(vbox
, 0, flag
=wx
.ALIGN_LEFT|wx
.ALL
, border
=5 )
127 self
.Bind(wx
.EVT_CHECKBOX
, self
.onHighlightEmpty
, id=highlight
.GetId())
128 self
.Bind(wx
.EVT_CHECKBOX
, self
.onDisallowEmpty
, id=disallow
.GetId())
129 self
.Bind(wx
.EVT_CHECKBOX
, self
.onShowFill
, id=showFill
.GetId())
131 grid
= wx
.FlexGridSizer( 0, 5, vgap
=10, hgap
=10 )
132 self
.labelGeneralTable(grid
)
134 # The following list is of the controls for the demo. Feel free to play around with
137 #description mask excl format regexp range,list,initial
138 ("Phone No", "(###) ###-#### x:###", "", 'F^-', "^\(\d{3}\) \d{3}-\d{4}", '','',''),
139 ("Social Sec#", "###-##-####", "", 'F', "\d{3}-\d{2}-\d{4}", '','',''),
140 ("Full Name", "C{14}", "", 'F_', '^[A-Z][a-zA-Z]+ [A-Z][a-zA-Z]+', '','',''),
141 ("Last Name Only", "C{14}", "", 'F {list}', '^[A-Z][a-zA-Z]+', '',('Smith','Jones','Williams'),''),
142 ("Zip plus 4", "#{5}-#{4}", "", 'F', "\d{5}-(\s{4}|\d{4})", '','',''),
143 ("Customer No", "\CAA-###", "", 'F!', "C[A-Z]{2}-\d{3}", '','',''),
144 ("Invoice Total", "#{9}.##", "", 'F-_,', "", '','',''),
145 ("Integer", "#{9}", "", 'F-_', "", '','',''),
148 self
.layoutGeneralTable(controls
, grid
)
149 self
.sizer
.Add( header
, 0, flag
=wx
.ALIGN_LEFT|wx
.ALL
, border
=5 )
150 self
.sizer
.Add( grid
, 0, flag
= wx
.ALIGN_LEFT|wx
.LEFT
, border
=5 )
151 self
.SetSizer(self
.sizer
)
152 self
.SetupScrolling()
153 self
.SetAutoLayout(1)
156 def onDisallowEmpty( self
, event
):
157 """ Set emptyInvalid parameter on/off """
158 self
.changeControlParams( event
, "emptyInvalid", True, False )
160 def onHighlightEmpty( self
, event
):
161 """ Highlight empty values"""
162 self
.changeControlParams( event
, "emptyBackgroundColour", "Blue", "White" )
164 def onShowFill( self
, event
):
165 """ Set fillChar parameter to '?' or ' ' """
166 self
.changeControlParams( event
, "fillChar", '?', ' ' )
169 class demoPage2(scroll
.ScrolledPanel
, demoMixin
):
170 def __init__( self
, parent
, log
):
172 scroll
.ScrolledPanel
.__init
__( self
, parent
, -1 )
173 self
.sizer
= wx
.BoxSizer( wx
.VERTICAL
)
175 label
= wx
.StaticText( self
, -1, """\
176 All these controls have been created by passing a single parameter, the autoformat code,
177 and use the factory class MaskedCtrl with its default controlType.
178 The maskededit module contains an internal dictionary of types and formats (autoformats).
179 Many of these already do complicated validation; To see some examples, try
180 29 Feb 2002 vs. 2004 for the date formats, or email address validation.
183 label
.SetForegroundColour( "Blue" )
184 self
.sizer
.Add( label
, 0, wx
.ALIGN_LEFT|wx
.ALL
, 5 )
186 description
= wx
.StaticText( self
, -1, "Description")
187 autofmt
= wx
.StaticText( self
, -1, "AutoFormat Code")
188 ctrl
= wx
.StaticText( self
, -1, "MaskedCtrl")
190 description
.SetFont( wx
.Font( 9, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD
) )
191 autofmt
.SetFont( wx
.Font( 9, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD
) )
192 ctrl
.SetFont( wx
.Font( 9, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD
) )
194 grid
= wx
.FlexGridSizer( 0, 3, vgap
=10, hgap
=5 )
195 grid
.Add( description
, 0, wx
.ALIGN_LEFT
)
196 grid
.Add( autofmt
, 0, wx
.ALIGN_LEFT
)
197 grid
.Add( ctrl
, 0, wx
.ALIGN_LEFT
)
199 for autoformat
, desc
in med
.autoformats
:
200 grid
.Add( wx
.StaticText( self
, -1, desc
), 0, wx
.ALIGN_LEFT
)
201 grid
.Add( wx
.StaticText( self
, -1, autoformat
), 0, wx
.ALIGN_LEFT
)
202 grid
.Add( mctl
.MaskedCtrl( self
, -1, "",
203 autoformat
= autoformat
,
208 self
.sizer
.Add( grid
, 0, wx
.ALIGN_LEFT|wx
.ALL
, border
=5 )
209 self
.SetSizer( self
.sizer
)
210 self
.SetAutoLayout( 1 )
211 self
.SetupScrolling()
214 class demoPage3(scroll
.ScrolledPanel
, demoMixin
):
215 def __init__(self
, parent
, log
):
217 scroll
.ScrolledPanel
.__init
__(self
, parent
, -1)
218 self
.sizer
= wx
.BoxSizer( wx
.VERTICAL
)
221 label
= wx
.StaticText( self
, -1, """\
222 Here MaskedTextCtrls that have default values. The states
223 control has a list of valid values, and the unsigned integer
224 has a legal range specified.
226 label
.SetForegroundColour( "Blue" )
227 requireValid
= wx
.CheckBox( self
, -1, "Require Valid Value" )
228 self
.Bind(wx
.EVT_CHECKBOX
, self
.onRequireValid
, id=requireValid
.GetId())
230 header
= wx
.BoxSizer( wx
.HORIZONTAL
)
231 header
.Add( label
, 0, flag
=wx
.ALIGN_LEFT|wx
.ALL
, border
= 5)
233 header
.Add( requireValid
, 0, flag
=wx
.ALIGN_LEFT|wx
.ALL
, border
=10 )
235 grid
= wx
.FlexGridSizer( 0, 5, vgap
=10, hgap
=10 )
236 self
.labelGeneralTable( grid
)
239 #description mask excl format regexp range,list,initial
240 ("U.S. State (2 char)", "AA", "", 'F!_', "[A-Z]{2}", '',med
.states
, med
.states
[0]),
241 ("Integer (signed)", "#{6}", "", 'F-_', "", '','', ' 0 '),
242 ("Integer (unsigned)\n(1-399)","######", "", 'F_', "", (1,399),'', '1 '),
243 ("Float (signed)", "#{6}.#{9}", "", 'F-_R', "", '','', '000000.000000000'),
244 ("Date (MDY) + Time", "##/##/#### ##:##:## AM", 'BCDEFGHIJKLMNOQRSTUVWXYZ','DF!',"", '','', wx
.DateTime_Now().Format("%m/%d/%Y %I:%M:%S %p")),
246 self
.layoutGeneralTable( controls
, grid
)
248 self
.sizer
.Add( header
, 0, flag
=wx
.ALIGN_LEFT|wx
.ALL
, border
=5 )
249 self
.sizer
.Add( grid
, 0, flag
=wx
.ALIGN_LEFT|wx
.ALL
, border
=5 )
251 self
.SetSizer( self
.sizer
)
252 self
.SetAutoLayout( 1 )
253 self
.SetupScrolling()
255 def onRequireValid( self
, event
):
256 """ Set validRequired parameter on/off """
257 self
.changeControlParams( event
, "validRequired", True, False )
260 class demoPage4(scroll
.ScrolledPanel
, demoMixin
):
261 def __init__( self
, parent
, log
):
263 scroll
.ScrolledPanel
.__init
__( self
, parent
, -1 )
264 self
.sizer
= wx
.BoxSizer( wx
.VERTICAL
)
266 label
= wx
.StaticText( self
, -1, """\
267 These controls have field-specific choice lists and allow autocompletion.
269 Down arrow or Page Down in an uncompleted field with an auto-completable field will attempt
270 to auto-complete a field if it has a choice list.
271 Page Down and Shift-Down arrow will also auto-complete, or cycle through the complete list.
272 Page Up and Shift-Up arrow will similarly cycle backwards through the list.
275 label
.SetForegroundColour( "Blue" )
276 self
.sizer
.Add( label
, 0, wx
.ALIGN_LEFT|wx
.ALL
, 5 )
278 description
= wx
.StaticText( self
, -1, "Description" )
279 autofmt
= wx
.StaticText( self
, -1, "AutoFormat Code" )
280 fields
= wx
.StaticText( self
, -1, "Field Objects" )
281 ctrl
= wx
.StaticText( self
, -1, "MaskedTextCtrl" )
283 description
.SetFont( wx
.Font( 9, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD
) )
284 autofmt
.SetFont( wx
.Font( 9, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD
) )
285 fields
.SetFont( wx
.Font( 9, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD
) )
286 ctrl
.SetFont( wx
.Font( 9, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD
) )
288 grid
= wx
.FlexGridSizer( 0, 4, vgap
=10, hgap
=10 )
289 grid
.Add( description
, 0, wx
.ALIGN_LEFT
)
290 grid
.Add( autofmt
, 0, wx
.ALIGN_LEFT
)
291 grid
.Add( fields
, 0, wx
.ALIGN_LEFT
)
292 grid
.Add( ctrl
, 0, wx
.ALIGN_LEFT
)
294 autoformat
= "USPHONEFULLEXT"
295 fieldsDict
= {0: med.Field(choices=["617","781","508","978","413"], choiceRequired=True)}
300 choiceRequired=True)}"""
301 grid
.Add( wx
.StaticText( self
, -1, "Restricted Area Code"), 0, wx
.ALIGN_LEFT
)
302 grid
.Add( wx
.StaticText( self
, -1, autoformat
), 0, wx
.ALIGN_LEFT
)
303 grid
.Add( wx
.StaticText( self
, -1, fieldsLabel
), 0, wx
.ALIGN_LEFT
)
304 grid
.Add( med
.MaskedTextCtrl( self
, -1, "",
305 autoformat
= autoformat
,
311 autoformat
= "EXPDATEMMYY"
312 fieldsDict
= {1: med.Field(choices=["03", "04", "05"], choiceRequired=True)}
316 choiceRequired=True)}"""
317 exp
= med
.MaskedTextCtrl( self
, -1, "",
318 autoformat
= autoformat
,
323 grid
.Add( wx
.StaticText( self
, -1, "Restricted Expiration"), 0, wx
.ALIGN_LEFT
)
324 grid
.Add( wx
.StaticText( self
, -1, autoformat
), 0, wx
.ALIGN_LEFT
)
325 grid
.Add( wx
.StaticText( self
, -1, fieldsLabel
), 0, wx
.ALIGN_LEFT
)
326 grid
.Add( exp
, 0, wx
.ALIGN_LEFT
)
328 fieldsDict
= {0: med
.Field(choices
=["02134","02155"], choiceRequired
=True),
329 1: med
.Field(choices
=["1234", "5678"], choiceRequired
=False)}
331 {0: Field(choices=["02134","02155"],
332 choiceRequired=True),
333 1: Field(choices=["1234", "5678"],
334 choiceRequired=False)}"""
335 autoformat
= "USZIPPLUS4"
336 zip = med
.MaskedTextCtrl( self
, -1, "",
337 autoformat
= autoformat
,
342 grid
.Add( wx
.StaticText( self
, -1, "Restricted Zip + 4"), 0, wx
.ALIGN_LEFT
)
343 grid
.Add( wx
.StaticText( self
, -1, autoformat
), 0, wx
.ALIGN_LEFT
)
344 grid
.Add( wx
.StaticText( self
, -1, fieldsLabel
), 0, wx
.ALIGN_LEFT
)
345 grid
.Add( zip, 0, wx
.ALIGN_LEFT
)
347 self
.sizer
.Add( grid
, 0, wx
.ALIGN_LEFT|wx
.ALL
, border
=5 )
348 self
.SetSizer( self
.sizer
)
349 self
.SetAutoLayout(1)
350 self
.SetupScrolling()
353 class demoPage5(scroll
.ScrolledPanel
, demoMixin
):
354 def __init__( self
, parent
, log
):
356 scroll
.ScrolledPanel
.__init
__( self
, parent
, -1 )
357 self
.sizer
= wx
.BoxSizer( wx
.VERTICAL
)
360 labelMaskedCombos
= wx
.StaticText( self
, -1, """\
361 These are some examples of MaskedComboBox:""")
362 labelMaskedCombos
.SetForegroundColour( "Blue" )
365 label_statecode
= wx
.StaticText( self
, -1, """\
366 A state selector; only
367 "legal" values can be
369 statecode
= med
.MaskedComboBox( self
, -1, med
.states
[0],
370 choices
= med
.states
,
371 autoformat
="USSTATE")
373 label_statename
= wx
.StaticText( self
, -1, """\
374 A state name selector,
375 with auto-select:""")
377 # Create this one using factory function:
378 statename
= mctl
.MaskedCtrl( self
, -1, med
.state_names
[0],
379 controlType
= mctl
.controlTypes
.MASKEDCOMBO
,
380 choices
= med
.state_names
,
381 autoformat
="USSTATENAME",
383 statename
.SetCtrlParameters(formatcodes
= 'F!V_')
386 numerators
= [ str(i
) for i
in range(1, 4) ]
387 denominators
= [ string
.ljust(str(i
), 2) for i
in [2,3,4,5,8,16,32,64] ]
388 fieldsDict
= {0: med
.Field(choices
=numerators
, choiceRequired
=False),
389 1: med
.Field(choices
=denominators
, choiceRequired
=True)}
392 for d
in denominators
:
394 choices
.append( '%s/%s' % (n
,d
) )
397 label_fraction
= wx
.StaticText( self
, -1, """\
398 A masked ComboBox for fraction selection.
399 Choices for each side of the fraction can
400 be selected with PageUp/Down:""")
402 fraction
= mctl
.MaskedCtrl( self
, -1, "",
403 controlType
= mctl
.MASKEDCOMBO
,
405 choiceRequired
= True,
408 validRegex
= "^\d\/\d\d?",
409 fields
= fieldsDict
)
412 label_code
= wx
.StaticText( self
, -1, """\
413 A masked ComboBox to validate
414 text from a list of numeric codes:""")
416 choices
= ["91", "136", "305", "4579"]
417 code
= med
.MaskedComboBox( self
, -1, choices
[0],
419 choiceRequired
= True,
423 label_selector
= wx
.StaticText( self
, -1, """\
426 self
.list_selector
= wx
.ComboBox(self
, -1, '', choices
= ['list1', 'list2', 'list3'])
427 self
.dynamicbox
= mctl
.MaskedCtrl( self
, -1, ' ',
428 controlType
= mctl
.controlTypes
.MASKEDCOMBO
,
431 # these are to give dropdown some initial height,
432 # as base control apparently only sets that size
433 # during initial construction <sigh>:
434 choices
= ['', '1', '2', '3', '4', '5'] )
436 self
.dynamicbox
.Clear() # get rid of initial choices used to size the dropdown
439 labelIpAddrs
= wx
.StaticText( self
, -1, """\
440 Here are some examples of IpAddrCtrl, a control derived from MaskedTextCtrl:""")
441 labelIpAddrs
.SetForegroundColour( "Blue" )
444 label_ipaddr1
= wx
.StaticText( self
, -1, "An empty control:")
445 ipaddr1
= med
.IpAddrCtrl( self
, -1, style
= wx
.TE_PROCESS_TAB
)
448 label_ipaddr2
= wx
.StaticText( self
, -1, "A restricted mask:")
449 ipaddr2
= med
.IpAddrCtrl( self
, -1, mask
=" 10. 1.109.###" )
452 label_ipaddr3
= wx
.StaticText( self
, -1, """\
453 A control with restricted legal values:
454 10. (1|2) . (129..255) . (0..255)""")
455 ipaddr3
= mctl
.MaskedCtrl( self
, -1,
456 controlType
= mctl
.controlTypes
.IPADDR
,
457 mask
=" 10. #.###.###")
458 ipaddr3
.SetFieldParameters(0, validRegex
="1|2",validRequired
=False ) # requires entry to match or not allowed
460 # This allows any value in penultimate field, but colors anything outside of the range invalid:
461 ipaddr3
.SetFieldParameters(1, validRange
=(129,255), validRequired
=False )
465 labelNumerics
= wx
.StaticText( self
, -1, """\
466 Here are some useful configurations of a MaskedTextCtrl for integer and floating point input that still treat
467 the control as a text control. (For a true numeric control, check out the MaskedNumCtrl class!)""")
468 labelNumerics
.SetForegroundColour( "Blue" )
470 label_intctrl1
= wx
.StaticText( self
, -1, """\
471 An integer entry control with
472 shifting insert enabled:""")
473 self
.intctrl1
= med
.MaskedTextCtrl(self
, -1, name
='intctrl', mask
="#{9}", formatcodes
= '_-,F>')
474 label_intctrl2
= wx
.StaticText( self
, -1, """\
475 Right-insert integer entry:""")
476 self
.intctrl2
= med
.MaskedTextCtrl(self
, -1, name
='intctrl', mask
="#{9}", formatcodes
= '_-,Fr')
478 label_floatctrl
= wx
.StaticText( self
, -1, """\
479 A floating point entry control
480 with right-insert for ordinal:""")
481 self
.floatctrl
= med
.MaskedTextCtrl(self
, -1, name
='floatctrl', mask
="#{9}.#{2}", formatcodes
="F,_-R", useParensForNegatives
=False)
482 self
.floatctrl
.SetFieldParameters(0, formatcodes
='r<', validRequired
=True) # right-insert, require explicit cursor movement to change fields
483 self
.floatctrl
.SetFieldParameters(1, defaultValue
='00') # don't allow blank fraction
485 label_numselect
= wx
.StaticText( self
, -1, """\
486 <= Programmatically set the value
487 of the float entry ctrl:""")
488 numselect
= wx
.ComboBox(self
, -1, choices
= [ '', '111', '222.22', '-3', '54321.666666666', '-1353.978',
489 '1234567', '-1234567', '123456789', '-123456789.1',
490 '1234567890.', '-1234567890.1' ])
492 parens_check
= wx
.CheckBox(self
, -1, "Use () to indicate negatives in above controls")
496 gridCombos
= wx
.FlexGridSizer( 0, 4, vgap
=10, hgap
= 10 )
497 gridCombos
.Add( label_statecode
, 0, wx
.ALIGN_LEFT
)
498 gridCombos
.Add( statecode
, 0, wx
.ALIGN_LEFT
)
499 gridCombos
.Add( label_fraction
, 0, wx
.ALIGN_LEFT
)
500 gridCombos
.Add( fraction
, 0, wx
.ALIGN_LEFT
)
501 gridCombos
.Add( label_statename
, 0, wx
.ALIGN_LEFT
)
502 gridCombos
.Add( statename
, 0, wx
.ALIGN_LEFT
)
503 gridCombos
.Add( label_code
, 0, wx
.ALIGN_LEFT
)
504 gridCombos
.Add( code
, 0, wx
.ALIGN_LEFT
)
505 gridCombos
.Add( label_selector
, 0, wx
.ALIGN_LEFT
)
506 hbox
= wx
.BoxSizer( wx
.HORIZONTAL
)
507 hbox
.Add( self
.list_selector
, 0, wx
.ALIGN_LEFT
)
508 hbox
.Add(wx
.StaticText(self
, -1, ' => '), 0, wx
.ALIGN_LEFT
)
509 hbox
.Add( self
.dynamicbox
, 0, wx
.ALIGN_LEFT
)
510 gridCombos
.Add( hbox
, 0, wx
.ALIGN_LEFT
)
512 gridIpAddrs
= wx
.FlexGridSizer( 0, 4, vgap
=10, hgap
= 15 )
513 gridIpAddrs
.Add( label_ipaddr1
, 0, wx
.ALIGN_LEFT
)
514 gridIpAddrs
.Add( ipaddr1
, 0, wx
.ALIGN_LEFT
)
515 gridIpAddrs
.Add( label_ipaddr2
, 0, wx
.ALIGN_LEFT
)
516 gridIpAddrs
.Add( ipaddr2
, 0, wx
.ALIGN_LEFT
)
517 gridIpAddrs
.Add( label_ipaddr3
, 0, wx
.ALIGN_LEFT
)
518 gridIpAddrs
.Add( ipaddr3
, 0, wx
.ALIGN_LEFT
)
520 gridNumerics
= wx
.FlexGridSizer( 0, 4, vgap
=10, hgap
= 10 )
521 gridNumerics
.Add( label_intctrl1
, 0, wx
.ALIGN_LEFT
)
522 gridNumerics
.Add( self
.intctrl1
, 0, wx
.ALIGN_LEFT
)
523 gridNumerics
.Add( label_intctrl2
, 0, wx
.ALIGN_RIGHT
)
524 gridNumerics
.Add( self
.intctrl2
, 0, wx
.ALIGN_LEFT
)
525 gridNumerics
.Add( label_floatctrl
, 0, wx
.ALIGN_LEFT
)
526 gridNumerics
.Add( self
.floatctrl
, 0, wx
.ALIGN_LEFT
)
527 gridNumerics
.Add( label_numselect
, 0, wx
.ALIGN_RIGHT
)
528 gridNumerics
.Add( numselect
, 0, wx
.ALIGN_LEFT
)
530 self
.sizer
.Add( labelMaskedCombos
, 0, wx
.ALIGN_LEFT|wx
.ALL
, 5 )
531 self
.sizer
.Add( gridCombos
, 0, wx
.ALIGN_LEFT|wx
.ALL
, border
=5 )
532 self
.sizer
.Add( wx
.StaticLine(self
, -1), 0, wx
.EXPAND|wx
.TOP|wx
.BOTTOM
, border
=8 )
533 self
.sizer
.Add( labelIpAddrs
, 0, wx
.ALIGN_LEFT|wx
.ALL
, 5 )
534 self
.sizer
.Add( gridIpAddrs
, 0, wx
.ALIGN_LEFT|wx
.ALL
, border
=5 )
535 self
.sizer
.Add( wx
.StaticLine(self
, -1), 0, wx
.EXPAND|wx
.TOP|wx
.BOTTOM
, border
=8 )
536 self
.sizer
.Add( labelNumerics
, 0, wx
.ALIGN_LEFT|wx
.ALL
, 5 )
537 self
.sizer
.Add( gridNumerics
, 0, wx
.ALIGN_LEFT|wx
.ALL
, border
=5 )
538 self
.sizer
.Add( parens_check
, 0, wx
.ALIGN_LEFT|wx
.ALL
, 5 )
540 self
.SetSizer( self
.sizer
)
541 self
.SetAutoLayout(1)
542 self
.SetupScrolling()
544 self
.Bind(wx
.EVT_COMBOBOX
, self
.OnComboSelection
, id=fraction
.GetId())
545 self
.Bind(wx
.EVT_COMBOBOX
, self
.OnComboSelection
, id=code
.GetId())
546 self
.Bind(wx
.EVT_COMBOBOX
, self
.OnComboSelection
, id=statecode
.GetId())
547 self
.Bind(wx
.EVT_COMBOBOX
, self
.OnComboSelection
, id=statename
.GetId())
548 self
.Bind(wx
.EVT_TEXT
, self
.OnTextChange
, id=code
.GetId())
549 self
.Bind(wx
.EVT_TEXT
, self
.OnTextChange
, id=statecode
.GetId())
550 self
.Bind(wx
.EVT_TEXT
, self
.OnTextChange
, id=statename
.GetId())
551 self
.Bind(wx
.EVT_COMBOBOX
, self
.OnListSelection
, id=self
.list_selector
.GetId())
553 self
.Bind(wx
.EVT_TEXT
, self
.OnTextChange
, id=self
.intctrl1
.GetId())
554 self
.Bind(wx
.EVT_TEXT
, self
.OnTextChange
, id=self
.intctrl2
.GetId())
555 self
.Bind(wx
.EVT_TEXT
, self
.OnTextChange
, id=self
.floatctrl
.GetId())
556 self
.Bind(wx
.EVT_COMBOBOX
, self
.OnNumberSelect
, id=numselect
.GetId())
557 self
.Bind(wx
.EVT_CHECKBOX
, self
.OnParensCheck
, id=parens_check
.GetId())
559 self
.Bind(wx
.EVT_TEXT
, self
.OnIpAddrChange
, id=ipaddr1
.GetId())
560 self
.Bind(wx
.EVT_TEXT
, self
.OnIpAddrChange
, id=ipaddr2
.GetId())
561 self
.Bind(wx
.EVT_TEXT
, self
.OnIpAddrChange
, id=ipaddr3
.GetId())
566 def OnComboSelection( self
, event
):
567 ctl
= self
.FindWindowById( event
.GetId() )
568 if not ctl
.IsValid():
569 self
.log
.write('current value not a valid choice')
570 self
.log
.write('new value = %s' % ctl
.GetValue())
572 def OnTextChange( self
, event
):
573 ctl
= self
.FindWindowById( event
.GetId() )
575 self
.log
.write('new value = %s\n' % ctl
.GetValue() )
577 def OnNumberSelect( self
, event
):
578 value
= event
.GetString()
579 # Format choice to fit into format for #{9}.#{2}, with sign position reserved:
580 # (ordinal + fraction == 11 + decimal point + sign == 13)
582 floattext
= "%13.2f" % float(value
)
584 floattext
= value
# clear the value again
586 self
.floatctrl
.SetValue(floattext
)
588 type, value
, tb
= sys
.exc_info()
589 for line
in traceback
.format_exception_only(type, value
):
592 def OnParensCheck( self
, event
):
593 self
.intctrl1
.SetCtrlParameters(useParensForNegatives
=event
.IsChecked())
594 self
.intctrl2
.SetCtrlParameters(useParensForNegatives
=event
.IsChecked())
595 self
.floatctrl
.SetCtrlParameters(useParensForNegatives
=event
.IsChecked())
597 def OnIpAddrChange( self
, event
):
598 ipaddr
= self
.FindWindowById( event
.GetId() )
600 self
.log
.write('new addr = %s\n' % ipaddr
.GetAddress() )
602 def OnListSelection( self
, event
):
603 list = self
.list_selector
.GetStringSelection()
606 choices
= ['abc', 'defg', 'hi']
608 elif list == 'list2':
609 choices
= ['1', '2', '34', '567']
616 self
.dynamicbox
.SetCtrlParameters( mask
= mask
,
620 formatcodes
=formatcodes
)
621 self
.dynamicbox
.SetValue(choices
[0])
623 # ---------------------------------------------------------------------
624 class TestMaskedTextCtrls(wx
.Notebook
):
625 def __init__(self
, parent
, id, log
):
626 wx
.Notebook
.__init
__(self
, parent
, id)
629 win
= demoPage1(self
, log
)
630 self
.AddPage(win
, "General examples")
632 win
= demoPage2(self
, log
)
633 self
.AddPage(win
, 'Auto-formatted controls')
635 win
= demoPage3(self
, log
)
636 self
.AddPage(win
, "Using default values")
638 win
= demoPage4(self
, log
)
639 self
.AddPage(win
, 'Using auto-complete fields')
641 win
= demoPage5(self
, log
)
642 self
.AddPage(win
, 'Other masked controls')
645 #----------------------------------------------------------------------------
647 def runTest(frame
, nb
, log
):
648 testWin
= TestMaskedTextCtrls(nb
, -1, log
)
652 app
= wx
.PySimpleApp()
653 frame
= wx
.Frame(None, -1, "Test MaskedTextCtrl", size
=(640, 480))
654 win
= TestMaskedTextCtrls(frame
, -1, sys
.stdout
)
657 #----------------------------------------------------------------------------
661 """ + med
.__doc
__ + """
665 if __name__
== "__main__":
668 run
.main(['', os
.path
.basename(sys
.argv
[0])])