]> git.saurik.com Git - wxWidgets.git/blob - wxPython/wx/lib/maskedctrl.py
Fix or add some DoGetBestSize's
[wxWidgets.git] / wxPython / wx / lib / maskedctrl.py
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 # 12/09/2003 - Jeff Grimmett (grimmtooth@softhome.net)
10 #
11 # o Updated for wx namespace (minor)
12 #
13 # 12/20/2003 - Jeff Grimmett (grimmtooth@softhome.net)
14 #
15 # o Removed wx prefix
16 #
17
18 """<html><body>
19 <P>
20 <B>MaskedCtrl</B> is actually a factory function for several types of
21 masked edit controls:
22 <P>
23 <UL>
24 <LI><b>MaskedTextCtrl</b> - standard masked edit text box</LI>
25 <LI><b>MaskedComboBox</b> - adds combobox capabilities</LI>
26 <LI><b>IpAddrCtrl</b> - adds logical input semantics for IP address entry</LI>
27 <LI><b>TimeCtrl</b> - special subclass handling lots of time formats as values</LI>
28 <LI><b>MaskedNumCtrl</b> - special subclass handling numeric values</LI>
29 </UL>
30 <P>
31 <B>MaskedCtrl</B> works by looking for a special <b><i>controlType</i></b>
32 parameter in the variable arguments of the control, to determine
33 what kind of instance to return.
34 controlType can be one of:
35 <PRE><FONT SIZE=-1>
36 controlTypes.MASKEDTEXT
37 controlTypes.MASKEDCOMBO
38 controlTypes.IPADDR
39 controlTypes.TIME
40 controlTypes.NUMBER
41 </FONT></PRE>
42 These constants are also available individually, ie, you can
43 use either of the following:
44 <PRE><FONT SIZE=-1>
45 from wxPython.wx.lib.maskedctrl import MaskedCtrl, MASKEDCOMBO, MASKEDTEXT, NUMBER
46 from wxPython.wx.lib.maskedctrl import MaskedCtrl, controlTypes
47 </FONT></PRE>
48 If not specified as a keyword argument, the default controlType is
49 controlTypes.MASKEDTEXT.
50 <P>
51 Each of the above classes has its own unique arguments, but MaskedCtrl
52 provides a single "unified" interface for masked controls. MaskedTextCtrl,
53 MaskedComboBox and IpAddrCtrl are all documented below; the others have
54 their own demo pages and interface descriptions.
55 </body></html>
56 """
57
58 from wx.lib.maskededit import MaskedTextCtrl, MaskedComboBox, IpAddrCtrl
59 from wx.lib.maskednumctrl import MaskedNumCtrl
60 from wx.lib.timectrl import TimeCtrl
61
62
63 # "type" enumeration for class instance factory function
64 MASKEDTEXT = 0
65 MASKEDCOMBO = 1
66 IPADDR = 2
67 TIME = 3
68 NUMBER = 4
69
70 # for ease of import
71 class controlTypes:
72 MASKEDTEXT = MASKEDTEXT
73 MASKEDCOMBO = MASKEDCOMBO
74 IPADDR = IPADDR
75 TIME = TIME
76 NUMBER = NUMBER
77
78
79 def MaskedCtrl( *args, **kwargs):
80 """
81 Actually a factory function providing a unifying
82 interface for generating masked controls.
83 """
84 if not kwargs.has_key('controlType'):
85 controlType = MASKEDTEXT
86 else:
87 controlType = kwargs['controlType']
88 del kwargs['controlType']
89
90 if controlType == MASKEDTEXT:
91 return MaskedTextCtrl(*args, **kwargs)
92
93 elif controlType == MASKEDCOMBO:
94 return MaskedComboBox(*args, **kwargs)
95
96 elif controlType == IPADDR:
97 return IpAddrCtrl(*args, **kwargs)
98
99 elif controlType == TIME:
100 return TimeCtrl(*args, **kwargs)
101
102 elif controlType == NUMBER:
103 return MaskedNumCtrl(*args, **kwargs)
104
105 else:
106 raise AttributeError(
107 "invalid controlType specified: %s" % repr(controlType))
108
109