Removing panels from a sizer/window

wxPyrts,

I am trying to build a dialog that dynamically adds and/or removes
panels to itself on request. Adds work fine, but when I remove a
panel, it doesn't away/get destroyed, and is still accessible in
the GUI. I don't know where the objects are still referenced and,
more importantly, how to get rid of them.

Enclosed is a sample application that behaves really funkily;

The dialog colors "removed" buttons in red (because I wanted
to be able to see the difference between "ok" and "deleted"
buttons.
To see the problem, run the enclosed program and:
1) Add a panel, and then remove the 2nd panel. This will cause
   the dialog to resize but leave the "deleted" panel partially
   visible with its button shown in red. (Cuz I told it to be red
   when "deleted.")

2) Similarly, if you instead delete the 1st panel, the dialog
   appears to display "correctly", with the remaining visible
   remove button greyed out; however, if you click on the disabled
   button, one "underneath" it gets activated, the button text
   goes red, and an IndexError results, because the panel asking
   to be deleted has already been removed from the parent's array
   of panels.

Can someone tell me what is going on here, and how do I fix
this program to "do what I want?"

Thanks in advance,
/Will Sadkin
Parlance Corporation

resizingDialog.py (5.22 KB)

Will Sadkin wrote:

wxPyrts,

I am trying to build a dialog that dynamically adds and/or removes
panels to itself on request. Adds work fine, but when I remove a
panel, it doesn't away/get destroyed, and is still accessible in the GUI. I don't know where the objects are still referenced and, more importantly, how to get rid of them.

Enclosed is a sample application that behaves really funkily;

The dialog colors "removed" buttons in red (because I wanted
to be able to see the difference between "ok" and "deleted"
buttons. To see the problem, run the enclosed program and:
1) Add a panel, and then remove the 2nd panel. This will cause the dialog to resize but leave the "deleted" panel partially visible with its button shown in red. (Cuz I told it to be red when "deleted.")

2) Similarly, if you instead delete the 1st panel, the dialog
   appears to display "correctly", with the remaining visible
   remove button greyed out; however, if you click on the disabled
   button, one "underneath" it gets activated, the button text
   goes red, and an IndexError results, because the panel asking
   to be deleted has already been removed from the parent's array
   of panels.

Can someone tell me what is going on here, and how do I fix this program to "do what I want?"

Removing a control from the sizer doesn't remove it from its parent window. You have to call panel.Hide() (if you just want to hide the panel, but possibly bring it back later) or panel.Destroy() after removing it from the sizer.

Also, I had some other problems getting seemed to be some other problems getting OnRemoveClause to work (which I solved by adding self = self and parent = parent to its argument list), but that may just be because I'm still using Python 1.5.2.

David

···

Thanks in advance,
/Will Sadkin
Parlance Corporation

------------------------------------------------------------------------

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org