Question

EDIT: I debugged a little more to realize, that most of the time consumed by action is actually spent creating the widgets, not placing them into sizer. So the question is how to create them faster?

I need to dynamically change the contents of a dialog by adding circa 300 checkboxes. I use a wx.GridSizer and a loop that adds them, but it is really slow. Is there a way to do it faster? Some method that waits for all widgets to be added and then calculate the positions and sizes manually since I believe that by calling Add method of a Sizer calculates the sizes immediately. This is a shortcut of what I do:

... #Destroy all widgets we used to have

for el in self.elements:
    _chk = wx.CheckBox(self,-1,el["name"])
    _t1 = wx.StaticText(self,-1,el["age"])
    _t2 = wx.StaticText(self,-1,el["city"])
    self.checkboxes.append(_chk)
    self.gridSizer.Add(_chk)
    self.gridSizer.Add(_t1)
    self.gridSizer.Add(_t2)
self.SetSizer(self.gridSizer)
self.Layout()
self.Refresh()
self.Update()

It takes about a minute to add some 300 elements, I believe there must be a faster way since e.g. apps like QIP or ICQ displayed lots of contacts in a second :) Thanks for any clue!

Additionally excuse my english.

Ray

Was it helpful?

Solution

I cannot think of any interface that has 300 widgets on it all at once. I don't believe there is a good way to accomplish this. Instead, you should think about redesigning the interface so the user doesn't have to deal with checking 300 checkboxes (or deal with hundreds of any widget). The only widget that might be able to handle that many checkboxes at once would probably be the ListCtrl with the checkbox mixin. See the demo for an example.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top