Py2Exe & Img2Py - 编译后图像丢失

发布于 2024-10-01 00:54:19 字数 764 浏览 7 评论 0原文

我不知道从哪里开始描述我遇到的问题。

我有一个使用大量图像的项目。工具栏、菜单、列表等。我正在 Eclipse 中使用 PyDev 进行开发。我能够从 Eclipse 中成功运行我的程序,但需要将其编译为可执行文件,以便可以部署它。

当我第一次尝试使用 Py2Exe 进行编译时,没有加载任何图像,因为它们使用的是相对路径。我在这里找到信息:http://www.daniweb.com/forums/thread255458.html 包含有关如何将相对路径转换为绝对路径的信息,但选择不走该路线,因为它需要在所有图像路径上使用额外的包装器。

相反,我选择使用 Img2Py 将所有图像转换为资源文件。我现在有一个资源文件夹,其中包含应用程序所需的每个图像的 .py 文件。使用 Py2Exe 重新编译时,我能够验证library.bin zip 文件是否包含我的资源文件夹以及每个图像的相应 .pyo 文件。当我启动可执行文件时,大部分图像都不会显示。例如,在我的工具栏上,启用状态图像正确显示,而禁用状态图像丢失。在我的列表中根本没有显示任何图像。菜单中的图像正确显示。

在我的 Toolbar 类中,如果我放弃禁用图像并允许 wx 使用它的默认行为将禁用状态显示的启用图像变灰,但这对我的列表图标没有帮助。我什至不确定哪些代码与此处显示相关 - 一切都在 Eclipse 中正常工作,只有在使用 Py2Exe 编译后我才遇到这些问题。

任何建议或建议将不胜感激。提前致谢,

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 resource 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,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

人心善变 2024-10-08 00:54:19

通过在对 img2py 的调用中添加 append=True 选项并删除图像模块名称中的下划线,我能够克服这个问题。考虑到有效的图像名称中也包含下划线,我不明白为什么这会产生影响,但它似乎允许我解决这个问题。我生成图像资源的代码最终是这样的:

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)

希望这对将来的其他人有用。我知道我最终会再次提及它。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文