1
2 try:
3 import wxversion
4 import wx
5 except ImportError:
6 from wxPython import wx
7
8 import string
9
10
13 self.enabled = 1
14
15
16
17
18
19
20
21
22
23 self.digits = range(48, 58)
24 self.print_other = range(18, 48) + range( 58 , 65) + range(91, 97) + range(123,126)
25 self.print_other.remove(32)
26 self.print_other.remove(39)
27 self.print_other.remove(45)
28 self.name_punctuation = [39, 45]
29
30
31
34
37
40
43
45 """wrapper for handling single space input"""
46 if self._allow_single_spaces(keyEvent) == 0:
47 keyEvent.Skip()
48
50 """intercepts space input and vetos extra spaces.
51 returns 1 if intercepted and Skip() was called or 0 if no event was handled.
52 """
53 textCtrl = keyEvent.GetEventObject()
54
55 if keyEvent.GetKeyCode() == WXK_TAB:
56 keyEvent.Skip(1)
57 return 1
58
59 if keyEvent.GetKeyCode() == WXK_SPACE and (
60 textCtrl.GetInsertionPoint() == 0
61 or textCtrl.GetValue()[textCtrl.GetInsertionPoint()-1] == ' '
62 ):
63 keyEvent.Skip(0)
64 return 1
65
66 return 0
67
69 """wrapper for converting to upper case and single spaces
70 converts intercepts lowercase input and puts in uppercase.
71 """
72
73 if not self._allow_case_only(keyEvent, string.lowercase, string.uppercase, exclusiveof = self.print_other + self.digits):
74 keyEvent.Skip()
75
77 """ wrapper to convert uppercase to lowercase.
78 """
79 if not self._allow_case_only( self, keyEvent, string.uppercase, string.lowercase):
80 keyEvent.Skip()
81
83
84 if self._allow_single_spaces(keyEvent):
85 return
86
87 k = keyEvent.GetKeyCode()
88
89 if chr(k) in string.letters or k in self.print_other or k in self.name_punctuation:
90 keyEvent.Skip(0)
91 return
92
93 keyEvent.Skip(1)
94
95
96
98 if self._allow_single_spaces(keyEvent):
99 return 1
100
101
102
103 c = keyEvent.GetEventObject()
104
105 if chr(keyEvent.GetKeyCode()) in case:
106
107 keyEvent.Skip(0)
108
109 p = c.GetInsertionPoint()
110
111
112 t = c.GetValue()
113 u = toCase[case.index(chr(keyEvent.GetKeyCode()))]
114
115
116
117 c.SetValue(t[:p]+u+t[p:])
118
119
120 c.SetInsertionPoint(p+1)
121 return 1
122
123 if exclusiveof <>[] and keyEvent.GetKeyCode() in exclusiveof:
124 keyEvent.Skip(0)
125 return 1
126 return 0
127
129 if not self._capitalize(keyEvent):
130 if keyEvent.GetKeyCode() in self.print_other + self.digits :
131 keyEvent.Skip(0)
132 return
133
134 keyEvent.Skip(1)
135
137 if (t.isspace() and len(t) == 1):
138 t = ''
139 return t
140
142 if self._allow_single_spaces(keyEvent):
143 return 1
144 k = keyEvent.GetKeyCode()
145 if chr(k) in string.lowercase:
146 keyEvent.Skip(0)
147 c = keyEvent.GetEventObject()
148 p = c.GetInsertionPoint()
149 t = c.GetValue()
150
151 t = self._remove_init_whitespace_bug(t)
152 t = t[:p] + chr(k) +t[p:]
153 l = t.split(' ')
154 l = self.capitalize_list(l)
155
156 t = ' '.join(l)
157
158 c.SetValue(t)
159 c.SetInsertionPoint(p+1)
160 return 1
161
162 return 0
163
165 for i in xrange(len(l)):
166 w = l[i].capitalize()
167 if '-' in w:
168 l[i] = '-'.join(self.capitalize_list(w.split('-')))
169
170 elif len(w) > 3 and w[:3] == 'Mac':
171 l[i] = w[:3] + w[3].upper() + w[4:]
172 elif len(w) > 2 and w[:2] == 'Mc':
173 l[i] = w[:2] + w[2].upper() + w[3:]
174 elif len(w) > 2 and w[1] == "'":
175 l[i] = w[:2] + w[2].upper() + w[3:]
176 else:
177 l[i] =w
178 return l
179
180
181 if __name__ == "__main__":
182
183
184 try:
185 import wxversion
186 import wx
187 except ImportError:
188 from wxPython import wx
189
190
193 self.c = txtCtrl
194 wx.EVT_TEXT( txtCtrl, txtCtrl.GetId(), self.checkSize)
195
197
198 yc = self.c.GetTextExtent('X')[1]
199 y = self.c.GetNumberOfLines() * yc
200 x0, y0 = self.c.GetClientSizeTuple()
201 print y, y0
202 if y > y0 :
203 self.c.SetClientSize( (x0, y0 + yc ))
204 print "window", self.c.GetId(), "size changed"
205 self.adjustParentsChildren(yc)
206
207 c = self.c
208 while c <> None:
209 if c.GetParent() is None:
210 (w,h) = c.GetSizeTuple()
211 c.SetSize( (w, h + yc))
212 break
213 c = c.GetParent()
214
216 c = self.c.GetParent()
217 l = c.GetChildren()
218 for w in l:
219 (x,y) = w.GetPositionTuple()
220 if y > self.c.GetPositionTuple()[1]:
221 w.SetPosition( ( x, y + yc) )
222
223
226 wx.Panel.__init__(self, parent, id)
227 szr1 = wx.BoxSizer(wx.VERTICAL)
228 self.wmap = {}
229 self.smap = {}
230
231
232
233 labels = [ 'S', 'O', 'A', 'P' ]
234 for i in range(0,4):
235 self.getLine(labels[i],szr1)
236 szr1.Add(1,1)
237 szr1.Add(1,1)
238 self.SetSizer(szr1)
239 szr1.Fit(self)
240
241
243 szr2 = wx.BoxSizer(wx.HORIZONTAL)
244 szr2.Add(wx.StaticText(self, -1, text) )
245
246 ctrl = wx.TextCtrl(self, -1, "\n", wx.DefaultPosition,
247 wx.DefaultSize, wx.TE_MULTILINE )
248 self.wmap[text] = ctrl
249 szr2.Add(ctrl, 1, wx.GROW )
250 self.smap[text] = REWResizer(ctrl)
251 szr.Add(szr2, 1, wx.GROW)
252 return szr
253
255
257 f = REFrame(None, -1, "Richards XPEditor")
258 f.Show(true)
259 f.p.SetSizer(None)
260 self.SetTopWindow(f)
261 self.f = f
262 return true
263
266
267
268
269 app = REApp()
270 v = CharValidator()
271
272 m = app.getSOAPMap()
273 v.setSingleSpace(m['S'])
274 v.setUpperAlpha(m['O'])
275 v.setCapitalize(m['A'])
276 v.setDigits(m['P'])
277
278
279 app.MainLoop()
280