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