7 import wx
.lib
.maskededit
as med
8 import wx
.lib
.maskedctrl
as mctl
9 import wx
.lib
.scrolledpanel
as scroll
14 Centralized routines common to demo pages, to remove repetition.
16 def labelGeneralTable(self
, sizer
):
17 description
= wx
.StaticText( self
, -1, "Description", )
18 mask
= wx
.StaticText( self
, -1, "Mask Value" )
19 formatcode
= wx
.StaticText( self
, -1, "Format" )
20 regex
= wx
.StaticText( self
, -1, "Regexp Validator(opt.)" )
21 ctrl
= wx
.StaticText( self
, -1, "MaskedTextCtrl" )
23 description
.SetFont( wx
.Font(9, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD
))
24 mask
.SetFont( wx
.Font(9, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD
))
25 formatcode
.SetFont( wx
.Font(9, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD
) )
26 regex
.SetFont( wx
.Font(9, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD
))
27 ctrl
.SetFont( wx
.Font(9, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD
))
29 sizer
.Add(description
)
36 def layoutGeneralTable(self
, controls
, sizer
):
37 for control
in controls
:
38 sizer
.Add( wx
.StaticText( self
, -1, control
[0]) )
39 sizer
.Add( wx
.StaticText( self
, -1, control
[1]) )
40 sizer
.Add( wx
.StaticText( self
, -1, control
[3]) )
41 sizer
.Add( wx
.StaticText( self
, -1, control
[4]) )
43 if control
in controls
:
44 newControl
= med
.MaskedTextCtrl( self
, -1, "",
46 excludeChars
= control
[2],
47 formatcodes
= control
[3],
49 validRegex
= control
[4],
50 validRange
= control
[5],
52 choiceRequired
= True,
53 defaultValue
= control
[7],
56 self
.editList
.append(newControl
)
60 def changeControlParams(self
, event
, parameter
, checked_value
, notchecked_value
):
61 if event
.IsChecked(): value
= checked_value
62 else: value
= notchecked_value
64 kwargs
= {parameter: value}
66 for control
in self
.editList
:
67 control
.SetCtrlParameters(**kwargs
)
74 #----------------------------------------------------------------------------
75 class demoPage1(scroll
.ScrolledPanel
, demoMixin
):
76 def __init__(self
, parent
, log
):
77 scroll
.ScrolledPanel
.__init
__(self
, parent
, -1)
78 self
.sizer
= wx
.BoxSizer( wx
.VERTICAL
)
81 label
= wx
.StaticText( self
, -1, """\
82 Here are some basic MaskedTextCtrls to give you an idea of what you can do
83 with this control. Note that all controls have been auto-sized by including 'F' in
86 Try entering nonsensical or partial values in validated fields to see what happens.
87 Note that the State and Last Name fields are list-limited (valid last names are:
88 Smith, Jones, Williams). Signs on numbers can be toggled with the minus key.
90 label
.SetForegroundColour( "Blue" )
91 header
= wx
.BoxSizer( wx
.HORIZONTAL
)
92 header
.Add( label
, 0, flag
=wx
.ALIGN_LEFT|wx
.ALL
, border
= 5 )
94 highlight
= wx
.CheckBox( self
, -1, "Highlight Empty" )
95 disallow
= wx
.CheckBox( self
, -1, "Disallow Empty" )
96 showFill
= wx
.CheckBox( self
, -1, "change fillChar" )
98 vbox
= wx
.BoxSizer( wx
.VERTICAL
)
99 vbox
.Add( highlight
, 0, wx
.ALIGN_LEFT|wx
.ALL
, 5 )
100 vbox
.Add( disallow
, 0, wx
.ALIGN_LEFT|wx
.ALL
, 5 )
101 vbox
.Add( showFill
, 0, wx
.ALIGN_LEFT|wx
.ALL
, 5 )
103 header
.Add(vbox
, 0, flag
=wx
.ALIGN_LEFT|wx
.ALL
, border
=5 )
105 self
.Bind(wx
.EVT_CHECKBOX
, self
.onHighlightEmpty
, id=highlight
.GetId())
106 self
.Bind(wx
.EVT_CHECKBOX
, self
.onDisallowEmpty
, id=disallow
.GetId())
107 self
.Bind(wx
.EVT_CHECKBOX
, self
.onShowFill
, id=showFill
.GetId())
109 grid
= wx
.FlexGridSizer( 0, 5, vgap
=10, hgap
=10 )
110 self
.labelGeneralTable(grid
)
112 # The following list is of the controls for the demo. Feel free to play around with
115 #description mask excl format regexp range,list,initial
116 ("Phone No", "(###) ###-#### x:###", "", 'F^-', "^\(\d{3}\) \d{3}-\d{4}", '','',''),
117 ("Social Sec#", "###-##-####", "", 'F', "\d{3}-\d{2}-\d{4}", '','',''),
118 ("Full Name", "C{14}", "", 'F_', '^[A-Z][a-zA-Z]+ [A-Z][a-zA-Z]+', '','',''),
119 ("Last Name Only", "C{14}", "", 'F {list}', '^[A-Z][a-zA-Z]+', '',('Smith','Jones','Williams'),''),
120 ("Zip plus 4", "#{5}-#{4}", "", 'F', "\d{5}-(\s{4}|\d{4})", '','',''),
121 ("Customer No", "\CAA-###", "", 'F!', "C[A-Z]{2}-\d{3}", '','',''),
122 ("Invoice Total", "#{9}.##", "", 'F-_,', "", '','',''),
123 ("Integer", "#{9}", "", 'F-_', "", '','',''),
126 self
.layoutGeneralTable(controls
, grid
)
127 self
.sizer
.Add( header
, 0, flag
=wx
.ALIGN_LEFT|wx
.ALL
, border
=5 )
128 self
.sizer
.Add( grid
, 0, flag
= wx
.ALIGN_LEFT|wx
.LEFT
, border
=5 )
129 self
.SetSizer(self
.sizer
)
130 self
.SetupScrolling()
131 self
.SetAutoLayout(1)
134 def onDisallowEmpty( self
, event
):
135 """ Set emptyInvalid parameter on/off """
136 self
.changeControlParams( event
, "emptyInvalid", True, False )
138 def onHighlightEmpty( self
, event
):
139 """ Highlight empty values"""
140 self
.changeControlParams( event
, "emptyBackgroundColour", "Blue", "White" )
142 def onShowFill( self
, event
):
143 """ Set fillChar parameter to '?' or ' ' """
144 self
.changeControlParams( event
, "fillChar", '?', ' ' )
147 class demoPage2(scroll
.ScrolledPanel
, demoMixin
):
148 def __init__( self
, parent
, log
):
150 scroll
.ScrolledPanel
.__init
__( self
, parent
, -1 )
151 self
.sizer
= wx
.BoxSizer( wx
.VERTICAL
)
153 label
= wx
.StaticText( self
, -1, """\
154 All these controls have been created by passing a single parameter, the autoformat code,
155 and use the factory class MaskedCtrl with its default controlType.
156 The maskededit module contains an internal dictionary of types and formats (autoformats).
157 Many of these already do complicated validation; To see some examples, try
158 29 Feb 2002 vs. 2004 for the date formats, or email address validation.
161 label
.SetForegroundColour( "Blue" )
162 self
.sizer
.Add( label
, 0, wx
.ALIGN_LEFT|wx
.ALL
, 5 )
164 description
= wx
.StaticText( self
, -1, "Description")
165 autofmt
= wx
.StaticText( self
, -1, "AutoFormat Code")
166 ctrl
= wx
.StaticText( self
, -1, "MaskedCtrl")
168 description
.SetFont( wx
.Font( 9, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD
) )
169 autofmt
.SetFont( wx
.Font( 9, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD
) )
170 ctrl
.SetFont( wx
.Font( 9, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD
) )
172 grid
= wx
.FlexGridSizer( 0, 3, vgap
=10, hgap
=5 )
173 grid
.Add( description
, 0, wx
.ALIGN_LEFT
)
174 grid
.Add( autofmt
, 0, wx
.ALIGN_LEFT
)
175 grid
.Add( ctrl
, 0, wx
.ALIGN_LEFT
)
177 for autoformat
, desc
in med
.autoformats
:
178 grid
.Add( wx
.StaticText( self
, -1, desc
), 0, wx
.ALIGN_LEFT
)
179 grid
.Add( wx
.StaticText( self
, -1, autoformat
), 0, wx
.ALIGN_LEFT
)
180 grid
.Add( mctl
.MaskedCtrl( self
, -1, "",
181 autoformat
= autoformat
,
186 self
.sizer
.Add( grid
, 0, wx
.ALIGN_LEFT|wx
.ALL
, border
=5 )
187 self
.SetSizer( self
.sizer
)
188 self
.SetAutoLayout( 1 )
189 self
.SetupScrolling()
192 class demoPage3(scroll
.ScrolledPanel
, demoMixin
):
193 def __init__(self
, parent
, log
):
195 scroll
.ScrolledPanel
.__init
__(self
, parent
, -1)
196 self
.sizer
= wx
.BoxSizer( wx
.VERTICAL
)
199 label
= wx
.StaticText( self
, -1, """\
200 Here MaskedTextCtrls that have default values. The states
201 control has a list of valid values, and the unsigned integer
202 has a legal range specified.
204 label
.SetForegroundColour( "Blue" )
205 requireValid
= wx
.CheckBox( self
, -1, "Require Valid Value" )
206 self
.Bind(wx
.EVT_CHECKBOX
, self
.onRequireValid
, id=requireValid
.GetId())
208 header
= wx
.BoxSizer( wx
.HORIZONTAL
)
209 header
.Add( label
, 0, flag
=wx
.ALIGN_LEFT|wx
.ALL
, border
= 5)
211 header
.Add( requireValid
, 0, flag
=wx
.ALIGN_LEFT|wx
.ALL
, border
=10 )
213 grid
= wx
.FlexGridSizer( 0, 5, vgap
=10, hgap
=10 )
214 self
.labelGeneralTable( grid
)
217 #description mask excl format regexp range,list,initial
218 ("U.S. State (2 char)", "AA", "", 'F!_', "[A-Z]{2}", '',med
.states
, med
.states
[0]),
219 ("Integer (signed)", "#{6}", "", 'F-_', "", '','', ' 0 '),
220 ("Integer (unsigned)\n(1-399)","######", "", 'F_', "", (1,399),'', '1 '),
221 ("Float (signed)", "#{6}.#{9}", "", 'F-_R', "", '','', '000000.000000000'),
222 ("Date (MDY) + Time", "##/##/#### ##:##:## AM", 'BCDEFGHIJKLMNOQRSTUVWXYZ','DF!',"", '','', wx
.DateTime_Now().Format("%m/%d/%Y %I:%M:%S %p")),
224 self
.layoutGeneralTable( controls
, grid
)
226 self
.sizer
.Add( header
, 0, flag
=wx
.ALIGN_LEFT|wx
.ALL
, border
=5 )
227 self
.sizer
.Add( grid
, 0, flag
=wx
.ALIGN_LEFT|wx
.ALL
, border
=5 )
229 self
.SetSizer( self
.sizer
)
230 self
.SetAutoLayout( 1 )
231 self
.SetupScrolling()
233 def onRequireValid( self
, event
):
234 """ Set validRequired parameter on/off """
235 self
.changeControlParams( event
, "validRequired", True, False )
238 class demoPage4(scroll
.ScrolledPanel
, demoMixin
):
239 def __init__( self
, parent
, log
):
241 scroll
.ScrolledPanel
.__init
__( self
, parent
, -1 )
242 self
.sizer
= wx
.BoxSizer( wx
.VERTICAL
)
244 label
= wx
.StaticText( self
, -1, """\
245 These controls have field-specific choice lists and allow autocompletion.
247 Down arrow or Page Down in an uncompleted field with an auto-completable field will attempt
248 to auto-complete a field if it has a choice list.
249 Page Down and Shift-Down arrow will also auto-complete, or cycle through the complete list.
250 Page Up and Shift-Up arrow will similarly cycle backwards through the list.
253 label
.SetForegroundColour( "Blue" )
254 self
.sizer
.Add( label
, 0, wx
.ALIGN_LEFT|wx
.ALL
, 5 )
256 description
= wx
.StaticText( self
, -1, "Description" )
257 autofmt
= wx
.StaticText( self
, -1, "AutoFormat Code" )
258 fields
= wx
.StaticText( self
, -1, "Field Objects" )
259 ctrl
= wx
.StaticText( self
, -1, "MaskedTextCtrl" )
261 description
.SetFont( wx
.Font( 9, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD
) )
262 autofmt
.SetFont( wx
.Font( 9, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD
) )
263 fields
.SetFont( wx
.Font( 9, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD
) )
264 ctrl
.SetFont( wx
.Font( 9, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD
) )
266 grid
= wx
.FlexGridSizer( 0, 4, vgap
=10, hgap
=10 )
267 grid
.Add( description
, 0, wx
.ALIGN_LEFT
)
268 grid
.Add( autofmt
, 0, wx
.ALIGN_LEFT
)
269 grid
.Add( fields
, 0, wx
.ALIGN_LEFT
)
270 grid
.Add( ctrl
, 0, wx
.ALIGN_LEFT
)
272 autoformat
= "USPHONEFULLEXT"
273 fieldsDict
= {0: med.Field(choices=["617","781","508","978","413"], choiceRequired=True)}
278 choiceRequired=True)}"""
279 grid
.Add( wx
.StaticText( self
, -1, "Restricted Area Code"), 0, wx
.ALIGN_LEFT
)
280 grid
.Add( wx
.StaticText( self
, -1, autoformat
), 0, wx
.ALIGN_LEFT
)
281 grid
.Add( wx
.StaticText( self
, -1, fieldsLabel
), 0, wx
.ALIGN_LEFT
)
282 grid
.Add( med
.MaskedTextCtrl( self
, -1, "",
283 autoformat
= autoformat
,
289 autoformat
= "EXPDATEMMYY"
290 fieldsDict
= {1: med.Field(choices=["03", "04", "05"], choiceRequired=True)}
294 choiceRequired=True)}"""
295 exp
= med
.MaskedTextCtrl( self
, -1, "",
296 autoformat
= autoformat
,
301 grid
.Add( wx
.StaticText( self
, -1, "Restricted Expiration"), 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( exp
, 0, wx
.ALIGN_LEFT
)
306 fieldsDict
= {0: med
.Field(choices
=["02134","02155"], choiceRequired
=True),
307 1: med
.Field(choices
=["1234", "5678"], choiceRequired
=False)}
309 {0: Field(choices=["02134","02155"],
310 choiceRequired=True),
311 1: Field(choices=["1234", "5678"],
312 choiceRequired=False)}"""
313 autoformat
= "USZIPPLUS4"
314 zip = med
.MaskedTextCtrl( self
, -1, "",
315 autoformat
= autoformat
,
320 grid
.Add( wx
.StaticText( self
, -1, "Restricted Zip + 4"), 0, wx
.ALIGN_LEFT
)
321 grid
.Add( wx
.StaticText( self
, -1, autoformat
), 0, wx
.ALIGN_LEFT
)
322 grid
.Add( wx
.StaticText( self
, -1, fieldsLabel
), 0, wx
.ALIGN_LEFT
)
323 grid
.Add( zip, 0, wx
.ALIGN_LEFT
)
325 self
.sizer
.Add( grid
, 0, wx
.ALIGN_LEFT|wx
.ALL
, border
=5 )
326 self
.SetSizer( self
.sizer
)
327 self
.SetAutoLayout(1)
328 self
.SetupScrolling()
331 class demoPage5(scroll
.ScrolledPanel
, demoMixin
):
332 def __init__( self
, parent
, log
):
334 scroll
.ScrolledPanel
.__init
__( self
, parent
, -1 )
335 self
.sizer
= wx
.BoxSizer( wx
.VERTICAL
)
338 labelMaskedCombos
= wx
.StaticText( self
, -1, """\
339 These are some examples of MaskedComboBox:""")
340 labelMaskedCombos
.SetForegroundColour( "Blue" )
343 label_statecode
= wx
.StaticText( self
, -1, """\
344 A state selector; only
345 "legal" values can be
347 statecode
= med
.MaskedComboBox( self
, -1, med
.states
[0],
348 choices
= med
.states
,
349 autoformat
="USSTATE")
351 label_statename
= wx
.StaticText( self
, -1, """\
352 A state name selector,
353 with auto-select:""")
355 # Create this one using factory function:
356 statename
= mctl
.MaskedCtrl( self
, -1, med
.state_names
[0],
357 controlType
= mctl
.controlTypes
.MASKEDCOMBO
,
358 choices
= med
.state_names
,
359 autoformat
="USSTATENAME",
361 statename
.SetCtrlParameters(formatcodes
= 'F!V_')
364 numerators
= [ str(i
) for i
in range(1, 4) ]
365 denominators
= [ string
.ljust(str(i
), 2) for i
in [2,3,4,5,8,16,32,64] ]
366 fieldsDict
= {0: med
.Field(choices
=numerators
, choiceRequired
=False),
367 1: med
.Field(choices
=denominators
, choiceRequired
=True)}
370 for d
in denominators
:
372 choices
.append( '%s/%s' % (n
,d
) )
375 label_fraction
= wx
.StaticText( self
, -1, """\
376 A masked ComboBox for fraction selection.
377 Choices for each side of the fraction can
378 be selected with PageUp/Down:""")
380 fraction
= mctl
.MaskedCtrl( self
, -1, "",
381 controlType
= mctl
.MASKEDCOMBO
,
383 choiceRequired
= True,
386 validRegex
= "^\d\/\d\d?",
387 fields
= fieldsDict
)
390 label_code
= wx
.StaticText( self
, -1, """\
391 A masked ComboBox to validate
392 text from a list of numeric codes:""")
394 choices
= ["91", "136", "305", "4579"]
395 code
= med
.MaskedComboBox( self
, -1, choices
[0],
397 choiceRequired
= True,
401 label_selector
= wx
.StaticText( self
, -1, """\
404 self
.list_selector
= wx
.ComboBox(self
, -1, '', choices
= ['list1', 'list2', 'list3'])
405 self
.dynamicbox
= mctl
.MaskedCtrl( self
, -1, ' ',
406 controlType
= mctl
.controlTypes
.MASKEDCOMBO
,
409 # these are to give dropdown some initial height,
410 # as base control apparently only sets that size
411 # during initial construction <sigh>:
412 choices
= ['', '1', '2', '3', '4', '5'] )
414 self
.dynamicbox
.Clear() # get rid of initial choices used to size the dropdown
417 labelIpAddrs
= wx
.StaticText( self
, -1, """\
418 Here are some examples of IpAddrCtrl, a control derived from MaskedTextCtrl:""")
419 labelIpAddrs
.SetForegroundColour( "Blue" )
422 label_ipaddr1
= wx
.StaticText( self
, -1, "An empty control:")
423 ipaddr1
= med
.IpAddrCtrl( self
, -1, style
= wx
.TE_PROCESS_TAB
)
426 label_ipaddr2
= wx
.StaticText( self
, -1, "A restricted mask:")
427 ipaddr2
= med
.IpAddrCtrl( self
, -1, mask
=" 10. 1.109.###" )
430 label_ipaddr3
= wx
.StaticText( self
, -1, """\
431 A control with restricted legal values:
432 10. (1|2) . (129..255) . (0..255)""")
433 ipaddr3
= mctl
.MaskedCtrl( self
, -1,
434 controlType
= mctl
.controlTypes
.IPADDR
,
435 mask
=" 10. #.###.###")
436 ipaddr3
.SetFieldParameters(0, validRegex
="1|2",validRequired
=False ) # requires entry to match or not allowed
438 # This allows any value in penultimate field, but colors anything outside of the range invalid:
439 ipaddr3
.SetFieldParameters(1, validRange
=(129,255), validRequired
=False )
443 labelNumerics
= wx
.StaticText( self
, -1, """\
444 Here are some useful configurations of a MaskedTextCtrl for integer and floating point input that still treat
445 the control as a text control. (For a true numeric control, check out the MaskedNumCtrl class!)""")
446 labelNumerics
.SetForegroundColour( "Blue" )
448 label_intctrl1
= wx
.StaticText( self
, -1, """\
449 An integer entry control with
450 shifting insert enabled:""")
451 self
.intctrl1
= med
.MaskedTextCtrl(self
, -1, name
='intctrl', mask
="#{9}", formatcodes
= '_-,F>')
452 label_intctrl2
= wx
.StaticText( self
, -1, """\
453 Right-insert integer entry:""")
454 self
.intctrl2
= med
.MaskedTextCtrl(self
, -1, name
='intctrl', mask
="#{9}", formatcodes
= '_-,Fr')
456 label_floatctrl
= wx
.StaticText( self
, -1, """\
457 A floating point entry control
458 with right-insert for ordinal:""")
459 self
.floatctrl
= med
.MaskedTextCtrl(self
, -1, name
='floatctrl', mask
="#{9}.#{2}", formatcodes
="F,_-R", useParensForNegatives
=False)
460 self
.floatctrl
.SetFieldParameters(0, formatcodes
='r<', validRequired
=True) # right-insert, require explicit cursor movement to change fields
461 self
.floatctrl
.SetFieldParameters(1, defaultValue
='00') # don't allow blank fraction
463 label_numselect
= wx
.StaticText( self
, -1, """\
464 <= Programmatically set the value
465 of the float entry ctrl:""")
466 numselect
= wx
.ComboBox(self
, -1, choices
= [ '', '111', '222.22', '-3', '54321.666666666', '-1353.978',
467 '1234567', '-1234567', '123456789', '-123456789.1',
468 '1234567890.', '-1234567890.1' ])
470 parens_check
= wx
.CheckBox(self
, -1, "Use () to indicate negatives in above controls")
474 gridCombos
= wx
.FlexGridSizer( 0, 4, vgap
=10, hgap
= 10 )
475 gridCombos
.Add( label_statecode
, 0, wx
.ALIGN_LEFT
)
476 gridCombos
.Add( statecode
, 0, wx
.ALIGN_LEFT
)
477 gridCombos
.Add( label_fraction
, 0, wx
.ALIGN_LEFT
)
478 gridCombos
.Add( fraction
, 0, wx
.ALIGN_LEFT
)
479 gridCombos
.Add( label_statename
, 0, wx
.ALIGN_LEFT
)
480 gridCombos
.Add( statename
, 0, wx
.ALIGN_LEFT
)
481 gridCombos
.Add( label_code
, 0, wx
.ALIGN_LEFT
)
482 gridCombos
.Add( code
, 0, wx
.ALIGN_LEFT
)
483 gridCombos
.Add( label_selector
, 0, wx
.ALIGN_LEFT
)
484 hbox
= wx
.BoxSizer( wx
.HORIZONTAL
)
485 hbox
.Add( self
.list_selector
, 0, wx
.ALIGN_LEFT
)
486 hbox
.Add(wx
.StaticText(self
, -1, ' => '), 0, wx
.ALIGN_LEFT
)
487 hbox
.Add( self
.dynamicbox
, 0, wx
.ALIGN_LEFT
)
488 gridCombos
.Add( hbox
, 0, wx
.ALIGN_LEFT
)
490 gridIpAddrs
= wx
.FlexGridSizer( 0, 4, vgap
=10, hgap
= 15 )
491 gridIpAddrs
.Add( label_ipaddr1
, 0, wx
.ALIGN_LEFT
)
492 gridIpAddrs
.Add( ipaddr1
, 0, wx
.ALIGN_LEFT
)
493 gridIpAddrs
.Add( label_ipaddr2
, 0, wx
.ALIGN_LEFT
)
494 gridIpAddrs
.Add( ipaddr2
, 0, wx
.ALIGN_LEFT
)
495 gridIpAddrs
.Add( label_ipaddr3
, 0, wx
.ALIGN_LEFT
)
496 gridIpAddrs
.Add( ipaddr3
, 0, wx
.ALIGN_LEFT
)
498 gridNumerics
= wx
.FlexGridSizer( 0, 4, vgap
=10, hgap
= 10 )
499 gridNumerics
.Add( label_intctrl1
, 0, wx
.ALIGN_LEFT
)
500 gridNumerics
.Add( self
.intctrl1
, 0, wx
.ALIGN_LEFT
)
501 gridNumerics
.Add( label_intctrl2
, 0, wx
.ALIGN_RIGHT
)
502 gridNumerics
.Add( self
.intctrl2
, 0, wx
.ALIGN_LEFT
)
503 gridNumerics
.Add( label_floatctrl
, 0, wx
.ALIGN_LEFT
)
504 gridNumerics
.Add( self
.floatctrl
, 0, wx
.ALIGN_LEFT
)
505 gridNumerics
.Add( label_numselect
, 0, wx
.ALIGN_RIGHT
)
506 gridNumerics
.Add( numselect
, 0, wx
.ALIGN_LEFT
)
508 self
.sizer
.Add( labelMaskedCombos
, 0, wx
.ALIGN_LEFT|wx
.ALL
, 5 )
509 self
.sizer
.Add( gridCombos
, 0, wx
.ALIGN_LEFT|wx
.ALL
, border
=5 )
510 self
.sizer
.Add( wx
.StaticLine(self
, -1), 0, wx
.EXPAND|wx
.TOP|wx
.BOTTOM
, border
=8 )
511 self
.sizer
.Add( labelIpAddrs
, 0, wx
.ALIGN_LEFT|wx
.ALL
, 5 )
512 self
.sizer
.Add( gridIpAddrs
, 0, wx
.ALIGN_LEFT|wx
.ALL
, border
=5 )
513 self
.sizer
.Add( wx
.StaticLine(self
, -1), 0, wx
.EXPAND|wx
.TOP|wx
.BOTTOM
, border
=8 )
514 self
.sizer
.Add( labelNumerics
, 0, wx
.ALIGN_LEFT|wx
.ALL
, 5 )
515 self
.sizer
.Add( gridNumerics
, 0, wx
.ALIGN_LEFT|wx
.ALL
, border
=5 )
516 self
.sizer
.Add( parens_check
, 0, wx
.ALIGN_LEFT|wx
.ALL
, 5 )
518 self
.SetSizer( self
.sizer
)
519 self
.SetAutoLayout(1)
520 self
.SetupScrolling()
522 self
.Bind(wx
.EVT_COMBOBOX
, self
.OnComboSelection
, id=fraction
.GetId())
523 self
.Bind(wx
.EVT_COMBOBOX
, self
.OnComboSelection
, id=code
.GetId())
524 self
.Bind(wx
.EVT_COMBOBOX
, self
.OnComboSelection
, id=statecode
.GetId())
525 self
.Bind(wx
.EVT_COMBOBOX
, self
.OnComboSelection
, id=statename
.GetId())
526 self
.Bind(wx
.EVT_TEXT
, self
.OnTextChange
, id=code
.GetId())
527 self
.Bind(wx
.EVT_TEXT
, self
.OnTextChange
, id=statecode
.GetId())
528 self
.Bind(wx
.EVT_TEXT
, self
.OnTextChange
, id=statename
.GetId())
529 self
.Bind(wx
.EVT_COMBOBOX
, self
.OnListSelection
, id=self
.list_selector
.GetId())
531 self
.Bind(wx
.EVT_TEXT
, self
.OnTextChange
, id=self
.intctrl1
.GetId())
532 self
.Bind(wx
.EVT_TEXT
, self
.OnTextChange
, id=self
.intctrl2
.GetId())
533 self
.Bind(wx
.EVT_TEXT
, self
.OnTextChange
, id=self
.floatctrl
.GetId())
534 self
.Bind(wx
.EVT_COMBOBOX
, self
.OnNumberSelect
, id=numselect
.GetId())
535 self
.Bind(wx
.EVT_CHECKBOX
, self
.OnParensCheck
, id=parens_check
.GetId())
537 self
.Bind(wx
.EVT_TEXT
, self
.OnIpAddrChange
, id=ipaddr1
.GetId())
538 self
.Bind(wx
.EVT_TEXT
, self
.OnIpAddrChange
, id=ipaddr2
.GetId())
539 self
.Bind(wx
.EVT_TEXT
, self
.OnIpAddrChange
, id=ipaddr3
.GetId())
544 def OnComboSelection( self
, event
):
545 ctl
= self
.FindWindowById( event
.GetId() )
546 if not ctl
.IsValid():
547 self
.log
.write('current value not a valid choice')
548 self
.log
.write('new value = %s' % ctl
.GetValue())
550 def OnTextChange( self
, event
):
551 ctl
= self
.FindWindowById( event
.GetId() )
553 self
.log
.write('new value = %s\n' % ctl
.GetValue() )
555 def OnNumberSelect( self
, event
):
556 value
= event
.GetString()
557 # Format choice to fit into format for #{9}.#{2}, with sign position reserved:
558 # (ordinal + fraction == 11 + decimal point + sign == 13)
560 floattext
= "%13.2f" % float(value
)
562 floattext
= value
# clear the value again
564 self
.floatctrl
.SetValue(floattext
)
566 type, value
, tb
= sys
.exc_info()
567 for line
in traceback
.format_exception_only(type, value
):
570 def OnParensCheck( self
, event
):
571 self
.intctrl1
.SetCtrlParameters(useParensForNegatives
=event
.IsChecked())
572 self
.intctrl2
.SetCtrlParameters(useParensForNegatives
=event
.IsChecked())
573 self
.floatctrl
.SetCtrlParameters(useParensForNegatives
=event
.IsChecked())
575 def OnIpAddrChange( self
, event
):
576 ipaddr
= self
.FindWindowById( event
.GetId() )
578 self
.log
.write('new addr = %s\n' % ipaddr
.GetAddress() )
580 def OnListSelection( self
, event
):
581 list = self
.list_selector
.GetStringSelection()
584 choices
= ['abc', 'defg', 'hi']
586 elif list == 'list2':
587 choices
= ['1', '2', '34', '567']
594 self
.dynamicbox
.SetCtrlParameters( mask
= mask
,
598 formatcodes
=formatcodes
)
599 self
.dynamicbox
.SetValue(choices
[0])
601 # ---------------------------------------------------------------------
602 class TestMaskedTextCtrls(wx
.Notebook
):
603 def __init__(self
, parent
, id, log
):
604 wx
.Notebook
.__init
__(self
, parent
, id)
607 win
= demoPage1(self
, log
)
608 self
.AddPage(win
, "General examples")
610 win
= demoPage2(self
, log
)
611 self
.AddPage(win
, 'Auto-formatted controls')
613 win
= demoPage3(self
, log
)
614 self
.AddPage(win
, "Using default values")
616 win
= demoPage4(self
, log
)
617 self
.AddPage(win
, 'Using auto-complete fields')
619 win
= demoPage5(self
, log
)
620 self
.AddPage(win
, 'Other masked controls')
623 #----------------------------------------------------------------------------
625 def runTest(frame
, nb
, log
):
626 testWin
= TestMaskedTextCtrls(nb
, -1, log
)
630 app
= wx
.PySimpleApp()
631 frame
= wx
.Frame(None, -1, "Test MaskedTextCtrl", size
=(640, 480))
632 win
= TestMaskedTextCtrls(frame
, -1, sys
.stdout
)
635 #----------------------------------------------------------------------------
639 """ + med
.__doc
__ + """
643 if __name__
== "__main__":
646 run
.main(['', os
.path
.basename(sys
.argv
[0])])