KeyEvent/ListCtrl Demo question

Tried this code but it gives an error message:

-- coding: cp1252 --

import wx
import liste2

class Kasse(wx.Frame):
def init(self):
wx.Frame.init(self, None, -1, “Kassensoftware”,
size=(1280, 800))
p = wx.Panel(self)
self.liste = liste2.VirtualListCtrl§
self.liste.SetColumnWidth(1, 100)
self.liste.SetColumnWidth(2, 140)
self.liste.SetColumnWidth(3, 150)
self.liste.SetColumnWidth(5, 100)
self.liste.SetColumnWidth(7, 100)

    self.entry11 = wx.TextCtrl(p, -1, size=(250, 40),
    style=wx.TE_NOHIDESEL|wx.TE_PROCESS_ENTER)
···

#------------------------------------------------------------------------------------------------------------------------------------
# Sizer
mainSizer = wx.BoxSizer(wx.VERTICAL)
sizer = wx.GridBagSizer(hgap=5, vgap=5)
sizer.Add(self.entry11, pos=(0, 0))
sizer.Add(self.liste, pos=(1, 0),span=(1, 3), flag=wx.GROW|wx.ALL)
# Main Sizer Add
mainSizer.Add(sizer, 0, wx.EXPAND|wx.ALL, 10)
p.SetSizer(mainSizer)
mainSizer.Fit§
mainSizer.SetSizeHints§
#------------------------------------------------------------------------------------------------------------------------------------
#Binding
self.Bind(wx.EVT_TEXT_ENTER, self.add_article, self.entry11)
#------------------------------------------------------------------------------------------------------------------------------------
def add_article(self, evt):
data = [1, 2, 3]
print data
id = self.liste.InsertStringItem(self.liste.GetItemCount(), ‘’)
self.liste.SetStringItem(id, 1, data[0])
self.liste.SetStringItem(id, 2, data[1])
self.liste.SetStringItem(id, 3, data[2])

if name == “main”:
app = wx.PySimpleApp()
frame = Kasse()
frame.Show()
app.MainLoop()

import wx
import sys, glob, random
columns = [“Position”, “Kunde”, “Artikelnummer”, “Artikelbezeichnung”, “Preis”, “Menge”, “MWST”,
“MWSTSUM”, “Rabatt”, “Summe”]

class VirtualListCtrl(wx.ListCtrl
#, listmix.TextEditMixin
):
“”"
A generic virtual listctrl that fetches data from a DataSource.
“”"
def init(self, parent):
wx.ListCtrl.init(self, parent,size=(1000, 200),
style=wx.LC_REPORT|wx.LC_SINGLE_SEL|wx.LC_HRULES|wx.LC_VRULES|wx.LC_VIRTUAL)
for col, text in enumerate(columns):
self.InsertColumn(col, text)

Error:

Traceback (most recent call last):
File “F:\Python_aktuelle Projekte\Kassensoftware\Code\post.py”, line 38, in add_article
id = self.liste.InsertStringItem(self.liste.GetItemCount(), ‘’)
File “C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx_controls.py”, line 4716, in InsertStringItem
return controls.ListCtrl_InsertStringItem(*args, **kwargs)
wx._core.PyAssertionError: C++ assertion “!IsVirtual()” failed at …\src\msw\listctrl.cpp(1548) in wxListCtrl::InsertItem(): can’t be used with virtual controls
What I do wrong? Thanks in advance!

Stefanie

Stefanie Lück wrote:

*Tried this code but it gives an error message:*
# -*- coding: cp1252 -*-
import wx
import liste2
class Kasse(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, -1, "Kassensoftware",
                          size=(1280, 800))
        p = wx.Panel(self)
        self.liste = liste2.VirtualListCtrl(p)
        self.liste.SetColumnWidth(1, 100)
        self.liste.SetColumnWidth(2, 140)
        self.liste.SetColumnWidth(3, 150)
        self.liste.SetColumnWidth(5, 100)
        self.liste.SetColumnWidth(7, 100)
               self.entry11 = wx.TextCtrl(p, -1, size=(250, 40),
        style=wx.TE_NOHIDESEL|wx.TE_PROCESS_ENTER)
#------------------------------------------------------------------------------------------------------------------------------------
        # Sizer
        mainSizer = wx.BoxSizer(wx.VERTICAL)
        sizer = wx.GridBagSizer(hgap=5, vgap=5)
        sizer.Add(self.entry11, pos=(0, 0))
        sizer.Add(self.liste, pos=(1, 0),span=(1, 3), flag=wx.GROW|wx.ALL)
        # Main Sizer Add
        mainSizer.Add(sizer, 0, wx.EXPAND|wx.ALL, 10)
        p.SetSizer(mainSizer)
        mainSizer.Fit(p)
        mainSizer.SetSizeHints(p)
#------------------------------------------------------------------------------------------------------------------------------------

        #Binding
        self.Bind(wx.EVT_TEXT_ENTER, self.add_article, self.entry11)
#------------------------------------------------------------------------------------------------------------------------------------
    def add_article(self, evt):
        data = [1, 2, 3]
        print data
        id = self.liste.InsertStringItem(self.liste.GetItemCount(), '')
        self.liste.SetStringItem(id, 1, data[0])
        self.liste.SetStringItem(id, 2, data[1])
        self.liste.SetStringItem(id, 3, data[2])
     if __name__ == "__main__":
    app = wx.PySimpleApp()
    frame = Kasse()
    frame.Show()
    app.MainLoop()
import wx
import sys, glob, random
columns = ["Position", "Kunde", "Artikelnummer", "Artikelbezeichnung", "Preis", "Menge", "MWST",
           "MWSTSUM", "Rabatt", "Summe"]
   class VirtualListCtrl(wx.ListCtrl
                      #, listmix.TextEditMixin
                      ):
    """
    A generic virtual listctrl that fetches data from a DataSource.
    """
    def __init__(self, parent):
        wx.ListCtrl.__init__(self, parent,size=(1000, 200),
            style=wx.LC_REPORT|wx.LC_SINGLE_SEL|wx.LC_HRULES|wx.LC_VRULES|wx.LC_VIRTUAL)
        for col, text in enumerate(columns):
            self.InsertColumn(col, text)
*Error:*
Traceback (most recent call last):
File "F:\Python_aktuelle Projekte\Kassensoftware\Code\post.py", line 38, in add_article
id = self.liste.InsertStringItem(self.liste.GetItemCount(), '')
File "C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx\_controls.py", line 4716, in InsertStringItem
return _controls_.ListCtrl_InsertStringItem(*args, **kwargs)
wx._core.PyAssertionError: C++ assertion "!IsVirtual()" failed at ..\..\src\msw\listctrl.cpp(1548) in wxListCtrl::InsertItem(): can't be used with virtual controls

*What I do wrong? Thanks in advance!*
** *Stefanie*

I've never used the virtual version of the listctrl, but it seems that it doesn't use the InsertItem() or InsertStringItem() methods. The code in the demo doesn't seem to show how they got the data in there...at least, it's not obvious to me. The book doesn't really help either. There is this recipe though:

http://code.activestate.com/recipes/426407/

It seems to indicate that you can use an Add() method to add rows to the control. The docs have this to say:

<quote>
To use virtual list control you must use SetItemCount <http://manuales.gfc.edu.co/wxWindows/wxwin234.html#wxlistctrlsetitemcount&gt; first and overload at least OnGetItemText <http://manuales.gfc.edu.co/wxWindows/wxwin234.html#wxlistctrlongetitemtext&gt; (and optionally OnGetItemImage <http://manuales.gfc.edu.co/wxWindows/wxwin234.html#wxlistctrlongetitemimage&gt; and OnGetItemAttr <http://manuales.gfc.edu.co/wxWindows/wxwin234.html#wxlistctrlongetitemattr&gt;\) to return the information about the items when the control requests it. Virtual list control can be used as a normal one except that no operations which can take time proportional to the number of items in the control happen -- this is required to allow having a practically infinite number of items. For example, in a multiple selection virtual list control, the selections won't be sent when many items are selected at once because this could mean iterating over all the items.
</quote>

http://manuales.gfc.edu.co/wxWindows/wxwin234.html

Hopefully someone else know more...

Mike

Mike Driscoll wrote:

I've never used the virtual version of the listctrl, but it seems that it doesn't use the InsertItem() or InsertStringItem() methods. The code in the demo doesn't seem to show how they got the data in there...at least, it's not obvious to me.

With a virtual list ctrl you *don't* put the data in it. Instead the ctrl asks you for the data as it needs it for displaying. (A similar concept is how wxGrid works when you use a custom GridTable.) You implement this in the list ctrl by overriding OnGetItemText. You can also provide the image index and the row attributes on demand by overriding other methods.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

If you’ve never used a ListCtrl before, you can save yourself a lot of
trouble by using an ObjectListView,
http://objectlistview.sourceforge.net/python

···

------------------------------------------------------------------------
Phillip Piper www.bigfoot.com/~phillip_piper phillip_piper@bigfoot.com
A man's life does not consist in the abundance of his possessions

From: wxpython-users-bounces@lists.wxwidgets.org
[mailto:wxpython-users-bounces@lists.wxwidgets.org] On Behalf Of Stefanie
Lück
Sent: Friday, 8 August 2008 12:21 PM
To: wxpython-users@lists.wxwidgets.org
Subject: [wxpython-users] Re: KeyEvent/ListCtrl Demo question

Tried this code but it gives an error message:

# -*- coding: cp1252 -*-

import wx
import liste2

class Kasse(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, "Kassensoftware",
size=(1280, 800))
p = wx.Panel(self)
self.liste = liste2.VirtualListCtrl(p)
self.liste.SetColumnWidth(1, 100)
self.liste.SetColumnWidth(2, 140)
self.liste.SetColumnWidth(3, 150)
self.liste.SetColumnWidth(5, 100)
self.liste.SetColumnWidth(7, 100)

    self\.entry11 = wx\.TextCtrl\(p, \-1, size=\(250, 40\),
    style=wx\.TE\_NOHIDESEL|wx\.TE\_PROCESS\_ENTER\)

#---------------------------------------------------------------------------
---------------------------------------------------------
# Sizer
mainSizer = wx.BoxSizer(wx.VERTICAL)
sizer = wx.GridBagSizer(hgap=5, vgap=5)
sizer.Add(self.entry11, pos=(0, 0))
sizer.Add(self.liste, pos=(1, 0),span=(1, 3), flag=wx.GROW|wx.ALL)
# Main Sizer Add
mainSizer.Add(sizer, 0, wx.EXPAND|wx.ALL, 10)
p.SetSizer(mainSizer)
mainSizer.Fit(p)
mainSizer.SetSizeHints(p)
#---------------------------------------------------------------------------
---------------------------------------------------------
#Binding
self.Bind(wx.EVT_TEXT_ENTER, self.add_article, self.entry11)
#---------------------------------------------------------------------------
---------------------------------------------------------
def add_article(self, evt):
data = [1, 2, 3]
print data
id = self.liste.InsertStringItem(self.liste.GetItemCount(), '')
self.liste.SetStringItem(id, 1, data[0])
self.liste.SetStringItem(id, 2, data[1])
self.liste.SetStringItem(id, 3, data[2])

if __name__ == "__main__":
app = wx.PySimpleApp()
frame = Kasse()
frame.Show()
app.MainLoop()

import wx
import sys, glob, random
columns = ["Position", "Kunde", "Artikelnummer", "Artikelbezeichnung",
"Preis", "Menge", "MWST",
"MWSTSUM", "Rabatt", "Summe"]

class VirtualListCtrl(wx.ListCtrl
#, listmix.TextEditMixin
):
"""
A generic virtual listctrl that fetches data from a DataSource.
"""
def __init__(self, parent):
wx.ListCtrl.__init__(self, parent,size=(1000, 200),

style=wx.LC_REPORT|wx.LC_SINGLE_SEL|wx.LC_HRULES|wx.LC_VRULES|wx.LC_VIRTUAL)
for col, text in enumerate(columns):
self.InsertColumn(col, text)

Error:

Traceback (most recent call last):
File "F:\Python_aktuelle Projekte\Kassensoftware\Code\post.py", line 38, in
add_article
id = self.liste.InsertStringItem(self.liste.GetItemCount(), '')
File "C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx\_controls.py",
line 4716, in InsertStringItem
return _controls_.ListCtrl_InsertStringItem(*args, **kwargs)
wx._core.PyAssertionError: C++ assertion "!IsVirtual()" failed at
..\..\src\msw\listctrl.cpp(1548) in wxListCtrl::InsertItem(): can't be used
with virtual controls

What I do wrong? Thanks in advance!

Stefanie