Dialog does not show contents after creation

Hello,

   I am finally at wits end trying to figure out why a dialog doesn't
display properly. I have a wxFrame app that otherwise runs fine in
that I can take input from menu items, but I cannot get a dialog box
to display properly. Here is the relevant code for the app
initialization:

class PyMapperApp(wx.App):

    def OnInit(self):
        self.res = xrc.XmlResource('gui2.xrc')
        self.init_frame()
        return True

    def init_frame(self):
        self.frame = self.res.LoadFrame(None, 'Frame_PyMapper')
        self.TestDialogDialog = self.res.LoadDialog(None,
'TestDialog')
        ....'do other stuff for the frame, binding and some variable
setup'
        self.frame.Show()
        self.frame.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
        PyMapperApp.ReadIniFile(self)
        self.frame.Raise()
        return

The test dialog is a simple dialog with two buttons. It was created
using XRCed version 0.2.0-5. The xml code follows:

<resource>
  <object class="wxDialog" name="TestDialog">
    <object class="wxBoxSizer">
      <orient>wxHORIZONTAL</orient>
      <object class="sizeritem">
        <object class="wxButton" name="Buton1">
          <label>Button One</label>
        </object>
      </object>
      <object class="sizeritem">
        <object class="wxButton" name="Button2">
          <label>Button Two</label>
        </object>
      </object>
    </object>
    <title>Test Dialog</title>
  </object>
</resource>

Note that I don't do any Bindings to the test dialog in the init_frame
() call. One of the menu items is bound to the following function to
get access to the dialog:

    def OnOptions (self, event):
      self.TestDialogDialog.ShowModal()

So, I run the app, select Options on the menu, and the dialog pops
up. However, all I have is what appears to be the frame, and no
buttons. The background of the 'frame' shows whatever was behind it.
It is like the frame is created but nothing is re-drawn over the
dialog. I am running Python 2.6 with wxWidgets 2.8.10 on WinXP SP3.
I have copied an example right out of the wxPython demo and got the
same results, so it's something I've done wrong somewhere. Any ideas
on what I should look to next?

Thanks!
Mike

Mike wrote:

So, I run the app, select Options on the menu, and the dialog pops
up. However, all I have is what appears to be the frame, and no
buttons. The background of the 'frame' shows whatever was behind it.
It is like the frame is created but nothing is re-drawn over the
dialog. I am running Python 2.6 with wxWidgets 2.8.10 on WinXP SP3.
I have copied an example right out of the wxPython demo and got the
same results, so it's something I've done wrong somewhere. Any ideas
on what I should look to next?

The dialog is probably hidden behind the frame. Try delaying its creation until you need it, and be sure to call its Destroy method when you are done with it. If that doesn't help then try duplicating the problem in a small standalone example.

···

--
Robin Dunn
Software Craftsman

Robin, thanks for the suggestions.

I went back through and removed the extraneous code from the program.
I think there is a problem with the way I'm handling Paint events. In
the init_frame function, I have the following line:

self.Bind(wx.EVT_PAINT, self.OnPaint)

This is done after the resources are loaded, but before .Show() is
called on the frame. I have the following function for the OnPaint:

    def OnPaint(self, evt):
      dc = wx.PaintDC(evt.GetEventObject())
      if (evt.GetEventObject() == self.MapPanel):
        PyMapperApp.DrawMapWindow(self) #draws graphics
to the Map panel
      elif (evt.GetEventObject() == self.TilePanel):
        if (globals.TilesLoaded):
          PyMapperApp.DrawTileWindow(self) #If loaded, draws tiles to
the Tile panel

I tried removing various line in this OnPaint function, but each time
when the dialog is to be displayed, it will pop up (in front of the
frame) but has nothing drawn on it. It is like the border of the
dialog is visible, but the buttons are hidden. Anyway, removing the
Bind statement corrects the problem, in that I can see the dialog
correctly, but without it, I can't get the panels in the frame to
update correctly.

···

On Jul 4, 3:09 pm, Robin Dunn <ro...@alldunn.com> wrote:

Mike wrote:
> So, I run the app, select Options on the menu, and the dialog pops
> up. However, all I have is what appears to be the frame, and no
> buttons. The background of the 'frame' shows whatever was behind it.
> It is like the frame is created but nothing is re-drawn over the
> dialog. I am running Python 2.6 with wxWidgets 2.8.10 on WinXP SP3.
> I have copied an example right out of the wxPython demo and got the
> same results, so it's something I've done wrong somewhere. Any ideas
> on what I should look to next?

The dialog is probably hidden behind the frame. Try delaying its
creation until you need it, and be sure to call its Destroy method when
you are done with it. If that doesn't help then try duplicating the
problem in a small standalone example.

--
Robin Dunn
Software Craftsmanhttp://wxPython.org

Mike wrote:

Robin, thanks for the suggestions.

I went back through and removed the extraneous code from the program.
I think there is a problem with the way I'm handling Paint events. In
the init_frame function, I have the following line:

self.Bind(wx.EVT_PAINT, self.OnPaint)

This is done after the resources are loaded, but before .Show() is
called on the frame. I have the following function for the OnPaint:

    def OnPaint(self, evt):
      dc = wx.PaintDC(evt.GetEventObject())
      if (evt.GetEventObject() == self.MapPanel):
        PyMapperApp.DrawMapWindow(self) #draws graphics
to the Map panel
      elif (evt.GetEventObject() == self.TilePanel):
        if (globals.TilesLoaded):
          PyMapperApp.DrawTileWindow(self) #If loaded, draws tiles to
the Tile panel

I tried removing various line in this OnPaint function, but each time
when the dialog is to be displayed, it will pop up (in front of the
frame) but has nothing drawn on it. It is like the border of the
dialog is visible, but the buttons are hidden. Anyway, removing the
Bind statement corrects the problem, in that I can see the dialog
correctly, but without it, I can't get the panels in the frame to
update correctly.

Please make a small standalone sample app that shows this problem. MakingSampleApps - wxPyWiki

···

--
Robin Dunn
Software Craftsman