[wxPython-users] wx.lib.pubsub and wx.EVT_CLOSE

Eric Ongerth ericongerth at gmail.com
Sun Jun 3 22:58:59 PDT 2007


On 6/3/07, Josiah Carlson <jcarlson at uci.edu> wrote:
>
> I don't know where you could look for more solutions.  At least with the
> obj.method-style calls, you can use a variant of what I provided in my
> last message.  It should automatically remove method references when
> they come to a PyDeadObjectError, and otherwise work the same as it
> did before.


> if you run myFrame.do_something(), and you don't later do 'self.panel =3D
> something', then self.panel keeps a reference to the destroyed panel.
> Without seeing your code (where you create references, where you destroy
> references, etc.), it would be very difficult for us to help you with
> fixing such issues.
>

Thank you, Josiah.  I hope I did not imply that I needed a "better" or more
complete answer.  I was only digging for all the learning I can get.  I also
did not mean to request help on a specific problem that I haven't explained
or provided any code for.  Just looking for leads to further study.

Having said that, here's my current problem.  **My program** is not
referencing or calling destroyed panels or widgets, unless I'm mistake.
>From what I can gather so far, it's a class I imported that is doing so.

>From wxPyWiki, I borrowed the TextCtrlAutoComplete control.  I needed an
autocomplete text control without digging too far into wx.STC and Scintilla,
and found this control does a pretty good job.

The problem is, TextCtrlAutoComplete hooks itself in pretty good in its
.__init__ method:

gp =3D self
while ( gp !=3D None ) :
        gp.Bind ( wx.EVT_MOVE , self.onControlChanged, gp )
        gp.Bind ( wx.EVT_SIZE , self.onControlChanged, gp )
        gp =3D gp.GetParent()

self.Bind( wx.EVT_KILL_FOCUS, self.onControlChanged, self )

I never reference any instance TextCtrlAutoComplete or anything connected to
it after its containing frame are

Wow, catching EVT_MOVE and EVT_SIZE for *every* window above it in the
hierarchy.  And what does OnControlChanged do?  It simply hides the
control's dropdown portion and calls event.Skip().  It seems a bit
heavy-handed to have all that event-catching just to make sure the dropdown
portion folds up whenever user activity takes place outside the control.

This situation improves if I remove the while loop and its contents -- there
are then many less dangling references to the control lying around in the
hierarchy.  However, the way the control is currently written, it sort of
relies on those hooks; its dropdown (a wx.PopupWindow) doesn't follow when
the control's parent is moved or resized.

I'm going to try giving TextCtrlAutoComplete just use a similar while loop
to disconnect from all those EVT_MOVE and EVT_SIZE events when it closes.
However, according to the page linked below, an occasional EVT_FOCUS is
still liable to come through even after the OnClose handler executes, so
there are more steps I'll have to take to safely use this control.

Learning about this brought me to the following page, and a combination of
it and your (Josiah's) suggested approach to just-in-time unsubscribing have
been very useful indeed.

wxPyWiki: Surviving with wxEVT_KILL_FOCUS under Microsoft
Windows<http://wiki.wxpython.org/Surviving_with_wxEVT_KILL_FOCUS_under_Micr=
osoft_Windows>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.wxwidgets.org/pipermail/wxpython-users/attachments/200706=
03/420081c3/attachment.htm


More information about the wxpython-users mailing list