ListCtrl InsertItem() Problem

Plattformunabhängige GUIs mit wxWidgets.
ete
User
Beiträge: 218
Registriert: Montag 19. Februar 2007, 13:19
Kontaktdaten:

ListCtrl InsertItem() Problem

Beitragvon ete » Freitag 8. August 2008, 11:05

Hallo!

Folgender Code:

Code: Alles auswählen

# -*- 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()


Code: Alles auswählen

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)


Gibt diese Fehlermeldung:
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

Ich möchte nach einem Enter-Event eine neue Zeile und die Daten in das ListCtrl einfügen. Was mach ich falsch?

Lg
Stefanie
Hillkorn
User
Beiträge: 12
Registriert: Samstag 19. Januar 2008, 19:31
Kontaktdaten:

Beitragvon Hillkorn » Sonntag 10. August 2008, 10:04

Hattest du es schonmal mit add oder append in der list versucht?
ete
User
Beiträge: 218
Registriert: Montag 19. Februar 2007, 13:19
Kontaktdaten:

Beitragvon ete » Montag 11. August 2008, 09:30

Ich habs hinbekommen:

Code: Alles auswählen

import wx
import sys, glob, random
import  wx.lib.mixins.listctrl  as  listmix
columns = ["Position", "Kunde", "Artikelnummer", "Artikelbezeichnung", "Preis", "Menge", "MWST",
           "MWSTSUM", "Rabatt", "Summe"]
               
class KeyLog(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin):
    colHeaders = ["Position", "Kunde", "Artikelnummer", "EAN", "Artikelbezeichnung", "Gruppe", "Preis", "Menge", "MWST",
           "MWSTSUM", "Rabatt", "Summe"]

    def __init__(self, parent):
        wx.ListCtrl.__init__(self, parent, -1, size=(1000, 200),
                            style = wx.LC_REPORT|wx.LC_VRULES|wx.LC_HRULES)
        listmix.ListCtrlAutoWidthMixin.__init__(self)

        for idx, header in enumerate(self.colHeaders):
            self.InsertColumn(idx, header)
        idx += 1
        self.InsertColumn(idx, "")


Liebe Grüsse
Stefanie

Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder