DataViewCtrl: how to scroll programmatically? (wxGTK)

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

What is ScrollLines returning? True or False or are you also getting an error?

Maybe dvc.EnsureVisible would help?

Werner

···

On 7/6/2014 9:17, dariogiova@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.

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

···

On Sunday, July 6, 2014 10:24:03 PM UTC+8, werner wrote:

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

#####################################################
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.

Hi,

...

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 (1.26 KB)

···

On 7/6/2014 16:55, dariogiova@gmail.com wrote:

On Sunday, July 6, 2014 10:24:03 PM UTC+8, werner wrote:

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.

···

On 07/07/14 15:51, Werner wrote:

Hi,

On 7/6/2014 16:55, dariogiova@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.

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

···

On 7/7/2014 15:53, Dario Giovannetti wrote:

On 07/07/14 15:51, Werner 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)

···

On Sunday, July 6, 2014 12:17:31 AM UTC-7, 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.

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

As pointed out in this wxpython-users post, dvc.HitTest() is not SWIGed properly yet and should not work.

With best regards

···

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)

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 :frowning:

test_dvscroll.py (937 Bytes)