]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/tests/test_evtHandler.py
   5 # This class is just an experiment to see how easy it would be to 
   6 # handle simulating transfer of ownership of object to a 'parent' 
   7 # object, and then automatically calling Destroy on those when the 
   8 # parent is destroyed.  Conclusion: It's not too hard at all. Now, 
   9 # what should I do with it... 
  10 class DestroyWrapper(object): 
  13         self
.items 
= weakref
.WeakValueDictionary() 
  15     def AddItem(self
, obj
): 
  16         self
.items
[len(self
.items
)+1] = obj
 
  19         for item 
in self
.items
.values(): 
  26 class MyEvtHandler(wx
.EvtHandler
): 
  30         wx
.EvtHandler
.__init
__(self
) 
  31         MyEvtHandler
.instCount 
+= 1 
  32         self
.cnt 
= MyEvtHandler
.instCount
 
  33         self
.Bind(wx
.EVT_CHECKBOX
, self
.OnCheckBox
) 
  36         print "%02d: deleted" % self
.cnt
 
  38     def OnCheckBox(self
, evt
): 
  39         print "%02d: %s" % (self
.cnt
, evt
.IsChecked()) 
  44 class MyFrame(wx
.Frame
): 
  46         wx
.Frame
.__init
__(self
, None, title
="wx.EvtHandler Test") 
  49         pushBtn 
= wx
.Button(p
, -1, "Push EvtHandler", (20,20)) 
  50         popBtn  
= wx
.Button(p
, -1, "Pop EvtHandler", (20,60)) 
  52         checkBox 
= wx
.CheckBox(p
, -1, "Test EvtHandler", (200, 25)) 
  54         self
.Bind(wx
.EVT_BUTTON
, self
.OnPushBtn
, pushBtn
) 
  55         self
.Bind(wx
.EVT_BUTTON
, self
.OnPopBtn
, popBtn
) 
  57 ##        self.dw = DestroyWrapper() 
  60     def OnPushBtn(self
, evt
): 
  62         self
.PushEventHandler(eh
) 
  63 ##        self.dw.AddItem(eh) 
  64         print "%02d: pushed" % eh
.cnt
 
  67     def OnPopBtn(self
, evt
): 
  68         eh 
= self
.GetEventHandler() 
  69         if eh
.this 
== self
.this
: 
  70             print "All already popped!" 
  72             eh 
= self
.PopEventHandler() 
  73             print "%02d: popped( %s )" % (eh
.cnt
, eh
.__class
__)