]>
Commit | Line | Data |
---|---|---|
d14a1e28 | 1 | #---------------------------------------------------------------------------- |
c878ceea | 2 | # Name: wxPython.lib.masked.ctrl.py |
d14a1e28 RD |
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 | #---------------------------------------------------------------------------- | |
b881fc78 RD |
9 | # 12/09/2003 - Jeff Grimmett (grimmtooth@softhome.net) |
10 | # | |
11 | # o Updated for wx namespace (minor) | |
c878ceea | 12 | # |
d4b73b1b RD |
13 | # 12/20/2003 - Jeff Grimmett (grimmtooth@softhome.net) |
14 | # | |
15 | # o Removed wx prefix | |
c878ceea | 16 | # |
d14a1e28 RD |
17 | |
18 | """<html><body> | |
19 | <P> | |
c878ceea | 20 | <B>masked.Ctrl</B> is actually a factory function for several types of |
d14a1e28 RD |
21 | masked edit controls: |
22 | <P> | |
23 | <UL> | |
c878ceea RD |
24 | <LI><b>masked.TextCtrl</b> - standard masked edit text box</LI> |
25 | <LI><b>masked.ComboBox</b> - adds combobox capabilities</LI> | |
26 | <LI><b>masked.IpAddrCtrl</b> - adds logical input semantics for IP address entry</LI> | |
27 | <LI><b>masked.TimeCtrl</b> - special subclass handling lots of time formats as values</LI> | |
28 | <LI><b>masked.NumCtrl</b> - special subclass handling numeric values</LI> | |
d14a1e28 RD |
29 | </UL> |
30 | <P> | |
c878ceea | 31 | <B>masked.Ctrl</B> works by looking for a special <b><i>controlType</i></b> |
d14a1e28 RD |
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> | |
c878ceea RD |
36 | controlTypes.TEXT |
37 | controlTypes.COMBO | |
d14a1e28 RD |
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> | |
c878ceea RD |
45 | from wxPython.wx.lib.masked import Ctrl, COMBO, TEXT, NUMBER, TIME |
46 | from wxPython.wx.lib.masked import Ctrl, controlTypes | |
d14a1e28 RD |
47 | </FONT></PRE> |
48 | If not specified as a keyword argument, the default controlType is | |
c878ceea | 49 | controlTypes.TEXT. |
d14a1e28 | 50 | <P> |
d4b73b1b | 51 | Each of the above classes has its own unique arguments, but MaskedCtrl |
c878ceea RD |
52 | provides a single "unified" interface for masked controls. Masked.TextCtrl, |
53 | masked.ComboBox and masked.IpAddrCtrl are all documented below; the others have | |
d14a1e28 RD |
54 | their own demo pages and interface descriptions. |
55 | </body></html> | |
56 | """ | |
57 | ||
c878ceea RD |
58 | from wx.lib.masked import TextCtrl, ComboBox, IpAddrCtrl |
59 | from wx.lib.masked import NumCtrl | |
60 | from wx.lib.masked import TimeCtrl | |
d14a1e28 RD |
61 | |
62 | ||
63 | # "type" enumeration for class instance factory function | |
c878ceea RD |
64 | TEXT = 0 |
65 | COMBO = 1 | |
d14a1e28 RD |
66 | IPADDR = 2 |
67 | TIME = 3 | |
68 | NUMBER = 4 | |
69 | ||
70 | # for ease of import | |
71 | class controlTypes: | |
c878ceea RD |
72 | TEXT = TEXT |
73 | COMBO = COMBO | |
d14a1e28 RD |
74 | IPADDR = IPADDR |
75 | TIME = TIME | |
76 | NUMBER = NUMBER | |
77 | ||
78 | ||
c878ceea | 79 | def Ctrl( *args, **kwargs): |
d14a1e28 RD |
80 | """ |
81 | Actually a factory function providing a unifying | |
82 | interface for generating masked controls. | |
83 | """ | |
84 | if not kwargs.has_key('controlType'): | |
c878ceea | 85 | controlType = TEXT |
d14a1e28 RD |
86 | else: |
87 | controlType = kwargs['controlType'] | |
88 | del kwargs['controlType'] | |
89 | ||
c878ceea RD |
90 | if controlType == TEXT: |
91 | return TextCtrl(*args, **kwargs) | |
d14a1e28 | 92 | |
c878ceea RD |
93 | elif controlType == COMBO: |
94 | return ComboBox(*args, **kwargs) | |
d14a1e28 RD |
95 | |
96 | elif controlType == IPADDR: | |
d4b73b1b | 97 | return IpAddrCtrl(*args, **kwargs) |
d14a1e28 RD |
98 | |
99 | elif controlType == TIME: | |
d4b73b1b | 100 | return TimeCtrl(*args, **kwargs) |
d14a1e28 RD |
101 | |
102 | elif controlType == NUMBER: | |
c878ceea | 103 | return NumCtrl(*args, **kwargs) |
d14a1e28 RD |
104 | |
105 | else: | |
106 | raise AttributeError( | |
107 | "invalid controlType specified: %s" % repr(controlType)) | |
8b9a4190 | 108 | |
8b9a4190 | 109 |