Hi all,
first of all I'd like to say that the more I play with wxPython the more
I'm satisfied with it. Very nice work.
Some annoying bug is still around but the whole thing is very close to
commercial quality (for one I suspect that the weird size event behavior
is a bug, if you have to deal with multiple nested windows getting out the
right resize behavior is a mess this way).
Oh, well, the question now: I'm using wxPython with Scintilla to build a
small programmers editor, but I refuse to learn a new programming language
(the point here is that this new programming is python :).
Now I stepped into a problem that looks like I'm not able to solve by
using my fantasy (as I did until now) and the problem is auto-indent.
I read the docs that come with scintilla and the proposed code to
implment auto-indent, beside being C++ this is a hell of a hack not what
I would call clear code.
I hardly understand what it does in C++, I can't do the same in python for
sure! So I decided to go another way using the idle time.
Here is a snipet of the original code:
class eSCICtrl(wxStyledTextCtrl):
def __init__(self, parent, id):
wxStyledTextCtrl.__init__(self, parent, id)
self.idle_indent = false
EVT_STC_MODIFIED(self, id, self.OnModified)
EVT_IDLE(self, self.OnIdle)
def OnIdle(self, event):
if self.idle_indent :
line = self.GetCurrentLine()
print 'current line: '+str(line)
if line > 0:
indent = self.GetLineIndentation(line-1)
if indent > 0:
prevline = self.GetLine(line-1)
i = 0
while prevline[i] == ' ' or prevline[i] == '\t':
self.AddText(prevline[i])
i = i+1
if prevline[len(prevline)-2] == '{':
self.AddText('\t')
self.idle_indent = false
def OnModified(self, event):
if event.GetModificationType() & wxEVT_STC_CHARADDED:
if event.GetText() == '\n' or event.GetText() == '\r':
self.idle_indent = true
Well it does work: since it looks like I cannot modify the actual contents
in the event handler I postpone the modifications in idle time. I just
hope you don't type too fast
The question is: does this code make sense?
Is this an acceptable way of solving the problem or this is plain wrong?
I have another thousand questions that raised from this small project (one
for all: why when I use StyleSetFont(wxSTC_STYLE_DEFAULT, font) the font
used is not exactly what I passed but one with the same typeface but
different size?).
If you are interested in the project and you think you can help with some
on my questions the code is at:
ftp://phd.cs.unibo.it/pub/rossi/e.tar.gz
My questions are marked by ##.
Please don't send me patches or new code, it's far too early, just tell me
how to fix my code.
I still don't know if the goal of building a programmer's editor with
wxPython is feasible, in the case I will work on it and it will be open
source.
Ciao,
Davide.
PS: I will be away from Aug 13 to Aug 21 so don't be worried if I don't
reply promply to my e-mail