vendredi 3 novembre 2017

How to bind an event to the checkbox in the objectlistview in wxpython

I'm using objectlistview in wxpython and I am very happy with it until now. I cannot find a way to add an event to the checkbox in my objectlistview. At the moment I have a workaround, the user have to click on a button and then something happens with the checked row. But I would like to make it happen when the user checks the checkbox. It have to toggle a graph in my plot.

A second question I have is how I can uncheck the checkboxes after the user clicked the button (this is for if there isn't a way to solve my first question).

My code (I just copied the necessary lines, because my program is very big)

self.tempmeasurements = ObjectListView(self, wx.ID_ANY, style=wx.LC_REPORT | wx.SUNKEN_BORDER)
self.tempmeasurements.SetColumns(microanalysis_options.TempMeasColumndefs)
self.tempmeasurements.CreateCheckStateColumn(0)
self.addbutton = wx.Button(self, wx.ID_ANY, "Add to plot")
self.rembutton = wx.Button(self, wx.ID_ANY,'Remove from plot')

self.Bind(wx.EVT_BUTTON, self.on_toggle_plotlist, self.addbutton)
self.Bind(wx.EVT_BUTTON, self.on_remove_from_plot,self.rembutton)

def on_toggle_plotlist(self, event):
    objectsAddPlotList = self.tempmeasurements.GetCheckedObjects()
    pub.sendMessage('MA_ADD_TO_PLOT', Container(origin=self, data=objectsAddPlotList)) #to microanalyse controller
    self.tempmeasurements.SetCheckState(objectsAddPlotList,False)

def on_remove_from_plot(self,event):
    objectsAddPlotList = self.tempmeasurements.GetCheckedObjects()
    pub.sendMessage('MA_REM_FROM_PLOT', Container(origin=self, data=objectsAddPlotList))  # to microanalyse controller

The self.tempmeasurements.SetCheckState(objectsAddPlotList,False) line I tried to use to uncheck the checkboxes after the user clicked the button.

this is how the list looks like:

list with checkboxes




Aucun commentaire:

Enregistrer un commentaire