]> git.saurik.com Git - wxWidgets.git/blob - wxPython/wx/lib/masked/ctrl.py
wx.lib.masked: Patch from Will Sadkin. Includes Unicode fixes, plus
[wxWidgets.git] / wxPython / wx / lib / masked / ctrl.py
1 #----------------------------------------------------------------------------
2 # Name: wxPython.lib.masked.ctrl.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 """
19
20 *masked.Ctrl* is actually a factory function for several types of
21 masked edit controls:
22
23 ================= =========================================================
24 masked.TextCtrl standard masked edit text box
25 masked.ComboBox adds combobox capabilities
26 masked.IpAddrCtrl adds logical input semantics for IP address entry
27 masked.TimeCtrl special subclass handling lots of time formats as values
28 masked.NumCtrl special subclass handling numeric values
29 ================= =========================================================
30
31 masked.Ctrl works by looking for a special *controlType*
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
36 controlTypes.TEXT
37 controlTypes.COMBO
38 controlTypes.IPADDR
39 controlTypes.TIME
40 controlTypes.NUMBER
41
42 These constants are also available individually, ie, you can
43 use either of the following::
44
45 from wxPython.wx.lib.masked import Ctrl, COMBO, TEXT, NUMBER, TIME
46 from wxPython.wx.lib.masked import Ctrl, controlTypes
47
48 If not specified as a keyword argument, the default controlType is
49 controlTypes.TEXT.
50
51 Each of the above classes has its own unique arguments, but Masked.Ctrl
52 provides a single "unified" interface for masked controls.
53
54
55 """
56
57 from wx.lib.masked import TextCtrl, ComboBox, IpAddrCtrl
58 from wx.lib.masked import NumCtrl
59 from wx.lib.masked import TimeCtrl
60
61
62 # "type" enumeration for class instance factory function
63 TEXT = 0
64 COMBO = 1
65 IPADDR = 2
66 TIME = 3
67 NUMBER = 4
68
69 # for ease of import
70 class controlTypes:
71 TEXT = TEXT
72 COMBO = COMBO
73 IPADDR = IPADDR
74 TIME = TIME
75 NUMBER = NUMBER
76
77
78 def Ctrl( *args, **kwargs):
79 """
80 Actually a factory function providing a unifying
81 interface for generating masked controls.
82 """
83 if not kwargs.has_key('controlType'):
84 controlType = TEXT
85 else:
86 controlType = kwargs['controlType']
87 del kwargs['controlType']
88
89 if controlType == TEXT:
90 return TextCtrl(*args, **kwargs)
91
92 elif controlType == COMBO:
93 return ComboBox(*args, **kwargs)
94
95 elif controlType == IPADDR:
96 return IpAddrCtrl(*args, **kwargs)
97
98 elif controlType == TIME:
99 return TimeCtrl(*args, **kwargs)
100
101 elif controlType == NUMBER:
102 return NumCtrl(*args, **kwargs)
103
104 else:
105 raise AttributeError(
106 "invalid controlType specified: %s" % repr(controlType))
107
108