Hello all,
I'm new with wxpython.
While testing events and derived controls i found this problem:
First, I derive a class from wx.TextCtrl and bind setfocus event:
class miTextCtrl_1(wx.TextCtrl):
def __init_(self, ..... )
wx.TextCtrl.__init__(self, .......)
self.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus) # bind the event
def OnSetFocus(self, event):
print "SetFocus on class: miTextCtrl_1"
event.Skip() # continue propagation
I test it and works OK.
Next I derive a new class from this, and bind on it the same event:
class miTextCtrl_2(miTextCtrl_1):
def __init__(self, ...... )
miTextCtrl_1.__init__(self, ...... )
self.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus) # bind the event
def OnSetFocus(self, event):
print "SetFocus on class: miTextCtrl_2"
event.Skip() # continue propagation
When test this class then event SetFocus run TWICE on class miTextCtrl_2 and no one in class miTextCtrl_1, instead of run fist in class miTextCtrl_2 and later in class miTextCtrl_1.
If i name diferent the event functions run OK.
Is normal this behavior?
Am I doing anything wrong?
Thanks (disculp my bad english)
···
--
*****************************************
Oswaldo Hernández
oswaldo@soft-com.es
*****************************************
Hello Oswaldo:
Your definition of the method OnSetFocus() in the class miTextCtrl_2
overrides the one in miTextCtrl_1. This is a fundamental part of object
oriented programming. If you want both methods to be used, they must
have different names.
···
On 8/29/05, Oswaldo Hernández <listas@soft-com.es> wrote:
Hello all,
I'm new with wxpython.
While testing events and derived controls i found this problem:
First, I derive a class from wx.TextCtrl and bind setfocus event:
class miTextCtrl_1(wx.TextCtrl):
def __init_(self, ..... )
wx.TextCtrl.__init__(self, .......)
self.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus) # bind the event
def OnSetFocus(self, event):
print "SetFocus on class: miTextCtrl_1"
event.Skip() # continue propagation
I test it and works OK.
Next I derive a new class from this, and bind on it the same event:
class miTextCtrl_2(miTextCtrl_1):
def __init__(self, ...... )
miTextCtrl_1.__init__(self, ...... )
self.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus) # bind the event
def OnSetFocus(self, event):
print "SetFocus on class: miTextCtrl_2"
event.Skip() # continue propagation
When test this class then event SetFocus run TWICE on class miTextCtrl_2
and no one in class miTextCtrl_1, instead of run fist in class
miTextCtrl_2 and later in class miTextCtrl_1.
If i name diferent the event functions run OK.
Is normal this behavior?
Am I doing anything wrong?
Thanks (disculp my bad english)
--
*****************************************
Oswaldo Hernández
oswaldo@soft-com.es
*****************************************
---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org
Learning is good!
You're explicitly calling initialization of in class mi1 in mi2.__init__
You could explicitly call OnSetFocus in the same fashion, from mi2's OnSetfocus ie. miTextCtrl_1.OnSetFocus(self, event) which would avoid the overriding effect achieved by using the same method name.
Since you're binding in in mi1, you don't need to bind again in mi2.
I don't know the reprocussion of calling event.Skip() twice tho.
As you've found by binding the same event twice, it gets called twice. Althought not in the scope anticipated.
There is power hidden in OO programing due to these features, it can be a little difficult to grasp at first. If you get too carried away with them, they can complicate your logic, or simplify it, depending on it's implementation.
Good luck and keep learning!
Oswaldo Hernández wrote:
···
Hello all,
I'm new with wxpython.
While testing events and derived controls i found this problem:
First, I derive a class from wx.TextCtrl and bind setfocus event:
class miTextCtrl_1(wx.TextCtrl): def __init_(self, ..... )
wx.TextCtrl.__init__(self, .......)
self.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus) # bind the event
def OnSetFocus(self, event):
print "SetFocus on class: miTextCtrl_1"
event.Skip() # continue propagation
I test it and works OK.
Next I derive a new class from this, and bind on it the same event:
class miTextCtrl_2(miTextCtrl_1):
def __init__(self, ...... )
miTextCtrl_1.__init__(self, ...... )
self.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus) # bind the event
def OnSetFocus(self, event):
print "SetFocus on class: miTextCtrl_2"
event.Skip() # continue propagation
When test this class then event SetFocus run TWICE on class miTextCtrl_2 and no one in class miTextCtrl_1, instead of run fist in class miTextCtrl_2 and later in class miTextCtrl_1.
If i name diferent the event functions run OK.
Is normal this behavior?
Am I doing anything wrong?
Thanks (disculp my bad english)