ich versuche gerade, mir eine Datumseingabe zu basteln. Dabei soll die Eingabe auf Gültigkeit überprüft werden. Allerdings ruft wx.TextCtrl die darin angegebene Validator-Klasse nicht auf.
Hier der Code:
Code: Alles auswählen
#!/usr/bin/python
#-*- coding: utf-8 -*-
import wx
class Frame(wx.Frame):
def __init__(self, parent, id, size, pos, title):
wx.Frame.__init__(self, parent, id, title, pos, size)
self.panel = wx.Panel(self)
self.datlabel = wx.StaticText(parent=self.panel, label="Datum", pos=(10,10))
self.datum = wx.TextCtrl(parent=self.panel, value="Datum", pos=(80,5), size=(250,-1),
validator=MyValidator())
self.status = wx.StaticText(parent=self.panel, label="Cancel oder Eingabe?", pos=(80,100))
buttonOK = wx.Button(parent=self.panel, label="OK", pos=(10,250))
buttonOK.Bind(wx.EVT_BUTTON, self.Ok, buttonOK)
buttonCANCEL = wx.Button(parent=self.panel, label="Cancel", pos=(100,250))
buttonCANCEL.Bind(wx.EVT_BUTTON, self.Cancel, buttonCANCEL)
def Ok(self, event):
self.status.SetLabel("Datumfeld: "+self.datum.GetValue())
def Cancel(self, event):
self.status.SetLabel("Cancel gedrückt...")
class MyValidator(wx.PyValidator):
def __init__(self):
print "init"
wx.PyValidator.__init__(self)
def Clone(self):
print "clone"
return MyValidator()
def Validate(self, win):
print "validate"
textCtrl = self.GetWindow()
text = textCtrl.GetValue()
if len(text) == 0:
wx.MessageBox("Feld ist leer!", "Error")
textCtrl.SetBackgroundColour("pink")
textCtrl.SetFocus()
textCtrl.Refresh()
return False
else:
textCtrl.SetBackgroundColour(
wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW))
textCtrl.Refresh()
return True
def TransferToWindow(self):
return True
def TransferFromWindow(self):
return True
class App(wx.App):
def __init__(self):
wx.App.__init__(self)
def OnInit(self):
frame = Frame(parent=None, id=-1, size=(600,500),
pos=(500,150), title='KalP')
frame.Show()
return True
if __name__ == '__main__':
app = App()
app.MainLoop()

Kann mir jemand helfen, mich aus meiner Sackgasse zu befreien??
Gruß
mutetella