XRC difference gtk2 vs. win32

Hello list,

I have written a wxpython app and made usage of the xrc system. It works
fine with linux and wx-gtk2 (2.6.1, python2.3, debian).

With win32 I run into problems :frowning:
MyApp loads the XmlResource, which contains a MainFrame derived from
wx.Frame. This gets loaded by xrc.
With win32 I can not access the controls with xrc.XRCCTRL(self, 'id'). I
just get NoneType objects in _get_controls(), but no errors (of course
later on I get errors about missing attributes when accessing this NoneType
objects ;).

I need this app for my studies and my prof wants to have this on win32, of
course asap. So any help is very appreciated :slight_smile:

This is the relevant code:

class MainFrame(wx.Frame):
聽聽聽聽def __init__(self):
聽聽聽聽聽聽聽聽p = wx.PreFrame()
聽聽聽聽聽聽聽聽# the Create step is done by XRC
聽聽聽聽聽聽聽聽self.PostCreate(p)
聽聽聽聽聽聽聽聽self.Bind(wx.EVT_WINDOW_CREATE, self.OnCreate)

聽聽聽聽def OnCreate(self, event):
聽聽聽聽聽聽聽聽self.Unbind(wx.EVT_WINDOW_CREATE)
聽聽聽聽聽聽聽聽self._PostInit()
聽聽聽聽聽聽聽聽event.Skip()
聽聽聽聽聽聽聽聽return True

聽聽聽聽def _PostInit(self):
聽聽聽聽聽聽聽聽# Do all init here
聽聽聽聽聽聽聽聽self._do_layout()
聽聽聽聽聽聽聽聽self._set_properties()

聽聽聽聽def _do_layout(self):
聽聽聽聽聽聽聽聽self._get_controls()
聽聽聽聽聽聽聽聽self.Fit()
聽聽聽聽聽聽聽聽self.SetAutoLayout(True)
聽聽聽聽聽聽聽聽self.Center(wx.BOTH)

聽聽聽聽def _set_properties(self):
聽聽聽聽聽聽聽聽self._connect_controls()
聽聽聽聽聽聽聽聽# This failes course btnStop is of Type NoneType:
聽聽聽聽聽聽聽聽self.btnStop.Enable(False)

聽聽聽聽def _get_controls(self):
聽聽聽聽聽聽聽聽"""Get controls from XML resources
聽聽聽聽聽聽聽聽聽聽聽This does not work with win32. I just get None.
聽聽聽聽聽聽聽聽"""
聽聽聽聽聽聽聽聽self.btnStart = xrc.XRCCTRL(self, 'btnStart')
聽聽聽聽聽聽聽聽self.btnStop = xrc.XRCCTRL(self, 'btnStop')
聽聽聽聽聽聽聽聽self.btnReset = xrc.XRCCTRL(self, 'btnReset')
聽聽聽聽聽聽聽聽self.sldT = xrc.XRCCTRL(self, 'sldT')
聽聽聽聽聽聽聽聽self.sldB = xrc.XRCCTRL(self, 'sldB')
聽聽聽聽聽聽聽聽self.lblM = xrc.XRCCTRL(self, 'lblM')
聽聽聽聽聽聽聽聽self.lblMmean = xrc.XRCCTRL(self, 'lblMmean')
聽聽聽聽聽聽聽聽self.gaugM = xrc.XRCCTRL(self, 'gaugM')
聽聽聽聽聽聽聽聽self.canvas = xrc.XRCCTRL(self, 'canvas')

聽聽聽聽def _connect_controls(self):
聽聽聽聽聽聽聽聽self.Bind(wx.EVT_BUTTON, self.OnBtnStart, self.btnStart)
聽聽聽聽聽聽聽聽self.Bind(wx.EVT_BUTTON, self.OnBtnStop, self.btnStop)
聽聽聽聽聽聽聽聽self.Bind(wx.EVT_BUTTON, self.OnBtnReset, self.btnReset)
聽聽聽聽聽聽聽聽self.Bind(wx.EVT_COMMAND_SCROLL_ENDSCROLL, self.OnSldT, self.sldT)
聽聽聽聽聽聽聽聽self.Bind(wx.EVT_COMMAND_SCROLL_THUMBTRACK, self.OnSldT, self.sldT)
聽聽聽聽聽聽聽聽self.Bind(wx.EVT_COMMAND_SCROLL_THUMBRELEASE, self.OnSldT,self.sldT)
聽聽聽聽聽聽聽聽self.Bind(wx.EVT_COMMAND_SCROLL_ENDSCROLL, self.OnSldB, self.sldB)
聽聽聽聽聽聽聽聽self.Bind(wx.EVT_COMMAND_SCROLL_THUMBTRACK, self.OnSldB, self.sldB)
聽聽聽聽聽聽聽聽self.Bind(wx.EVT_COMMAND_SCROLL_THUMBRELEASE, self.OnSldB,self.sldB)

I have read the wxpython wiki about xrc, Robin Dunn's email referenced
there, and searched the list archive, but don't know what to do to fix
this.

Thanks for any help,
聽聽Dave J盲ckel

Hello all,

my problem still persists.
I now have a minimal version of a wxpython gui with xrc, which does fine
with linux gtk2 port, but does not work with win32.
Just save the attached three files in any directory and execute 'python
main.py'.

With linux xrc.XRCCTRL(self, 'id') returns the button as expected, the
button gets a label and binds to OnBtnExit. With win32 xrc.XRCCTRL silently
returns 'None' and so self.btnExit is again just 'None' :confused:

So what is the right way(c) to instantiate a derived widget with xrc and get
access to its childs? And why is there a difference with win32 and gtk2
ports?

I'm using python2.3 and wxpython2.6.1 unicode on both platforms.

Any help is most welcome. My prof wants to see this piece of software on
monday, and I found this problem just yesterday afternoon.

Regards,
  Dave J盲ckel

gui.xrc (1004 Bytes)

main.py (697 Bytes)

mainFrame.py (800 Bytes)

路路路

Am Samstag, 2. Juli 2005 23:36 schrieb Ferry Dave J盲ckel:

With win32 I run into problems :frowning:
MyApp loads the XmlResource, which contains a MainFrame derived from
wx.Frame. This gets loaded by xrc.
With win32 I can not access the controls with xrc.XRCCTRL(self, 'id'). I
just get NoneType objects in _get_controls(), but no errors (of course
later on I get errors about missing attributes when accessing this
NoneType objects ;).

Is there really nobody who knows how to use xrc with subclassed frames and
panels on win32 (WinXP) the right way?

I've tried an ugly hack:
Calling myFrame.PostInit() from the parent, just before myFrame.Show(). But
this just a workaround, as this fails with nested classes (myApp with a
myFrame with has several myPanelA and MyPanelB which have...) and
especially with a custom BufferedDrawPanel.

I don't think that a custom class has to get initialised by its parents. It
should do it by itself.

Anyone an idea?
  Dave J盲ckel

路路路

I now have a minimal version of a wxpython gui with xrc, which does fine
with linux gtk2 port, but does not work with win32.

With linux xrc.XRCCTRL(self, 'id') returns the button as expected, the
button gets a label and binds to OnBtnExit. With win32 xrc.XRCCTRL
silently returns 'None' and so self.btnExit is again just 'None' :confused:

So what is the right way(c) to instantiate a derived widget with xrc and
get access to its childs? And why is there a difference with win32 and
gtk2 ports?

Dom, 2005-07-03 脿s 12:53 +0200, Ferry Dave J盲ckel escreveu:

Hello all,

my problem still persists.
I now have a minimal version of a wxpython gui with xrc, which does fine
with linux gtk2 port, but does not work with win32.
Just save the attached three files in any directory and execute 'python
main.py'.

With linux xrc.XRCCTRL(self, 'id') returns the button as expected, the
button gets a label and binds to OnBtnExit. With win32 xrc.XRCCTRL silently
returns 'None' and so self.btnExit is again just 'None' :confused:

So what is the right way(c) to instantiate a derived widget with xrc and get
access to its childs? And why is there a difference with win32 and gtk2
ports?

I'm using python2.3 and wxpython2.6.1 unicode on both platforms.

Any help is most welcome. My prof wants to see this piece of software on
monday, and I found this problem just yesterday afternoon.

In the MainFrame OnCreate method change the call:
    self._PostInit()
to
    wx.CallAfter(self._PostInit)

Ricardo

Hi Ricardo,

In the MainFrame OnCreate method change the call:
    self._PostInit()
to
    wx.CallAfter(self._PostInit)

Thank you! That did it! This works well with win32 and gtk port of wxpython.

Now I have some other problems with win32, but this will be another
thread :wink:

Greets,
  Dave J盲ckel

Just for the interested/newbies/other people with XRC problems :wink:

I have added the complete, small and working example of this nonsense
mini-app to the wxpyhton wiki. Maybe it is of some use to somebody.
  http://wiki.wxpython.org/index.cgi/UsingXmlResources

Regards,
  Dave

路路路

Am Sonntag, 3. Juli 2005 17:21 schrieb Ricardo Pedroso:

Dom, 2005-07-03 脿s 12:53 +0200, Ferry Dave J盲ckel escreveu:
> So what is the right way(c) to instantiate a derived widget with xrc
> and get access to its childs? And why is there a difference with win32
> and gtk2 ports?

In the MainFrame OnCreate method change the call:
    self._PostInit()
to
    wx.CallAfter(self._PostInit)

I notice that you put the self._PostInit without the wx.CallAfter in the
wiki page. It is correct? You find another you to make it work on
windows?

Ricardo

Seg, 2005-07-04 脿s 02:25 +0200, Ferry Dave J盲ckel escreveu:

路路路

Just for the interested/newbies/other people with XRC problems :wink:

I have added the complete, small and working example of this nonsense
mini-app to the wxpyhton wiki. Maybe it is of some use to somebody.
  http://wiki.wxpython.org/index.cgi/UsingXmlResources

Regards,
  Dave

Am Sonntag, 3. Juli 2005 17:21 schrieb Ricardo Pedroso:
> Dom, 2005-07-03 脿s 12:53 +0200, Ferry Dave J盲ckel escreveu:
> > So what is the right way(c) to instantiate a derived widget with xrc
> > and get access to its childs? And why is there a difference with win32
> > and gtk2 ports?

> In the MainFrame OnCreate method change the call:
> self._PostInit()
> to
> wx.CallAfter(self._PostInit)

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

Hello Ricardo,

I notice that you put the self._PostInit without the wx.CallAfter in the
wiki page. It is correct? You find another you to make it work on
windows?

Argh, of course this doesn't work. I written this on my linux box. I must
have taken an old file for cut'n paste by accident :frowning:
Thanks to your sharp eyes no one will try and try and just curse this
code :slight_smile: I hope it's now correct.

Maybe I should get some sleep and hope to fix my drawing problems a few
hours later...

Dave

路路路

Am Montag, 4. Juli 2005 03:13 schrieb Ricardo Pedroso:

Is this a different problem than you were having before, which from
the previous thread looked resolved? I don't have any trouble with
using XRC with derived classes on Win32. My code using it is all at
home, but I'll check it this afternoon and make sure I'm not doing
anything special. My classes definitely initiliaze themselves fully
without needing to be initialized by the wx.App or the parent or
whatever.

路路路

On 7/3/05, Ferry Dave J盲ckel <dave@eddy.uni-duisburg.de> wrote:

Is there really nobody who knows how to use xrc with subclassed frames and
panels on win32 (WinXP) the right way?

I've tried an ugly hack:
Calling myFrame.PostInit() from the parent, just before myFrame.Show(). But
this just a workaround, as this fails with nested classes (myApp with a
myFrame with has several myPanelA and MyPanelB which have...) and
especially with a custom BufferedDrawPanel.

I don't think that a custom class has to get initialised by its parents. It
should do it by itself.

Anyone an idea?
        Dave J盲ckel

> I now have a minimal version of a wxpython gui with xrc, which does fine
> with linux gtk2 port, but does not work with win32.

> With linux xrc.XRCCTRL(self, 'id') returns the button as expected, the
> button gets a label and binds to OnBtnExit. With win32 xrc.XRCCTRL
> silently returns 'None' and so self.btnExit is again just 'None' :confused:
>
> So what is the right way(c) to instantiate a derived widget with xrc and
> get access to its childs? And why is there a difference with win32 and
> gtk2 ports?

Hello Chris,

路路路

Am Freitag, 8. Juli 2005 14:07 schrieb Chris Mellon:

On 7/3/05, Ferry Dave J盲ckel <dave@eddy.uni-duisburg.de> wrote:
> > With linux xrc.XRCCTRL(self, 'id') returns the button as expected,
> > the button gets a label and binds to OnBtnExit. With win32
> > xrc.XRCCTRL silently returns 'None' and so self.btnExit is again just
> > 'None' :confused:
> > So what is the right way(c) to instantiate a derived widget with xrc
> > and get access to its childs? And why is there a difference with
> > win32 and gtk2 ports?

Is this a different problem than you were having before, which from
the previous thread looked resolved? I don't have any trouble with
using XRC with derived classes on Win32.

This problem had the same cause and so the same solution: calling
'wx.CallAfter(self._PostInit)' instead of 'self._PostInit()'.

So it got solved by changing my OnCreate-Method.

Thanks for your reply,
  Ferry Dave