so what I'm doing is building my own python IDE using PyQt.
nothing can do what I need it to without a loss of something else, let alone properly.
so I'm using a QPainter and getting the best results yet.
however I'm having a problem trying to build indent guides like NotePad++ or VS2010 among other IDEs.
what I need to do is build an array specifying the indentation level as an int (basically the amount of tabs to draw) for each line
I've been trying to do it using python's tokenize, however I can't seem to get it to properly indent then dedent.
anyone know of anything better??
I don't see how tokenize can fail: it generates INDENT and DEDENT tokens that you could use to compute the indentation level. Also note that it is better to indent python code with space characters than tabs. A good python editor needs the 4 space indentation.
Unfortunately, I'm not using windows tools such as notepad++ and VS2010, so I don't really understand what you want to do.
lines = this.data.splitlines(True)
indents = *(lines.__len__()+2) # 2 because of an index error with erow
for toktype, toktext, (srow, scol), (erow, ecol), line in tokenize.generate_tokens( iter(lines).next ):
if toktype == tokenize.INDENT:
indents[srow-1] = 1
if toktype == tokenize.DEDENT:
indents[erow-1] = -1
pos = 0
for indent in indents: pos+=indent; this.indents.append(pos)
I got it working as well as it was before, however it still extends past the dedent in some cases
what exactly am I doing wrong??
so the code in my last post is what builds the indents...
here's what parses/draws them:
for ln,line in enumerate(lines[TextStartY:TextEndY]):
painter.setPen( this.indentColor )
x1 = xpos*this.font_width
for i in range(this.indents[ln]):
x = x1+(i*4*this.font_width)
except: pass # index error with this.indents[ln], not sure why
fixed the index error :)
not sure what I did, but I'm sure it has something to do with the fixups to the intellisesne database.
(note: when I say "the intellisense database", don't expect too much out of that, it's still being designed)
also y1 is just the start of the line (the text displayed uses this as well)
and y2 should really be labeled h
but no, these work correctly or the text would be messed up too ;)
the indent line is only drawn to the text-height the painter only displays what's in it's view area ;)
well, I know what to do, since tokenize can't do this correctly.
python's ast module should be able to return a much more accurate representation for what I need.
do note, the code editor is currently borked due to the implementation of a new regex engine that can handle recursive expressions for a better syntax highlighter (QRegExp() and the multi-expressive implementations I did are faaaar too slow)
I hate this new layout (can't post and answer at the same time)
would've been nice if there was an answer button at the bottom of the page.
stupid modernization >_<