XRC fits from the command line

Hi,

I am having a weird issue with XRC in my wxPython app. I am using Python
2.4, wxPython 2.8 on Windows XP. I can run it fine by double-clicking the
file and from just running the file from within IDLE. However, if I run it
from the command line, the application locks up and if I run it from a
batch file, I get the following traceback:

Traceback (most recent call last):
  File
"\\servername\netlogon\PythonPackages\Development\Timesheet\login.py",
line
152, in ?
    app = LoginScreen(False)
  File
"\\servername\netlogon\Python24\lib\site-packages\wx-2.6-msw-ansi\wx\_core
.p
y", line 7700, in __init__
    self._BootstrapApp()
  File
"\\servername\netlogon\Python24\lib\site-packages\wx-2.6-msw-ansi\wx\_core
.p
y", line 7352, in _BootstrapApp
    return _core_.PyApp__BootstrapApp(*args, **kwargs)
  File
"\\servername\netlogon\PythonPackages\Development\Timesheet\login.py",
line
29, in OnInit
    self.createWidgets()
  File
"\\servername\netlogon\PythonPackages\Development\Timesheet\login.py",
line
34, in createWidgets
    panel = xrc.XRCCTRL(self.frame, 'panel')
  File
"\\servername\netlogon\Python24\lib\site-packages\wx-2.6-msw-ansi\wx\xrc.p
y"
, line 249, in XRCCTRL
    return window.FindWindowById(XRCID(str_id))
AttributeError: 'NoneType' object has no attribute 'FindWindowById'

LoginScreen is subclassed from wx.App.

Any help is appreciated.

Mike Driscoll
Applications Specialist
MCIS - Technology Center

Mike Driscoll wrote:

Hi,

I am having a weird issue with XRC in my wxPython app. I am using Python
2.4, wxPython 2.8 on Windows XP. I can run it fine by double-clicking the
file and from just running the file from within IDLE. However, if I run it
from the command line, the application locks up and if I run it from a
batch file, I get the following traceback:

[...]

, line 249, in XRCCTRL
    return window.FindWindowById(XRCID(str_id))
AttributeError: 'NoneType' object has no attribute 'FindWindowById'

I expect that it is failing to load the xrc data. How are you doing that? Is a full pathname used? Or is it assuming that the xrc file is in the current directory but your current directory is somewhere else?

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Mr. Dunn,

I have the xrc file in the same directory as the python file that loads
it. So I use the following to load it:

self.res = xrc.XmlResource('login.xrc')

The .cmd file that I am using calls the file by executing the following
command:

%PYTHONHOME%\python.exe
%NLPath%\PythonPackages\Development\Timesheet\backup\login_XRC.py

Where %PYTHONHOME% points to the path that holds the python executable and
where %NLPath% points to the path that the python file is.

I use this call all the time for other GUI's I've created that don't use
the XRC method yet. I am hoping to re-write some of that code to use it as
I like the ease of use of XRC.

Hopefully this will give you the information you need.

Mike

···

-----Original Message-----
From: Robin Dunn [mailto:robin@alldunn.com]
Sent: Wednesday, May 02, 2007 3:55 PM
To: wxPython-users@lists.wxwidgets.org
Subject: Re: [wxPython-users] XRC fits from the command line

Mike Driscoll wrote:

Hi,

I am having a weird issue with XRC in my wxPython app. I am using
Python 2.4, wxPython 2.8 on Windows XP. I can run it fine by
double-clicking the file and from just running the file from within
IDLE. However, if I run it from the command line, the application
locks up and if I run it from a batch file, I get the following

traceback:

[...]

, line 249, in XRCCTRL
    return window.FindWindowById(XRCID(str_id))
AttributeError: 'NoneType' object has no attribute 'FindWindowById'

I expect that it is failing to load the xrc data. How are you doing that?
Is a full pathname used? Or is it assuming that the xrc file is in the
current directory but your current directory is somewhere else?

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Mike Driscoll wrote:

Mr. Dunn,

I have the xrc file in the same directory as the python file that loads
it. So I use the following to load it:

self.res = xrc.XmlResource('login.xrc')

This looks for 'login.xrc' in the current dir...

The .cmd file that I am using calls the file by executing the following
command:

%PYTHONHOME%\python.exe
%NLPath%\PythonPackages\Development\Timesheet\backup\login_XRC.py

... and here you seem to want to be able to start the script from any location
so that in the end 'login.xrc' is not in the current dir.

I use something like the following to find the location of the xrc file:

xrcfile = os.path.splitext(os.path.abspath(__file__))[0]+'.xrc'

Christian

Mike Driscoll wrote:

Christian,

Thanks for the tip. Unfortunately, my program's location is in a UNC path
and the app is run on windows, so when you double-click the cmd file, it
reverts to C:\Windows since it doesn't support UNC.

I got it to work by hard-coding the location of the xrc file though. I
just wish there was a better way. I was trying to avoid that.

You're already hard coding the application path in the cmd script, so another approach to take is to set it in an environment variable instead and then use it both in the script and in your Python.

set APP_PATH=%NLPath%\PythonPackages\Development\Timesheet\backup
%PYTHONHOME%\python.exe %APP_PATH%\login_XRC.py

Then in your Python code do something like this:

  xrcpath = os.path.join(os.environ['APP_PATH'], 'login.xrc')
  self.res = xrc.XmlResource(xrcpath)

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Thanks for your help, guys. Sorry I ask so many ignorant questions. I hope
that at some point I too can be a guru.

Have a great weekend!

Mike

···

-----Original Message-----
From: Robin Dunn [mailto:robin@alldunn.com]
Sent: Friday, May 04, 2007 11:48 AM
To: wxPython-users@lists.wxwidgets.org
Subject: Re: [wxPython-users] RE: XRC fits from the command line

Mike Driscoll wrote:

Christian,

Thanks for the tip. Unfortunately, my program's location is in a UNC
path and the app is run on windows, so when you double-click the cmd
file, it reverts to C:\Windows since it doesn't support UNC.

I got it to work by hard-coding the location of the xrc file though. I
just wish there was a better way. I was trying to avoid that.

You're already hard coding the application path in the cmd script, so
another approach to take is to set it in an environment variable instead
and then use it both in the script and in your Python.

set APP_PATH=%NLPath%\PythonPackages\Development\Timesheet\backup
%PYTHONHOME%\python.exe %APP_PATH%\login_XRC.py

Then in your Python code do something like this:

  xrcpath = os.path.join(os.environ['APP_PATH'], 'login.xrc')
  self.res = xrc.XmlResource(xrcpath)

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!