wxPython PropertyGrid SetPropertValidator崩溃

时间:2015-03-07 03:06:34

标签: validation wxpython propertygrid

我试图使用wxPython构建一个PropertyGrid。对于某些属性,我想对输入的值进行特定验证。但是,当我在目标属性字段中输入任何内容时,我尝试使用SetPropertyValidator()python崩溃时,我已经查看了文档。这是代码的精简版本。关于我缺少的任何想法?

import wx
import wx.propgrid as wxpg

class TestPanel(wx.Panel):
    def __init__(self,parent):
        wx.Panel.__init__(self,parent)
        self.SetSizer(wx.BoxSizer(wx.VERTICAL))
        self.pg = wxpg.PropertyGridManager(self,
                    style=wxpg.PG_SPLITTER_AUTO_CENTER |
                          wxpg.PG_AUTO_SORT |
                          wxpg.PG_TOOLBAR)

        # Show help as tooltips
        self.pg.SetExtraStyle(wxpg.PG_EX_HELP_AS_TOOLTIPS)
        self.pg.Append(wxpg.IntProperty("number"))
        p = self.pg.Append(wxpg.StringProperty("word"))
        self.pg.SetPropertyValidator(p,TestValidator())
        self.Bind(wxpg.EVT_PG_CHANGED, self.OnPropGridChanged)
        self.GetSizer().Add(self.pg,proportion=1,flag=wx.EXPAND)



class TestValidator(wx.PyValidator):
    def __init__(self):
        wx.PyValidator.__init__(self)

    def Clone(self):
        return TestValidator()

    def Validate(self,win):       
        return True

    def TransferToWindow(self):
        return True # Prevent wxDialog from complaining.

    def TransferFromWindow(self):
        return True # Prevent wxDialog from complaining.


class wxFrame(wx.Frame):
    def __init__(self, parent, title):
        wx.Frame.__init__(self, parent, title=title)
        self.panel = TestPanel(self)
        self.Show(True)

if __name__ == "__main__":
    app = wx.App(False)
    frame = wxFrame(None, 'Property Validator')
    app.MainLoop()    

0 个答案:

没有答案