Gtk: How can I get part of a file in text form with scrollbars related to the full file

I am trying to create a very large file editor (where the editor only stores part of the buffer in memory at a time), but I am stuck when creating a textview object. Basically, I know that I have to dynamically update the text view buffer, and I don’t know what it takes for the scroll bars to link to the full file, while the text view contains only a small file buffer.

I played with Gtk.Adjustment on Gtk.ScrolledWindow and ScrollBars, but although I can expand the range of scrollbars, they still apply to the buffer range and not to the file size (which I am trying to set via Gtk.Adjustment Options) when loading into text window. I need a widget that “knows” that it is looking at a part of the file and can load / unload buffers, if necessary, to view different parts of the file. So far, I believe that I will answer “change_view” to calculate when I will leave, or just about to leave the current buffer and load the next one, but I don’t know how to force the scroll bars the top part refers to the beginning of the file and the bottom the part refers to the end of the file, not to the loaded buffer in the text view.

Any help would be greatly appreciated, thanks!

+5
source share
2 answers

You should probably create your own implementation of Gtk.TextBuffer, since the default is to store the entire buffer in memory.

+1
source

I agree with el.pescado's answer, but you can also try to fake it. Count the number of lines in the edited file. Put one screen of text in the buffer and fill in the remaining lines so that the buffer has the same number of lines as the file.

changed , , , . , , , , , .

, ( , Python ):

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()
0

All Articles