If you have built up some of your own custom controls, there won't be a built-in handler for them in XRC. However, it's still possible to use XRC with your custom controls as XRC can be extended by defining custom XML handlers to instantiate your controls. In this recipe, we will show you how to create a custom XRC resource handler to load custom user-defined controls from an XRC file.
Here are the steps:
First, we will define the custom XRC handler to load a custom class called
PhoneButtonPanel
. The handler requires overriding two methods to check whether the handler can handle the XML tag and then create an instance of the object from the tag. The following code will help us do this:class PhoneBtnPanelHandler(xrc.XmlResourceHandler): def CanHandle(self, node): return self.IsOfClass(node, "PhoneButtonPanel") def DoCreateResource(self): panel = PhoneButtonPanel(self.GetParentAsWindow()) self.SetupWindow(panel)...