i derived my custom control class from wxTextCtrl and still have problem
with overriding
EVT_KILL_FOCUS.
One question: how to catch this event also on dialog level ?
MSW, wxpython 2.3.2
marcin andrzejewski
m.andrzejewski@dmz.com.pl
keson@post.pl
from wxPython.wx import *
class myCtrl(wxWindow):
def __init__(self,parent,pos=None,desc="",desc_pos=1, txt="", hor =
wxDefaultSize,ver=-1,style=1):
self.parent=parent
self.ver = ver
self.hor = hor
self.desc = desc
self.style=style
self.Id = NewId()
txtSize = wxSize(self.hor,self.ver)
if (pos==None):
self.pos=wxDefaultPosition
else:
self.pos=pos
self.field = wxTextCtrl(self.parent, self.Id,
txt,self.pos,txtSize,style=self.style,validator=wxDefaultValidator)
lc = wxLayoutConstraints()
self.desc = wxStaticText(self.parent, -1, label=self.desc, pos=wxPoint(1,
1),style=wxALIGN_RIGHT|wxST_NO_AUTORESIZE )
lc = wxLayoutConstraints()
if (desc_pos ==1):
lc.right.LeftOf (self.field, 5)
lc.centreY.SameAs (self.field, wxCentreY)
else:
lc.left.SameAs (self.field, wxLeft)
lc.bottom.SameAs (self.field, wxTop)
lc.height.AsIs()
lc.width.AsIs()
self.desc.SetConstraints(lc)
EVT_KILL_FOCUS(self.field, self.OnKillFocus)
def OnKillFocus(self,event):
print 'ctrl'
event.Skip()
class MyApp(wxApp):
def OnInit(self):
self.dialog = wxDialog(None, -1, "Test", wxDefaultPosition, wxSize(250,
100))
self.dialog.ctrlA=myCtrl(self.dialog,(80,20),'User :',hor=140)
self.dialog.ctrlA.field.SetFocus()
self.dialog.ctrlB=myCtrl(self.dialog,(80,40),'Password
:',hor=140,style=wxTE_PASSWORD)
self.dialog.Layout()
self.dialog.Show(true)
EVT_CLOSE(self.dialog, self.Close)
EVT_KILL_FOCUS(self.dialog.ctrlA.field, self.OnKillFocus)
EVT_KILL_FOCUS(self.dialog.ctrlB.field, self.OnKillFocus)
return 1
def OnKillFocus(self,event):
print 'dlg'
event.Skip()
def Close(self, event):
self.dialog.Destroy()
app = MyApp(0)
app.MainLoop()