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
16 import wx
.lib
.maskededit
as med
17 import wx
.lib
.maskedctrl
as mctl
18 import wx
.lib
.scrolledpanel
as scroll
23 Centralized routines common to demo pages, to remove repetition.
25 def labelGeneralTable(self
, sizer
):
26 description
= wx
.StaticText( self
, -1, "Description", )
27 mask
= wx
.StaticText( self
, -1, "Mask Value" )
28 formatcode
= wx
.StaticText( self
, -1, "Format" )
29 regex
= wx
.StaticText( self
, -1, "Regexp Validator(opt.)" )
30 ctrl
= wx
.StaticText( self
, -1, "wxMaskedTextCtrl" )
32 description
.SetFont( wx
.Font(9, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD
))
33 mask
.SetFont( wx
.Font(9, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD
))
34 formatcode
.SetFont( wx
.Font(9, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD
) )
35 regex
.SetFont( wx
.Font(9, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD
))
36 ctrl
.SetFont( wx
.Font(9, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD
))
38 sizer
.Add(description
)
45 def layoutGeneralTable(self
, controls
, sizer
):
46 for control
in controls
:
47 sizer
.Add( wx
.StaticText( self
, -1, control
[0]) )
48 sizer
.Add( wx
.StaticText( self
, -1, control
[1]) )
49 sizer
.Add( wx
.StaticText( self
, -1, control
[3]) )
50 sizer
.Add( wx
.StaticText( self
, -1, control
[4]) )
52 if control
in controls
:
53 newControl
= med
.wxMaskedTextCtrl( self
, -1, "",
55 excludeChars
= control
[2],
56 formatcodes
= control
[3],
58 validRegex
= control
[4],
59 validRange
= control
[5],
61 choiceRequired
= True,
62 defaultValue
= control
[7],
65 self
.editList
.append(newControl
)
69 def changeControlParams(self
, event
, parameter
, checked_value
, notchecked_value
):
70 if event
.IsChecked(): value
= checked_value
71 else: value
= notchecked_value
73 kwargs
= {parameter: value}
75 for control
in self
.editList
:
76 control
.SetCtrlParameters(**kwargs
)
83 #----------------------------------------------------------------------------
84 class demoPage1(scroll
.wxScrolledPanel
, demoMixin
):
85 def __init__(self
, parent
, log
):
86 scroll
.wxScrolledPanel
.__init
__(self
, parent
, -1)
87 self
.sizer
= wx
.BoxSizer( wx
.VERTICAL
)
90 label
= wx
.StaticText( self
, -1, """\
91 Here are some basic MaskedTextCtrls to give you an idea of what you can do
92 with this control. Note that all controls have been auto-sized by including 'F' in
95 Try entering nonsensical or partial values in validated fields to see what happens.
96 Note that the State and Last Name fields are list-limited (valid last names are:
97 Smith, Jones, Williams). Signs on numbers can be toggled with the minus key.
99 label
.SetForegroundColour( "Blue" )
100 header
= wx
.BoxSizer( wx
.HORIZONTAL
)
101 header
.Add( label
, 0, flag
=wx
.ALIGN_LEFT|wx
.ALL
, border
= 5 )
103 highlight
= wx
.CheckBox( self
, -1, "Highlight Empty" )
104 disallow
= wx
.CheckBox( self
, -1, "Disallow Empty" )
105 showFill
= wx
.CheckBox( self
, -1, "change fillChar" )
107 vbox
= wx
.BoxSizer( wx
.VERTICAL
)
108 vbox
.Add( highlight
, 0, wx
.ALIGN_LEFT|wx
.ALL
, 5 )
109 vbox
.Add( disallow
, 0, wx
.ALIGN_LEFT|wx
.ALL
, 5 )
110 vbox
.Add( showFill
, 0, wx
.ALIGN_LEFT|wx
.ALL
, 5 )
112 header
.Add(vbox
, 0, flag
=wx
.ALIGN_LEFT|wx
.ALL
, border
=5 )
114 self
.Bind(wx
.EVT_CHECKBOX
, self
.onHighlightEmpty
, id=highlight
.GetId())
115 self
.Bind(wx
.EVT_CHECKBOX
, self
.onDisallowEmpty
, id=disallow
.GetId())
116 self
.Bind(wx
.EVT_CHECKBOX
, self
.onShowFill
, id=showFill
.GetId())
118 grid
= wx
.FlexGridSizer( 0, 5, vgap
=10, hgap
=10 )
119 self
.labelGeneralTable(grid
)
121 # The following list is of the controls for the demo. Feel free to play around with
124 #description mask excl format regexp range,list,initial
125 ("Phone No", "(###) ###-#### x:###", "", 'F^-', "^\(\d{3}\) \d{3}-\d{4}", '','',''),
126 ("Social Sec#", "###-##-####", "", 'F', "\d{3}-\d{2}-\d{4}", '','',''),
127 ("Full Name", "C{14}", "", 'F_', '^[A-Z][a-zA-Z]+ [A-Z][a-zA-Z]+', '','',''),
128 ("Last Name Only", "C{14}", "", 'F {list}', '^[A-Z][a-zA-Z]+', '',('Smith','Jones','Williams'),''),
129 ("Zip plus 4", "#{5}-#{4}", "", 'F', "\d{5}-(\s{4}|\d{4})", '','',''),
130 ("Customer No", "\CAA-###", "", 'F!', "C[A-Z]{2}-\d{3}", '','',''),
131 ("Invoice Total", "#{9}.##", "", 'F-_,', "", '','',''),
132 ("Integer", "#{9}", "", 'F-_', "", '','',''),
135 self
.layoutGeneralTable(controls
, grid
)
136 self
.sizer
.Add( header
, 0, flag
=wx
.ALIGN_LEFT|wx
.ALL
, border
=5 )
137 self
.sizer
.Add( grid
, 0, flag
= wx
.ALIGN_LEFT|wx
.LEFT
, border
=5 )
138 self
.SetSizer(self
.sizer
)
139 self
.SetupScrolling()
140 self
.SetAutoLayout(1)
143 def onDisallowEmpty( self
, event
):
144 """ Set emptyInvalid parameter on/off """
145 self
.changeControlParams( event
, "emptyInvalid", True, False )
147 def onHighlightEmpty( self
, event
):
148 """ Highlight empty values"""
149 self
.changeControlParams( event
, "emptyBackgroundColour", "Blue", "White" )
151 def onShowFill( self
, event
):
152 """ Set fillChar parameter to '?' or ' ' """
153 self
.changeControlParams( event
, "fillChar", '?', ' ' )
156 class demoPage2(scroll
.wxScrolledPanel
, demoMixin
):
157 def __init__( self
, parent
, log
):
159 scroll
.wxScrolledPanel
.__init
__( self
, parent
, -1 )
160 self
.sizer
= wx
.BoxSizer( wx
.VERTICAL
)
162 label
= wx
.StaticText( self
, -1, """\
163 All these controls have been created by passing a single parameter, the autoformat code,
164 and use the factory class wxMaskedCtrl with its default controlType.
165 The maskededit module contains an internal dictionary of types and formats (autoformats).
166 Many of these already do complicated validation; To see some examples, try
167 29 Feb 2002 vs. 2004 for the date formats, or email address validation.
170 label
.SetForegroundColour( "Blue" )
171 self
.sizer
.Add( label
, 0, wx
.ALIGN_LEFT|wx
.ALL
, 5 )
173 description
= wx
.StaticText( self
, -1, "Description")
174 autofmt
= wx
.StaticText( self
, -1, "AutoFormat Code")
175 ctrl
= wx
.StaticText( self
, -1, "MaskedCtrl")
177 description
.SetFont( wx
.Font( 9, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD
) )
178 autofmt
.SetFont( wx
.Font( 9, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD
) )
179 ctrl
.SetFont( wx
.Font( 9, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD
) )
181 grid
= wx
.FlexGridSizer( 0, 3, vgap
=10, hgap
=5 )
182 grid
.Add( description
, 0, wx
.ALIGN_LEFT
)
183 grid
.Add( autofmt
, 0, wx
.ALIGN_LEFT
)
184 grid
.Add( ctrl
, 0, wx
.ALIGN_LEFT
)
186 for autoformat
, desc
in med
.autoformats
:
187 grid
.Add( wx
.StaticText( self
, -1, desc
), 0, wx
.ALIGN_LEFT
)
188 grid
.Add( wx
.StaticText( self
, -1, autoformat
), 0, wx
.ALIGN_LEFT
)
189 grid
.Add( mctl
.wxMaskedCtrl( self
, -1, "",
190 autoformat
= autoformat
,
195 self
.sizer
.Add( grid
, 0, wx
.ALIGN_LEFT|wx
.ALL
, border
=5 )
196 self
.SetSizer( self
.sizer
)
197 self
.SetAutoLayout( 1 )
198 self
.SetupScrolling()
201 class demoPage3(scroll
.wxScrolledPanel
, demoMixin
):
202 def __init__(self
, parent
, log
):
204 scroll
.wxScrolledPanel
.__init
__(self
, parent
, -1)
205 self
.sizer
= wx
.BoxSizer( wx
.VERTICAL
)
208 label
= wx
.StaticText( self
, -1, """\
209 Here wxMaskedTextCtrls that have default values. The states
210 control has a list of valid values, and the unsigned integer
211 has a legal range specified.
213 label
.SetForegroundColour( "Blue" )
214 requireValid
= wx
.CheckBox( self
, -1, "Require Valid Value" )
215 self
.Bind(wx
.EVT_CHECKBOX
, self
.onRequireValid
, id=requireValid
.GetId())
217 header
= wx
.BoxSizer( wx
.HORIZONTAL
)
218 header
.Add( label
, 0, flag
=wx
.ALIGN_LEFT|wx
.ALL
, border
= 5)
220 header
.Add( requireValid
, 0, flag
=wx
.ALIGN_LEFT|wx
.ALL
, border
=10 )
222 grid
= wx
.FlexGridSizer( 0, 5, vgap
=10, hgap
=10 )
223 self
.labelGeneralTable( grid
)
226 #description mask excl format regexp range,list,initial
227 ("U.S. State (2 char)", "AA", "", 'F!_', "[A-Z]{2}", '',med
.states
, med
.states
[0]),
228 ("Integer (signed)", "#{6}", "", 'F-_', "", '','', ' 0 '),
229 ("Integer (unsigned)\n(1-399)","######", "", 'F_', "", (1,399),'', '1 '),
230 ("Float (signed)", "#{6}.#{9}", "", 'F-_R', "", '','', '000000.000000000'),
231 ("Date (MDY) + Time", "##/##/#### ##:##:## AM", 'BCDEFGHIJKLMNOQRSTUVWXYZ','DF!',"", '','', wx
.DateTime_Now().Format("%m/%d/%Y %I:%M:%S %p")),
233 self
.layoutGeneralTable( controls
, grid
)
235 self
.sizer
.Add( header
, 0, flag
=wx
.ALIGN_LEFT|wx
.ALL
, border
=5 )
236 self
.sizer
.Add( grid
, 0, flag
=wx
.ALIGN_LEFT|wx
.ALL
, border
=5 )
238 self
.SetSizer( self
.sizer
)
239 self
.SetAutoLayout( 1 )
240 self
.SetupScrolling()
242 def onRequireValid( self
, event
):
243 """ Set validRequired parameter on/off """
244 self
.changeControlParams( event
, "validRequired", True, False )
247 class demoPage4(scroll
.wxScrolledPanel
, demoMixin
):
248 def __init__( self
, parent
, log
):
250 scroll
.wxScrolledPanel
.__init
__( self
, parent
, -1 )
251 self
.sizer
= wx
.BoxSizer( wx
.VERTICAL
)
253 label
= wx
.StaticText( self
, -1, """\
254 These controls have field-specific choice lists and allow autocompletion.
256 Down arrow or Page Down in an uncompleted field with an auto-completable field will attempt
257 to auto-complete a field if it has a choice list.
258 Page Down and Shift-Down arrow will also auto-complete, or cycle through the complete list.
259 Page Up and Shift-Up arrow will similarly cycle backwards through the list.
262 label
.SetForegroundColour( "Blue" )
263 self
.sizer
.Add( label
, 0, wx
.ALIGN_LEFT|wx
.ALL
, 5 )
265 description
= wx
.StaticText( self
, -1, "Description" )
266 autofmt
= wx
.StaticText( self
, -1, "AutoFormat Code" )
267 fields
= wx
.StaticText( self
, -1, "Field Objects" )
268 ctrl
= wx
.StaticText( self
, -1, "wxMaskedTextCtrl" )
270 description
.SetFont( wx
.Font( 9, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD
) )
271 autofmt
.SetFont( wx
.Font( 9, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD
) )
272 fields
.SetFont( wx
.Font( 9, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD
) )
273 ctrl
.SetFont( wx
.Font( 9, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD
) )
275 grid
= wx
.FlexGridSizer( 0, 4, vgap
=10, hgap
=10 )
276 grid
.Add( description
, 0, wx
.ALIGN_LEFT
)
277 grid
.Add( autofmt
, 0, wx
.ALIGN_LEFT
)
278 grid
.Add( fields
, 0, wx
.ALIGN_LEFT
)
279 grid
.Add( ctrl
, 0, wx
.ALIGN_LEFT
)
281 autoformat
= "USPHONEFULLEXT"
282 fieldsDict
= {0: med.Field(choices=["617","781","508","978","413"], choiceRequired=True)}
287 choiceRequired=True)}"""
288 grid
.Add( wx
.StaticText( self
, -1, "Restricted Area Code"), 0, wx
.ALIGN_LEFT
)
289 grid
.Add( wx
.StaticText( self
, -1, autoformat
), 0, wx
.ALIGN_LEFT
)
290 grid
.Add( wx
.StaticText( self
, -1, fieldsLabel
), 0, wx
.ALIGN_LEFT
)
291 grid
.Add( med
.wxMaskedTextCtrl( self
, -1, "",
292 autoformat
= autoformat
,
298 autoformat
= "EXPDATEMMYY"
299 fieldsDict
= {1: med.Field(choices=["03", "04", "05"], choiceRequired=True)}
303 choiceRequired=True)}"""
304 exp
= med
.wxMaskedTextCtrl( self
, -1, "",
305 autoformat
= autoformat
,
310 grid
.Add( wx
.StaticText( self
, -1, "Restricted Expiration"), 0, wx
.ALIGN_LEFT
)
311 grid
.Add( wx
.StaticText( self
, -1, autoformat
), 0, wx
.ALIGN_LEFT
)
312 grid
.Add( wx
.StaticText( self
, -1, fieldsLabel
), 0, wx
.ALIGN_LEFT
)
313 grid
.Add( exp
, 0, wx
.ALIGN_LEFT
)
315 fieldsDict
= {0: med
.Field(choices
=["02134","02155"], choiceRequired
=True),
316 1: med
.Field(choices
=["1234", "5678"], choiceRequired
=False)}
318 {0: Field(choices=["02134","02155"],
319 choiceRequired=True),
320 1: Field(choices=["1234", "5678"],
321 choiceRequired=False)}"""
322 autoformat
= "USZIPPLUS4"
323 zip = med
.wxMaskedTextCtrl( self
, -1, "",
324 autoformat
= autoformat
,
329 grid
.Add( wx
.StaticText( self
, -1, "Restricted Zip + 4"), 0, wx
.ALIGN_LEFT
)
330 grid
.Add( wx
.StaticText( self
, -1, autoformat
), 0, wx
.ALIGN_LEFT
)
331 grid
.Add( wx
.StaticText( self
, -1, fieldsLabel
), 0, wx
.ALIGN_LEFT
)
332 grid
.Add( zip, 0, wx
.ALIGN_LEFT
)
334 self
.sizer
.Add( grid
, 0, wx
.ALIGN_LEFT|wx
.ALL
, border
=5 )
335 self
.SetSizer( self
.sizer
)
336 self
.SetAutoLayout(1)
337 self
.SetupScrolling()
340 class demoPage5(scroll
.wxScrolledPanel
, demoMixin
):
341 def __init__( self
, parent
, log
):
343 scroll
.wxScrolledPanel
.__init
__( self
, parent
, -1 )
344 self
.sizer
= wx
.BoxSizer( wx
.VERTICAL
)
347 labelMaskedCombos
= wx
.StaticText( self
, -1, """\
348 These are some examples of wxMaskedComboBox:""")
349 labelMaskedCombos
.SetForegroundColour( "Blue" )
352 label_statecode
= wx
.StaticText( self
, -1, """\
353 A state selector; only
354 "legal" values can be
356 statecode
= med
.wxMaskedComboBox( self
, -1, med
.states
[0],
357 choices
= med
.states
,
358 autoformat
="USSTATE")
360 label_statename
= wx
.StaticText( self
, -1, """\
361 A state name selector,
362 with auto-select:""")
364 # Create this one using factory function:
365 statename
= mctl
.wxMaskedCtrl( self
, -1, med
.state_names
[0],
366 controlType
= mctl
.controlTypes
.MASKEDCOMBO
,
367 choices
= med
.state_names
,
368 autoformat
="USSTATENAME",
370 statename
.SetCtrlParameters(formatcodes
= 'F!V_')
373 numerators
= [ str(i
) for i
in range(1, 4) ]
374 denominators
= [ string
.ljust(str(i
), 2) for i
in [2,3,4,5,8,16,32,64] ]
375 fieldsDict
= {0: med
.Field(choices
=numerators
, choiceRequired
=False),
376 1: med
.Field(choices
=denominators
, choiceRequired
=True)}
379 for d
in denominators
:
381 choices
.append( '%s/%s' % (n
,d
) )
384 label_fraction
= wx
.StaticText( self
, -1, """\
385 A masked ComboBox for fraction selection.
386 Choices for each side of the fraction can
387 be selected with PageUp/Down:""")
389 fraction
= mctl
.wxMaskedCtrl( self
, -1, "",
390 controlType
= mctl
.MASKEDCOMBO
,
392 choiceRequired
= True,
395 validRegex
= "^\d\/\d\d?",
396 fields
= fieldsDict
)
399 label_code
= wx
.StaticText( self
, -1, """\
400 A masked ComboBox to validate
401 text from a list of numeric codes:""")
403 choices
= ["91", "136", "305", "4579"]
404 code
= med
.wxMaskedComboBox( self
, -1, choices
[0],
406 choiceRequired
= True,
410 label_selector
= wx
.StaticText( self
, -1, """\
413 self
.list_selector
= wx
.ComboBox(self
, -1, '', choices
= ['list1', 'list2', 'list3'])
414 self
.dynamicbox
= mctl
.wxMaskedCtrl( self
, -1, ' ',
415 controlType
= mctl
.controlTypes
.MASKEDCOMBO
,
418 # these are to give dropdown some initial height,
419 # as base control apparently only sets that size
420 # during initial construction <sigh>:
421 choices
= ['', '1', '2', '3', '4', '5'] )
423 self
.dynamicbox
.Clear() # get rid of initial choices used to size the dropdown
426 labelIpAddrs
= wx
.StaticText( self
, -1, """\
427 Here are some examples of wxIpAddrCtrl, a control derived from wxMaskedTextCtrl:""")
428 labelIpAddrs
.SetForegroundColour( "Blue" )
431 label_ipaddr1
= wx
.StaticText( self
, -1, "An empty control:")
432 ipaddr1
= med
.wxIpAddrCtrl( self
, -1, style
= wx
.TE_PROCESS_TAB
)
435 label_ipaddr2
= wx
.StaticText( self
, -1, "A restricted mask:")
436 ipaddr2
= med
.wxIpAddrCtrl( self
, -1, mask
=" 10. 1.109.###" )
439 label_ipaddr3
= wx
.StaticText( self
, -1, """\
440 A control with restricted legal values:
441 10. (1|2) . (129..255) . (0..255)""")
442 ipaddr3
= mctl
.wxMaskedCtrl( self
, -1,
443 controlType
= mctl
.controlTypes
.IPADDR
,
444 mask
=" 10. #.###.###")
445 ipaddr3
.SetFieldParameters(0, validRegex
="1|2",validRequired
=False ) # requires entry to match or not allowed
447 # This allows any value in penultimate field, but colors anything outside of the range invalid:
448 ipaddr3
.SetFieldParameters(1, validRange
=(129,255), validRequired
=False )
452 labelNumerics
= wx
.StaticText( self
, -1, """\
453 Here are some useful configurations of a wxMaskedTextCtrl for integer and floating point input that still treat
454 the control as a text control. (For a true numeric control, check out the wxMaskedNumCtrl class!)""")
455 labelNumerics
.SetForegroundColour( "Blue" )
457 label_intctrl1
= wx
.StaticText( self
, -1, """\
458 An integer entry control with
459 shifting insert enabled:""")
460 self
.intctrl1
= med
.wxMaskedTextCtrl(self
, -1, name
='intctrl', mask
="#{9}", formatcodes
= '_-,F>')
461 label_intctrl2
= wx
.StaticText( self
, -1, """\
462 Right-insert integer entry:""")
463 self
.intctrl2
= med
.wxMaskedTextCtrl(self
, -1, name
='intctrl', mask
="#{9}", formatcodes
= '_-,Fr')
465 label_floatctrl
= wx
.StaticText( self
, -1, """\
466 A floating point entry control
467 with right-insert for ordinal:""")
468 self
.floatctrl
= med
.wxMaskedTextCtrl(self
, -1, name
='floatctrl', mask
="#{9}.#{2}", formatcodes
="F,_-R", useParensForNegatives
=False)
469 self
.floatctrl
.SetFieldParameters(0, formatcodes
='r<', validRequired
=True) # right-insert, require explicit cursor movement to change fields
470 self
.floatctrl
.SetFieldParameters(1, defaultValue
='00') # don't allow blank fraction
472 label_numselect
= wx
.StaticText( self
, -1, """\
473 <= Programmatically set the value
474 of the float entry ctrl:""")
475 numselect
= wx
.ComboBox(self
, -1, choices
= [ '', '111', '222.22', '-3', '54321.666666666', '-1353.978',
476 '1234567', '-1234567', '123456789', '-123456789.1',
477 '1234567890.', '-1234567890.1' ])
479 parens_check
= wx
.CheckBox(self
, -1, "Use () to indicate negatives in above controls")
483 gridCombos
= wx
.FlexGridSizer( 0, 4, vgap
=10, hgap
= 10 )
484 gridCombos
.Add( label_statecode
, 0, wx
.ALIGN_LEFT
)
485 gridCombos
.Add( statecode
, 0, wx
.ALIGN_LEFT
)
486 gridCombos
.Add( label_fraction
, 0, wx
.ALIGN_LEFT
)
487 gridCombos
.Add( fraction
, 0, wx
.ALIGN_LEFT
)
488 gridCombos
.Add( label_statename
, 0, wx
.ALIGN_LEFT
)
489 gridCombos
.Add( statename
, 0, wx
.ALIGN_LEFT
)
490 gridCombos
.Add( label_code
, 0, wx
.ALIGN_LEFT
)
491 gridCombos
.Add( code
, 0, wx
.ALIGN_LEFT
)
492 gridCombos
.Add( label_selector
, 0, wx
.ALIGN_LEFT
)
493 hbox
= wx
.BoxSizer( wx
.HORIZONTAL
)
494 hbox
.Add( self
.list_selector
, 0, wx
.ALIGN_LEFT
)
495 hbox
.Add(wx
.StaticText(self
, -1, ' => '), 0, wx
.ALIGN_LEFT
)
496 hbox
.Add( self
.dynamicbox
, 0, wx
.ALIGN_LEFT
)
497 gridCombos
.Add( hbox
, 0, wx
.ALIGN_LEFT
)
499 gridIpAddrs
= wx
.FlexGridSizer( 0, 4, vgap
=10, hgap
= 15 )
500 gridIpAddrs
.Add( label_ipaddr1
, 0, wx
.ALIGN_LEFT
)
501 gridIpAddrs
.Add( ipaddr1
, 0, wx
.ALIGN_LEFT
)
502 gridIpAddrs
.Add( label_ipaddr2
, 0, wx
.ALIGN_LEFT
)
503 gridIpAddrs
.Add( ipaddr2
, 0, wx
.ALIGN_LEFT
)
504 gridIpAddrs
.Add( label_ipaddr3
, 0, wx
.ALIGN_LEFT
)
505 gridIpAddrs
.Add( ipaddr3
, 0, wx
.ALIGN_LEFT
)
507 gridNumerics
= wx
.FlexGridSizer( 0, 4, vgap
=10, hgap
= 10 )
508 gridNumerics
.Add( label_intctrl1
, 0, wx
.ALIGN_LEFT
)
509 gridNumerics
.Add( self
.intctrl1
, 0, wx
.ALIGN_LEFT
)
510 gridNumerics
.Add( label_intctrl2
, 0, wx
.ALIGN_RIGHT
)
511 gridNumerics
.Add( self
.intctrl2
, 0, wx
.ALIGN_LEFT
)
512 gridNumerics
.Add( label_floatctrl
, 0, wx
.ALIGN_LEFT
)
513 gridNumerics
.Add( self
.floatctrl
, 0, wx
.ALIGN_LEFT
)
514 gridNumerics
.Add( label_numselect
, 0, wx
.ALIGN_RIGHT
)
515 gridNumerics
.Add( numselect
, 0, wx
.ALIGN_LEFT
)
517 self
.sizer
.Add( labelMaskedCombos
, 0, wx
.ALIGN_LEFT|wx
.ALL
, 5 )
518 self
.sizer
.Add( gridCombos
, 0, wx
.ALIGN_LEFT|wx
.ALL
, border
=5 )
519 self
.sizer
.Add( wx
.StaticLine(self
, -1), 0, wx
.EXPAND|wx
.TOP|wx
.BOTTOM
, border
=8 )
520 self
.sizer
.Add( labelIpAddrs
, 0, wx
.ALIGN_LEFT|wx
.ALL
, 5 )
521 self
.sizer
.Add( gridIpAddrs
, 0, wx
.ALIGN_LEFT|wx
.ALL
, border
=5 )
522 self
.sizer
.Add( wx
.StaticLine(self
, -1), 0, wx
.EXPAND|wx
.TOP|wx
.BOTTOM
, border
=8 )
523 self
.sizer
.Add( labelNumerics
, 0, wx
.ALIGN_LEFT|wx
.ALL
, 5 )
524 self
.sizer
.Add( gridNumerics
, 0, wx
.ALIGN_LEFT|wx
.ALL
, border
=5 )
525 self
.sizer
.Add( parens_check
, 0, wx
.ALIGN_LEFT|wx
.ALL
, 5 )
527 self
.SetSizer( self
.sizer
)
528 self
.SetAutoLayout(1)
529 self
.SetupScrolling()
531 self
.Bind(wx
.EVT_COMBOBOX
, self
.OnComboSelection
, id=fraction
.GetId())
532 self
.Bind(wx
.EVT_COMBOBOX
, self
.OnComboSelection
, id=code
.GetId())
533 self
.Bind(wx
.EVT_COMBOBOX
, self
.OnComboSelection
, id=statecode
.GetId())
534 self
.Bind(wx
.EVT_COMBOBOX
, self
.OnComboSelection
, id=statename
.GetId())
535 self
.Bind(wx
.EVT_TEXT
, self
.OnTextChange
, id=code
.GetId())
536 self
.Bind(wx
.EVT_TEXT
, self
.OnTextChange
, id=statecode
.GetId())
537 self
.Bind(wx
.EVT_TEXT
, self
.OnTextChange
, id=statename
.GetId())
538 self
.Bind(wx
.EVT_COMBOBOX
, self
.OnListSelection
, id=self
.list_selector
.GetId())
540 self
.Bind(wx
.EVT_TEXT
, self
.OnTextChange
, id=self
.intctrl1
.GetId())
541 self
.Bind(wx
.EVT_TEXT
, self
.OnTextChange
, id=self
.intctrl2
.GetId())
542 self
.Bind(wx
.EVT_TEXT
, self
.OnTextChange
, id=self
.floatctrl
.GetId())
543 self
.Bind(wx
.EVT_COMBOBOX
, self
.OnNumberSelect
, id=numselect
.GetId())
544 self
.Bind(wx
.EVT_CHECKBOX
, self
.OnParensCheck
, id=parens_check
.GetId())
546 self
.Bind(wx
.EVT_TEXT
, self
.OnIpAddrChange
, id=ipaddr1
.GetId())
547 self
.Bind(wx
.EVT_TEXT
, self
.OnIpAddrChange
, id=ipaddr2
.GetId())
548 self
.Bind(wx
.EVT_TEXT
, self
.OnIpAddrChange
, id=ipaddr3
.GetId())
553 def OnComboSelection( self
, event
):
554 ctl
= self
.FindWindowById( event
.GetId() )
555 if not ctl
.IsValid():
556 self
.log
.write('current value not a valid choice')
557 self
.log
.write('new value = %s' % ctl
.GetValue())
559 def OnTextChange( self
, event
):
560 ctl
= self
.FindWindowById( event
.GetId() )
562 self
.log
.write('new value = %s\n' % ctl
.GetValue() )
564 def OnNumberSelect( self
, event
):
565 value
= event
.GetString()
566 # Format choice to fit into format for #{9}.#{2}, with sign position reserved:
567 # (ordinal + fraction == 11 + decimal point + sign == 13)
569 floattext
= "%13.2f" % float(value
)
571 floattext
= value
# clear the value again
573 self
.floatctrl
.SetValue(floattext
)
575 type, value
, tb
= sys
.exc_info()
576 for line
in traceback
.format_exception_only(type, value
):
579 def OnParensCheck( self
, event
):
580 self
.intctrl1
.SetCtrlParameters(useParensForNegatives
=event
.Checked())
581 self
.intctrl2
.SetCtrlParameters(useParensForNegatives
=event
.Checked())
582 self
.floatctrl
.SetCtrlParameters(useParensForNegatives
=event
.Checked())
584 def OnIpAddrChange( self
, event
):
585 ipaddr
= self
.FindWindowById( event
.GetId() )
587 self
.log
.write('new addr = %s\n' % ipaddr
.GetAddress() )
589 def OnListSelection( self
, event
):
590 list = self
.list_selector
.GetStringSelection()
593 choices
= ['abc', 'defg', 'hi']
595 elif list == 'list2':
596 choices
= ['1', '2', '34', '567']
603 self
.dynamicbox
.SetCtrlParameters( mask
= mask
,
607 formatcodes
=formatcodes
)
608 self
.dynamicbox
.SetValue(choices
[0])
610 # ---------------------------------------------------------------------
611 class TestMaskedTextCtrls(wx
.Notebook
):
612 def __init__(self
, parent
, id, log
):
613 wx
.Notebook
.__init
__(self
, parent
, id)
616 win
= demoPage1(self
, log
)
617 self
.AddPage(win
, "General examples")
619 win
= demoPage2(self
, log
)
620 self
.AddPage(win
, 'Auto-formatted controls')
622 win
= demoPage3(self
, log
)
623 self
.AddPage(win
, "Using default values")
625 win
= demoPage4(self
, log
)
626 self
.AddPage(win
, 'Using auto-complete fields')
628 win
= demoPage5(self
, log
)
629 self
.AddPage(win
, 'Other masked controls')
632 #----------------------------------------------------------------------------
634 def runTest(frame
, nb
, log
):
635 testWin
= TestMaskedTextCtrls(nb
, -1, log
)
639 app
= wx
.PySimpleApp()
640 frame
= wx
.Frame(None, -1, "Test MaskedTextCtrl", size
=(640, 480))
641 win
= TestMaskedTextCtrls(frame
, -1, sys
.stdout
)
644 #----------------------------------------------------------------------------
648 """ + med
.__doc
__ + """
652 if __name__
== "__main__":
655 run
.main(['', os
.path
.basename(sys
.argv
[0])])