[wxPython-users] Retrieving a resource bitmap from a py2exe
application
Robin Dunn
robin at alldunn.com
Mon Apr 2 11:30:48 PDT 2007
Artur Matos wrote:
> Hi to all,
>
> I have an application that displays a fixed bitmap,
> and I am packaging this application as a windows .exe
> file, using py2exe. I am trying to add the bitmap as a
> windows resource, so that it gets packaged inside the
> .exe file. py2exe has a bitmap_resources options that
> allow us to do this, so I've added something like this
> to my setup.py file:
>
> setup(
> windows= [
> {
> ...
> "bitmap_resources": [(1, "a.bmp")
> ...
>
> The problem is on how to access this bitmap from the
> wxPython application. The wiki has some explanation on
> how to do this for icons, but not for bitmaps. I have
> tried to do something similar to what is written in
> the wiki, something like this:
>
> # Gets the name of the application
> exe_name =
> win32api.GetModuleFileName(win32api.GetModuleHandle(None))
> # Retrieves the bitmap
> bitmap = wx.Bitmap("%s;%s" % (exe_name, 1),
> wx.BITMAP_TYPE_BMP)
>
> But this is not working, and I only get an empty
> bitmap. I have noticed that the wxWidgets C++
> documentation has a wxBITMAP_TYPE_BMP_RESOURCE bitmap
> type, so I thought that using that should solve the
> problem, but this type is not defined in wxPython.
> Does anyone has any sugestions to solve this? I am
> using wxPython 2.8.
The main reason that I didn't include the *_RESOURCE IDs is because they
can't be used at all from an unfrozen version of the app, (IOW not
py2exe'd) and I thought that it would be better to not enable that kind
of confusion for developers. What you can do instead that will work in
either form of the program is to embed the image data in a .py file.
See the img2py utility that is installed with wxPython.
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!
More information about the wxpython-users
mailing list