From: Kevin A. <al...@se...> - 2001-10-23 17:08:11
|
I'm evaluating how to do things in wxPython that we're doing today in PythonCard user code. I thought I would post the tests to the list as I do them in case anyone else has comments or suggestions. If you aren't familiar with wxPython, then most of this message isn't going to make much sense. The example below is done with the minimal sample as the starting point, so you can open minimal with a shell and try it yourself. What I wanted to do was bind a method to a wxButton control, so that when you click the button, it puts some text into the wxTextCtrl named field1 at the same level in the hierarchy (both controls sit on a wxPanel). In PythonCard: def on_btn1_mouseClick(self, target, event): self.components.field1.text = 'click btn1' The name of the mouseClick method below is just a name, it doesn't have to be 'mouseClick' though that is descriptive. The next question is probably where would the handler be defined in user code? Also, to be safe, rather than using 'self', event.GetEventObject() would probably have to be used instead to get the wxButton instance. >>> bg = pcapp.getCurrentBackground() >>> comp = bg.components >>> from wxPython.wx import * >>> b = wxButton(bg.panel, -1, 'btn1', (0, 30), name='btn1') >>> b.GetParent() <C wxPanel instance at _1516878_wxPanel_p> >>> p = b.GetParent() >>> p.FindWindowByName('field1') <C wxTextCtrl instance at _7e2858_wxTextCtrl_p> >>> b.GetParent().FindWindowByName('field1') <C wxTextCtrl instance at _7e2858_wxTextCtrl_p> >>> b.GetParent().FindWindowByName('field1').SetValue('hello btn1') >>> def mouseClick(self, event): ... self.GetParent().FindWindowByName('field1').SetValue('click btn1') ... >>> import new >>> m = new.instancemethod(mouseClick, b, wxButton) >>> m <method wxButton.mouseClick of wxButton instance at 0154706C> >>> EVT_BUTTON(b, b.GetId(), m) ka |