Well, nobody has answered so far, and now I even more confused with XRC
usage with wxPython then before.
Can somebody please explain me, how can I derive a class from wxFrame
(say) and load its contents from the .xrc file in it's constructor?
On wxWindows, as I've just learned from
http://cvs.wxwindows.org/viewcvs.cgi/wxWindows/contrib/samples/xrc/myfra
me.cpp?rev=1.1&content-type=text/vnd.viewcvs-markup
that one could define subclass of wxFrame and then call the
wxXmlResource like this:
wxXmlResource::Get()->LoadFrame(this, parent, "main_frame");
this will load frame contents from the .xrc file into our own derived
class.
I'm not an expert in the C++, but from what I've learn, 'this' is a C++
way to say 'self',
parent is a pointer to the parent window (and in this example
parent=None) and "main_frame" is the name of this frame in the .xrc
file.
But wxPython's wxXmlResource.LoadFrame expect *only* two parameters: the
parent and the xml resource name.
You can use it like this (assuming res is an instance of wxXmlResource):
my_frame = res.LoadFrame(parent, "main_frame")
and after this my_frame will hold the frame loaded from .xrc file, but
how can I do the trick in the __init__ function of my subclass derived
from wxFrame?
Victor.
···
-----Original Message-----
From: Krjukov Victor
Sent: Thursday, November 28, 2002 11:43 PM
To: wxPython-users@lists.wxwindows.org
Subject: [wxPython-users] XRC question: how to receive wxMenu
non-top object?Greetings list,
Vaclav or anybody,
could you please explain me why in the following code:
==>
res = wxXmlResourse("menu.xrc")
self.menuBar = res.LoadMenuBar("MainMenuBar")
self.fileMenu = XRCCTRL(self.menuBar, "FileMenu")
<==I receive a created menubar in self.menuBar (that's ok), but I receive
None if self.fileMenu?I know, of course, that I can receive the file menu via
==>
self.fileMenu = self.menuBar.GetMenu(self.menuBar.FindMenu("File"))
<==but it looks a little bit odd. And Vaclav - <object_ref ...>
didn't work
either (I've tried to use it with
==>
self.fileMenu = res.LoadMenu("MyFileMenu")
<==
but it says "XRC resource 'MyFileMenu' (class 'wxMenu') not found!"What am I doing wrong?
Here is my menu.xrc:
==>
<?xml version="1.0" ?>
<resource>
<object class="wxMenuBar" name="MainMenubar">
<object class="wxMenu" name="FileMenu">
<label>&File</label>
<object class="wxMenuItem" name="NewFileMenu">
<label>&New</label>
<accel>Ctrl-N</accel>
<help>New XRC file</help>
</object>
[skipped...]
</object>
</object>
<object_ref name="MyFileMenu" ref="FileMenu"/>
</resource>
<==My second question: is there any way to set window id for MenuItem
inside a .xrc file (instead of writing ugly code such as:
==>
FileMenuItem = <code for receiving 'New file' menu item - it is not
obvious for the above reasons ;)>
FileMenuItem.SetId(wxNEW_ID)
<==Thanks a lot,
--Victor.
---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail:
wxPython-users-help@lists.wxwindows.org