Two stage creation of object from XRC file.How ?

Hi,
I would like to create object from XRC file.
How can i do this trick?
I've seen recipe on the wiki but it's kind of uncomplete for novice
python users like me.
Here is the code :
--- wxApp.py ---
from wxPython.wx import *
from wxPython.xrc import *

···

#----------------------------------------------------------------------
class MyFrame(wxFrame):
    def __init__(self, parent):
        pre=wxPreFrame()
        wxXmlResource_Get().LoadOnFrame(pre,parent,"TheFrameXRCName")
        self.this=pre.this
        self._setOORInfo(self)
#----------------------------------------------------------------------
class MyApp(wxApp):
    def OnInit(self):
        self.res = wxXmlResource('')
        self.res.Load('main.xrc')
# How can i create an instance of MyFrame from XRC file?
# frame = MyFrame(self)
# frame.Show(true)
        return true
myapp = MyApp(0)
myapp.MainLoop()

--- main.xrc ---

<?xml version="1.0" ?>
<resource>
  <encoding></encoding>
  <object class="wxFrame" name="TheFrameXRCName">
    <title></title>
  </object>
</resource>
  
Thanks in advance.
Igor.

Here's what worked for me. There may be another way to do it, but I've
had good luck with this. I've also seen examples work where the
developer chose to pass in a wxXmlResource instance to the constructor,
so that the resource is only loaded once. Hope this helps.

Nathan

--- wxApp.py ---
from wxPython.wx import *
from wxPython.xrc import *

···

#----------------------------------------------------------------------
class MyFrame(wxFrame):
    def __init__(self, parent):
  pre = wxPreFrame()
        wxXmlResource("main.xrc").LoadOnFrame(
            pre, parent, "TheFrameXRCName")
        self.this = pre.this
        self._setOORInfo(self)

#----------------------------------------------------------------------
class MyApp(wxApp):
    def OnInit(self):
        self.res = wxXmlResource('')
        self.res.Load('main.xrc')
# How can i create an instance of MyFrame from XRC file?
# frame = MyFrame(self)
# frame.Show(true)
        return true
myapp = MyApp(0)
myapp.MainLoop()

On Wed, 2003-05-07 at 06:08, Igor Prischepoff wrote:

Hi,
I would like to create object from XRC file.
How can i do this trick?
I've seen recipe on the wiki but it's kind of uncomplete for novice
python users like me.
Here is the code :
--- wxApp.py ---
from wxPython.wx import *
from wxPython.xrc import *

#----------------------------------------------------------------------
class MyFrame(wxFrame):
    def __init__(self, parent):
        pre=wxPreFrame()
        wxXmlResource_Get().LoadOnFrame(pre,parent,"TheFrameXRCName")
        self.this=pre.this
        self._setOORInfo(self)
#----------------------------------------------------------------------
class MyApp(wxApp):
    def OnInit(self):
        self.res = wxXmlResource('')
        self.res.Load('main.xrc')
# How can i create an instance of MyFrame from XRC file?
# frame = MyFrame(self)
# frame.Show(true)
        return true
myapp = MyApp(0)
myapp.MainLoop()

--- main.xrc ---

<?xml version="1.0" ?>
<resource>
  <encoding></encoding>
  <object class="wxFrame" name="TheFrameXRCName">
    <title></title>
  </object>
</resource>
  
Thanks in advance.
Igor.

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org

--
Nathan R. Yergler
http://yergler.net/~nathan

Thanks for answering,Nathan.

Here's what worked for me. There may be another way to do it, but I've
had good luck with this. I've also seen examples work where the
developer chose to pass in a wxXmlResource instance to the constructor,
so that the resource is only loaded once. Hope this helps.

Didn't working for me. :frowning:
When running your sample i've got blank text console window.No blank
Frame window.By the way - i'm on win2k, if it matters.
The only distinction which i spotted is

        wxXmlResource("main.xrc").LoadOnFrame(

             ^^^^^^^^^^^^^^^^^^^^^^^^^
But where is object of class MyFrame is created?
Should i call
frame = MyFrame(self) ?
if i did so, then i've got
"Type error in argument 3 in wxXMLResource_LoadOnFrame"
Below is the tested code :

···

--------------------------------
class MyFrame(wxFrame):
     def __init__(self, parent):
         pre = wxPreFrame()
         wxXmlResource("main.xrc").LoadOnFrame(pre, parent, "TheFrameXRCName")
         self.this = pre.this
         self._setOORInfo(self)

class MyApp(wxApp):
     def OnInit(self):
         self.res = wxXmlResource('')
         self.res.Load('main.xrc')
# How can i create an instance of MyFrame from XRC file?
# frame = MyFrame(self)
# frame.Show(true)
         return true
myapp = MyApp(0)
myapp.MainLoop()
-------------
Can you tell me what's happening on your computer when you running
this sample?
Thanks in advance, Igor.

Sorry, I didn't notice the commented out section of the App class. I
didn't run your code before so I didn't catch that. Yes, you will need
to call the frame constructor. The error message about parameter 3,
however, is because you're calling the constructor from a wxApp and not
a wxWindow. The line should be:

frame = MyFrame(None)

After I changed that it worked for me (Linux, Python 2.2.2, wxP 2.4.0.2)
Don't know if you've looked at this yet, but you can find more on basic
XRC stuff in the wiki at
http://wiki.wxpython.org/index.cgi/UsingXmlResources.

Let me know if you have other problems with this.

Nathan

···

On Wed, 2003-05-07 at 08:27, Igor Prischepoff wrote:

Thanks for answering,Nathan.
> Here's what worked for me. There may be another way to do it, but I've
> had good luck with this. I've also seen examples work where the
> developer chose to pass in a wxXmlResource instance to the constructor,
> so that the resource is only loaded once. Hope this helps.
Didn't working for me. :frowning:
When running your sample i've got blank text console window.No blank
Frame window.By the way - i'm on win2k, if it matters.
The only distinction which i spotted is
> wxXmlResource("main.xrc").LoadOnFrame(
             ^^^^^^^^^^^^^^^^^^^^^^^^^
But where is object of class MyFrame is created?
Should i call
frame = MyFrame(self) ?
if i did so, then i've got
"Type error in argument 3 in wxXMLResource_LoadOnFrame"
Below is the tested code :
--------------------------------
class MyFrame(wxFrame):
     def __init__(self, parent):
         pre = wxPreFrame()
         wxXmlResource("main.xrc").LoadOnFrame(pre, parent, "TheFrameXRCName")
         self.this = pre.this
         self._setOORInfo(self)

class MyApp(wxApp):
     def OnInit(self):
         self.res = wxXmlResource('')
         self.res.Load('main.xrc')
# How can i create an instance of MyFrame from XRC file?
# frame = MyFrame(self)
# frame.Show(true)
         return true
myapp = MyApp(0)
myapp.MainLoop()
-------------
Can you tell me what's happening on your computer when you running
this sample?
Thanks in advance, Igor.

--
Nathan R. Yergler
http://yergler.net/~nathan

Thanks Nathan!
It works! :slight_smile:

Igor.