wx with huge number of panels/components in a grid sizer

Hello,

So I have the following problem. I have a N x N connectivity matrix
which I want to display in a 2d matrix. Now for each i and j, a color
from a min-max range will show how strong those two nodes are connected
and the user should have to possibility to click on a box to see
details, edit values etc. The average N for my problem will be around
72-90.

Now my first attempt was to create a GridSizer of N x N, in which I add
some ClickableBox(wx.Panel) that so far has only a simple
wx.EVT_LEFT_DOWN binded that changes it's color. Since the total matrix
will be quite big on screen, all of this is added to a
wx.lib.scrolledpanel.ScrolledPanel. Now the problem is that for a 70
matrix, when you try to scroll there is a huge lag. Also if I try to add
some more logic to this, like add a label to each ClickableBox to
display the actual value, everything freezez up.

Not too surprising since most applications have at most few dozen widgets active at once and you're trying to do around 10,000. Each of them will be processing their own paint and other events, and that adds up quick.

Now I'm guessing I'm going the wrong way around this. I could try to
actually draw the boxes instead of using panels

Yes, that would be the way to go.

for them but that would
come with a very hard interaction afterwards.

In what way?

Are there any performance
tips/ things to avoid that could harm performance in this case? Is there
any way to optimize the scrolling since that seems to be the main
bottleneck?

You can use the update region in the paint event to know what areas of the window need to be refreshed and only draw those portions. The ColourDB sample in the demo shows one way to do this. If the drawing of the boxes is complex and time consuming then you could maintain a bitmap with the contents already drawn and then painting (due to scrolling or other needs) becomes a simple matter of drawing the bitmap(s).

···

On 1/3/12 6:31 AM, Neacsa Bogdan Valentin wrote:

--
Robin Dunn
Software Craftsman