pythonobjectlistview-python

python + objectlistview + updatelist


I have an objectlistview. I remove a line from it and then I want to update the list without the removed line. I fill the list with data from a database. I tried repopulatelist, but then it seems to use the data that is already in the list.

I think I can solve it with clearAll (clearing the list) and then addobjects and add the database again. But it seems that it should be possible to just update the list. This is my code:

def deletemeas(self):

    MAid = self.objectma.id
    MAname = self.pagename

    objectsRemList = self.tempmeasurements.GetCheckedObjects()

    print 'objectremlist', objectsRemList
    for measurement in objectsRemList:
        print measurement
        Measname = measurement.filename
        Measid = database.Measurement.select(database.Measurement.q.filename == Measname)[0].id
        deleteMeas = []
        deleteMeas.append(MAid)
        deleteMeas.append(Measid)
        pub.sendMessage('DELETE_MEAS', Container(data=deleteMeas)) #to microanalyse controller
    #here I get the latest information from the database what should be viewed in the objectlist self.tempmeasurements
    MeasInListFromDB = list(database.Microanalysismeasurement.select(database.Microanalysismeasurement.q.microanalysisid == MAid))

    print 'lijstmetingen:', MeasInListFromDB
    #this doesn't work
    self.tempmeasurements.RefreshObjects(MeasInListFromDB) 

Solution

  • Ok, this was actually easier than I thought ...

    I added this line:

    self.tempmeasurements.RemoveObject(measurement)
    

    So I first removed the data from my database table and then I just removed the line in my objectlistview.