ico and xrc files not packed with GUI2Exe ?

Hi Andrea,

I used GUI2Exe successfully to compile my application.

All works besides a small problem.

The application is using an ico and xrc files, and unless I put those in my Current Working Directory (CWD), my application won’t run.

I tried to add these two files in “Data Files” and “Other Resources”, but it does not work: if I delete them from the CWD, the script won’t run.

The setup file is below.

I could live with the limitation of having to copy these files to the CWD, but it would be much cleaner if they are packed into the exe file.

Any help would be appreciated.

Bye,

BR.

···

======================================================#

File automagically generated by GUI2Exe version 0.1

Andrea Gavana, 31 March 2007

======================================================#

Let’s start with some default (for me) imports…

from distutils.core import setup
import py2exe
import glob
import os
import zlib
import shutil

shutil.rmtree(“build”, ignore_errors=True)

manifest_template = “”"

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> svm Program """

class Target(object):
“”" A simple class that holds information on our executable file. “”"
def init(self, **kw):
“”" Default class constructor. Update as you need. “”"
self.dict.update(kw)
# for the versioninfo resources
self.version = “1.0.5”
self.company_name = “LSI”
self.copyright = “LSI 2008”
self.name = “SVM5 Parser”

Ok, let’s explain why I am doing that.

Often, data_files, excludes and dll_excludes (but also resources)

can be very long list of things, and this will clutter too much

the setup call at the end of this file. So, I put all the big lists

here and I wrap them using the textwrap module.

data_files = [(‘dpm08’, [‘C:\Documents and Settings\RBARAK\rbarak_devel\dpm08\svm_initial_splitter_windows.xrc’,
‘C:\Documents and Settings\RBARAK\rbarak_devel\dpm08\SVM.ico’])]

includes = []
excludes = [‘Tkconstants’, ‘Tkinter’, ‘_gtkagg’, ‘_tkagg’, ‘bsddb’,
‘curses’, ‘email’, ‘pywin.debugger’, ‘pywin.debugger.dbgcon’,
‘pywin.dialogs’, ‘tcl’]
packages = []
dll_excludes = [‘libgdk-win32-2.0-0.dll’, ‘libgobject-2.0-0.dll’, ‘tcl84.dll’,
‘tk84.dll’]
icon_resources = []
bitmap_resources = []
other_resources = [(24, 1, manifest_template), (2, 24, ‘C:\Documents and Settings\RBARAK\rbarak_devel\dpm08\svm_initial_splitter_windows.xrc’),
(3, 24, ‘C:\Documents and Settings\RBARAK\rbarak_devel\dpm08\SVM.ico’)]

This is a place where the user custom code may go. You can do almost

whatever you want, even modify the data_files, includes and friends

here as long as they have the same variable name that the setup call

below is expecting.

No custom code added

Ok, now we are going to build our target class.

I chose this building strategy as it works perfectly for me :smiley:

test_wx = Target(
# what to build
script = “svm.py”,
icon_resources = icon_resources,
bitmap_resources = bitmap_resources,
other_resources = other_resources
)

That’s serious now: we have all (or almost all) the options py2exe

supports. I put them all even if some of them are usually defaulted

and not used. Some of them I didn’t even know about.

setup(

data_files = data_files,

options = {“py2exe”: {“compressed”: 2,
“optimize”: 1,
“includes”: includes,
“excludes”: excludes,
“packages”: packages,
“dll_excludes”: dll_excludes,
“bundle_files”: 1,
“dist_dir”: “dist”,
“xref”: False,
“skip_archive”: False,
“ascii”: False,
“custom_boot_script”: ‘’,
}
},

zipfile = None,
windows = [test_wx]
)

And we are done. That’s a setup script :smiley:

Hi Ron,

Hi Andrea,

I used GUI2Exe successfully to compile my application.
All works besides a small problem.

The application is using an ico and xrc files, and unless I put those in my
Current Working Directory (CWD), my application won't run.

I tried to add these two files in "Data Files" and "Other Resources", but it
does not work: if I delete them from the CWD, the script won't run.

The setup file is below.

I could live with the limitation of having to copy these files to the CWD,
but it would be much cleaner if they are packed into the exe file.

Any help would be appreciated.

For the icon file, there is a specific list control in GUI2Exe which
allows to specify the icon you want to use for your executable. It's
called "icon resources" and it is at the bottom left of the py2exe
panel. If you hit Ctrl+A on that list control you will be able to
specify the icon you want by choosing it using a file dialog.
However, py2exe does not explicitely copy any icon/xrc things to your
unless you add them to the data files section: if you need them to be
in the executable directory, simply add them as data files using "."
(a dot) as directory name when asked by GUI2Exe.

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/

···

On 8/31/08, Barak, Ron wrote:

···

From: Andrea Gavana [mailto:andrea.gavana@gmail.com]
Sent: Monday, 01 September, 2008 11:00
To: wxpython-users@lists.wxwidgets.org
Subject: Re: [wxpython-users] ico and xrc files not packed with GUI2Exe ?

Hi Ron,
[Ron Barak] Hi Andrea,

On 8/31/08, Barak, Ron wrote:

Hi Andrea,

I used GUI2Exe successfully to compile my application.
All works besides a small problem.

The application is using an ico and xrc files, and unless I put those
in my Current Working Directory (CWD), my application won’t run.

I tried to add these two files in “Data Files” and “Other Resources”,
but it does not work: if I delete them from the CWD, the script won’t run.

The setup file is below.

I could live with the limitation of having to copy these files to the
CWD, but it would be much cleaner if they are packed into the exe file.

Any help would be appreciated.

For the icon file, there is a specific list control in GUI2Exe which allows to specify the icon you want to use for your executable. It’s called “icon resources” and it is at the bottom left of the py2exe panel. If you hit Ctrl+A on that list control you will be able to specify the icon you want by choosing it using a file dialog.
However, py2exe does not explicitely copy any icon/xrc things to your unless you add them to the data files section: if you need them to be in the executable directory, simply add them as data files using “.”
(a dot) as directory name when asked by GUI2Exe.
[Ron Barak] I tried your above suggestion. Alas, when the ico file is not in CWD, I get

But, when the ico file is copied to the CWD, this error does not appear.

[Ron Barak] BTW, the ico file is used by a wxGlade 0.6.3 xrc resource file when building the initial application screen.

Also, apart from the ico file, is there a way to have GUI2Exe incorporate the xrc file ?

The line in my app that refers to it is:


WXGLADE_XML = ‘svm_initial_splitter_windows.xrc’ # GUI wxGlade description

xml_resource = xrc.XmlResource(WXGLADE_XML)

[Ron Barak] Thanks for the prompt answer and good luck with the next version of GUI2Exe.

Bye,
Ron.

Andrea.

“Imagination Is The Only Weapon In The War Against Reality.”
http://xoomer.alice.it/infinity77/

Barak, Ron wrote:

------------------------------------------------------------------------
*From:* Andrea Gavana [mailto:andrea.gavana@gmail.com]
*Sent:* Monday, 01 September, 2008 11:00
*To:* wxpython-users@lists.wxwidgets.org
*Subject:* Re: [wxpython-users] ico and xrc files not packed with GUI2Exe ?

    Hi Ron,
    [Ron Barak] Hi Andrea,

     >
     > Hi Andrea,
     >
     > I used GUI2Exe successfully to compile my application.
     > All works besides a small problem.
     >
     > The application is using an ico and xrc files, and unless I put those
     > in my Current Working Directory (CWD), my application won't run.
     >
     > I tried to add these two files in "Data Files" and "Other Resources",
     > but it does not work: if I delete them from the CWD, the script
    won't run.
     >
     > The setup file is below.
     >
     > I could live with the limitation of having to copy these files to the
     > CWD, but it would be much cleaner if they are packed into the exe
    file.
     >
     > Any help would be appreciated.

    For the icon file, there is a specific list control in GUI2Exe which
    allows to specify the icon you want to use for your executable. It's
    called "icon resources" and it is at the bottom left of the py2exe
    panel. If you hit Ctrl+A on that list control you will be able to
    specify the icon you want by choosing it using a file dialog.
    However, py2exe does not explicitely copy any icon/xrc things to
    your unless you add them to the data files section: if you need them
    to be in the executable directory, simply add them as data files
    using "."
    (a dot) as directory name when asked by GUI2Exe.
    [Ron Barak] I tried your above suggestion. Alas, when the ico file
    is not in CWD, I get

     But, when the ico file is copied to the CWD, this error does not
    appear.

    [Ron Barak] BTW, the ico file is used by a wxGlade 0.6.3 xrc
    resource file when building the initial application screen.

    Also, apart from the ico file, is there a way to have GUI2Exe
    incorporate the xrc file ?

    The line in my app that refers to it is:

    ...
    WXGLADE_XML = 'svm_initial_splitter_windows.xrc' # GUI wxGlade
    description
    ...

     xml_resource = xrc.XmlResource(WXGLADE_XML)

    [Ron Barak] Thanks for the prompt answer and good luck with the next
    version of GUI2Exe.

Keep in mind that the CWD of a program may or may not be the same as the installed location of the exe and supporting files. If you want to be able to reliably find these files at runtime then you should certainly *not* depend on the CWD and be a little smarter about how you load the files and use full pathnames where possible. On Windows you can usually safely use something like os.path.join(os.path.basename(sys.argv[0]), 'filename') to get the executable location. Take a look at the wx.StandardPaths class too.

···

    On 8/31/08, Barak, Ron wrote:

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

Hi Robin,

Thanks for your helpful remarks.

However (as was alluded previously on this thread), I’m using GUI2Exe, partially to avoid issues like calculating $path on different file systems.

Ideally, the py2exe created exe would incorporate the two auxiliary (ico and xrc) files, so they won’t have to be distributed separately.

To rephrase my question:
How do I make GUI2Exe incorporate the “SVM.ico” and “svm_initial_splitter_windows.xrc” files inside the GUI2Exe created exe file ?

These files are referenced in my code like so:

In svm.py


from wx import xrc

WXGLADE_XML = ‘svm_initial_splitter_windows.xrc’

xml_resource = xrc.XmlResource(WXGLADE_XML)
self.root = xml_resource.LoadFrame(None,‘svm5parser’)

and in svm_initial_splitter_windows.xrc:


SVM.ico

BTW, my script works just fine from the command line. It’s only when it’s compiled into an exe that problems occur.

Bye,
Ron.

···

-----Original Message-----
From: Robin Dunn [mailto:]
Sent: Monday, 01 September, 2008 23:51
To: wxpython-users@lists.wxwidgets.org
Subject: Re: [wxpython-users] ico and xrc files not packed with GUI2Exe ?

Barak, Ron wrote:



From: Andrea Gavana [mailto:]
Sent: Monday, 01 September, 2008 11:00
To: wxpython-users@lists.wxwidgets.org
Subject: Re: [wxpython-users] ico and xrc files not packed with GUI2Exe ?

Hi Ron,
[Ron Barak] Hi Andrea,

On 8/31/08, Barak, Ron wrote:
 >
 > Hi Andrea,
 >
 > I used GUI2Exe successfully to compile my application.
 > All works besides a small problem.
 >
 > The application is using an ico and xrc files, and unless I put those
 > in my Current Working Directory (CWD), my application won't run.
 >
 > I tried to add these two files in "Data Files" and "Other Resources",
 > but it does not work: if I delete them from the CWD, the script
won't run.
 >
 > The setup file is below.
 >
 > I could live with the limitation of having to copy these files to the
 > CWD, but it would be much cleaner if they are packed into the exe
file.
 >
 > Any help would be appreciated.

For the icon file, there is a specific list control in GUI2Exe which
allows to specify the icon you want to use for your executable. It's
called "icon resources" and it is at the bottom left of the py2exe
panel. If you hit Ctrl+A on that list control you will be able to
specify the icon you want by choosing it using a file dialog.
However, py2exe does not explicitely copy any icon/xrc things to
your unless you add them to the data files section: if you need them
to be in the executable directory, simply add them as data files
using "."
(a dot) as directory name when asked by GUI2Exe.
[Ron Barak] I tried your above suggestion. Alas, when the ico file
is not in CWD, I get

 But, when the ico file is copied to the CWD, this error does not
appear.

[Ron Barak] BTW, the ico file is used by a wxGlade 0.6.3 xrc
resource file when building the initial application screen.

Also, apart from the ico file, is there a way to have GUI2Exe
incorporate the xrc file ?

The line in my app that refers to it is:

...
WXGLADE_XML = 'svm_initial_splitter_windows.xrc'    # GUI wxGlade
description
...

 xml_resource = xrc.XmlResource(WXGLADE_XML)

[Ron Barak] Thanks for the prompt answer and good luck with the next
version of GUI2Exe.

Keep in mind that the CWD of a program may or may not be the same as the installed location of the exe and supporting files. If you want to be able to reliably find these files at runtime then you should certainly
not depend on the CWD and be a little smarter about how you load the files and use full pathnames where possible. On Windows you can usually safely use something like os.path.join(os.path.basename(sys.argv[0]),
‘filename’) to get the executable location. Take a look at the wx.StandardPaths class too.


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

Ron,

Barak, Ron wrote:

Hi Robin,

Thanks for your helpful remarks.

However (as was alluded previously on this thread), I'm using GUI2Exe, partially to avoid issues like calculating $path on different file systems.

Ideally, the py2exe created exe would incorporate the two auxiliary (ico and xrc) files, so they won't have to be distributed separately.

To rephrase my question:
How do I make GUI2Exe incorporate the "SVM.ico" and "svm_initial_splitter_windows.xrc" files inside the GUI2Exe created exe file ?

Isn't the answer Andrea gave (2nd post in this thread) you working for you?

Werner

Barak, Ron wrote:

Hi Robin,

Thanks for your helpful remarks.

However (as was alluded previously on this thread), I'm using GUI2Exe, partially to avoid issues like calculating $path on different file systems.

Ideally, the py2exe created exe would incorporate the two auxiliary (ico and xrc) files, so they won't have to be distributed separately.

To rephrase my question:
How do I make GUI2Exe incorporate the "SVM.ico" and "svm_initial_splitter_windows.xrc" files inside the GUI2Exe created exe file ?

These files are referenced in my code like so:

In svm.py

...
from wx import xrc
...
WXGLADE_XML = 'svm_initial_splitter_windows.xrc'
...
xml_resource = xrc.XmlResource(WXGLADE_XML)
self.root = xml_resource.LoadFrame(None,'svm5parser')
...

and in svm_initial_splitter_windows.xrc:

...
       <icon>SVM.ico</icon>
...

BTW, my script works just fine from the command line. It's only when it's compiled into an exe that problems occur.

Bye,
Ron.

As one of the others has already asked, didn't Andrea's solution work? It should have...I know that the icon solution does as I have been doing that for over a year. I don't know about the xrc file as I have yet to compile an application that uses xrc. However, Andrea's solution should work. Even on the off-chance that it doesn't, you should be able to use Robin's suggestion for path finding.

Or you could use Inno Setup to collect all the files you need and install them together in the same folder with an installer.

···

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org
Python Extension Building Network: http://www.pythonlibrary.org

Barak, Ron wrote:

Ideally, the py2exe created exe would incorporate the two auxiliary (ico and xrc) files, so they won't have to be distributed separately.

I don't think py2ex can do this at all. It bundles up the python interpreter and all your python code files, into the *.exe file, but auxiliary data files are simply put alongside them. Icons can be converted to importable python files with img2py, but I don't know if there is any way to convert XRC files similarly -- it would be nice, though.

complex python apps have a whole pile of files to distribute when using py2exe -- but then so do complex apps written in any other language.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Christopher Barker wrote:

Barak, Ron wrote:

Ideally, the py2exe created exe would incorporate the two auxiliary (ico and xrc) files, so they won't have to be distributed separately.

Ah, sorry. I had misunderstood your question before.

I don't think py2ex can do this at all. It bundles up the python interpreter and all your python code files, into the *.exe file, but auxiliary data files are simply put alongside them. Icons can be converted to importable python files with img2py, but I don't know if there is any way to convert XRC files similarly -- it would be nice, though.

Yes, the pywxrc tool can do that.

···

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