]> git.saurik.com Git - wxWidgets.git/blob - wxPython/samples/ide/activegrid/tool/PerlEditor.py
Tweaks for demos on MacOSX
[wxWidgets.git] / wxPython / samples / ide / activegrid / tool / PerlEditor.py
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
65 def __init__(self, parent, id=-1, style=wx.NO_FULL_REPAINT_ON_RESIZE):
66 CodeEditor.CodeCtrl.__init__(self, parent, id, style)
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 def GetIcon(self):
137 return getPerlIcon()
138
139
140 PERLKEYWORDS = [
141 "abs",
142 "accept",
143 "alarm",
144 "atan2",
145 "bind",
146 "binmode",
147 "bless",
148 "caller",
149 "chdir",
150 "chmod",
151 "chomp",
152 "chop",
153 "chown",
154 "chr",
155 "chroot",
156 "close",
157 "closedir",
158 "connect",
159 "continue",
160 "cos",
161 "crypt",
162 "dbmclose",
163 "dbmopen",
164 "defined",
165 "delete",
166 "die",
167 "do",
168 "dump",
169 "each",
170 "endgrent",
171 "endhostent",
172 "endnetent",
173 "endprotoent",
174 "endpwent",
175 "endservent",
176 "eof",
177 "eval",
178 "exec",
179 "exists",
180 "exit",
181 "exp",
182 "fcntl",
183 "fileno",
184 "flock",
185 "fork",
186 "format",
187 "formline",
188 "getc",
189 "getgrent",
190 "getgrgid",
191 "getgrnam",
192 "gethostbyaddr",
193 "gethostbyname",
194 "gethostent",
195 "getlogin",
196 "getnetbyaddr",
197 "getnetbyname",
198 "getnetent",
199 "getpeername",
200 "getpgrp",
201 "getppid",
202 "getpriority",
203 "getprotobyname",
204 "getprotobynumber",
205 "getprotoent",
206 "getpwent",
207 "getpwnam",
208 "getpwuid",
209 "getservbyname",
210 "getservbyport",
211 "getservent",
212 "getsockname",
213 "getsockopt",
214 "glob",
215 "gmtime",
216 "goto",
217 "grep",
218 "hex",
219 "import",
220 "index",
221 "int",
222 "ioctl",
223 "join",
224 "keys",
225 "kill",
226 "last",
227 "lc",
228 "lcfirst",
229 "length",
230 "link",
231 "listen",
232 "local",
233 "localtime",
234 "log",
235 "lstat",
236 "m//",
237 "map",
238 "mkdir",
239 "msgctl",
240 "msgget",
241 "msgrcv",
242 "msgsnd",
243 "my",
244 "next",
245 "no",
246 "oct",
247 "open",
248 "opendir",
249 "ord",
250 "pack",
251 "package",
252 "pipe",
253 "pop",
254 "pos",
255 "print",
256 "printf",
257 "prototype",
258 "push",
259 "q/STRING/",
260 "qq/STRING/",
261 "quotemeta",
262 "qw",
263 "qw/STRING/",
264 "qx",
265 "qx/STRING/",
266 "rand",
267 "read",
268 "readdir",
269 "readline",
270 "readlink",
271 "readpipe",
272 "recv",
273 "redo",
274 "ref",
275 "rename",
276 "require",
277 "reset",
278 "return",
279 "reverse",
280 "rewinddir",
281 "rindex",
282 "rmdir",
283 "s///",
284 "scalar",
285 "seek",
286 "seekdir",
287 "select",
288 "semctl",
289 "semget",
290 "semop",
291 "send",
292 "setgrent",
293 "sethostent",
294 "setnetent",
295 "setpgrp",
296 "setpriority",
297 "setprotoent",
298 "setpwent",
299 "setservent",
300 "setsockopt",
301 "shift",
302 "shmctl",
303 "shmget",
304 "shmread",
305 "shmwrite",
306 "shutdown",
307 "sin",
308 "sleep",
309 "socket",
310 "socketpair",
311 "sort",
312 "splice",
313 "split",
314 "sprintf",
315 "sqrt",
316 "srand",
317 "stat",
318 "study",
319 "sub",
320 "substr",
321 "symlink",
322 "syscall",
323 "sysopen",
324 "sysread",
325 "sysseek",
326 "system",
327 "syswrite",
328 "tell",
329 "telldir",
330 "tie",
331 "tied",
332 "times",
333 "tr///",
334 "truncate",
335 "uc",
336 "ucfirst",
337 "umask",
338 "undef",
339 "unlink",
340 "unpack",
341 "unshift",
342 "untie",
343 "use",
344 "utime",
345 "values",
346 "vec",
347 "wait",
348 "waitpid",
349 "wantarray",
350 "warn",
351 "write",
352 "y///",
353 "eq",
354 "ne",
355 "lt",
356 "le",
357 "gt",
358 "ge",
359 "cmp",
360 "if",
361 "else"
362 "not",
363 "and",
364 "xor",
365 "or",
366 "if",
367 "while",
368 "until",
369 "for",
370 "foreach",
371 "last",
372 "next",
373 "redo",
374 "goto",
375 "STDIN",
376 "STDOUT",
377 "STDERR",
378 "WHEncE",
379 "BEGIN",
380 "END",
381 "require",
382 "integer",
383 "less",
384 "sigtrap",
385 "strict",
386 "subs"
387 ]
388
389
390 #----------------------------------------------------------------------------
391 # Icon Bitmaps - generated by encode_bitmaps.py
392 #----------------------------------------------------------------------------
393 from wx import ImageFromStream, BitmapFromImage
394 import cStringIO
395
396
397 def getPerlData():
398 return \
399 "\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x10\x08\x06\
400 \x00\x00\x00\x1f\xf3\xffa\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\
401 \x00\x01CIDAT8\x8d\x95\x93\xbfN\x02A\x10\x87\xbf[\xef\x05\xach|\x02m}\x008\
402 \x881Z\xd2\x1a\x13\x0bKx\x02{\xa3\xa13\xc6\xc6\xc6\xd2DZ+s\\\x83\x95\x1d\xa2\
403 &V\x104\x01/p\x01\t\xa0\xe8X\xc0\x9d\x87\xdc^\xf0\x97Lfw3\xdf\xec\xcc\xfe1\
404 \xca\x95\xba0\x95\xeb\xf5\x01h\xb4\xda\x00x\xde\x90\x83\xfd\r\x838\x95+u\xa9\
405 \rDj\x03\x91\xe7\xbe\xc8}wb\xa7\xc5\xb2\xdc\xbe\x89\xe4\x8f\xae\xc4PK\xe8L\
406 \xc5%\xef\x8da{7K\xee\xf0Rt1\xa6\xeb\xf5Y\x01>\xbea\xf45Y\xec\x8e&\xe5\xdf]\
407 \xdb4\xdd\x0e\xaf/-\xed&&\x110\xc0\xfa\x96\xc5\xf1N\x06\x80\xe5\xb5\xac6\x81\
408 \x82y\xb87\x9e\r\xeaT\x8b3s+\x95\x14+\x95\x14\x00\xd5h\xb5\xe9\x8e\xe6a\x7f\
409 \xf70\x14\xf6\xfeXy\xde0\x08\xf2\xe1\xf6gt\xb9V*)v\xc9\t\xae\xd5.9\x86\x19\
410 \x05\x9e\xefe\xe6i\x8dT\xd3\xed\xfc\x0b\x0e\xb7\x00\xd3C\xd4\x95\x1c'\xbf\
411 \x15\x15\xbe\xe3\xc6;l\x9e\xdc\x00\xbf\xfe/`\x97\x1c#|\x0e&@\xb1p\x16\x04>U\
412 \x1fI\x00\x17\xb9<\t\xa0\xc9*\t\x1e\xf4\xa5D\xbd\xeft:-q~\xe1\xbf\xb0\x88b\
413 \x13\x84{\x8d\x9a\x03\xfc\x00\xea\x7f\xa9A\xa7\xc3Vo\x00\x00\x00\x00IEND\xae\
414 B`\x82"
415
416
417 def getPerlBitmap():
418 return BitmapFromImage(getPerlImage())
419
420 def getPerlImage():
421 stream = cStringIO.StringIO(getPerlData())
422 return ImageFromStream(stream)
423
424 def getPerlIcon():
425 return wx.IconFromBitmap(getPerlBitmap())