TwoStageCreation Initialization

30 views
Skip to first unread message

Patrick Ruoff

unread,
May 25, 2012, 5:16:39 AM5/25/12
to wxpytho...@googlegroups.com
Hello,

I'm trying to add a custom listcontrol to an XRC dialog following the TwoStageCreation description in the wiki.
As suggested in the example, I am adding columns to my control in the wx.EVT_WINDOW_CREATE handler.
However, I don't understand at which point I can safely use the created widget, i.e. add items to the columns.
In the following example application where a dialog is loaded when the user presses a button


import wx
import wx.xrc as xrc
           
app = wx.App(False)
frame = wx.Frame(None)
xrc_res = xrc.XmlResource('test.xrc')

def OnButton(evt):
    dlg = xrc_res.LoadDialog(frame, 'MyDialog');
    print 'adding items'
    dlg.ShowModal();
   
button = wx.Button(frame)
button.Bind(wx.EVT_BUTTON, OnButton)
frame.Show()
app.MainLoop()


and the dialog resource contains a MyListControl of this form

import wx

class MyListCtrl(wx.ListCtrl):
    def __init__(self):
        pre = wx.PreListCtrl()
        self.PostCreate(pre)   
        self.Bind(wx.EVT_WINDOW_CREATE, self.OnCreate)

    def OnCreate(self, event):
        print 'creating columns'

I would like to add items to the list's columns at the point where 'adding items' is printed.
(I can't do it in OnCreate as it needs additional information)
However, this does not work, because the EVT_WINDOW_CREATE handler is called afterwards on Linux.
So where is the place to safely add items after OnCreate?

thanks in advance...
Patrick

Robin Dunn

unread,
May 28, 2012, 4:20:25 PM5/28/12
to wxpytho...@googlegroups.com
On 5/25/12 2:16 AM, Patrick Ruoff wrote:
> Hello,
>
> I'm trying to add a custom listcontrol to an XRC dialog following the
> TwoStageCreation <http://wiki.wxpython.org/TwoStageCreation> description
You could have your OnCreate handler call a method on the parent or
something that does it, or perhaps just a standalone function that you
pass the listctrl to. I think it would probably work in a
EVT_INIT_DIALOG event handler too, although you'll want to double-check
that it happens after the EVT_CREATE_WINDOW event.

--
Robin Dunn
Software Craftsman
http://wxPython.org

Reply all
Reply to author
Forward
0 new messages