class ibCheckBoxHandler(xrc.XmlResourceHandler):
    def __init__(self):
        xrc.XmlResourceHandler.__init__(self)
        self.AddWindowStyles()
        
    def CanHandle(self,node):
        return self.IsOfClass(node,'wxCheckBox')

    def FindParentDialog(self,node):
        _pnode=node.GetParent()
        if not _pnode:
            return ''
        if _pnode.GetName() == 'object':
            if _pnode.GetPropVal('class','') == 'wxDialog':
                _name=_pnode.GetPropVal('name','')
                if _name:
                    return _name
        return self.FindParentDialog(_pnode)

    def DoCreateResource(self):
        _attr=None
        _validator=wx.DefaultValidator
        _class=self.GetClass()
        if _class == 'wxCheckBox':
            _parent=self.FindParentDialog(self.GetNode())
            try:
                _attr=wx.GetApp()._dialogs[_parent][self.GetName()]
            except:
                pass
                
            if _attr:
                if _attr.fields.validator:
                    _type=_attr.fields.field_type
                    if not _type:
                        _type='str'
                    exec "_validator="+_attr.fields.validator+"(dialog='"+_parent+"',msg='"+_attr.fields.message+"', dbtable='"+_attr.fields.dbtable+"',dbfield='"+_attr.fields.dbfield+"',dbtype='"+_type+"')"
                else:
                    _type=_attr.fields.field_type
                    if not _type:
                        _type='str'
                    _validator=DefaultValidator(dialog=_parent,
                                                msg=_attr.fields.message,
                                                dbtable=_attr.fields.dbtable,
                                                dbfield=_attr.fields.dbfield,
                                                dbtype=_type)
            else:
                print "No DB Record for",self.GetName()
                
            ct=wx.CheckBox(self.GetParentAsWindow(),
                           self.GetID(),
                           self.GetText('label'),
                           self.GetPosition(),
                           self.GetSize(),
                           self.GetStyle(),
                           _validator,
                           self.GetName()
                           )

            self.SetupWindow(ct)
            return ct
