]> git.saurik.com Git - wxWidgets.git/blob - src/stc/gen_iface.py
finished implementation for stencil and colored patterns
[wxWidgets.git] / src / stc / gen_iface.py
1 #!/bin/env python
2 #----------------------------------------------------------------------------
3 # Name: gen_iface.py
4 # Purpose: Generate stc.h and stc.cpp from the info in Scintilla.iface
5 #
6 # Author: Robin Dunn
7 #
8 # Created: 5-Sept-2000
9 # RCS-ID: $Id$
10 # Copyright: (c) 2000 by Total Control Software
11 # Licence: wxWindows license
12 #----------------------------------------------------------------------------
13
14
15 import sys, string, re, os
16 from fileinput import FileInput
17
18
19 IFACE = os.path.abspath('./scintilla/include/Scintilla.iface')
20 H_TEMPLATE = os.path.abspath('./stc.h.in')
21 CPP_TEMPLATE = os.path.abspath('./stc.cpp.in')
22 H_DEST = os.path.abspath('../../include/wx/stc/stc.h')
23 CPP_DEST = os.path.abspath('./stc.cpp')
24 DOCSTR_DEST = os.path.abspath('../../../wxPython/contrib/stc/_stc_gendocs.i')
25
26
27 # Value prefixes to convert
28 valPrefixes = [('SCI_', ''),
29 ('SC_', ''),
30 ('SCN_', None), # just toss these out...
31 ('SCEN_', None),
32 ('SCE_', ''),
33 ('SCLEX_', 'LEX_'),
34 ('SCK_', 'KEY_'),
35 ('SCFIND_', 'FIND_'),
36 ('SCWS_', 'WS_'),
37 ]
38
39 # Message function values that should have a CMD_ constant generated
40 cmdValues = [ (2300, 2349),
41 2011,
42 2013,
43 (2176, 2180),
44 (2390, 2393),
45 (2395, 2396),
46 2404,
47 (2413, 2416),
48 (2426, 2442),
49 (2450, 2455),
50 ]
51
52
53 # Should a funciton be also generated for the CMDs?
54 FUNC_FOR_CMD = True
55
56
57 # Map some generic typenames to wx types, using return value syntax
58 retTypeMap = {
59 'position': 'int',
60 'string': 'wxString',
61 'colour': 'wxColour',
62 }
63
64 # Map some generic typenames to wx types, using parameter syntax
65 paramTypeMap = {
66 'position': 'int',
67 'string': 'const wxString&',
68 'colour': 'const wxColour&',
69 'keymod': 'int',
70 }
71
72 # Map of method info that needs tweaked. Either the name needs changed, or
73 # the method definition/implementation. Tuple items are:
74 #
75 # 1. New method name. None to skip the method, 0 to leave the
76 # default name.
77 # 2. Method definition for the .h file, 0 to leave alone
78 # 3. Method implementation for the .cpp file, 0 to leave alone.
79 # 4. tuple of Doc string lines, or 0 to leave alone.
80 #
81 methodOverrideMap = {
82 'AddText' : (0,
83 'void %s(const wxString& text);',
84
85 '''void %s(const wxString& text) {
86 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
87 SendMsg(%s, strlen(buf), (long)(const char*)buf);''',
88 0),
89
90 'AddStyledText' : (0,
91 'void %s(const wxMemoryBuffer& data);',
92
93 '''void %s(const wxMemoryBuffer& data) {
94 SendMsg(%s, data.GetDataLen(), (long)data.GetData());''',
95 0),
96
97 'AppendText' : (0,
98 'void %s(const wxString& text);',
99
100 '''void %s(const wxString& text) {
101 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
102 SendMsg(%s, strlen(buf), (long)(const char*)buf);''',
103 0),
104
105 'GetViewWS' : ( 'GetViewWhiteSpace', 0, 0, 0),
106 'SetViewWS' : ( 'SetViewWhiteSpace', 0, 0, 0),
107
108 'GetCharAt' :
109 ( 0, 0,
110 '''int %s(int pos) {
111 return (unsigned char)SendMsg(%s, pos, 0);''',
112 0),
113
114 'GetStyleAt' :
115 ( 0, 0,
116 '''int %s(int pos) {
117 return (unsigned char)SendMsg(%s, pos, 0);''',
118 0),
119
120 'GetStyledText' :
121 (0,
122 'wxMemoryBuffer %s(int startPos, int endPos);',
123
124 '''wxMemoryBuffer %s(int startPos, int endPos) {
125 wxMemoryBuffer buf;
126 if (endPos < startPos) {
127 int temp = startPos;
128 startPos = endPos;
129 endPos = temp;
130 }
131 int len = endPos - startPos;
132 if (!len) return buf;
133 TextRange tr;
134 tr.lpstrText = (char*)buf.GetWriteBuf(len*2+1);
135 tr.chrg.cpMin = startPos;
136 tr.chrg.cpMax = endPos;
137 len = SendMsg(%s, 0, (long)&tr);
138 buf.UngetWriteBuf(len);
139 return buf;''',
140
141 ('Retrieve a buffer of cells.',)),
142
143
144 'PositionFromPoint' :
145 (0,
146 'int %s(wxPoint pt);',
147
148 '''int %s(wxPoint pt) {
149 return SendMsg(%s, pt.x, pt.y);''',
150 0),
151
152 'GetCurLine' :
153 (0,
154 '#ifdef SWIG\n wxString %s(int* OUTPUT);\n#else\n wxString GetCurLine(int* linePos=NULL);\n#endif',
155
156 '''wxString %s(int* linePos) {
157 int len = LineLength(GetCurrentLine());
158 if (!len) {
159 if (linePos) *linePos = 0;
160 return wxEmptyString;
161 }
162
163 wxMemoryBuffer mbuf(len+1);
164 char* buf = (char*)mbuf.GetWriteBuf(len+1);
165
166 int pos = SendMsg(%s, len+1, (long)buf);
167 mbuf.UngetWriteBuf(len);
168 mbuf.AppendByte(0);
169 if (linePos) *linePos = pos;
170 return stc2wx(buf);''',
171
172 0),
173
174 'SetUsePalette' : (None, 0,0,0),
175
176 'MarkerSetFore' : ('MarkerSetForeground', 0, 0, 0),
177 'MarkerSetBack' : ('MarkerSetBackground', 0, 0, 0),
178
179 'MarkerDefine' :
180 (0,
181 '''void %s(int markerNumber, int markerSymbol,
182 const wxColour& foreground = wxNullColour,
183 const wxColour& background = wxNullColour);''',
184
185 '''void %s(int markerNumber, int markerSymbol,
186 const wxColour& foreground,
187 const wxColour& background) {
188
189 SendMsg(%s, markerNumber, markerSymbol);
190 if (foreground.Ok())
191 MarkerSetForeground(markerNumber, foreground);
192 if (background.Ok())
193 MarkerSetBackground(markerNumber, background);''',
194
195 ('Set the symbol used for a particular marker number,',
196 'and optionally the fore and background colours.')),
197
198
199 'MarkerDefinePixmap' :
200 ('MarkerDefineBitmap',
201 '''void %s(int markerNumber, const wxBitmap& bmp);''',
202 '''void %s(int markerNumber, const wxBitmap& bmp) {
203 // convert bmp to a xpm in a string
204 wxMemoryOutputStream strm;
205 wxImage img = bmp.ConvertToImage();
206 if (img.HasAlpha())
207 img.ConvertAlphaToMask();
208 img.SaveFile(strm, wxBITMAP_TYPE_XPM);
209 size_t len = strm.GetSize();
210 char* buff = new char[len+1];
211 strm.CopyTo(buff, len);
212 buff[len] = 0;
213 SendMsg(%s, markerNumber, (long)buff);
214 delete [] buff;
215 ''',
216 ('Define a marker from a bitmap',)),
217
218
219 'SetMarginTypeN' : ('SetMarginType', 0, 0, 0),
220 'GetMarginTypeN' : ('GetMarginType', 0, 0, 0),
221 'SetMarginWidthN' : ('SetMarginWidth', 0, 0, 0),
222 'GetMarginWidthN' : ('GetMarginWidth', 0, 0, 0),
223 'SetMarginMaskN' : ('SetMarginMask', 0, 0, 0),
224 'GetMarginMaskN' : ('GetMarginMask', 0, 0, 0),
225 'SetMarginSensitiveN' : ('SetMarginSensitive', 0, 0, 0),
226 'GetMarginSensitiveN' : ('GetMarginSensitive', 0, 0, 0),
227
228 'StyleSetFore' : ('StyleSetForeground', 0, 0, 0),
229 'StyleSetBack' : ('StyleSetBackground', 0, 0, 0),
230 'SetSelFore' : ('SetSelForeground', 0, 0, 0),
231 'SetSelBack' : ('SetSelBackground', 0, 0, 0),
232 'SetCaretFore' : ('SetCaretForeground', 0, 0, 0),
233 'StyleSetFont' : ('StyleSetFaceName', 0, 0, 0),
234 'StyleSetCharacterSet' : (None, 0, 0, 0),
235
236 'AssignCmdKey' :
237 ('CmdKeyAssign',
238 'void %s(int key, int modifiers, int cmd);',
239
240 '''void %s(int key, int modifiers, int cmd) {
241 SendMsg(%s, MAKELONG(key, modifiers), cmd);''',
242 0),
243
244
245 'ClearCmdKey' :
246 ('CmdKeyClear',
247 'void %s(int key, int modifiers);',
248
249 '''void %s(int key, int modifiers) {
250 SendMsg(%s, MAKELONG(key, modifiers));''',
251 0),
252
253 'ClearAllCmdKeys' : ('CmdKeyClearAll', 0, 0, 0),
254
255
256 'SetStylingEx' :
257 ('SetStyleBytes',
258 'void %s(int length, char* styleBytes);',
259
260 '''void %s(int length, char* styleBytes) {
261 SendMsg(%s, length, (long)styleBytes);''',
262 0),
263
264
265 'IndicSetStyle' : ('IndicatorSetStyle', 0, 0, 0),
266 'IndicGetStyle' : ('IndicatorGetStyle', 0, 0, 0),
267 'IndicSetFore' : ('IndicatorSetForeground', 0, 0, 0),
268 'IndicGetFore' : ('IndicatorGetForeground', 0, 0, 0),
269
270 'SetWhitespaceFore' : ('SetWhitespaceForeground', 0, 0, 0),
271 'SetWhitespaceBack' : ('SetWhitespaceBackground', 0, 0, 0),
272
273 'AutoCShow' : ('AutoCompShow', 0, 0, 0),
274 'AutoCCancel' : ('AutoCompCancel', 0, 0, 0),
275 'AutoCActive' : ('AutoCompActive', 0, 0, 0),
276 'AutoCPosStart' : ('AutoCompPosStart', 0, 0, 0),
277 'AutoCComplete' : ('AutoCompComplete', 0, 0, 0),
278 'AutoCStops' : ('AutoCompStops', 0, 0, 0),
279 'AutoCSetSeparator' : ('AutoCompSetSeparator', 0, 0, 0),
280 'AutoCGetSeparator' : ('AutoCompGetSeparator', 0, 0, 0),
281 'AutoCSelect' : ('AutoCompSelect', 0, 0, 0),
282 'AutoCSetCancelAtStart' : ('AutoCompSetCancelAtStart', 0, 0, 0),
283 'AutoCGetCancelAtStart' : ('AutoCompGetCancelAtStart', 0, 0, 0),
284 'AutoCSetFillUps' : ('AutoCompSetFillUps', 0, 0, 0),
285 'AutoCSetChooseSingle' : ('AutoCompSetChooseSingle', 0, 0, 0),
286 'AutoCGetChooseSingle' : ('AutoCompGetChooseSingle', 0, 0, 0),
287 'AutoCSetIgnoreCase' : ('AutoCompSetIgnoreCase', 0, 0, 0),
288 'AutoCGetIgnoreCase' : ('AutoCompGetIgnoreCase', 0, 0, 0),
289 'AutoCSetAutoHide' : ('AutoCompSetAutoHide', 0, 0, 0),
290 'AutoCGetAutoHide' : ('AutoCompGetAutoHide', 0, 0, 0),
291 'AutoCSetDropRestOfWord' : ('AutoCompSetDropRestOfWord', 0,0,0),
292 'AutoCGetDropRestOfWord' : ('AutoCompGetDropRestOfWord', 0,0,0),
293 'AutoCGetTypeSeparator' : ('AutoCompGetTypeSeparator', 0, 0, 0),
294 'AutoCSetTypeSeparator' : ('AutoCompSetTypeSeparator', 0, 0, 0),
295 'AutoCGetCurrent' : ('AutoCompGetCurrent', 0, 0, 0),
296
297 'RegisterImage' :
298 (0,
299 '''void %s(int type, const wxBitmap& bmp);''',
300 '''void %s(int type, const wxBitmap& bmp) {
301 // convert bmp to a xpm in a string
302 wxMemoryOutputStream strm;
303 wxImage img = bmp.ConvertToImage();
304 if (img.HasAlpha())
305 img.ConvertAlphaToMask();
306 img.SaveFile(strm, wxBITMAP_TYPE_XPM);
307 size_t len = strm.GetSize();
308 char* buff = new char[len+1];
309 strm.CopyTo(buff, len);
310 buff[len] = 0;
311 SendMsg(%s, type, (long)buff);
312 delete [] buff;
313 ''',
314 ('Register an image for use in autocompletion lists.',)),
315
316
317 'ClearRegisteredImages' : (0, 0, 0,
318 ('Clear all the registered images.',)),
319
320
321 'SetHScrollBar' : ('SetUseHorizontalScrollBar', 0, 0, 0),
322 'GetHScrollBar' : ('GetUseHorizontalScrollBar', 0, 0, 0),
323
324 'SetVScrollBar' : ('SetUseVerticalScrollBar', 0, 0, 0),
325 'GetVScrollBar' : ('GetUseVerticalScrollBar', 0, 0, 0),
326
327 'GetCaretFore' : ('GetCaretForeground', 0, 0, 0),
328
329 'GetUsePalette' : (None, 0, 0, 0),
330
331 'FindText' :
332 (0,
333 '''int %s(int minPos, int maxPos, const wxString& text, int flags=0);''',
334
335 '''int %s(int minPos, int maxPos,
336 const wxString& text,
337 int flags) {
338 TextToFind ft;
339 ft.chrg.cpMin = minPos;
340 ft.chrg.cpMax = maxPos;
341 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
342 ft.lpstrText = (char*)(const char*)buf;
343
344 return SendMsg(%s, flags, (long)&ft);''',
345 0),
346
347 'FormatRange' :
348 (0,
349 '''int %s(bool doDraw,
350 int startPos,
351 int endPos,
352 wxDC* draw,
353 wxDC* target,
354 wxRect renderRect,
355 wxRect pageRect);''',
356 ''' int %s(bool doDraw,
357 int startPos,
358 int endPos,
359 wxDC* draw,
360 wxDC* target,
361 wxRect renderRect,
362 wxRect pageRect) {
363 RangeToFormat fr;
364
365 if (endPos < startPos) {
366 int temp = startPos;
367 startPos = endPos;
368 endPos = temp;
369 }
370 fr.hdc = draw;
371 fr.hdcTarget = target;
372 fr.rc.top = renderRect.GetTop();
373 fr.rc.left = renderRect.GetLeft();
374 fr.rc.right = renderRect.GetRight();
375 fr.rc.bottom = renderRect.GetBottom();
376 fr.rcPage.top = pageRect.GetTop();
377 fr.rcPage.left = pageRect.GetLeft();
378 fr.rcPage.right = pageRect.GetRight();
379 fr.rcPage.bottom = pageRect.GetBottom();
380 fr.chrg.cpMin = startPos;
381 fr.chrg.cpMax = endPos;
382
383 return SendMsg(%s, doDraw, (long)&fr);''',
384 0),
385
386
387 'GetLine' :
388 (0,
389 'wxString %s(int line);',
390
391 '''wxString %s(int line) {
392 int len = LineLength(line);
393 if (!len) return wxEmptyString;
394
395 wxMemoryBuffer mbuf(len+1);
396 char* buf = (char*)mbuf.GetWriteBuf(len+1);
397 SendMsg(%s, line, (long)buf);
398 mbuf.UngetWriteBuf(len);
399 mbuf.AppendByte(0);
400 return stc2wx(buf);''',
401
402 ('Retrieve the contents of a line.',)),
403
404 'SetSel' : ('SetSelection', 0, 0, 0),
405
406 'GetSelText' :
407 ('GetSelectedText',
408 'wxString %s();',
409
410 '''wxString %s() {
411 int start;
412 int end;
413
414 GetSelection(&start, &end);
415 int len = end - start;
416 if (!len) return wxEmptyString;
417
418 wxMemoryBuffer mbuf(len+2);
419 char* buf = (char*)mbuf.GetWriteBuf(len+1);
420 SendMsg(%s, 0, (long)buf);
421 mbuf.UngetWriteBuf(len);
422 mbuf.AppendByte(0);
423 return stc2wx(buf);''',
424
425 ('Retrieve the selected text.',)),
426
427
428 'GetTextRange' :
429 (0,
430 'wxString %s(int startPos, int endPos);',
431
432 '''wxString %s(int startPos, int endPos) {
433 if (endPos < startPos) {
434 int temp = startPos;
435 startPos = endPos;
436 endPos = temp;
437 }
438 int len = endPos - startPos;
439 if (!len) return wxEmptyString;
440 wxMemoryBuffer mbuf(len+1);
441 char* buf = (char*)mbuf.GetWriteBuf(len);
442 TextRange tr;
443 tr.lpstrText = buf;
444 tr.chrg.cpMin = startPos;
445 tr.chrg.cpMax = endPos;
446 SendMsg(%s, 0, (long)&tr);
447 mbuf.UngetWriteBuf(len);
448 mbuf.AppendByte(0);
449 return stc2wx(buf);''',
450
451 ('Retrieve a range of text.',)),
452
453 'PointXFromPosition' : (None, 0, 0, 0),
454 'PointYFromPosition' : (None, 0, 0, 0),
455
456 'ScrollCaret' : ('EnsureCaretVisible', 0, 0, 0),
457 'ReplaceSel' : ('ReplaceSelection', 0, 0, 0),
458 'Null' : (None, 0, 0, 0),
459
460 'GetText' :
461 (0,
462 'wxString %s();',
463
464 '''wxString %s() {
465 int len = GetTextLength();
466 wxMemoryBuffer mbuf(len+1); // leave room for the null...
467 char* buf = (char*)mbuf.GetWriteBuf(len+1);
468 SendMsg(%s, len+1, (long)buf);
469 mbuf.UngetWriteBuf(len);
470 mbuf.AppendByte(0);
471 return stc2wx(buf);''',
472
473 ('Retrieve all the text in the document.', )),
474
475 'GetDirectFunction' : (None, 0, 0, 0),
476 'GetDirectPointer' : (None, 0, 0, 0),
477
478 'CallTipPosStart' : ('CallTipPosAtStart', 0, 0, 0),
479 'CallTipSetHlt' : ('CallTipSetHighlight', 0, 0, 0),
480 'CallTipSetBack' : ('CallTipSetBackground', 0, 0, 0),
481 'CallTipSetFore' : ('CallTipSetForeground', 0, 0, 0),
482 'CallTipSetForeHlt' : ('CallTipSetForegroundHighlight', 0, 0, 0),
483
484 'SetHotspotActiveFore' : ('SetHotspotActiveForeground', 0, 0, 0),
485 'SetHotspotActiveBack' : ('SetHotspotActiveBackground', 0, 0, 0),
486
487
488 'ReplaceTarget' :
489 (0,
490 'int %s(const wxString& text);',
491
492 '''
493 int %s(const wxString& text) {
494 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
495 return SendMsg(%s, strlen(buf), (long)(const char*)buf);''',
496 0),
497
498 'ReplaceTargetRE' :
499 (0,
500 'int %s(const wxString& text);',
501
502 '''
503 int %s(const wxString& text) {
504 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
505 return SendMsg(%s, strlen(buf), (long)(const char*)buf);''',
506 0),
507
508 'SearchInTarget' :
509 (0,
510 'int %s(const wxString& text);',
511
512 '''
513 int %s(const wxString& text) {
514 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
515 return SendMsg(%s, strlen(buf), (long)(const char*)buf);''',
516 0),
517
518 # not sure what to do about these yet
519 'TargetAsUTF8' : ( None, 0, 0, 0),
520 'SetLengthForEncode' : ( None, 0, 0, 0),
521 'EncodedFromUTF8' : ( None, 0, 0, 0),
522
523
524 'GetDocPointer' :
525 (0,
526 'void* %s();',
527 '''void* %s() {
528 return (void*)SendMsg(%s);''',
529 0),
530
531 'SetDocPointer' :
532 (0,
533 'void %s(void* docPointer);',
534 '''void %s(void* docPointer) {
535 SendMsg(%s, 0, (long)docPointer);''',
536 0),
537
538 'CreateDocument' :
539 (0,
540 'void* %s();',
541 '''void* %s() {
542 return (void*)SendMsg(%s);''',
543 0),
544
545 'AddRefDocument' :
546 (0,
547 'void %s(void* docPointer);',
548 '''void %s(void* docPointer) {
549 SendMsg(%s, 0, (long)docPointer);''',
550 0),
551
552 'ReleaseDocument' :
553 (0,
554 'void %s(void* docPointer);',
555 '''void %s(void* docPointer) {
556 SendMsg(%s, 0, (long)docPointer);''',
557 0),
558
559 'SetCodePage' :
560 (0,
561 0,
562 '''void %s(int codePage) {
563 #if wxUSE_UNICODE
564 wxASSERT_MSG(codePage == wxSTC_CP_UTF8,
565 wxT("Only wxSTC_CP_UTF8 may be used when wxUSE_UNICODE is on."));
566 #else
567 wxASSERT_MSG(codePage != wxSTC_CP_UTF8,
568 wxT("wxSTC_CP_UTF8 may not be used when wxUSE_UNICODE is off."));
569 #endif
570 SendMsg(%s, codePage);''',
571 ("Set the code page used to interpret the bytes of the document as characters.",) ),
572
573
574 'GrabFocus' : (None, 0, 0, 0),
575
576 # Rename some that would otherwise hide the wxWindow methods
577 'SetFocus' : ('SetSTCFocus', 0, 0, 0),
578 'GetFocus' : ('GetSTCFocus', 0, 0, 0),
579 'SetCursor' : ('SetSTCCursor', 0, 0, 0),
580 'GetCursor' : ('GetSTCCursor', 0, 0, 0),
581
582 'LoadLexerLibrary' : (None, 0,0,0),
583
584
585 '' : ('', 0, 0, 0),
586
587 }
588
589 #----------------------------------------------------------------------------
590
591 def processIface(iface, h_tmplt, cpp_tmplt, h_dest, cpp_dest, docstr_dest):
592 curDocStrings = []
593 values = []
594 methods = []
595 cmds = []
596
597 # parse iface file
598 fi = FileInput(iface)
599 for line in fi:
600 line = line[:-1]
601 if line[:2] == '##' or line == '':
602 #curDocStrings = []
603 continue
604
605 op = line[:4]
606 if line[:2] == '# ': # a doc string
607 curDocStrings.append(line[2:])
608
609 elif op == 'val ':
610 parseVal(line[4:], values, curDocStrings)
611 curDocStrings = []
612
613 elif op == 'fun ' or op == 'set ' or op == 'get ':
614 parseFun(line[4:], methods, curDocStrings, cmds)
615 curDocStrings = []
616
617 elif op == 'cat ':
618 if string.strip(line[4:]) == 'Deprecated':
619 break # skip the rest of the file
620
621 elif op == 'evt ':
622 pass
623
624 elif op == 'enu ':
625 pass
626
627 elif op == 'lex ':
628 pass
629
630 else:
631 print '***** Unknown line type: ', line
632
633
634 # process templates
635 data = {}
636 data['VALUES'] = processVals(values)
637 data['CMDS'] = processVals(cmds)
638 defs, imps, docstrings = processMethods(methods)
639 data['METHOD_DEFS'] = defs
640 data['METHOD_IMPS'] = imps
641
642 # get template text
643 h_text = open(h_tmplt).read()
644 cpp_text = open(cpp_tmplt).read()
645
646 # do the substitutions
647 h_text = h_text % data
648 cpp_text = cpp_text % data
649
650 # write out destination files
651 open(h_dest, 'w').write(h_text)
652 open(cpp_dest, 'w').write(cpp_text)
653 open(docstr_dest, 'w').write(docstrings)
654
655
656
657 #----------------------------------------------------------------------------
658
659 def processVals(values):
660 text = []
661 for name, value, docs in values:
662 if docs:
663 text.append('')
664 for x in docs:
665 text.append('// ' + x)
666 text.append('#define %s %s' % (name, value))
667 return string.join(text, '\n')
668
669 #----------------------------------------------------------------------------
670
671 def processMethods(methods):
672 defs = []
673 imps = []
674 dstr = []
675
676 for retType, name, number, param1, param2, docs in methods:
677 retType = retTypeMap.get(retType, retType)
678 params = makeParamString(param1, param2)
679
680 name, theDef, theImp, docs = checkMethodOverride(name, number, docs)
681
682 if name is None:
683 continue
684
685 # Build docstrings
686 st = 'DocStr(wxStyledTextCtrl::%s,\n' \
687 '"%s", "");\n' % (name, '\n'.join(docs))
688 dstr.append(st)
689
690 # Build the method definition for the .h file
691 if docs:
692 defs.append('')
693 for x in docs:
694 defs.append(' // ' + x)
695 if not theDef:
696 theDef = ' %s %s(%s);' % (retType, name, params)
697 defs.append(theDef)
698
699 # Build the method implementation string
700 if docs:
701 imps.append('')
702 for x in docs:
703 imps.append('// ' + x)
704 if not theImp:
705 theImp = '%s wxStyledTextCtrl::%s(%s) {\n ' % (retType, name, params)
706
707 if retType == 'wxColour':
708 theImp = theImp + 'long c = '
709 elif retType != 'void':
710 theImp = theImp + 'return '
711 theImp = theImp + 'SendMsg(%s, %s, %s)' % (number,
712 makeArgString(param1),
713 makeArgString(param2))
714 if retType == 'bool':
715 theImp = theImp + ' != 0'
716 if retType == 'wxColour':
717 theImp = theImp + ';\n return wxColourFromLong(c)'
718
719 theImp = theImp + ';\n}'
720 imps.append(theImp)
721
722
723 return '\n'.join(defs), '\n'.join(imps), '\n'.join(dstr)
724
725
726 #----------------------------------------------------------------------------
727
728 def checkMethodOverride(name, number, docs):
729 theDef = theImp = None
730 if methodOverrideMap.has_key(name):
731 item = methodOverrideMap[name]
732
733 try:
734 if item[0] != 0:
735 name = item[0]
736 if item[1] != 0:
737 theDef = ' ' + (item[1] % name)
738 if item[2] != 0:
739 theImp = item[2] % ('wxStyledTextCtrl::'+name, number) + '\n}'
740 if item[3] != 0:
741 docs = item[3]
742 except:
743 print "*************", name
744 raise
745
746 return name, theDef, theImp, docs
747
748 #----------------------------------------------------------------------------
749
750 def makeArgString(param):
751 if not param:
752 return '0'
753
754 typ, name = param
755
756 if typ == 'string':
757 return '(long)(const char*)wx2stc(%s)' % name
758 if typ == 'colour':
759 return 'wxColourAsLong(%s)' % name
760
761 return name
762
763 #----------------------------------------------------------------------------
764
765 def makeParamString(param1, param2):
766 def doOne(param):
767 if param:
768 aType = paramTypeMap.get(param[0], param[0])
769 return aType + ' ' + param[1]
770 else:
771 return ''
772
773 st = doOne(param1)
774 if st and param2:
775 st = st + ', '
776 st = st + doOne(param2)
777 return st
778
779
780 #----------------------------------------------------------------------------
781
782 def parseVal(line, values, docs):
783 name, val = string.split(line, '=')
784
785 # remove prefixes such as SCI, etc.
786 for old, new in valPrefixes:
787 lo = len(old)
788 if name[:lo] == old:
789 if new is None:
790 return
791 name = new + name[lo:]
792
793 # add it to the list
794 values.append( ('wxSTC_' + name, val, docs) )
795
796 #----------------------------------------------------------------------------
797
798 funregex = re.compile(r'\s*([a-zA-Z0-9_]+)' # <ws>return type
799 '\s+([a-zA-Z0-9_]+)=' # <ws>name=
800 '([0-9]+)' # number
801 '\(([ a-zA-Z0-9_]*),' # (param,
802 '([ a-zA-Z0-9_]*)\)') # param)
803
804 def parseFun(line, methods, docs, values):
805 def parseParam(param):
806 param = string.strip(param)
807 if param == '':
808 param = None
809 else:
810 param = tuple(string.split(param))
811 return param
812
813 mo = funregex.match(line)
814 if mo is None:
815 print "***** Line doesn't match! : " + line
816
817 retType, name, number, param1, param2 = mo.groups()
818
819 param1 = parseParam(param1)
820 param2 = parseParam(param2)
821
822 # Special case. For the key command functions we want a value defined too
823 num = string.atoi(number)
824 for v in cmdValues:
825 if (type(v) == type(()) and v[0] <= num <= v[1]) or v == num:
826 parseVal('CMD_%s=%s' % (string.upper(name), number), values, docs)
827
828 # if we are not also doing a function for CMD values, then
829 # just return, otherwise fall through to the append blow.
830 if not FUNC_FOR_CMD:
831 return
832
833 methods.append( (retType, name, number, param1, param2, tuple(docs)) )
834
835
836 #----------------------------------------------------------------------------
837
838
839 def main(args):
840 # TODO: parse command line args to replace default input/output files???
841
842 # Now just do it
843 processIface(IFACE, H_TEMPLATE, CPP_TEMPLATE, H_DEST, CPP_DEST, DOCSTR_DEST)
844
845
846
847 if __name__ == '__main__':
848 main(sys.argv)
849
850 #----------------------------------------------------------------------------
851