开发者

Py2Exe & Img2Py - Images Missing after Compiling

开发者 https://www.devze.com 2023-01-23 12:19 出处:网络
I am not sure where to even begin describing the issue I\'m having. I have a project which uses a large number of images.Toolbars, Menus, Lists, etc.I\'m developing in Eclipse with PyDev.I\'m able to

I am not sure where to even begin describing the issue I'm having.

I have a project which uses a large number of images. Toolbars, Menus, Lists, etc. I'm developing in Eclipse with PyDev. I'm able to run my program from within Eclipse successfully, but will need to compile it to an executable so it can be deployed.

When I first attempted to compile using Py2Exe none of my images loaded because they were using relative paths. I found information here: http://www.daniweb.com/forums/thread255458.html with information about how to turn relative paths into absolute paths, but opted not to go that route as it required an extra wrapper on all image paths.

Instead, I opted to use Img2Py to convert all of my images into Resource Files. I now have a resource folder that contains .py files for each image that's required by my application. When re-compiling with Py2Exe I am able to verify that the library.bin zip file contains my resou开发者_如何学编程rce folder and the corresponding .pyo files for each image. When I launch my executable most of my images do not display. On my Toolbars, for example, Enabled state images are shown properly while Disabled state images are missing. In my Lists none of my images display at all. In the Menus images appear properly.

In my Toolbar class, if I leave off the Disabled Images and instead allow wx to use it's default behavior to gray the Enabled Images the Disabled state displays, but that doesn't help me with my List Icons. I'm not even sure what code is relevant to show here - everything works properly in Eclipse, it's only after compiling using Py2Exe that I encounter these issues.

Any suggestions or advice will be much appreciated. Thanks in advance,


I was able to overcome this by adding the append=True option to my calls to img2py and by removing underscores in the image module names. I don't understand why this had an effect considering that the images that worked also contained underscores in their names, but it appears to have allowed me to step around the problem. My code to generate the Images resource ends up being this:

from wx.tools.img2py import img2py
from glob import glob

for f in glob('*.png'):
  o = f.replace('-', '').replace('_', '').replace('.png', '')
  img2py(f, 'Images.py', append=True, imgName=o, icon=True)

Hopefully this may prove useful to someone else in the future. I know I'll end up referring back to it.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号