wxDataViewCtrl and SQLAlchemy

I am trying to get the above to work, and looking at the different demos and wx documentation.

The demo uses PyDataViewModel but I guess that for the above I should use PyDataViewVirtualListModel.

However I can't see/find how to use it, in particular:

- how to load the data and map the row index to e.g. a database primary key? Should I use the DataViewListStore.AppendItem
- OnCacheHint equivalent of wx.ListCtrl and wx.LC_VIRTUAL

And there is probably more I need.

There isn't any sample code for it?

Werner

I am trying to get the above to work, and looking at the different demos
and wx documentation.

The demo uses PyDataViewModel but I guess that for the above I should
use PyDataViewVirtualListModel.

Yes, or PyDataViewIndexListModel would work too if you won't be displaying mega-many items. On the other hand, these model classes are derived from the base DataViewModel so if you're already using PyDataViewModel and it's working for you then there really isn't much need to change. In a list model all items are children of the hidden root node.

However I can't see/find how to use it, in particular:

- how to load the data and map the row index to e.g. a database primary
key? Should I use the DataViewListStore.AppendItem

DataViewListStore is the model used by DataViewListCtrl (the wx.ListCtrl act-alike) so I don't think you want to use that unless you are actually using DataViewListCtrl.

The row numbers of an item in the model never change[*] so you should be able to just use a Python dictionary to map from row numbers to keys, or even to the objects once they've been read from the DB.

[*] now that I think about it a bit I'm not sure that is true if items are deleted from the model...

- OnCacheHint equivalent of wx.ListCtrl and wx.LC_VIRTUAL

I don't see anything like that in the code, and I don't remember if there has been any discussion about it. You may want to make a feature request ticket for this.

In the meantime, you could probably just do something like reading and caching rows X-N to X+N when row X is requested and hasn't been read from the DB yet.

···

On 1/3/11 4:01 AM, werner wrote:

--
Robin Dunn
Software Craftsman

Robin,

Thanks for your tips.

Decided to first worry about getting a basic version working, i.e. just creating a list using wxDataViewCtrl and this works quit well with the exception that it hicks up on date column.

I get the following exception:
Traceback (most recent call last):
   File "C:\dev\aaTests\sqla\dbsampleWXDVC\dvcPanel.py", line 141, in IsContainer
     if not item:
   File "C:\Python26\lib\site-packages\wx-2.9.1-msw\wx\dataview.py", line 107, in __nonzero__
     def __nonzero__(self): return self.IsOk()
   File "C:\Python26\lib\site-packages\wx-2.9.1-msw\wx\dataview.py", line 105, in IsOk
     return _dataview.DataViewItem_IsOk(*args, **kwargs)
wx._core.PyAssertionError: C++ assertion "jdn > -2" failed at ..\..\src\common\datetime.cpp(1578) in wxDateTime::GetTm(): JDN out of range

Sample data:
2003-10-01 <type 'datetime.date'>

results into 11/07/1238273

So, searched for converting my datetime.date to wxDateTime and found the code in wx.calendar, but I get still the same exception with the same end result.

Changed the GetValue code to:
             val = getattr(node, self.colMap[col]['dbcol'])
             if isinstance(val, (datetime.datetime, datetime.date)):
                 date = _pydate2wxdate(val)
                 print date, type(date)
                 return date
             else:
                 return val

Sample data:
01/10/2003 00:00:00 <class 'wx._misc.DateTime'>

results into 11/07/1238273

What is a date column expecting, couldn't find any documentation defining what type of data each column type wants.

Werner

It should be a wx.DateTime, but it looks like I'll need to do some more work to get it working correctly.

···

On 1/4/11 9:18 AM, werner wrote:

What is a date column expecting, couldn't find any documentation
defining what type of data each column type wants.

--
Robin Dunn
Software Craftsman

Robin,

···

On 05/01/2011 06:35, Robin Dunn wrote:

On 1/4/11 9:18 AM, werner wrote:

What is a date column expecting, couldn't find any documentation
defining what type of data each column type wants.

It should be a wx.DateTime, but it looks like I'll need to do some more work to get it working correctly.

Sorry to put more onto your Todo list.

BTW, how will it display the date, i.e. where is it getting the formatting information from d-m-y, m/d/y etc?

Werner

Robin,

What is a date column expecting, couldn't find any documentation
defining what type of data each column type wants.

It should be a wx.DateTime, but it looks like I'll need to do some
more work to get it working correctly.

Sorry to put more onto your Todo list.

It turned out to be just a few lines of code and I fished it just after sending that message last night.

BTW, how will it display the date, i.e. where is it getting the
formatting information from d-m-y, m/d/y etc?

It uses wxDateTime::FormatDate(), which the docs say is the same as using "%x" for the format string, which will use the locale's preferred date representation.

···

On 1/5/11 12:05 AM, werner wrote:

On 05/01/2011 06:35, Robin Dunn wrote:

On 1/4/11 9:18 AM, werner wrote:

--
Robin Dunn
Software Craftsman