今天在wxPython2.7中实现了一个继承自wx.PyValidator 的判断是否是数字的validator,用于TectCtrl中。代码编写好后,在每次运行时会弹出个对话框,提示warning "Could not transfer data to window ", 但功能运行是正常的。
在百度上按全句匹配搜了一下,没有结果。在google中就搜出来了几个,看来还是google实力强些。但是google搜出的结果也没回答到要点上。
后来执行看了一下wxpython demo中的代码,发现在TextObjectValidator中实现了如下几个函数,说是防止wxDialog抱怨的,照样试了一下,果真解决了问题。另外,在Panel中用的validator不需要添加这几个函数。
在百度上按全句匹配搜了一下,没有结果。在google中就搜出来了几个,看来还是google实力强些。但是google搜出的结果也没回答到要点上。
后来执行看了一下wxpython demo中的代码,发现在TextObjectValidator中实现了如下几个函数,说是防止wxDialog抱怨的,照样试了一下,果真解决了问题。另外,在Panel中用的validator不需要添加这几个函数。
def
TransferToWindow(self):
""" Transfer data from validator to window.
The default implementation returns False, indicating that an error
occurred. We simply return True, as we don't do any data transfer.
"""
return True # Prevent wxDialog from complaining.
def TransferFromWindow(self):
""" Transfer data from window to validator.
The default implementation returns False, indicating that an error
occurred. We simply return True, as we don't do any data transfer.
"""
return True # Prevent wxDialog from complaining.
""" Transfer data from validator to window.
The default implementation returns False, indicating that an error
occurred. We simply return True, as we don't do any data transfer.
"""
return True # Prevent wxDialog from complaining.
def TransferFromWindow(self):
""" Transfer data from window to validator.
The default implementation returns False, indicating that an error
occurred. We simply return True, as we don't do any data transfer.
"""
return True # Prevent wxDialog from complaining.