[pygtk] Restore a scrolling position

Lionel Dricot zeploum at gmail.com
Thu Feb 19 22:45:05 WST 2009


I just found a solution by randomly googling :
https://numexp.org/svn/gnumexp/src/console/Numexp_Console/textview_display.py

My solution is the following :

def restore_vscroll(old_position) :
            vadjust = self.task_tview.get_vadjustment()
            vscroll = min(old_position,(vadjust.upper - vadjust.page_size))
            vadjust.set_value(vscroll)
gobject.idle_add(restore_vscroll,vscroll_value)


The not really intuitive bit is that in order to have the current max value
acceptable for your scroll, you have to do :
vadjust.upper - vadjust.page_size

It makes sense because the scroll value is computed from the start of the
page but it's nonetheless not trivial to found out ;-)

On Thu, Feb 19, 2009 at 2:09 PM, Lionel Dricot <zeploum at gmail.com> wrote:

>
> Hi Walter,
>
> Thank for your reply but I don't think it might fit my usecase as the
> TreeView might be refreshed without any selected cell.
>
> Example :
>
> 1) The user scroll at the bottom without selecting anything
> 2) The user trigger a refresh action
> 3) What will happen with your method ?
>
> Anyway, thanks for the suggestion
>
> Lionel
>
>
> On Thu, Feb 19, 2009 at 1:23 PM, Walter Leibbrandt <
> walter at translate.org.za> wrote:
>
>> Hi,
>>
>> If you are changing the store, I would suggest a different approach:
>>
>> This would require you to have some way to identify any given row uniquely
>> (unless the first "matching" row is acceptable) and also to "remember" the
>> selected row before performing your update. Then you can use
>> gtk.TreeView.scroll_to_cell() to scroll back to the remembered row. Using
>> scroll_to_cell(path, column, True, 0.5, 0.5) you can get the remembered row
>> nice and centered (if possible). See the docs () for more details on the
>> parameters:
>> http://www.pygtk.org/docs/pygtk/class-gtktreeview.html#method-gtktreeview--scroll-to-cell
>>
>> HTH
>>
>>
>> Lionel Dricot wrote:
>>
>>> Hello,
>>>
>>> In a previous mail, I asked about restoring the scrolling position in a
>>> treeview :
>>> http://www.mail-archive.com/pygtk@daa.com.au/msg17224.html
>>>
>>> This was solved thanks to Neil and Walter with the following line of
>>> codes at the end of my refresh function :
>>>
>>> gobject.idle_add(self.task_tview.get_vadjustment().set_value,vscroll_value)
>>>
>>> gobject.idle_add(self.task_tview.get_hadjustment().set_value,hscroll_value)
>>>
>>> (with values being read at the start of the refresh function, of course)
>>>
>>>
>>> But I discovered a problem : if elements have been removed from the
>>> treeview, the scroll will go to an empty position.
>>>
>>> In some case, it means that you will see only a blank treeview because
>>> remaining elements are hidden on top (but no scrollbar are displayed).
>>>
>>> So how can check before inserting the scroll_value that I didn't pass the
>>> upper bound of the possible scroll ?
>>>
>>
>> --
>> Walter Leibbrandt                  http://translate.org.za/blogs/walter
>> Software Developer                                  +27 12 460 1095 (w)
>> Translate.org.za
>>
>> Recent blogs:
>> * Virtaal's MVCisation
>> http://www.translate.org.za/blogs/walter/en/content/virtaals-mvcisation
>> * Things that changed the way I code
>> * Switching from Subversion to git
>>
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.daa.com.au/pipermail/pygtk/attachments/20090219/961b4f6a/attachment.htm 


More information about the pygtk mailing list