vendredi 31 juillet 2015

check box issue using UltimateListCtrl in vitural mode to display data in wxPython

OK, Bear with me, I have a application in python , that display result, from Database query, when can return 100 rows, or 100000+, so I am using UltimateListCtrl as part of wxPython lib, I can get it to display Data, no issue, but one of the requirements, is to have on every row on the data for an certain Colum, a checkbox, so user can select or not but this is what I am having trouble with, I know you can add wxWidgets, to UltimateListCtrl rows , but not sure how to do it in Virtual mode , as I scroll around data Below is my code

any help, adive, examples, is welcome, as it been doing my head in for a few weeks.

import wx from wx.lib.agw import ultimatelistctrl as ULC

class clsVCList00(ULC.UltimateListCtrl):

def __init__(self, parent):
    #
    self.cols = ["Select","Index","Research Key","Results"]   
    self.hdr_index = 0
    #
    ULC.UltimateListCtrl.__init__(self, parent , -1, agwStyle=wx.LC_REPORT|wx.LC_VIRTUAL|wx.LC_VRULES)
    #
    for hdr in self.cols:
        res = self.InsertColumn(self.hdr_index, hdr, width=150)
        if hdr == "Select":
           chk = ULC.UltimateListItem()
           chk._mask = wx.LIST_MASK_TEXT | wx.LIST_MASK_IMAGE | wx.LIST_MASK_FORMAT | ULC.ULC_MASK_CHECK
           chk._image = []
           chk._format = wx.LIST_FORMAT_LEFT
           chk._text = "Select"
           chk._kind = 1      
           self.SetColumn(res,chk)
        self.hdr_index = self.hdr_index + 1 
    #
    #    
    self.attr1 = ULC.UltimateListItemAttr()
    self.attr1.SetBackgroundColour(wx.NamedColour("yellow"))
    self.attr2 = ULC.UltimateListItemAttr()
    self.attr2.SetBackgroundColour(wx.NamedColour("light blue"))
    self.SetItemCount(10000)


def OnGetItemAttr(self, item):
    if item % 3 == 1:
        return self.attr1
    elif item % 3 == 2:
        return self.attr2
    else:
        return None

def OnGetItemImage(self, item):
    return []

def OnGetItemText(self, item, col):
    return "Item %d, column %d" % (item, col)

def OnGetItemToolTip(self, item, col):
    if item == 0:
        return "Tooltip: Item %d, column %d" % (item, col)
    return None

def OnGetItemTextColour(self, item, col):
    if item == 0 and col == 0:
        return wx.Colour(255,0,0)
    elif item == 0 and col == 1:
        return wx.Colour(0,255,0)
    elif item == 0 and col == 2:
        return wx.Colour(0,0,255)
    else:
        return None




Aucun commentaire:

Enregistrer un commentaire