[PyKDE] QScintilla Lexers

yawber yawber.w at ukonline.co.uk
Mon Jan 10 23:38:46 GMT 2005


Thanks for your reply.

On Monday 10 Jan 2005 10:27, you wrote:
> QScintilla is a port of Scintilla, not an enhancement of it. If there are
> issues with how well lexers work (or if you want a new lexer) then these
> should be fixed in Scintilla itself and they will then appear in QScintilla.

Okay - I'll try the Scintilla mailing list on these issues.

> > The real point of all this is to introduce a couple proposals for
> > improving the lexers in QScintilla. The first one is obvious: make
> > QextScintillaLexer Python-friendly so it can be fully sub-classed.
>
> It's not clear from your explanation exactly what the problem is. Can you
> give some specific examples?
>
> Phil

If I was writing a Qt app in C++ which used QScintilla, I could just go ahead 
and sub-class QextScintillaLexer without any problems. But because I'm a 
Python programmer using QScintilla via PyQt, I can't.

To make the Python problems explicit in code, here's how I might set a lexer 
language using QScintilla's low-level API:

	qsb.SendScintilla(qsb.SCI_SETLEXERLANGUAGE, QString('perl').latin1())

This works because QString can pass a const char* to the function even though 
Python can't do it itself.

Here's the same thing from the C++ source code for QextScintilla.setLexer():

	SendScintilla(SCI_SETLEXERLANGUAGE, lex -> lexer());

Now if 'lex' is a Python sub-class of QextScintillaLexer that I have passed to 
setLexer(), I can't pull the QString trick any more. And since Python 
functions can't return const char*, whenever lex.lexer() gets called all I'll 
see is a segmentation fault.

There are two reasons why I'm bothering with any of this. The first is because 
I want to set custom keyword lists. This would allow me to, say, provide HTML 
syntax highlighting to suit different browsers or different versions of the 
w3c standards. The second is to access more of Scintilla's 60 lexers by 
creating my own lexer classes. (I assume QScintilla won't be implementing 
classes for all 50 of the remaining lexers any time soon...)

I can partially achieve both these things using the low-level API, but this 
entails needlessly duplicating a whole load of code which has already been 
done better by QScintilla. As I say, if I could only sub-class 
QextScintillaLexer in Python, all these problems would go away.





More information about the PyQt mailing list