diff --git a/demo/XmlResource.py b/demo/XmlResource.py index 8b7060e6..268b2a89 100644 --- a/demo/XmlResource.py +++ b/demo/XmlResource.py @@ -18,8 +18,10 @@ class TestPanel(wx.Panel): label = wx.StaticText(self, -1, "The lower panel was built from this XML:") label.SetFont(wx.Font(12, wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD)) - resourceText = open(RESFILE).read() - text = wx.TextCtrl(self, -1, resourceText, + with open(RESFILE, 'rb') as f: + resourceBytes = f.read() + + text = wx.TextCtrl(self, -1, resourceBytes, style=wx.TE_READONLY|wx.TE_MULTILINE) text.SetInsertionPoint(0) @@ -33,13 +35,14 @@ class TestPanel(wx.Panel): elif 1: # or from a Virtual FileSystem: wx.FileSystem.AddHandler(wx.MemoryFSHandler()) - wx.MemoryFSHandler().AddFile("XRC_Resources/data_file", resourceText) - res = xrc.XmlResource("memory:XRC_Resources/data_file") + wx.MemoryFSHandler.AddFile("my_XRC_data", resourceBytes) + # notice the matching filename + res = xrc.XmlResource("memory:my_XRC_data") else: - # or from a string, like this: - res = xrc.EmptyXmlResource() - res.LoadFromString(resourceText) + # or from a buffer compatible object, like this: + res = xrc.XmlResource() + res.LoadFromBuffer(resourceBytes) # Now create a panel from the resource data diff --git a/demo/XmlResourceHandler.py b/demo/XmlResourceHandler.py index cf10c439..33339195 100644 --- a/demo/XmlResourceHandler.py +++ b/demo/XmlResourceHandler.py @@ -5,7 +5,7 @@ import wx.xrc as xrc #---------------------------------------------------------------------- -resourceText = r''' +resourceText = br''' @@ -48,8 +48,7 @@ class MyCustomPanel(wx.Panel): # the different requirements are. class PreMyCustomPanel(wx.Panel): def __init__(self): - p = wx.PrePanel() - self.PostCreate(p) + wx.Panel.__init__(self) def Create(self, parent, id, pos, size, style, name): wx.Panel.Create(self, parent, id, pos, size, style, name) @@ -84,12 +83,10 @@ class MyCustomPanelXmlHandler(xrc.XmlResourceHandler): def DoCreateResource(self): # NOTE: wxWindows can be created in either a single-phase or # in a two-phase way. Single phase is what you normally do, - # and two-phase creates the instnace first, and then later + # and two-phase creates the instance first, and then later # creates the actual window when the Create method is called. - # (In wxPython the first phase is done using the wxPre* - # function, for example, wxPreFrame, wxPrePanel, etc.) # - # wxXmlResource supports either method, a premade instance can + # wxXmlResource supports either method, a pre-made instance can # be created and populated by xrc using the appropriate # LoadOn* method (such as LoadOnPanel) or xrc can create the # instance too, using the Load* method. However this makes @@ -98,7 +95,7 @@ class MyCustomPanelXmlHandler(xrc.XmlResourceHandler): # instance, then you can make the handle much simpler. I'll # show both methods below. - if 1: + if 0: # The simple method assumes that there is no existing # instance. Be sure of that with an assert. assert self.GetInstance() is None @@ -156,9 +153,9 @@ class TestPanel(wx.Panel): line = wx.StaticLine(self, -1) # Load the resource - res = xrc.EmptyXmlResource() + res = xrc.XmlResource() res.InsertHandler(MyCustomPanelXmlHandler()) - res.LoadFromString(resourceText) + res.LoadFromBuffer(resourceText) # Now create a panel from the resource data panel = res.LoadObject(self, "MyPanel", "MyCustomPanel") @@ -171,7 +168,6 @@ class TestPanel(wx.Panel): sizer.Add(panel, 1, wx.EXPAND|wx.ALL, 5) self.SetSizer(sizer) - self.SetAutoLayout(True) #---------------------------------------------------------------------- diff --git a/demo/XmlResourceSubclass.py b/demo/XmlResourceSubclass.py index 07b44b8a..3ffb043f 100644 --- a/demo/XmlResourceSubclass.py +++ b/demo/XmlResourceSubclass.py @@ -5,7 +5,7 @@ import wx.xrc as xrc #---------------------------------------------------------------------- -resourceText = r''' +resourceText = br'''