DataViewCtrl: how to scroll programmatically? (wxGTK)

172 views
Skip to first unread message

dario...@gmail.com

unread,
Jul 6, 2014, 3:17:31 AM7/6/14
to wxpytho...@googlegroups.com
Is it possible to scroll a DataViewCtrl programmatically? Or to know the current scroll position?

Methods like Window.GetScrollPos and Window.ScrollLines don't seem to work; the former even raises "PyAssertionError: C++ assertion "sb" failed at ./src/gtk/window.cpp(4764) in GetScrollPos(): this window is not scrollable", which makes me think the answer is going to be no...

In case the answer is no, is it planned for some future milestone? I haven't been able to find any related bug report.

My system:
wxPython 3.0.0.0
wxGTK 3.0.1
GTK 2.24.24
Arch Linux x86_64

Werner

unread,
Jul 6, 2014, 10:24:03 AM7/6/14
to wxpytho...@googlegroups.com
On 7/6/2014 9:17, dario...@gmail.com wrote:
> Is it possible to scroll a DataViewCtrl programmatically? Or to know
> the current scroll position?
>
> Methods like Window.GetScrollPos and Window.ScrollLines don't seem to
> work; the former even raises "PyAssertionError: C++ assertion "sb"
> failed at ./src/gtk/window.cpp(4764) in GetScrollPos(): this window is
> not scrollable", which makes me think the answer is going to be no...
>
> In case the answer is no, is it planned for some future milestone? I
> haven't been able to find any related bug report.
What is ScrollLines returning? True or False or are you also getting an
error?

Maybe dvc.EnsureVisible would help?

Werner

dario...@gmail.com

unread,
Jul 6, 2014, 10:55:43 AM7/6/14
to wxpytho...@googlegroups.com

Thank you Werner, this is the code I'm using for testing:

#####################################################
import wx
import wx.dataview as dv


class Model(dv.PyDataViewIndexListModel):
    def __init__(self):
        self.data = [str(n) for n in range(100)]
        super(Model, self).__init__()

    def GetValueByRow(self, row, col):
        return self.data[row]

    def GetColumnCount(self):
        return 1

    def GetCount(self):
        return 100


class List(dv.DataViewCtrl):
    def __init__(self, parent):
        super(List, self).__init__(parent)
        self.model = Model()
        self.AssociateModel(self.model)
        self.column = self.AppendTextColumn('Test', 0)
        self.model.Reset(100)

        wx.CallLater(2000, self.scroll)

    def scroll(self):
        try:
            print('POS1', self.GetScrollPos(wx.VERTICAL))
        except wx._core.PyAssertionError as err:
            print('ERROR', err)

        print('SCROLL', self.ScrollLines(20))

        try:
            print('POS2', self.GetScrollPos(wx.VERTICAL))
        except wx._core.PyAssertionError as err:
            print('ERROR', err)


app = wx.App()
frame = wx.Frame(None)
List(frame)
frame.Show()
app.MainLoop()
#####################################################

The output is:

#####################################################
('ERROR', PyAssertionError(u'C++ assertion "sb" failed at ./src/gtk/window.cpp(4764) in GetScrollPos(): this window is not scrollable',))
('SCROLL', False)
('ERROR', PyAssertionError(u'C++ assertion "sb" failed at ./src/gtk/window.cpp(4764) in GetScrollPos(): this window is not scrollable',))
#####################################################

So ScrollLines returns False with no error, but the docs say that on wxGTK it's only implemented for TextCtrl...

EnsureVisible could be a temporary solution, although not optimal, but anyway I want to preserve the current scroll position through a Reset, so I still need to get the current scroll.

Werner

unread,
Jul 7, 2014, 3:51:51 AM7/7/14
to wxpytho...@googlegroups.com
Hi,

On 7/6/2014 16:55, dario...@gmail.com wrote:
> On Sunday, July 6, 2014 10:24:03 PM UTC+8, werner wrote:
>
...
> The output is:
>
> #####################################################
> ('ERROR', PyAssertionError(u'C++ assertion "sb" failed at
> ./src/gtk/window.cpp(4764) in GetScrollPos(): this window is not
> scrollable',))
> ('SCROLL', False)
> ('ERROR', PyAssertionError(u'C++ assertion "sb" failed at
> ./src/gtk/window.cpp(4764) in GetScrollPos(): this window is not
> scrollable',))
> #####################################################
>
> So ScrollLines returns False with no error, but the docs say that on
> wxGTK it's only implemented for TextCtrl...
>
> EnsureVisible could be a temporary solution, although not optimal, but
> anyway I want to preserve the current scroll position through a Reset,
> so I still need to get the current scroll.

Hi,

On 2.9.5 Windows I see:
2.9.5.0
('POS1', 0)
('SCROLL', True)
('POS2', 20)

and on 3.0.1 Phoenix I see this:
3.0.1.dev76109
('POS1', 0)
('SCROLL', True)
('POS2', 20)

This is all on Windows 8.1, so it looks like a problem in 3.0 or a GTK one.

Hopefully someone else with *nix know how can help.

Werner

P.S.
Attached the code which makes it run on Phoenix without deprecation
warnings.

dvcscroll.py

Dario Giovannetti

unread,
Jul 7, 2014, 9:53:54 AM7/7/14
to wxpytho...@googlegroups.com
I see, I'm using 3.0.1 too, so it must be limited to wxGTK. Going back
to my original post, and given that the docs say that ScrollLines is
only implemented for TextCtrl (but don't say anything about
GetScrollPos), do you think it's worth opening a bug report at this
stage? I don't understand if the implementation is already planned for
some future version or not.

Werner

unread,
Jul 7, 2014, 10:07:21 AM7/7/14
to wxpytho...@googlegroups.com
On 7/7/2014 15:53, Dario Giovannetti wrote:
> On 07/07/14 15:51, Werner wrote:
>> Hi,
>>
>>
...
> I see, I'm using 3.0.1 too, so it must be limited to wxGTK. Going back
> to my original post, and given that the docs say that ScrollLines is
> only implemented for TextCtrl (but don't say anything about
> GetScrollPos), do you think it's worth opening a bug report at this
> stage? I don't understand if the implementation is already planned for
> some future version or not.
I don't know, as I know just about zero on wxPython on Linux.

Hopefully some Linux user can give you some feedback/help.

Werner



Nathan McCorkle

unread,
Jul 7, 2014, 6:16:02 PM7/7/14
to wxpytho...@googlegroups.com
If you have an item selected, and want to return there... maybe dvc.GetSelection()would work... otherwise maybe HitTest() (i.e. always using the top-left coordinate and storing the row that returns True)

nepix32

unread,
Jul 8, 2014, 4:43:12 AM7/8/14
to wxpytho...@googlegroups.com

On Tuesday, July 8, 2014 12:16:02 AM UTC+2, Nathan McCorkle wrote:
If you have an item selected, and want to return there... maybe dvc.GetSelection()would work... otherwise maybe HitTest() (i.e. always using the top-left coordinate and storing the row that returns True)
As pointed out in this wxpython-users post, dvc.HitTest() is not SWIGed properly yet and should not work.
 
With best regards

Dario Giovannetti

unread,
Jul 9, 2014, 12:39:13 AM7/9/14
to wxpytho...@googlegroups.com
Thanks guys, I've implemented an acceptable workaround for the scrolling
part, see the attached file: it's based on werner's suggestion to use
EnsureVisible, which initially I didn't like because it would leave the
item at the bottom of the page, however doing a pre-scroll to the last
item fixes it rather elegantly.
The problem of retrieving the current scroll state is still open,
though, and I can't base it on selections unfortunately :(
test_dvscroll.py
Reply all
Reply to author
Forward
0 new messages