]>
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 | 17 | |
f54a36bb RD |
18 | """ |
19 | ||
20 | *masked.Ctrl* is actually a factory function for several types of | |
d14a1e28 | 21 | masked edit controls: |
f54a36bb RD |
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* | |
d14a1e28 RD |
32 | parameter in the variable arguments of the control, to determine |
33 | what kind of instance to return. | |
f54a36bb RD |
34 | controlType can be one of:: |
35 | ||
c878ceea RD |
36 | controlTypes.TEXT |
37 | controlTypes.COMBO | |
d14a1e28 RD |
38 | controlTypes.IPADDR |
39 | controlTypes.TIME | |
40 | controlTypes.NUMBER | |
f54a36bb | 41 | |
d14a1e28 | 42 | These constants are also available individually, ie, you can |
f54a36bb RD |
43 | use either of the following:: |
44 | ||
c878ceea RD |
45 | from wxPython.wx.lib.masked import Ctrl, COMBO, TEXT, NUMBER, TIME |
46 | from wxPython.wx.lib.masked import Ctrl, controlTypes | |
f54a36bb | 47 | |
d14a1e28 | 48 | If not specified as a keyword argument, the default controlType is |
c878ceea | 49 | controlTypes.TEXT. |
f54a36bb RD |
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 | ||
d14a1e28 RD |
55 | """ |
56 | ||
c878ceea RD |
57 | from wx.lib.masked import TextCtrl, ComboBox, IpAddrCtrl |
58 | from wx.lib.masked import NumCtrl | |
59 | from wx.lib.masked import TimeCtrl | |
d14a1e28 RD |
60 | |
61 | ||
62 | # "type" enumeration for class instance factory function | |
c878ceea RD |
63 | TEXT = 0 |
64 | COMBO = 1 | |
d14a1e28 RD |
65 | IPADDR = 2 |
66 | TIME = 3 | |
67 | NUMBER = 4 | |
68 | ||
69 | # for ease of import | |
70 | class controlTypes: | |
c878ceea RD |
71 | TEXT = TEXT |
72 | COMBO = COMBO | |
d14a1e28 RD |
73 | IPADDR = IPADDR |
74 | TIME = TIME | |
75 | NUMBER = NUMBER | |
76 | ||
77 | ||
c878ceea | 78 | def Ctrl( *args, **kwargs): |
d14a1e28 RD |
79 | """ |
80 | Actually a factory function providing a unifying | |
81 | interface for generating masked controls. | |
82 | """ | |
83 | if not kwargs.has_key('controlType'): | |
c878ceea | 84 | controlType = TEXT |
d14a1e28 RD |
85 | else: |
86 | controlType = kwargs['controlType'] | |
87 | del kwargs['controlType'] | |
88 | ||
c878ceea RD |
89 | if controlType == TEXT: |
90 | return TextCtrl(*args, **kwargs) | |
d14a1e28 | 91 | |
c878ceea RD |
92 | elif controlType == COMBO: |
93 | return ComboBox(*args, **kwargs) | |
d14a1e28 RD |
94 | |
95 | elif controlType == IPADDR: | |
d4b73b1b | 96 | return IpAddrCtrl(*args, **kwargs) |
d14a1e28 RD |
97 | |
98 | elif controlType == TIME: | |
d4b73b1b | 99 | return TimeCtrl(*args, **kwargs) |
d14a1e28 RD |
100 | |
101 | elif controlType == NUMBER: | |
c878ceea | 102 | return NumCtrl(*args, **kwargs) |
d14a1e28 RD |
103 | |
104 | else: | |
105 | raise AttributeError( | |
106 | "invalid controlType specified: %s" % repr(controlType)) | |
8b9a4190 | 107 | |
8b9a4190 | 108 |