xrc and wxStatusBar probs

Hi, I am trying to instantiate a wxStatus Bar, but not having much luck.

Hi Marc Risney,

Here is my element in the .xrc file

<object class="sizeritem">
          <object class="wxStatusBar" name="ID_STATUS_BAR">
            <fields>2</fields>
            <widths></widths>
            <style>wxST_SIZEGRIP</style>
          </object>
          <flag>wxEXPAND</flag>
        </object>
       </object>

I don't know much about xrc, but

and here is my python code

class Application(wx.App):
    def OnInit(self):
        self.res = xrc.XmlResource("gui.xrc")
        self.InitFrame()
        self.InitMenu()
        self.InitStatusBar()
        self.InitEverythingElse()
        return True

    def InitFrame(self):
        self.frame = self.res.LoadFrame(None, "ID_MAIN_FRAME")
        self.panel = xrc.XRCCTRL(self.frame, "ID_MAIN_PANEL")
    
    def InitMenu(self):
        self.menuBar = self.res.LoadMenuBar("ID_MENU_BAR")
        self.frame.SetMenuBar(self.menuBar)
        self.frame.Bind(wx.EVT_MENU, self.OnOpen, id=xrc.XRCID("ID_OPEN"))

    def InitStatusBar(self):
        self.statusBar = wx.StatusBar
        self.statusBar = self.res.LoadObject(self,"ID_STATUS_BAR","wxStatusBar")

Here you gave self as first parameter (with self in the object itself,
its the second one). self is wx.app, but wx.window * is expected, so you
have to write:

self.statusBar =
self.res.LoadObject(self.frame,"ID_STATUS_BAR","wxStatusBar")

        self.frame.SetStatusBar = self.statusBar
        self.statusBar.SetStatusText("test",0)

This is the error I get when I try to start my app:

File "D:\projects\CarsonCity\Python\gui\ncats.py", line 79, in main
   app = Application(0)
File
"D:\Python\Python24\Lib\site-packages\wx-2.6-msw-unicode\wx\_core.py", li
e 7700, in __init__
   self._BootstrapApp()
File
"D:\Python\Python24\Lib\site-packages\wx-2.6-msw-unicode\wx\_core.py", li
e 7352, in _BootstrapApp
   return _core_.PyApp__BootstrapApp(*args, **kwargs)
File "D:\projects\CarsonCity\Python\gui\ncats.py", line 17, in OnInit
   self.InitStatusBar()
File "D:\projects\CarsonCity\Python\gui\ncats.py", line 34, in
InitStatusBar
   self.statusBar = self.res.LoadObject(self,"ID_STATUS_BAR","wxStatusBar")
File
"D:\Python\Python24\Lib\site-packages\wx-2.6-msw-unicode\wx\xrc.py", line
157, in LoadObject
   return _xrc.XmlResource_LoadObject(*args, **kwargs)
ypeError: argument number 2: a 'wxWindow *' is expected,
'PySwigObject(_p_wxPyA
p)' is received

any suggestions?

Marc

Hope this helps you.

Best regards,
DASPRiD

Here you gave self as first parameter (with self in the object itself,
its the second one). self is wx.app, but wx.window * is expected, so you
have to write:

self.statusBar =
self.res.LoadObject(self.frame,"ID_STATUS_BAR","wxStatusBar")

        self.frame.SetStatusBar = self.statusBar
        self.statusBar.SetStatusText("test",0)

I changed my method to:

def InitStatusBar(self):
    self.statusBar = wx.StatusBar
    self.statusBar = self.res.LoadObject(self.frame,"ID_STATUS_BAR","wxStatusBar")
    self.frame.SetStatusBar = self.statusBar
    self.frame.SetStatusText("test",0)

as per your suggestion and now I get this error:

D:\projects\CarsonCity\Python\gui>ncats.py
Traceback (most recent call last):
   File "D:\projects\CarsonCity\Python\gui\ncats.py", line 83, in ?
     main()
   File "D:\projects\CarsonCity\Python\gui\ncats.py", line 79, in main
     app = Application(0)
   File "D:\Python\Python24\Lib\site-packages\wx-2.6-msw-unicode\wx\_core.py", li
ne 7700, in __init__
     self._BootstrapApp()
   File "D:\Python\Python24\Lib\site-packages\wx-2.6-msw-unicode\wx\_core.py", li
ne 7352, in _BootstrapApp
     return _core_.PyApp__BootstrapApp(*args, **kwargs)
   File "D:\projects\CarsonCity\Python\gui\ncats.py", line 17, in OnInit
     self.InitStatusBar()
   File "D:\projects\CarsonCity\Python\gui\ncats.py", line 36, in InitStatusBar
     self.frame.SetStatusText("test",0)
   File "D:\Python\Python24\Lib\site-packages\wx-2.6-msw-unicode\wx\_windows.py",
  line 545, in SetStatusText
     return _windows_.Frame_SetStatusText(*args, **kwargs)
wx._core.PyAssertionError: C++ assertion "wxAssertFailure" failed in ..\..\src\c
ommon\framecmn.cpp(343): no statusbar to set text for

and when I comment out that line, where I am trying to set some arbitrary text, I get a windows Modal error:
XRC resource 'ID_STATUS_BAR'(class 'wxStatusBar') not found

when I try to start my app

attached is my xrc file, with my element:

<object class="wxStatusBar" name="ID_STATUS_BAR">
             <fields>2</fields>
             <widths></widths>
             <style>wxST_SIZEGRIP</style>
           </object>

what am I doing wrong? and where can I find more example??

gui.xrc (2.15 KB)

Ok Marc,

I took a deeper look on XRC now. As far as I know now, your code is
absolute correct. The problem is just another. As I read in another
mailing list archive some minutes ago, 1 year ago XRC did not support
StatusBars. The wxGlade programmer implemented it after it was
implemented in XRC, but I could not find anything about StatusBar in the
XRC-files of python.

So now you have 2 options:
First, you create the StatusBar directly in python without XRC, this
should not make any trouble and work clean. By the way, this isn't realy
much code.
Your second option is, if I am right, to load an up-to-date so/dll and
overwrite the current one in the site-packages directory. As I said, if
I am right, and the StatusBar is simply not supported in your current
version, and everything is compatible, you should be able to use
StatusBar in XRC then.

Hope this helps you, following the quote of the mailing list archive:

> I use wxGlade for generating XRC files.
> If I use a statusbar in my frame then I get this code in the XRC
> file:<!-- code generator for wxStatusBar objects not available -->
>
> I read this in the tutorial:
> Some widgets are not supported at all (e.g. status bar and grid):
> for them no code will be generated, but instead the XRC output file
> will contain a comment like this:
> <!-- code generator for wxStatusBar objects not available -->
>
> But why isn't a statusbar supported?
> Will this be supported in the future?
>
> I tried this with dialogblocks and this program does create code for
> a statusbar which works, but I prefer the fantastic wxGlade :slight_smile:

Well, it wasn't supported by wxGlade because it wasn't supported by
XRC at the time :slight_smile: But if it is now, I'll add it.

Alberto

DASPRiD