views:

141

answers:

1

It seems that this is specific to windows, here is an example that reproduces the effect:

import wx


def makegrid(window):
    grid = wx.GridSizer(24, 10, 1, 1)
    window.SetSizer(grid)
    for i in xrange(240):
        cell = wx.Panel(window)
        cell.SetBackgroundColour(wx.Color(i, i, i))
        grid.Add(cell, flag=wx.EXPAND)


class TestFrame(wx.Frame):
    def __init__(self, parent):
        wx.Frame.__init__(self, parent)
        makegrid(self)


class TestDialog(wx.Dialog):
    def __init__(self, parent):
        wx.Dialog.__init__(self, parent)
        makegrid(self)


class Test(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None)
        btn1 = wx.Button(self, label="Show Frame")
        btn2 = wx.Button(self, label="Show Dialog")
        sizer = wx.BoxSizer(wx.VERTICAL)
        self.SetSizer(sizer)
        sizer.Add(btn1, flag=wx.EXPAND)
        sizer.Add(btn2, flag=wx.EXPAND)
        btn1.Bind(wx.EVT_BUTTON, self.OnShowFrame)
        btn2.Bind(wx.EVT_BUTTON, self.OnShowDialog)

    def OnShowFrame(self, event):
        TestFrame(self).Show()

    def OnShowDialog(self, event):
        TestDialog(self).ShowModal()


app = wx.PySimpleApp()
app.TopWindow = Test()
app.TopWindow.Show()
app.MainLoop()

I have tried this on the following configurations:

  • Windows 7 with Python 2.5.4 and wxPython 2.8.10.1
  • Windows XP with Python 2.5.2 and wxPython 2.8.7.1
  • Windows XP with Python 2.6.0 and wxPython 2.8.9.1
  • Ubuntu 9.04 with Python 2.6.2 and wxPython 2.8.9.1

The wxDialog wasn't slow only on Ubuntu.

+2  A: 

I got a reply on the wxPython-users mailing list, the problem can be fixed by calling Layout explicitly before the dialog is shown.

This is really weird...

My guess is that this is due to Windows and wxWidgets not dealing very well with overlapping siblings, and so when the sizer is doing the initial layout and moving all the panels from (0,0) to where they need to be that something about the dialog is causing all of them to be refreshed and repainted at each move. If you instead do the initial layout before the dialog is shown then it is just as fast as the frame.

You can do this by adding a call to window.Layout() at the end of makegrid.

-- Robin Dunn

Toni Ruža