]>
Commit | Line | Data |
---|---|---|
d14a1e28 RD |
1 | #---------------------------------------------------------------------------- |
2 | # Name: wxPython.lib.maskedctrl.py | |
3 | # Author: Will Sadkin | |
4 | # Created: 09/24/2003 | |
5 | # Copyright: (c) 2003 by Will Sadkin | |
6 | # RCS-ID: $Id$ | |
7 | # License: wxWindows license | |
8 | #---------------------------------------------------------------------------- | |
9 | ||
10 | """<html><body> | |
11 | <P> | |
12 | <B>wxMaskedCtrl</B> is actually a factory function for several types of | |
13 | masked edit controls: | |
14 | <P> | |
15 | <UL> | |
16 | <LI><b>wxMaskedTextCtrl</b> - standard masked edit text box</LI> | |
17 | <LI><b>wxMaskedComboBox</b> - adds combobox capabilities</LI> | |
18 | <LI><b>wxIpAddrCtrl</b> - adds logical input semantics for IP address entry</LI> | |
19 | <LI><b>wxTimeCtrl</b> - special subclass handling lots of time formats as values</LI> | |
20 | <LI><b>wxMaskedNumCtrl</b> - special subclass handling numeric values</LI> | |
21 | </UL> | |
22 | <P> | |
23 | <B>wxMaskedCtrl</B> works by looking for a special <b><i>controlType</i></b> | |
24 | parameter in the variable arguments of the control, to determine | |
25 | what kind of instance to return. | |
26 | controlType can be one of: | |
27 | <PRE><FONT SIZE=-1> | |
28 | controlTypes.MASKEDTEXT | |
29 | controlTypes.MASKEDCOMBO | |
30 | controlTypes.IPADDR | |
31 | controlTypes.TIME | |
32 | controlTypes.NUMBER | |
33 | </FONT></PRE> | |
34 | These constants are also available individually, ie, you can | |
35 | use either of the following: | |
36 | <PRE><FONT SIZE=-1> | |
37 | from wxPython.wx.lib.maskedctrl import wxMaskedCtrl, MASKEDCOMBO, MASKEDTEXT, NUMBER | |
38 | from wxPython.wx.lib.maskedctrl import wxMaskedCtrl, controlTypes | |
39 | </FONT></PRE> | |
40 | If not specified as a keyword argument, the default controlType is | |
41 | controlTypes.MASKEDTEXT. | |
42 | <P> | |
43 | Each of the above classes has its own unique arguments, but wxMaskedCtrl | |
44 | provides a single "unified" interface for masked controls. wxMaskedTextCtrl, | |
45 | wxMaskedComboBox and wxIpAddrCtrl are all documented below; the others have | |
46 | their own demo pages and interface descriptions. | |
47 | </body></html> | |
48 | """ | |
49 | ||
50 | from wxPython.lib.maskededit import wxMaskedTextCtrl, wxMaskedComboBox, wxIpAddrCtrl | |
51 | from wxPython.lib.maskednumctrl import wxMaskedNumCtrl | |
52 | from wxPython.lib.timectrl import wxTimeCtrl | |
53 | ||
54 | ||
55 | # "type" enumeration for class instance factory function | |
56 | MASKEDTEXT = 0 | |
57 | MASKEDCOMBO = 1 | |
58 | IPADDR = 2 | |
59 | TIME = 3 | |
60 | NUMBER = 4 | |
61 | ||
62 | # for ease of import | |
63 | class controlTypes: | |
64 | MASKEDTEXT = MASKEDTEXT | |
65 | MASKEDCOMBO = MASKEDCOMBO | |
66 | IPADDR = IPADDR | |
67 | TIME = TIME | |
68 | NUMBER = NUMBER | |
69 | ||
70 | ||
71 | def wxMaskedCtrl( *args, **kwargs): | |
72 | """ | |
73 | Actually a factory function providing a unifying | |
74 | interface for generating masked controls. | |
75 | """ | |
76 | if not kwargs.has_key('controlType'): | |
77 | controlType = MASKEDTEXT | |
78 | else: | |
79 | controlType = kwargs['controlType'] | |
80 | del kwargs['controlType'] | |
81 | ||
82 | if controlType == MASKEDTEXT: | |
83 | return wxMaskedTextCtrl(*args, **kwargs) | |
84 | ||
85 | elif controlType == MASKEDCOMBO: | |
86 | return wxMaskedComboBox(*args, **kwargs) | |
87 | ||
88 | elif controlType == IPADDR: | |
89 | return wxIpAddrCtrl(*args, **kwargs) | |
90 | ||
91 | elif controlType == TIME: | |
92 | return wxTimeCtrl(*args, **kwargs) | |
93 | ||
94 | elif controlType == NUMBER: | |
95 | return wxMaskedNumCtrl(*args, **kwargs) | |
96 | ||
97 | else: | |
98 | raise AttributeError( | |
99 | "invalid controlType specified: %s" % repr(controlType)) | |
8b9a4190 | 100 | |
8b9a4190 | 101 |