XRCed: Most simple example won't work, what am I doing wrong?

Hello,

I'm using XRCed 0.1.8-5 from the wxPython 2.8.3 doc and demos installation.

I have created a small xrc file:

---%<---
<?xml version="1.0" encoding="cp1252"?>
<resource>
   <object class="wxFrame" name="FRAME1">
     <title></title>
     <object class="wxMenuBar">
       <object class="wxMenu" name="MENU_FILE">
         <label>&amp;File</label>
         <object class="wxMenuItem" name="COMMAND_QUIT">
           <label>&amp;Quit</label>
         </object>
       </object>
     </object>
   </object>
</resource>
--->%---

I tell XRCed to generate the Python code for me, resulting in the following class:

---%<---
class xrcFRAME1(wx.Frame):
     def PreCreate(self, pre):
         """ This function is called during the class's initialization.

         Override it for custom setup before the window is created usually to
         set additional window styles using SetWindowStyle() and SetExtraStyle()."""
         pass

     def __init__(self, parent):
         # Two stage creation (see http://wiki.wxpython.org/index.cgi/TwoStageCreation)
         pre = wx.PreFrame()
         self.PreCreate(pre)
         get_resources().LoadOnFrame(pre, parent, "FRAME1")
         self.PostCreate(pre)

         # Define variables for the controls
         self.MENU_FILE = xrc.XRCCTRL(self, "MENU_FILE")
         self.COMMAND_QUIT = self.FindItemById(xrc.XRCID("COMMAND_QUIT"))
--->%---

When trying to instantiate this class, I get the following error:

---%<---
...
    self.COMMAND_QUIT = self.FindItemById(xrc.XRCID("COMMAND_QUIT"))
AttributeError: 'xrcFRAME1' object has no attribute 'FindItemById'
--->%---

Now, could anybody please tell me what I am doing wrong?

TIA, Markus

Hi,

It's a bug in pywrc tool - it does not support a MenuBar inside a
top-level window (actually it supposes all window children can be found
by FindItemById from the main objct which is not the case for menu
classes).

  self.MENU_FILE = xrc.XRCCTRL(self, "MENU_FILE")
  self.COMMAND_QUIT = self.FindItemById(xrc.XRCID("COMMAND_QUIT"))

it sould have generated something like

        self.MENU_FILE = self.GetMenuBar()
  self.COMMAND_QUIT = self.MENU_FILE.FindItemById(xrc.XRCID("COMMAND_QUIT"))

GetMenuBar is needed because XRCCTRL can't find the menubar object
(maybe because it's not really a control). Actually the name MENU_FILE
in the XRC file is probably ignored colpletely.

pywrc is a separate tool which is called by XRCed, and provides only
basic code generaion, which can be often used as a starting point for a
project but sometimes requires hand-editing. I'm working on a general
way to provide code-generation from XRCed in the future version.

Roman

···

On Thu, 2007-05-10 at 13:01 +0200, Markus Schöpflin wrote:

Hello,

I'm using XRCed 0.1.8-5 from the wxPython 2.8.3 doc and demos installation.

I have created a small xrc file:

---%<---
<?xml version="1.0" encoding="cp1252"?>
<resource>
   <object class="wxFrame" name="FRAME1">
     <title></title>
     <object class="wxMenuBar">
       <object class="wxMenu" name="MENU_FILE">
         <label>&amp;File</label>
         <object class="wxMenuItem" name="COMMAND_QUIT">
           <label>&amp;Quit</label>
         </object>
       </object>
     </object>
   </object>
</resource>
--->%---

I tell XRCed to generate the Python code for me, resulting in the following class:

---%<---
class xrcFRAME1(wx.Frame):
     def PreCreate(self, pre):
         """ This function is called during the class's initialization.

         Override it for custom setup before the window is created usually to
         set additional window styles using SetWindowStyle() and SetExtraStyle()."""
         pass

     def __init__(self, parent):
         # Two stage creation (see http://wiki.wxpython.org/index.cgi/TwoStageCreation)
         pre = wx.PreFrame()
         self.PreCreate(pre)
         get_resources().LoadOnFrame(pre, parent, "FRAME1")
         self.PostCreate(pre)

         # Define variables for the controls
         self.MENU_FILE = xrc.XRCCTRL(self, "MENU_FILE")
         self.COMMAND_QUIT = self.FindItemById(xrc.XRCID("COMMAND_QUIT"))
--->%---

When trying to instantiate this class, I get the following error:

---%<---
...
    self.COMMAND_QUIT = self.FindItemById(xrc.XRCID("COMMAND_QUIT"))
AttributeError: 'xrcFRAME1' object has no attribute 'FindItemById'
--->%---

Now, could anybody please tell me what I am doing wrong?

TIA, Markus

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