Reputation: 31
I have a program displaying a gtk Treeview with 5-6 columns and a great number of rows, therefore there is a scrollbar on the side.
I would like to ensure that if you quit the program and restart it, the position and sort order that was in the last state before closing is loaded up again.
So:
I have seen some answers on SO on how to store the selected item position but not how to display it again in the same way.
I'd appreciate if you have any tips on how to do that.
Upvotes: 1
Views: 837
Reputation: 841
I'm afraid I'm answering in C rather than Python as that's what I'm familiar with. You should be able to translate the function names easily enough. You can get and retrieve the selected row with gtk_tree_view_get_cursor
and gtk_tree_view_set_cursor
If you store the path it should be the same when you reload the data. You can use gtk_tree_view_get_columns
and g_list_find
to find which column is selected. Setting the cursor will scroll the window so it is visible. This will restore the view to roughly what it was when saved. If you want to be more precise try looking at gtk_scrollable_get_vadjustment
and gtk_scrollable_get_hadjustment
To store the sort order you can use gtk_tree_sortable_get_sort_column_id
and set it with gtk_tree_sortable_set_sort_column_id
I hope that gets you started, it's well worth spending some time familiarising yourself with the tree view documentation.I t can be a bit overwhelming at first but it is worth the effort in the long run.
Upvotes: 2