]> git.saurik.com Git - wxWidgets.git/blame - src/stc/gen_iface.py
show the standard wxWin fonts (modified patch 530698)
[wxWidgets.git] / src / stc / gen_iface.py
CommitLineData
f97d84a6
RD
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
65ec6247 15import sys, string, re, os
f97d84a6
RD
16from fileinput import FileInput
17
18
65ec6247
RD
19IFACE = os.path.abspath('./scintilla/include/Scintilla.iface')
20H_TEMPLATE = os.path.abspath('./stc.h.in')
21CPP_TEMPLATE = os.path.abspath('./stc.cpp.in')
22H_DEST = os.path.abspath('../../include/wx/stc/stc.h')
23CPP_DEST = os.path.abspath('./stc.cpp')
f97d84a6
RD
24
25
26# Value prefixes to convert
27valPrefixes = [('SCI_', ''),
28 ('SC_', ''),
37d62433 29 ('SCN_', None), # just toss these out...
f97d84a6
RD
30 ('SCEN_', None),
31 ('SCE_', ''),
32 ('SCLEX_', 'LEX_'),
33 ('SCK_', 'KEY_'),
34 ('SCFIND_', 'FIND_'),
35 ('SCWS_', 'WS_'),
36]
37
60869eaf 38# Message function values that should have a CMD_ constant as well
f97d84a6
RD
39cmdValues = [ (2300, 2350), 2011, 2013, (2176, 2180) ]
40
41
42# Map some generic typenames to wx types, using return value syntax
43retTypeMap = {
44 'position': 'int',
45 'string': 'wxString',
46 'colour': 'wxColour',
47 }
48
49# Map some generic typenames to wx types, using parameter syntax
50paramTypeMap = {
51 'position': 'int',
52 'string': 'const wxString&',
53 'colour': 'const wxColour&',
54 'keymod': 'int',
55}
56
57# Map of method info that needs tweaked. Either the name needs changed, or
58# the method definition/implementation. Tuple items are:
59#
60# 1. New method name. None to skip the method, 0 to leave the
61# default name.
62# 2. Method definition for the .h file, 0 to leave alone
63# 3. Method implementation for the .cpp file, 0 to leave alone.
64# 4. tuple of Doc string lines, or 0 to leave alone.
65#
66methodOverrideMap = {
67 'AddText' : (0,
68 'void %s(const wxString& text);',
69
70 '''void %s(const wxString& text) {
71 SendMsg(%s, text.Len(), (long)text.c_str());''',
72 0),
73
74 'AddStyledText' : (0,
75 'void %s(const wxString& text);',
76
77 '''void %s(const wxString& text) {
78 SendMsg(%s, text.Len(), (long)text.c_str());''',
79 0),
80
81 'GetViewWS' : ( 'GetViewWhiteSpace', 0, 0, 0),
82 'SetViewWS' : ( 'SetViewWhiteSpace', 0, 0, 0),
83
84 'GetStyledText' : (0,
85 'wxString %s(int startPos, int endPos);',
86
87 '''wxString %s(int startPos, int endPos) {
88 wxString text;
e1a93f46
RD
89 if (endPos < startPos) {
90 int temp = startPos;
91 startPos = endPos;
92 endPos = temp;
93 }
f97d84a6 94 int len = endPos - startPos;
abb69c6c 95 if (!len) return "";
f97d84a6 96 TextRange tr;
abb69c6c 97 tr.lpstrText = text.GetWriteBuf(len*2);
f97d84a6
RD
98 tr.chrg.cpMin = startPos;
99 tr.chrg.cpMax = endPos;
100 SendMsg(%s, 0, (long)&tr);
101 text.UngetWriteBuf(len*2);
102 return text;''',
103
104 ('Retrieve a buffer of cells.',)),
105
106
107 'PositionFromPoint' : (0,
108 'int %s(wxPoint pt);',
109
110 '''int %s(wxPoint pt) {
111 return SendMsg(%s, pt.x, pt.y);''',
112
113 0),
114
115 'GetCurLine' : (0,
8de28db9 116 '#ifdef SWIG\n wxString %s(int* OUTPUT);\n#else\n wxString GetCurLine(int* linePos=NULL);\n#endif',
f97d84a6
RD
117
118 '''wxString %s(int* linePos) {
119 wxString text;
120 int len = LineLength(GetCurrentLine());
8de28db9
RD
121 if (!len) {
122 if (linePos) *linePos = 0;
123 return "";
124 }
125 // Need an extra byte because SCI_GETCURLINE writes a null to the string
126 char* buf = text.GetWriteBuf(len+1);
127
128 int pos = SendMsg(%s, len+1, (long)buf);
abb69c6c 129 text.UngetWriteBuf(len);
f97d84a6
RD
130 if (linePos) *linePos = pos;
131
132 return text;''',
133
134 0),
135
136 'SetUsePalette' : (None, 0,0,0),
137
138 'MarkerSetFore' : ('MarkerSetForeground', 0, 0, 0),
139 'MarkerSetBack' : ('MarkerSetBackground', 0, 0, 0),
140
141 'MarkerDefine' : (0,
142 '''void %s(int markerNumber, int markerSymbol,
143 const wxColour& foreground = wxNullColour,
144 const wxColour& background = wxNullColour);''',
145
146 '''void %s(int markerNumber, int markerSymbol,
147 const wxColour& foreground,
148 const wxColour& background) {
149
150 SendMsg(%s, markerNumber, markerSymbol);
151 if (foreground.Ok())
152 MarkerSetForeground(markerNumber, foreground);
153 if (background.Ok())
154 MarkerSetBackground(markerNumber, background);''',
155
156 ('Set the symbol used for a particular marker number,',
1a2fb4cd 157 'and optionally the fore and background colours.')),
f97d84a6
RD
158
159 'SetMarginTypeN' : ('SetMarginType', 0, 0, 0),
160 'GetMarginTypeN' : ('GetMarginType', 0, 0, 0),
161 'SetMarginWidthN' : ('SetMarginWidth', 0, 0, 0),
162 'GetMarginWidthN' : ('GetMarginWidth', 0, 0, 0),
163 'SetMarginMaskN' : ('SetMarginMask', 0, 0, 0),
164 'GetMarginMaskN' : ('GetMarginMask', 0, 0, 0),
165 'SetMarginSensitiveN' : ('SetMarginSensitive', 0, 0, 0),
166 'GetMarginSensitiveN' : ('GetMarginSensitive', 0, 0, 0),
167
168 'StyleSetFore' : ('StyleSetForeground', 0, 0, 0),
169 'StyleSetBack' : ('StyleSetBackground', 0, 0, 0),
170 'SetSelFore' : ('SetSelForeground', 0, 0, 0),
171 'SetSelBack' : ('SetSelBackground', 0, 0, 0),
172 'SetCaretFore' : ('SetCaretForeground', 0, 0, 0),
173 'StyleSetFont' : ('StyleSetFaceName', 0, 0, 0),
174
175 # need to fix this to map between wx and scintilla encoding flags, leave it out for now...
176 'StyleSetCharacterSet' : (None, 0, 0, 0),
177
178 'AssignCmdKey' : ('CmdKeyAssign',
179 'void %s(int key, int modifiers, int cmd);',
180
181 '''void %s(int key, int modifiers, int cmd) {
182 SendMsg(%s, MAKELONG(key, modifiers), cmd);''',
183
184 0),
185
186 'ClearCmdKey' : ('CmdKeyClear',
187 'void %s(int key, int modifiers);',
188
189 '''void %s(int key, int modifiers) {
190 SendMsg(%s, MAKELONG(key, modifiers));''',
191
192 0),
193
194 'ClearAllCmdKeys' : ('CmdKeyClearAll', 0, 0, 0),
195
196
197 'SetStylingEx' : ('SetStyleBytes',
198 'void %s(int length, char* styleBytes);',
199
200 '''void %s(int length, char* styleBytes) {
201 SendMsg(%s, length, (long)styleBytes);''',
202
203 0),
204
205
206 'IndicSetStyle' : ('IndicatorSetStyle', 0, 0, 0),
207 'IndicGetStyle' : ('IndicatorGetStyle', 0, 0, 0),
208 'IndicSetFore' : ('IndicatorSetForeground', 0, 0, 0),
209 'IndicGetFore' : ('IndicatorGetForeground', 0, 0, 0),
210
211 'AutoCShow' : ('AutoCompShow', 0, 0, 0),
212 'AutoCCancel' : ('AutoCompCancel', 0, 0, 0),
213 'AutoCActive' : ('AutoCompActive', 0, 0, 0),
214 'AutoCPosStart' : ('AutoCompPosStart', 0, 0, 0),
215 'AutoCComplete' : ('AutoCompComplete', 0, 0, 0),
216 'AutoCStops' : ('AutoCompStops', 0, 0, 0),
217 'AutoCSetSeparator' : ('AutoCompSetSeparator', 0, 0, 0),
218 'AutoCGetSeparator' : ('AutoCompGetSeparator', 0, 0, 0),
219 'AutoCSelect' : ('AutoCompSelect', 0, 0, 0),
220 'AutoCSetCancelAtStart' : ('AutoCompSetCancelAtStart', 0, 0, 0),
221 'AutoCGetCancelAtStart' : ('AutoCompGetCancelAtStart', 0, 0, 0),
222 'AutoCSetFillUps' : ('AutoCompSetFillUps', 0, 0, 0),
223 'AutoCSetChooseSingle' : ('AutoCompSetChooseSingle', 0, 0, 0),
224 'AutoCGetChooseSingle' : ('AutoCompGetChooseSingle', 0, 0, 0),
225 'AutoCSetIgnoreCase' : ('AutoCompSetIgnoreCase', 0, 0, 0),
226 'AutoCGetIgnoreCase' : ('AutoCompGetIgnoreCase', 0, 0, 0),
65ec6247
RD
227 'AutoCSetAutoHide' : ('AutoCompSetAutoHide', 0, 0, 0),
228 'AutoCGetAutoHide' : ('AutoCompGetAutoHide', 0, 0, 0),
1a2fb4cd
RD
229 'AutoCSetDropRestOfWord' : ('AutoCompSetDropRestOfWord', 0,0,0),
230 'AutoCGetDropRestOfWord' : ('AutoCompGetDropRestOfWord', 0,0,0),
65ec6247 231
f97d84a6
RD
232
233 'SetHScrollBar' : ('SetUseHorizontalScrollBar', 0, 0, 0),
234 'GetHScrollBar' : ('GetUseHorizontalScrollBar', 0, 0, 0),
235
236 'GetCaretFore' : ('GetCaretForeground', 0, 0, 0),
237
238 'GetUsePalette' : (None, 0, 0, 0),
239
240 'FindText' : (0,
241 '''int %s(int minPos, int maxPos,
242 const wxString& text,
243 bool caseSensitive, bool wholeWord);''',
244 '''int %s(int minPos, int maxPos,
245 const wxString& text,
246 bool caseSensitive, bool wholeWord) {
247 TextToFind ft;
248 int flags = 0;
249
250 flags |= caseSensitive ? SCFIND_MATCHCASE : 0;
251 flags |= wholeWord ? SCFIND_WHOLEWORD : 0;
252 ft.chrg.cpMin = minPos;
253 ft.chrg.cpMax = maxPos;
254 ft.lpstrText = (char*)text.c_str();
255
256 return SendMsg(%s, flags, (long)&ft);''',
257 0),
258
259 'FormatRange' : (0,
260 '''int %s(bool doDraw,
261 int startPos,
262 int endPos,
263 wxDC* draw,
264 wxDC* target, // Why does it use two? Can they be the same?
265 wxRect renderRect,
266 wxRect pageRect);''',
267 ''' int %s(bool doDraw,
268 int startPos,
269 int endPos,
270 wxDC* draw,
271 wxDC* target, // Why does it use two? Can they be the same?
272 wxRect renderRect,
273 wxRect pageRect) {
274 RangeToFormat fr;
275
e1a93f46
RD
276 if (endPos < startPos) {
277 int temp = startPos;
278 startPos = endPos;
279 endPos = temp;
280 }
f97d84a6
RD
281 fr.hdc = draw;
282 fr.hdcTarget = target;
283 fr.rc.top = renderRect.GetTop();
284 fr.rc.left = renderRect.GetLeft();
285 fr.rc.right = renderRect.GetRight();
286 fr.rc.bottom = renderRect.GetBottom();
287 fr.rcPage.top = pageRect.GetTop();
288 fr.rcPage.left = pageRect.GetLeft();
289 fr.rcPage.right = pageRect.GetRight();
290 fr.rcPage.bottom = pageRect.GetBottom();
291 fr.chrg.cpMin = startPos;
292 fr.chrg.cpMax = endPos;
293
294 return SendMsg(%s, doDraw, (long)&fr);''',
295 0),
296
297
298 'GetLine' : (0,
299 'wxString %s(int line);',
300
301 '''wxString %s(int line) {
302 wxString text;
303 int len = LineLength(line);
abb69c6c 304 if (!len) return "";
afc2b641 305 char* buf = text.GetWriteBuf(len);
f97d84a6
RD
306
307 int pos = SendMsg(%s, line, (long)buf);
abb69c6c 308 text.UngetWriteBuf(len);
f97d84a6
RD
309
310 return text;''',
311
312 ('Retrieve the contents of a line.',)),
313
314 'SetSel' : ('SetSelection', 0, 0, 0),
315 'GetSelText' : ('GetSelectedText',
316 'wxString %s();',
317
318 '''wxString %s() {
319 wxString text;
320 int start;
321 int end;
322
323 GetSelection(&start, &end);
324 int len = end - start;
abb69c6c
RD
325 if (!len) return "";
326 char* buff = text.GetWriteBuf(len);
f97d84a6
RD
327
328 SendMsg(%s, 0, (long)buff);
abb69c6c 329 text.UngetWriteBuf(len);
f97d84a6
RD
330 return text;''',
331
332 ('Retrieve the selected text.',)),
333
334 'GetTextRange' : (0,
335 'wxString %s(int startPos, int endPos);',
336
337 '''wxString %s(int startPos, int endPos) {
338 wxString text;
e1a93f46
RD
339 if (endPos < startPos) {
340 int temp = startPos;
341 startPos = endPos;
342 endPos = temp;
343 }
f97d84a6 344 int len = endPos - startPos;
abb69c6c
RD
345 if (!len) return "";
346 char* buff = text.GetWriteBuf(len);
f97d84a6
RD
347 TextRange tr;
348 tr.lpstrText = buff;
349 tr.chrg.cpMin = startPos;
350 tr.chrg.cpMax = endPos;
351
352 SendMsg(%s, 0, (long)&tr);
abb69c6c 353 text.UngetWriteBuf(len);
f97d84a6
RD
354 return text;''',
355
356 ('Retrieve a range of text.',)),
357
358 'PointXFromPosition' : (None, 0, 0, 0),
359 'PointYFromPosition' : (None, 0, 0, 0),
360
361 'ScrollCaret' : ('EnsureCaretVisible', 0, 0, 0),
362 'ReplaceSel' : ('ReplaceSelection', 0, 0, 0),
363 'Null' : (None, 0, 0, 0),
364
365 'GetText' : (0,
366 'wxString %s();',
367
368 '''wxString %s() {
369 wxString text;
8de28db9
RD
370 int len = GetTextLength();
371 char* buff = text.GetWriteBuf(len+1); // leave room for the null...
f97d84a6 372
8de28db9
RD
373 SendMsg(%s, len+1, (long)buff);
374 text.UngetWriteBuf(len);
f97d84a6
RD
375 return text;''',
376
377 ('Retrieve all the text in the document.', )),
378
379 'GetDirectFunction' : (None, 0, 0, 0),
380 'GetDirectPointer' : (None, 0, 0, 0),
381
382 'CallTipPosStart' : ('CallTipPosAtStart', 0, 0, 0),
383 'CallTipSetHlt' : ('CallTipSetHighlight', 0, 0, 0),
384 'CallTipSetBack' : ('CallTipSetBackground', 0, 0, 0),
385
386
65ec6247
RD
387 'ReplaceTarget' : (0,
388 'int %s(const wxString& text);',
389
390 '''
391 int %s(const wxString& text) {
392 return SendMsg(%s, text.Len(), (long)text.c_str());
393 ''',
394
395 0),
396
397 'ReplaceTargetRE' : (0,
398 'int %s(const wxString& text);',
399
400 '''
401 int %s(const wxString& text) {
402 return SendMsg(%s, text.Len(), (long)text.c_str());
403 ''',
404
405 0),
406
407 'SearchInTarget' : (0,
408 'int %s(const wxString& text);',
409
410 '''
411 int %s(const wxString& text) {
412 return SendMsg(%s, text.Len(), (long)text.c_str());
413 ''',
414
415 0),
416
417
418
f97d84a6
RD
419 # Remove all methods that are key commands since they can be
420 # executed with CmdKeyExecute
421 'LineDown' : (None, 0, 0, 0),
422 'LineDownExtend' : (None, 0, 0, 0),
423 'LineUp' : (None, 0, 0, 0),
424 'LineUpExtend' : (None, 0, 0, 0),
425 'CharLeft' : (None, 0, 0, 0),
426 'CharLeftExtend' : (None, 0, 0, 0),
427 'CharRight' : (None, 0, 0, 0),
428 'CharRightExtend' : (None, 0, 0, 0),
429 'WordLeft' : (None, 0, 0, 0),
430 'WordLeftExtend' : (None, 0, 0, 0),
431 'WordRight' : (None, 0, 0, 0),
432 'WordRightExtend' : (None, 0, 0, 0),
433 'Home' : (None, 0, 0, 0),
434 'HomeExtend' : (None, 0, 0, 0),
435 'LineEnd' : (None, 0, 0, 0),
436 'LineEndExtend' : (None, 0, 0, 0),
437 'DocumentStart' : (None, 0, 0, 0),
438 'DocumentStartExtend' : (None, 0, 0, 0),
439 'DocumentEnd' : (None, 0, 0, 0),
440 'DocumentEndExtend' : (None, 0, 0, 0),
441 'PageUp' : (None, 0, 0, 0),
442 'PageUpExtend' : (None, 0, 0, 0),
443 'PageDown' : (None, 0, 0, 0),
444 'PageDownExtend' : (None, 0, 0, 0),
445 'EditToggleOvertype' : (None, 0, 0, 0),
446 'Cancel' : (None, 0, 0, 0),
447 'DeleteBack' : (None, 0, 0, 0),
448 'Tab' : (None, 0, 0, 0),
449 'BackTab' : (None, 0, 0, 0),
450 'NewLine' : (None, 0, 0, 0),
451 'FormFeed' : (None, 0, 0, 0),
452 'VCHome' : (None, 0, 0, 0),
453 'VCHomeExtend' : (None, 0, 0, 0),
454 'ZoomIn' : (None, 0, 0, 0),
455 'ZoomOut' : (None, 0, 0, 0),
456 'DelWordLeft' : (None, 0, 0, 0),
457 'DelWordRight' : (None, 0, 0, 0),
458 'LineCut' : (None, 0, 0, 0),
459 'LineDelete' : (None, 0, 0, 0),
460 'LineTranspose' : (None, 0, 0, 0),
461 'LowerCase' : (None, 0, 0, 0),
462 'UpperCase' : (None, 0, 0, 0),
463 'LineScrollDown' : (None, 0, 0, 0),
464 'LineScrollUp' : (None, 0, 0, 0),
465
466
467 'GetDocPointer' : (0,
468 'void* %s();',
469 '''void* %s() {
470 return (void*)SendMsg(%s);''',
471 0),
472
473 'SetDocPointer' : (0,
474 'void %s(void* docPointer);',
475 '''void %s(void* docPointer) {
65ec6247 476 SendMsg(%s, 0, (long)docPointer);''',
f97d84a6
RD
477 0),
478
479 'CreateDocument' : (0,
480 'void* %s();',
481 '''void* %s() {
482 return (void*)SendMsg(%s);''',
483 0),
484
485 'AddRefDocument' : (0,
486 'void %s(void* docPointer);',
487 '''void %s(void* docPointer) {
488 SendMsg(%s, (long)docPointer);''',
489 0),
490
491 'ReleaseDocument' : (0,
492 'void %s(void* docPointer);',
493 '''void %s(void* docPointer) {
494 SendMsg(%s, (long)docPointer);''',
495 0),
496
497 'GrabFocus' : (None, 0, 0, 0),
8de28db9
RD
498 'SetFocus' : ('SetSTCFocus', 0, 0, 0),
499 'GetFocus' : ('GetSTCFocus', 0, 0, 0),
500
f97d84a6
RD
501
502 '' : ('', 0, 0, 0),
503
504 }
505
506#----------------------------------------------------------------------------
507
508def processIface(iface, h_tmplt, cpp_tmplt, h_dest, cpp_dest):
509 curDocStrings = []
510 values = []
511 methods = []
512
513 # parse iface file
514 fi = FileInput(iface)
515 for line in fi:
516 line = line[:-1]
517 if line[:2] == '##' or line == '':
518 #curDocStrings = []
519 continue
520
521 op = line[:4]
522 if line[:2] == '# ': # a doc string
523 curDocStrings.append(line[2:])
524
525 elif op == 'val ':
526 parseVal(line[4:], values, curDocStrings)
527 curDocStrings = []
528
529 elif op == 'fun ' or op == 'set ' or op == 'get ':
530 parseFun(line[4:], methods, curDocStrings, values)
531 curDocStrings = []
532
533 elif op == 'cat ':
534 if string.strip(line[4:]) == 'Deprecated':
535 break # skip the rest of the file
536
537 elif op == 'evt ':
538 pass
539
540 else:
541 print '***** Unknown line type: ', line
542
543
544 # process templates
545 data = {}
546 data['VALUES'] = processVals(values)
547 defs, imps = processMethods(methods)
548 data['METHOD_DEFS'] = defs
549 data['METHOD_IMPS'] = imps
550
551 # get template text
552 h_text = open(h_tmplt).read()
553 cpp_text = open(cpp_tmplt).read()
554
555 # do the substitutions
556 h_text = h_text % data
557 cpp_text = cpp_text % data
558
559 # write out destination files
560 open(h_dest, 'w').write(h_text)
561 open(cpp_dest, 'w').write(cpp_text)
562
563
564
565#----------------------------------------------------------------------------
566
567def processVals(values):
568 text = []
569 for name, value, docs in values:
570 if docs:
571 text.append('')
572 for x in docs:
573 text.append('// ' + x)
574 text.append('#define %s %s' % (name, value))
575 return string.join(text, '\n')
576
577#----------------------------------------------------------------------------
578
579def processMethods(methods):
580 defs = []
581 imps = []
582
583 for retType, name, number, param1, param2, docs in methods:
584 retType = retTypeMap.get(retType, retType)
585 params = makeParamString(param1, param2)
586
587 name, theDef, theImp, docs = checkMethodOverride(name, number, docs)
588
589 if name is None:
590 continue
591
592 # Build the method definition for the .h file
593 if docs:
594 defs.append('')
595 for x in docs:
596 defs.append(' // ' + x)
597 if not theDef:
598 theDef = ' %s %s(%s);' % (retType, name, params)
599 defs.append(theDef)
600
601 # Build the method implementation string
602 if docs:
603 imps.append('')
604 for x in docs:
605 imps.append('// ' + x)
606 if not theImp:
607 theImp = '%s wxStyledTextCtrl::%s(%s) {\n ' % (retType, name, params)
608
609 if retType == 'wxColour':
610 theImp = theImp + 'long c = '
611 elif retType != 'void':
612 theImp = theImp + 'return '
613 theImp = theImp + 'SendMsg(%s, %s, %s)' % (number,
614 makeArgString(param1),
615 makeArgString(param2))
616 if retType == 'bool':
617 theImp = theImp + ' != 0'
618 if retType == 'wxColour':
619 theImp = theImp + ';\n return wxColourFromLong(c)'
620
621 theImp = theImp + ';\n}'
622 imps.append(theImp)
623
624
625 return string.join(defs, '\n'), string.join(imps, '\n')
626
627
628#----------------------------------------------------------------------------
629
630def checkMethodOverride(name, number, docs):
631 theDef = theImp = None
632 if methodOverrideMap.has_key(name):
633 item = methodOverrideMap[name]
634
635 if item[0] != 0:
636 name = item[0]
637 if item[1] != 0:
638 theDef = ' ' + (item[1] % name)
639 if item[2] != 0:
640 theImp = item[2] % ('wxStyledTextCtrl::'+name, number) + '\n}'
641 if item[3] != 0:
642 docs = item[3]
643
644 return name, theDef, theImp, docs
645
646#----------------------------------------------------------------------------
647
648def makeArgString(param):
649 if not param:
650 return '0'
651
652 typ, name = param
653
654 if typ == 'string':
655 return '(long)%s.c_str()' % name
656 if typ == 'colour':
657 return 'wxColourAsLong(%s)' % name
658
659 return name
660
661#----------------------------------------------------------------------------
662
663def makeParamString(param1, param2):
664 def doOne(param):
665 if param:
666 aType = paramTypeMap.get(param[0], param[0])
667 return aType + ' ' + param[1]
668 else:
669 return ''
670
671 st = doOne(param1)
672 if st and param2:
673 st = st + ', '
674 st = st + doOne(param2)
675 return st
676
677
678#----------------------------------------------------------------------------
679
680def parseVal(line, values, docs):
681 name, val = string.split(line, '=')
682
683 # remove prefixes such as SCI, etc.
684 for old, new in valPrefixes:
685 lo = len(old)
686 if name[:lo] == old:
687 if new is None:
688 return
689 name = new + name[lo:]
690
691 # add it to the list
692 values.append( ('wxSTC_' + name, val, docs) )
693
694#----------------------------------------------------------------------------
695
696funregex = re.compile(r'\s*([a-zA-Z0-9_]+)' # <ws>return type
697 '\s+([a-zA-Z0-9_]+)=' # <ws>name=
698 '([0-9]+)' # number
699 '\(([ a-zA-Z0-9_]*),' # (param,
700 '([ a-zA-Z0-9_]*)\)') # param)
701
702def parseFun(line, methods, docs, values):
703 def parseParam(param):
704 param = string.strip(param)
705 if param == '':
706 param = None
707 else:
708 param = tuple(string.split(param))
709 return param
710
711 mo = funregex.match(line)
712 if mo is None:
713 print "***** Line doesn't match! : " + line
714
715 retType, name, number, param1, param2 = mo.groups()
716
717 param1 = parseParam(param1)
718 param2 = parseParam(param2)
719
720 # Special case. For the key command functionss we want a value defined too
721 num = string.atoi(number)
722 for v in cmdValues:
723 if (type(v) == type(()) and v[0] <= num < v[1]) or v == num:
724 parseVal('CMD_%s=%s' % (string.upper(name), number), values, ())
725
726 #if retType == 'void' and not param1 and not param2:
727
728 methods.append( (retType, name, number, param1, param2, tuple(docs)) )
729
730
731#----------------------------------------------------------------------------
732
733
734def main(args):
735 # TODO: parse command line args to replace default input/output files???
736
737 # Now just do it
738 processIface(IFACE, H_TEMPLATE, CPP_TEMPLATE, H_DEST, CPP_DEST)
739
740
741
742if __name__ == '__main__':
743 main(sys.argv)
744
745#----------------------------------------------------------------------------
746