Is there a more efficient way to get the total number of display lines (not just visible ones) that are left in a tkinter
Text
widget after the text in
Okay, I found an answer (and yes, this is purposefully an answer; it's not part of my question).
The following code will much more efficiently give the number of display lines left after the text insert:
def get_display_lines(start="insert", end="end-1c")
try:
count=myTextWidget.count(start, end, "displaylines")[0]
except TypeError:
count=0
return count
Although this is much more efficient, it is still not totally efficient and will have trouble with large files (if you're using the arrow keys a lot during autoscroll). The count() method returns a tuple; hence, the zero index. Because this does not always contain a number (like when the insert is at the end of the document), that is why I use a try/except block (although you could do this lots of other ways; however you please).
Because this is not efficient for large files, you might just get the current lines left once, save them, and increment/decrement this variable when updating the status (granted, that will require editing a bunch of functions, but it is more efficient). You'll need to update the total during edits, though (fortunately, that is less common while autoscrolling).
Because messing around with a lot of other functions is a lot of overhead, and increases the complexity of editing the code, I suggest just only having it update on the autoscroll intervals, rather than when the user manually moves the cursor. Also, to increase efficiency, don't have it calculate the lines left (let alone the time left from that) in the statusbar update method, but only calculate it in a saved variable from the method called by the timer, and just print the variable in the statusbar.