Hi Alec,
Hello,
I have done some searching but as you can imagine the results are polluted with loads of tutorials.
the situation is this:
I derive from TreeListCtrl (in gizmos) and it binds to something not in wxWidgets to receive events.
When it is destroyed it must unbind, obviously.
Are you sure you have to unbind? In my code I just have unbind on some floatcanvas stuff where I need to bind/unbind depending the mode a user selects, otherwise wxPython does the 'right thing' for me.
"Something **NOT** in wxWidgets" - Yes I am sure I have to bind to it, and unbind when I am done.
I don't really want to use the python "__del__" method because... well destruction is something I want to be deterministic, this could be called after the thing it bound to is actually destroyed, or something...
I've tried binding to EVT_CLOSE in the class, I don't get an event when the parent frame is closed.
I've also overridden the "Close" and "Destroy" methods of TreeListCtrl, they are also not called when the frame is closed.
I think that should work, can you show some sample code showing the problem. MakingSampleApps - wxPyWiki
import wx
class MyApp(wxApp):
def __init__(self):
wxApp.__init__(self)
def OnInit(self):
frame = MyFrame()
frame.Show()
class MyFrame(wxFrame):
def __init__(self):
wxFrame.__init__(self,None,wxID_ANY,title="Whatever",size=(1000,500))
sizer = wxBoxSizer(wxVERTICAL)
self.SetSizer(sizer)
sizer.Add(MyThing(self))
class MyThing(wx.gizmos.TreeListCtrl):
def __init__(self,parent):
wx.gizmos.TreeListCtrl(self,parent,wxID_ANY)
EVT_CLOSE(self,self.onClose)
print "I would do that binding Alec is on about here"
def onClose(self,evt):
print "I'd like to unbind here (or something)"
I quite literally wrote this in my email client. To quote myself:
"I've tried binding to EVT_CLOSE in the class, I don't get an event when the parent frame is closed. "
I've also tried overriding Close and Destroy (then calling the base's Close and Destroy of course) with something like "print "Close caught"" or something - nothing.
Either this is a bug, or I am doing it wrong, where do I get a chance to do my destructor?
(I mainly use wxWidgets you see, I love wxPython though, largely because nothing changes, I just discovered that the dot was optional (example wx.Expand verses wxExpand ) by spotting it and there being a lack of errors, I am now even happier! I don't even have to force myself to use the dot! I am not sure how you achieved that (from "import wx"))
sorry don't get this
If you do 'import wx' then it would be 'wx.EXPAND'
Yet "wxEXPAND" works, and EVT_BUTTON, no wx needed, brilliant stuff! I only noticed because I saw sample code that had wx. This makes it even easier for us C++ lot to use wxPython easily.
···
On 10/07/14 08:56, Werner wrote:
On 7/10/2014 9:08, Alec Teal wrote:
Werner