[pygtk] Large textview textbuffers files
Funky Fred
funkyfredmale at hotmail.com
Wed Feb 28 10:53:28 WST 2007
Hello all,
The first question would be if there was a way of searching the mailing
list archives - I couldn't find one.
But the real question I'm looking for is what the best way to go about
handling the display of large files in gtk.TextViews. I googled around, and
couldn't really find what I'm looking for. The basic idea is I have a
gtk.Notebook, to which I add several tabs, each containing a Frame,
containing a ScrollableWindow, containing a TextView. I dump content into
each textview like so:
...
textBuf = gtk.TextBuffer()
buffer.set_text( fileBuffer ) #this contains the whole content of the file
textVw = gtk.TextView()
textVw.set_buffer( buf )
....
Now I have several files/tabs, and concievably will want a decent amount
more. Right now I have buffers of size: 7b, 9b, 13b, 67b, 1640b, 100k,
200k, 230k, 230k. And the memory usage shoots up a bit (not unexpected), but
also the cpu is pretty much maxed out and the gui unresponsive (sort of
unexpected). After initializing everything, it settles down after a bit (too
long), but scrolling the window takes too long. I tried with smaller
buffers, and everything is great. I'm on vmware on a 2.8 GHz machine without
much else running & 512M allocated to the VM.
Even if I go to bare hardware, I want to be able to handle files of 1-1.5M,
and not have the CPU pegged. (Actually, I don't care that much if the cpu is
pegged, as long as the gui stays responsive :P)
So my first instinct would only to put what I can currently show in the
textview in the buffer, and then add & delete to the buffer as the user
scrolls up and down.
- Is this the right way to go about something like this, or am I off track?
- What's the easiest way to glue all this together?
My basic idea is to use:
(s,e) = gtk.TextView.window_to_buffer_coords() (would I use
gtk.TEXT_WINDOW_WIDGET?)
to get where I need to be in the buffer.
textBuffer.delete( 0, s )
textBuffer.insert( buf[prev_e:e], prev_e, e )
- If the above is right, can I count on the the textBuffer coordinates
mapping to the actual buffer indexes in the file? Or is another translation
possible?
Thanks for any and all help!
-Stu
_________________________________________________________________
Find a local pizza place, movie theater, and more
.then map the best route!
http://maps.live.com/?icid=hmtag1&FORM=MGAC01
More information about the pygtk
mailing list