]>
Commit | Line | Data |
---|---|---|
1f780e48 RD |
1 | #---------------------------------------------------------------------------- |
2 | # Name: PerlEditor.py | |
3 | # Purpose: Perl Script Editor for pydocview tbat uses the Styled Text Control | |
4 | # | |
5 | # Author: Morgan Hua | |
6 | # | |
7 | # Created: 1/5/04 | |
8 | # CVS-ID: $Id$ | |
9 | # Copyright: (c) 2005 ActiveGrid, Inc. | |
10 | # License: wxWindows License | |
11 | #---------------------------------------------------------------------------- | |
12 | ||
13 | import wx | |
14 | import string | |
15 | import STCTextEditor | |
16 | import CodeEditor | |
17 | ||
18 | ||
19 | class PerlDocument(CodeEditor.CodeDocument): | |
20 | ||
21 | pass | |
22 | ||
23 | ||
24 | class PerlView(CodeEditor.CodeView): | |
25 | ||
26 | ||
27 | def GetCtrlClass(self): | |
28 | """ Used in split window to instantiate new instances """ | |
29 | return PerlCtrl | |
30 | ||
31 | ||
32 | def GetAutoCompleteHint(self): | |
33 | pos = self.GetCtrl().GetCurrentPos() | |
34 | if pos == 0: | |
35 | return None, None | |
36 | ||
37 | validLetters = string.letters + string.digits + '_/' | |
38 | word = '' | |
39 | while (True): | |
40 | pos = pos - 1 | |
41 | if pos < 0: | |
42 | break | |
43 | char = chr(self.GetCtrl().GetCharAt(pos)) | |
44 | if char not in validLetters: | |
45 | break | |
46 | word = char + word | |
47 | ||
48 | return None, word | |
49 | ||
50 | ||
51 | def GetAutoCompleteDefaultKeywords(self): | |
52 | return PERLKEYWORDS | |
53 | ||
54 | ||
55 | class PerlService(CodeEditor.CodeService): | |
56 | ||
57 | ||
58 | def __init__(self): | |
59 | CodeEditor.CodeService.__init__(self) | |
60 | ||
61 | ||
62 | class PerlCtrl(CodeEditor.CodeCtrl): | |
63 | ||
64 | ||
26ee3a06 RD |
65 | def __init__(self, parent, id=-1, style=wx.NO_FULL_REPAINT_ON_RESIZE): |
66 | CodeEditor.CodeCtrl.__init__(self, parent, id, style) | |
1f780e48 RD |
67 | self.SetLexer(wx.stc.STC_LEX_PERL) |
68 | self.SetKeyWords(0, string.join(PERLKEYWORDS)) | |
69 | ||
70 | ||
71 | def CanWordWrap(self): | |
72 | return True | |
73 | ||
74 | ||
75 | def SetViewDefaults(self): | |
76 | CodeEditor.CodeCtrl.SetViewDefaults(self, configPrefix = "Perl", hasWordWrap = True, hasTabs = True) | |
77 | ||
78 | ||
79 | def GetFontAndColorFromConfig(self): | |
80 | return CodeEditor.CodeCtrl.GetFontAndColorFromConfig(self, configPrefix = "Perl") | |
81 | ||
82 | ||
83 | def UpdateStyles(self): | |
84 | CodeEditor.CodeCtrl.UpdateStyles(self) | |
85 | ||
86 | if not self.GetFont(): | |
87 | return | |
88 | ||
89 | faces = { 'font' : self.GetFont().GetFaceName(), | |
90 | 'size' : self.GetFont().GetPointSize(), | |
91 | 'size2': self.GetFont().GetPointSize() - 2, | |
92 | 'color' : "%02x%02x%02x" % (self.GetFontColor().Red(), self.GetFontColor().Green(), self.GetFontColor().Blue()) | |
93 | } | |
94 | ||
95 | # Perl Styles | |
96 | self.StyleSetSpec(wx.stc.STC_PL_DEFAULT, "face:%(font)s,fore:#000000,face:%(font)s,size:%(size)d" % faces) | |
97 | self.StyleSetSpec(wx.stc.STC_PL_COMMENTLINE, "face:%(font)s,fore:#007F00,italic,face:%(font)s,size:%(size)d" % faces) | |
98 | self.StyleSetSpec(wx.stc.STC_PL_NUMBER, "face:%(font)s,fore:#007F7F,size:%(size)d" % faces) | |
99 | self.StyleSetSpec(wx.stc.STC_PL_CHARACTER, "face:%(font)s,fore:#7F007F,face:%(font)s,size:%(size)d" % faces) | |
100 | self.StyleSetSpec(wx.stc.STC_PL_STRING, "face:%(font)s,fore:#7F007F,face:%(font)s,size:%(size)d" % faces) | |
101 | self.StyleSetSpec(wx.stc.STC_PL_STRING_Q, "face:%(font)s,fore:#7F007F,face:%(font)s,size:%(size)d" % faces) | |
102 | self.StyleSetSpec(wx.stc.STC_PL_STRING_QQ, "face:%(font)s,fore:#7F007F,face:%(font)s,size:%(size)d" % faces) | |
103 | self.StyleSetSpec(wx.stc.STC_PL_STRING_QX, "face:%(font)s,fore:#7F007F,face:%(font)s,size:%(size)d" % faces) | |
104 | self.StyleSetSpec(wx.stc.STC_PL_STRING_QR, "face:%(font)s,fore:#7F007F,face:%(font)s,size:%(size)d" % faces) | |
105 | self.StyleSetSpec(wx.stc.STC_PL_STRING_QW, "face:%(font)s,fore:#7F007F,face:%(font)s,size:%(size)d" % faces) | |
106 | self.StyleSetSpec(wx.stc.STC_PL_BACKTICKS, "face:%(font)s,fore:#7F007F,face:%(font)s,size:%(size)d" % faces) | |
107 | self.StyleSetSpec(wx.stc.STC_PL_WORD, "face:%(font)s,fore:#00007F,bold,size:%(size)d" % faces) # keyword | |
108 | self.StyleSetSpec(wx.stc.STC_PL_IDENTIFIER, "face:%(font)s,fore:#%(color)s,face:%(font)s,size:%(size)d" % faces) | |
109 | ||
110 | # Default | |
111 | self.StyleSetSpec(wx.stc.STC_PL_ARRAY, "face:%(font)s,fore:#000000,face:%(font)s,size:%(size)d" % faces) | |
112 | self.StyleSetSpec(wx.stc.STC_PL_DATASECTION, "face:%(font)s,fore:#000000,face:%(font)s,size:%(size)d" % faces) | |
113 | self.StyleSetSpec(wx.stc.STC_PL_ERROR, "face:%(font)s,fore:#000000,face:%(font)s,size:%(size)d" % faces) | |
114 | self.StyleSetSpec(wx.stc.STC_PL_HASH, "face:%(font)s,fore:#000000,face:%(font)s,size:%(size)d" % faces) | |
115 | self.StyleSetSpec(wx.stc.STC_PL_HERE_DELIM, "face:%(font)s,fore:#000000,face:%(font)s,size:%(size)d" % faces) | |
116 | self.StyleSetSpec(wx.stc.STC_PL_HERE_Q, "face:%(font)s,fore:#000000,face:%(font)s,size:%(size)d" % faces) | |
117 | self.StyleSetSpec(wx.stc.STC_PL_HERE_QQ, "face:%(font)s,fore:#000000,face:%(font)s,size:%(size)d" % faces) | |
118 | self.StyleSetSpec(wx.stc.STC_PL_HERE_QX, "face:%(font)s,fore:#000000,face:%(font)s,size:%(size)d" % faces) | |
119 | self.StyleSetSpec(wx.stc.STC_PL_LONGQUOTE, "face:%(font)s,fore:#000000,face:%(font)s,size:%(size)d" % faces) | |
120 | self.StyleSetSpec(wx.stc.STC_PL_OPERATOR, "face:%(font)s,fore:#000000,face:%(font)s,size:%(size)d" % faces) | |
121 | self.StyleSetSpec(wx.stc.STC_PL_POD, "face:%(font)s,fore:#000000,face:%(font)s,size:%(size)d" % faces) | |
122 | self.StyleSetSpec(wx.stc.STC_PL_PREPROCESSOR, "face:%(font)s,fore:#000000,face:%(font)s,size:%(size)d" % faces) | |
123 | self.StyleSetSpec(wx.stc.STC_PL_PUNCTUATION, "face:%(font)s,fore:#000000,face:%(font)s,size:%(size)d" % faces) | |
124 | self.StyleSetSpec(wx.stc.STC_PL_REGEX, "face:%(font)s,fore:#000000,face:%(font)s,size:%(size)d" % faces) | |
125 | self.StyleSetSpec(wx.stc.STC_PL_REGSUBST, "face:%(font)s,fore:#000000,face:%(font)s,size:%(size)d" % faces) | |
126 | self.StyleSetSpec(wx.stc.STC_PL_SCALAR, "face:%(font)s,fore:#000000,face:%(font)s,size:%(size)d" % faces) | |
127 | self.StyleSetSpec(wx.stc.STC_PL_SYMBOLTABLE, "face:%(font)s,fore:#000000,face:%(font)s,size:%(size)d" % faces) | |
128 | ||
129 | ||
130 | class PerlOptionsPanel(STCTextEditor.TextOptionsPanel): | |
131 | ||
132 | def __init__(self, parent, id): | |
133 | STCTextEditor.TextOptionsPanel.__init__(self, parent, id, configPrefix = "Perl", label = "Perl", hasWordWrap = True, hasTabs = True) | |
134 | ||
135 | ||
136 | PERLKEYWORDS = [ | |
137 | "abs", | |
138 | "accept", | |
139 | "alarm", | |
140 | "atan2", | |
141 | "bind", | |
142 | "binmode", | |
143 | "bless", | |
144 | "caller", | |
145 | "chdir", | |
146 | "chmod", | |
147 | "chomp", | |
148 | "chop", | |
149 | "chown", | |
150 | "chr", | |
151 | "chroot", | |
152 | "close", | |
153 | "closedir", | |
154 | "connect", | |
155 | "continue", | |
156 | "cos", | |
157 | "crypt", | |
158 | "dbmclose", | |
159 | "dbmopen", | |
160 | "defined", | |
161 | "delete", | |
162 | "die", | |
163 | "do", | |
164 | "dump", | |
165 | "each", | |
166 | "endgrent", | |
167 | "endhostent", | |
168 | "endnetent", | |
169 | "endprotoent", | |
170 | "endpwent", | |
171 | "endservent", | |
172 | "eof", | |
173 | "eval", | |
174 | "exec", | |
175 | "exists", | |
176 | "exit", | |
177 | "exp", | |
178 | "fcntl", | |
179 | "fileno", | |
180 | "flock", | |
181 | "fork", | |
182 | "format", | |
183 | "formline", | |
184 | "getc", | |
185 | "getgrent", | |
186 | "getgrgid", | |
187 | "getgrnam", | |
188 | "gethostbyaddr", | |
189 | "gethostbyname", | |
190 | "gethostent", | |
191 | "getlogin", | |
192 | "getnetbyaddr", | |
193 | "getnetbyname", | |
194 | "getnetent", | |
195 | "getpeername", | |
196 | "getpgrp", | |
197 | "getppid", | |
198 | "getpriority", | |
199 | "getprotobyname", | |
200 | "getprotobynumber", | |
201 | "getprotoent", | |
202 | "getpwent", | |
203 | "getpwnam", | |
204 | "getpwuid", | |
205 | "getservbyname", | |
206 | "getservbyport", | |
207 | "getservent", | |
208 | "getsockname", | |
209 | "getsockopt", | |
210 | "glob", | |
211 | "gmtime", | |
212 | "goto", | |
213 | "grep", | |
214 | "hex", | |
215 | "import", | |
216 | "index", | |
217 | "int", | |
218 | "ioctl", | |
219 | "join", | |
220 | "keys", | |
221 | "kill", | |
222 | "last", | |
223 | "lc", | |
224 | "lcfirst", | |
225 | "length", | |
226 | "link", | |
227 | "listen", | |
228 | "local", | |
229 | "localtime", | |
230 | "log", | |
231 | "lstat", | |
232 | "m//", | |
233 | "map", | |
234 | "mkdir", | |
235 | "msgctl", | |
236 | "msgget", | |
237 | "msgrcv", | |
238 | "msgsnd", | |
239 | "my", | |
240 | "next", | |
241 | "no", | |
242 | "oct", | |
243 | "open", | |
244 | "opendir", | |
245 | "ord", | |
246 | "pack", | |
247 | "package", | |
248 | "pipe", | |
249 | "pop", | |
250 | "pos", | |
251 | "print", | |
252 | "printf", | |
253 | "prototype", | |
254 | "push", | |
255 | "q/STRING/", | |
256 | "qq/STRING/", | |
257 | "quotemeta", | |
258 | "qw", | |
259 | "qw/STRING/", | |
260 | "qx", | |
261 | "qx/STRING/", | |
262 | "rand", | |
263 | "read", | |
264 | "readdir", | |
265 | "readline", | |
266 | "readlink", | |
267 | "readpipe", | |
268 | "recv", | |
269 | "redo", | |
270 | "ref", | |
271 | "rename", | |
272 | "require", | |
273 | "reset", | |
274 | "return", | |
275 | "reverse", | |
276 | "rewinddir", | |
277 | "rindex", | |
278 | "rmdir", | |
279 | "s///", | |
280 | "scalar", | |
281 | "seek", | |
282 | "seekdir", | |
283 | "select", | |
284 | "semctl", | |
285 | "semget", | |
286 | "semop", | |
287 | "send", | |
288 | "setgrent", | |
289 | "sethostent", | |
290 | "setnetent", | |
291 | "setpgrp", | |
292 | "setpriority", | |
293 | "setprotoent", | |
294 | "setpwent", | |
295 | "setservent", | |
296 | "setsockopt", | |
297 | "shift", | |
298 | "shmctl", | |
299 | "shmget", | |
300 | "shmread", | |
301 | "shmwrite", | |
302 | "shutdown", | |
303 | "sin", | |
304 | "sleep", | |
305 | "socket", | |
306 | "socketpair", | |
307 | "sort", | |
308 | "splice", | |
309 | "split", | |
310 | "sprintf", | |
311 | "sqrt", | |
312 | "srand", | |
313 | "stat", | |
314 | "study", | |
315 | "sub", | |
316 | "substr", | |
317 | "symlink", | |
318 | "syscall", | |
319 | "sysopen", | |
320 | "sysread", | |
321 | "sysseek", | |
322 | "system", | |
323 | "syswrite", | |
324 | "tell", | |
325 | "telldir", | |
326 | "tie", | |
327 | "tied", | |
328 | "times", | |
329 | "tr///", | |
330 | "truncate", | |
331 | "uc", | |
332 | "ucfirst", | |
333 | "umask", | |
334 | "undef", | |
335 | "unlink", | |
336 | "unpack", | |
337 | "unshift", | |
338 | "untie", | |
339 | "use", | |
340 | "utime", | |
341 | "values", | |
342 | "vec", | |
343 | "wait", | |
344 | "waitpid", | |
345 | "wantarray", | |
346 | "warn", | |
347 | "write", | |
348 | "y///", | |
349 | "eq", | |
350 | "ne", | |
351 | "lt", | |
352 | "le", | |
353 | "gt", | |
354 | "ge", | |
355 | "cmp", | |
356 | "if", | |
357 | "else" | |
358 | "not", | |
359 | "and", | |
360 | "xor", | |
361 | "or", | |
362 | "if", | |
363 | "while", | |
364 | "until", | |
365 | "for", | |
366 | "foreach", | |
367 | "last", | |
368 | "next", | |
369 | "redo", | |
370 | "goto", | |
371 | "STDIN", | |
372 | "STDOUT", | |
373 | "STDERR", | |
374 | "WHEncE", | |
375 | "BEGIN", | |
376 | "END", | |
377 | "require", | |
378 | "integer", | |
379 | "less", | |
380 | "sigtrap", | |
381 | "strict", | |
382 | "subs" | |
383 | ] | |
384 | ||
385 | ||
386 | #---------------------------------------------------------------------------- | |
387 | # Icon Bitmaps - generated by encode_bitmaps.py | |
388 | #---------------------------------------------------------------------------- | |
389 | from wx import ImageFromStream, BitmapFromImage | |
1f780e48 RD |
390 | import cStringIO |
391 | ||
392 | ||
393 | def getPerlData(): | |
394 | return \ | |
bbf7159c RD |
395 | '\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x10\x08\x06\ |
396 | \x00\x00\x00\x1f\xf3\xffa\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\ | |
397 | \x00\x01\x81IDAT8\x8d\xa5S1n\xe30\x10\x1cJ\xf9\x80;U\x04\x04~\xc06\xdc\xa9\ | |
398 | \x10\xd4\xb3K\xf2\x01\xf9\x01F\x92\xce\x8d:vI\x84\xdc\xd5\xaa\xdc%\xd1\x17\ | |
399 | \x0c\x17ns\xa7\x07,\x16\xe0G6E@B\x91\x9c*\x0b\x10 \xb9\xe4\xecpg\xa8T\x92\ | |
400 | \xe27q5^\xbc\xbf\xbd\n\x00\\\xdf\xdc\xaa\xb0\xf7\xfc\xf4(\xcc\x8c<\xcfqw\xff\ | |
401 | \xa0\xa6\x00PI\x8aa\x18\xa4m[\xd9\xedvb\xad\x95a\x18D%)\xfa\xbe\x97\xc5b!\ | |
402 | \xd6Z\xb1\xd6J\xdb\xb6\xa2\x92\x14\xe3\x91\x00\xc0r\xb5VZ\xeb\x08z<\x1e\xf1\ | |
403 | \xfe\xf6*]\xd7\xc1\x18\x03c\x0c\xea\xba\x063\xe3\xff\xbf\x0f\xf9\xf1\tD\x14\ | |
404 | \xe7\xce9\xec\xf7{\x00\x80\xf7\xfe\x1b\xf88\x920\xf1\xde\xc7j\xcc\x8c,\xcb\ | |
405 | \xe2:\xe4\xeb\xba\x06\x80o,"\x03\xad5\x0e\x87C\xacz>\x9fAD\xb1\xba\xd6\x1aD\ | |
406 | \x04f\x063\xcf\x19\\\xdf\xdc\xaa\xa2(p:\x9d\xe0\xbd\x07\x11\xc19\x07\xad5\ | |
407 | \x98\x19\xce9l\xb7[\x10\x11\xf2<\x9f\x03\x00\xc0\xcb\x9f\xbf\xaa,\xcbX!\xcb2\ | |
408 | t]\x17\xf3M\xd3\xc4\'\xc5\x98\xca\x12d\xddl6\x12d\x0c\x12\xab$\x85\xb5Vf2N\ | |
409 | \x83\x88P\x14\x05\xbc\xf7h\x9a\x06UUE\xda\xc6\x98\xcbM\x1c\x871\x06\xde{TU\ | |
410 | \x05\xe0\xcb\'\xe1RY\x96X\xae\xd6\xd1\x91\x17\x19\x00_]_\xae\xd6\x8a\x88\xf0\ | |
411 | \xfc\xf4(\xe1\xd2\xb4\x07?\x02\x8c\x0f\x8e\x1d85\xd2\xc5\x06\xf6}?\xf3|\x18\ | |
412 | \xb3\xdco\xbf\xf3\'`\xa6\xbc1\xa7\xd6\xcb\xbf\x00\x00\x00\x00IEND\xaeB`\x82'\ | |
1f780e48 RD |
413 | |
414 | ||
415 | def getPerlBitmap(): | |
416 | return BitmapFromImage(getPerlImage()) | |
417 | ||
418 | def getPerlImage(): | |
419 | stream = cStringIO.StringIO(getPerlData()) | |
420 | return ImageFromStream(stream) | |
421 | ||
422 | def getPerlIcon(): | |
bbf7159c | 423 | return wx.IconFromBitmap(getPerlBitmap()) |