Creating a wxDataViewCtrl from XRC

Hi.

As said in the title, I’m trying to create a wxDataViewCtrl from a XRC file.

Here is the xml code I’m trying to load :

wxVERTICAL

wxBORDER_THEME|DV_ROW_LINES|DV_VERT_RULES

wxALL|wxEXPAND

5

And here is the code used to load this xrc part :

import os

import wx

import wx.adv

import wx.xrc as xrc

import wx.dataview

class MainFrame(wx.Frame):

def init(self):

wx.Frame.init(self, None, title=‘XRC Test’)

res = xrc.XmlResource(os.path.join(APP_PATH, ‘gui.xml’))

panel = res.LoadPanel(self, ‘pnlTest’)

But I get an error at startup saying :

XRC error : no handler found for XML node “object” (class “wxDataViewCtrl”)

XRC error : unexpected item in sizer

What am I doing wrong, or what did I forgot to do ?

Thanks in advance.

Regards

Xav’

You didn’t do anything wrong. The problem is exactly what it says, there is no built-in C++ wxXmlResourceHandler for the wxDataViewCtrl class for some reason. You can make one yourself however, there is an example in the demo that shows how to do it for a custom panel class.

···

Robin

On Wednesday, March 14, 2018 at 2:54:00 PM UTC-7, Xaviou wrote:

Hi.

As said in the title, I’m trying to create a wxDataViewCtrl from a XRC file.

Here is the xml code I’m trying to load :

wxVERTICAL

wxBORDER_THEME|DV_ROW_LINES|DV_VERT_RULES

wxALL|wxEXPAND

5

And here is the code used to load this xrc part :

import os

import wx

import wx.adv

import wx.xrc as xrc

import wx.dataview

class MainFrame(wx.Frame):

def init(self):

wx.Frame.init(self, None, title=‘XRC Test’)

res = xrc.XmlResource(os.path.join(APP_PATH, ‘gui.xml’))

panel = res.LoadPanel(self, ‘pnlTest’)

But I get an error at startup saying :

XRC error : no handler found for XML node “object” (class “wxDataViewCtrl”)

XRC error : unexpected item in sizer

What am I doing wrong, or what did I forgot to do ?

Thanks in advance.

Regards

Xav’

Thank you very much for your response.
It worked fine, with a very few lines of code.

Here they are, for those who needs :

class wxDataViewCtrlXmlHandler(xrc.XmlResourceHandler):

def init(self):

xrc.XmlResourceHandler.init(self)

Specify the styles recognized by wxDataViewCtrl

self.AddStyle(‘wxDV_SINGLE’, dv.DV_SINGLE)

self.AddStyle(‘wxDV_MULTIPLE’, dv.DV_MULTIPLE)

self.AddStyle(‘wxDV_ROW_LINES’, dv.DV_ROW_LINES)

self.AddStyle(‘wxDV_HORIZ_RULES’, dv.DV_HORIZ_RULES)

self.AddStyle(‘wxDV_VERT_RULES’, dv.DV_VERT_RULES)

self.AddStyle(‘wxDV_VARIABLE_LINE_HEIGHT’, dv.DV_VARIABLE_LINE_HEIGHT)

self.AddStyle(‘wxDV_NO_HEADER’, dv.DV_NO_HEADER)

self.AddWindowStyles()

Required methods for XmlResourceHandlers

def CanHandle(self, node):

return self.IsOfClass(node, ‘wxDataViewCtrl’)

def DoCreateResource(self):

Be sure that there is no existing instance

assert self.GetInstance() is None

Now create the object

ctrl = dv.DataViewCtrl(self.GetParentAsWindow(),

self.GetID(),

self.GetPosition(),

self.GetSize(),

self.GetStyle(“style”, 0),

wx.DefaultValidator,

self.GetName()

)

Set standard window attributes

self.SetupWindow(ctrl)

Create any child windows of this node

self.CreateChildren(ctrl)

return ctrl

Regards

Xav’

···

On Thursday, March 15, 2018 at 1:28:10 AM UTC+1, Robin Dunn wrote:

You didn’t do anything wrong. The problem is exactly what it says, there is no built-in C++ wxXmlResourceHandler for the wxDataViewCtrl class for some reason. You can make one yourself however, there is an example in the demo that shows how to do it for a custom panel class.

Robin