What signals should I catch when scrolling in the Gtk ScrolledWindow?

I am developing a python plugin for Rhythmbox - this contains a GtkScrolledWindow with a child, which is a GtkIconView. IconView is loaded from Gtk.TreeModel.

It looks like this:

enter image description here

Currently - and somewhat inefficiently, each icon is drawn for each line in the tree model - each icon is a GdkPixbuf from a file. If you have thousands of lines, it can take quite a while for the entire icon to be fully updated with each image.

What I'm trying to achieve is to only update the icons that are in the current area of ​​the drawing - when the user scrolls and releases the scroll bar (or moves on the keyboard), the icons in the new drawing area should be updated with the appropriate images.

NB - the tree model will be fully populated at this point - only the icons would not be loaded.

This is actually not my area of ​​expertise. I am looking for pointers for a better approach, which I should use to achieve the above.

In particular, which Gtk + 3 signal for drawing (or signals) can be set (Gtk.ScrolledWindow / Gtk.IconView?) To write python-based code to calculate which icons should be updated?

+4
source share
2 answers

You must review your application to find out what takes time.

Is it loading images? If so, then loading the default image and adding it everywhere in your view will be fast enough since you will only upload one image. Then you download and update the images on demand using idle_add , based on the images that should be displayed in the viewport.

If it takes time to add images to the model, you will need to add an on-demand add by checking what is visible on the viewport in the idle_add callback.

If both of them are slow, you will need a combination of both: download and add on demand.

Also consider a proxy design template that can be useful for creating a fake cover object that will load in the background and contain a download policy.

For signals, your GtkIconView widget implements GtkScrollable , which explains how to scroll . You have set the vertical setting and check when it has changed by connecting it to value-changed . This would mean that the user scrolls up or down, and you would need to start the timer with timeout_add . If after a short timeout (from 0.5 to 1 s, I think, but needs to be tested), the setting has not changed, this means that the user has stopped scrolling, and you can update the displayed one. Otherwise, it will be updated during scrolling, slowing everything down. You just need to figure out how to find which items appear in the viewport, update their cover.

I've never done this before, but I know a little bit of GTK and just tried to figure out how this would be done, so read this with some caution. In any case, the response to reactivity is “on demand”.

+4
source

But on the other hand, if you need to scroll completely down, you have to wait until each page is built. Therefore, I think you should better consider the idle_add function of the idle_add loop.

Thus, your screen does not lock, and your computer does not need to wait for the user to load the page view page. Win-Win for you and your application .; -)

0
source

Source: https://habr.com/ru/post/1444963/


All Articles