OnInitDialog event

I have a quick question about hooking the event wx.EVT_INIT_DIALOG.
The online docs seem to mention that this event can be hooked by a
wxPanel. So I tried that with the following bind statement but to no
avail. My problem is that I am trying to initialize the panel with
data & need to resize some ctrls on it & ask for a ctrls width, but it
comes back as zero since the panel isn't shown yet. What's the best
way to know when the panel is shown?

class MyPanel(wx.Panel):
    def __init__(self):
        self.Bind(wx.EVT_INIT_DIALOG, self.OnInitDialog)

    def OnInitDialog(self, event):
        print 'hello world'

Thanks for any help in advance.
Steve

Stephen Burke wrote:

I have a quick question about hooking the event wx.EVT_INIT_DIALOG.
The online docs seem to mention that this event can be hooked by a
wxPanel. So I tried that with the following bind statement but to no
avail. My problem is that I am trying to initialize the panel with
data & need to resize some ctrls on it & ask for a ctrls width, but it
comes back as zero since the panel isn't shown yet. What's the best
way to know when the panel is shown?

class MyPanel(wx.Panel):
    def __init__(self):
        self.Bind(wx.EVT_INIT_DIALOG, self.OnInitDialog)

    def OnInitDialog(self, event):
        print 'hello world'

Thanks for any help in advance.
Steve
_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users
  
You probably want 2-stage creation of the panel. I tried to do it just now, but I couldn't quite get it. Here's some links though:

http://wiki.wxpython.org/TwoStageCreation
http://www.nabble.com/wx.EVT_WINDOW_CREATE-on-windows-vs-mac-td20818861.html

Hope that helps!

···

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org
Python Extension Building Network: http://www.pythonlibrary.org

Thanks. I’ll take a look at the 2-phase construction and post something once I’m done.

Steve

···

On Mon, Dec 29, 2008 at 10:04 AM, Mike Driscoll mike@pythonlibrary.org wrote:

Stephen Burke wrote:

I have a quick question about hooking the event wx.EVT_INIT_DIALOG.

The online docs seem to mention that this event can be hooked by a

wxPanel. So I tried that with the following bind statement but to no

avail. My problem is that I am trying to initialize the panel with

data & need to resize some ctrls on it & ask for a ctrls width, but it

comes back as zero since the panel isn’t shown yet. What’s the best

way to know when the panel is shown?

class MyPanel(wx.Panel):

def __init__(self):

    self.Bind(wx.EVT_INIT_DIALOG, self.OnInitDialog)



def OnInitDialog(self, event):

    print 'hello world'

Thanks for any help in advance.

Steve


wxpython-users mailing list

wxpython-users@lists.wxwidgets.org

http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

You probably want 2-stage creation of the panel. I tried to do it just now, but I couldn’t quite get it. Here’s some links though:

http://wiki.wxpython.org/TwoStageCreation

http://www.nabble.com/wx.EVT_WINDOW_CREATE-on-windows-vs-mac-td20818861.html

Hope that helps!


Mike Driscoll

Blog: http://blog.pythonlibrary.org

Python Extension Building Network: http://www.pythonlibrary.org


wxpython-users mailing list

wxpython-users@lists.wxwidgets.org

http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

Stephen Burke wrote:

I have a quick question about hooking the event wx.EVT_INIT_DIALOG.
The online docs seem to mention that this event can be hooked by a
wxPanel. So I tried that with the following bind statement but to no
avail. My problem is that I am trying to initialize the panel with
data & need to resize some ctrls on it & ask for a ctrls width, but it
comes back as zero since the panel isn't shown yet. What's the best
way to know when the panel is shown?

class MyPanel(wx.Panel):
    def __init__(self):
        self.Bind(wx.EVT_INIT_DIALOG, self.OnInitDialog)

    def OnInitDialog(self, event):
        print 'hello world'

IIRC the EVT_INIT_DIALOG event is only sent automatically to dialogs. To use it on a panel you need to call the InitDialog method yourself, which in this case really doesn't buy you anything since you can just as easily call some method that does what you are trying to do in the event handler instead.

What are you really needing? A panel is shown by default when it is created, but its parent top level window may not be shown yet, so catching the panel's EVT_SHOW won't help. You mention sizes, do you just want to know when the size changes? EVT_SIZE will help you do that, but if you use a sizer then be careful to not block the default size handler from doing the sizer layout. If you just need to do something once after the panel has been created and after the current pending events (like showing and sizing the window) have been completed then use wx.CallAfter to invoke your function at the next idle event.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

What I am trying to do is size the columns of a list control, which
happens to be in a panel based on the width of the panel. If I
perform the calculations before the panel is shown I get a width size
of zero. What's the correct handler to use to size the columns of a
list control.

Thanks.
Steve

···

On Wed, Dec 31, 2008 at 2:41 AM, Robin Dunn <robin@alldunn.com> wrote:

Stephen Burke wrote:

I have a quick question about hooking the event wx.EVT_INIT_DIALOG.
The online docs seem to mention that this event can be hooked by a
wxPanel. So I tried that with the following bind statement but to no
avail. My problem is that I am trying to initialize the panel with
data & need to resize some ctrls on it & ask for a ctrls width, but it
comes back as zero since the panel isn't shown yet. What's the best
way to know when the panel is shown?

class MyPanel(wx.Panel):
   def __init__(self):
       self.Bind(wx.EVT_INIT_DIALOG, self.OnInitDialog)

   def OnInitDialog(self, event):
       print 'hello world'

IIRC the EVT_INIT_DIALOG event is only sent automatically to dialogs. To use it on a panel you need to call the InitDialog method yourself, which in this case really doesn't buy you anything since you can just as easily call some method that does what you are trying to do in the event handler instead.

What are you really needing? A panel is shown by default when it is created, but its parent top level window may not be shown yet, so catching the panel's EVT_SHOW won't help. You mention sizes, do you just want to know when the size changes? EVT_SIZE will help you do that, but if you use a sizer then be careful to not block the default size handler from doing the sizer layout. If you just need to do something once after the panel has been created and after the current pending events (like showing and sizing the window) have been completed then use wx.CallAfter to invoke your function at the next idle event.

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

Stephen Burke wrote:

What I am trying to do is size the columns of a list control, which
happens to be in a panel based on the width of the panel. If I
perform the calculations before the panel is shown I get a width size
of zero. What's the correct handler to use to size the columns of a
list control.

Probably EVT_SIZE. See the wx.lib.mixins.listctrl.ListCtrlAutoWidthMixin class for an example, or you may be able to use it directly.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!