Thank Michael you for your answer, I am trying to simplify the calls to Tk
but I didn't manage much.
BTW I saw that IDLE has a very nice and fast highlighting
but I didn't understand the way. I see that somehow it overrides the
insert and delete function of the Text (not of the subclass) with a 
register function and applies the highlighting from there.
(ColorDelegator.py and Percolator.py)

V.


________________________________________
From: Tkinter-discuss 
[[email protected]] on behalf of 
Michael Lange [[email protected]]
Sent: 26 August 2014 10:34
To: [email protected]
Subject: Re: [Tkinter-discuss] Text() highlight

On Mon, 25 Aug 2014 14:15:59 +0000
Vasilis Vlachoudis <[email protected]> wrote:

> Hi all,
>
> I am trying to implement a small g-code editor and real time viewer in
> tkinter. I am using the Text() widget as an editor, but I have troubles
> in highlighting the text during editing. Its slow when editing big
> files.
(...)

I don't have much experience with the text widget's advanced
capabilities, so I can just give a general hint on how to speed up
repeating tasks in Tkinter.
In my experience calls to Python commands are usually fast enough, the
bottleneck is the calls to Tk, though I am not sure if this is because Tk
is slow in itself or if it is the mechanism of the Tcl interpreter that
is somehow "embedded" into Python that makes things slow.
So as a rule of thumb I suggest that if you want to speed up things I
would try to eliminate as many of the calls to Tkinter widgets from the
repeating routine as possible.
If you want to track down which of these calls are particularly time
expensive sometimes it proved useful to add some calls to time.time() to
measure the duration a particular command took.
So my suggestion is to see, if you can store some of the information
about the tags that you query in your highlight() routine again and again
e.g. with the text widgets search() or compare() methods in a python list
or dictionary and access the information from there. This might
complicate parts of the code but will probably result in a remarkable
speed-up of your routine.

Regards

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

Kirk to Enterprise -- beam down yeoman Rand and a six-pack.
_______________________________________________
Tkinter-discuss mailing list
[email protected]
https://mail.python.org/mailman/listinfo/tkinter-discuss
_______________________________________________
Tkinter-discuss mailing list
[email protected]
https://mail.python.org/mailman/listinfo/tkinter-discuss

Reply via email to