tags:

views:

161

answers:

2

I'm trying to make a very large file editor (where the editor only stores a part of the buffer in memory at a time), but I'm stuck while building my textview object. Basically- I know that I have to be able to update the text view buffer dynamically, and I don't know hot to get the scrollbars to relate to the full file while the textview contains only a small buffer of the file.

I've played with Gtk.Adjustment on a Gtk.ScrolledWindow and ScrollBars, but though I can extend the range of the scrollbars, they still apply to the range of the buffer and not the filesize (which I try to set via Gtk.Adjustment parameters) when I load into textview. I need to have a widget that "knows" that it is looking at a part of a file, and can load/unload buffers as necessary to view different parts of the file. So far, I believe I'll respond to the "change_view" to calculate when I'm off, or about to be off the current buffer and need to load the next, but I don't know how to get the scrollbars to have the top relate to the beginning of the file, and the bottom relate to the end of the file, rather than to the loaded buffer in textview.

Any help would be greatly appreciated, thanks!

+1  A: 

You probably should create your own Gtk.TextBuffer implementation, as the default one relies on storing whole buffer in memory.

el.pescado
A: 

I agree with el.pescado's answer, but you could also try to fake it. Count the number of lines in the file you're editing. Put one screenful of text in the buffer and fill the rest with newlines so the buffer has the same number of lines as the file.

Then connect to the changed signal of the vertical adjustment of the scrolled window that contains the text view, this will notify you whenever the window is scrolled. When that happens, replace the text you already had in the buffer with newlines, and load the section you are now looking at.

You can tell which line numbers you are supposed to be looking at in a text view with this code (may have bugs, I'm doing this from memory and translating into Python on the fly):

visible_rect = textview.get_visible_rect()
top = textview.get_iter_at_location(visible_rect.x, visible_rect.y)
bottom = textview.get_iter_at_location(visible_rect.x, visible_rect.y + visible_rect.height)
top_line, bottom_line = top.get_line(), bottom.get_line()
ptomato