如何处理 PyGTK ComboBox 中的缓慢渲染
我在 PyGTK 中实现了一个自定义 CellRenderer,其渲染时间可能比理想情况要长。可能有多个图像需要缩放,因此当用户单击 ComboBox 时,在渲染完成之前它甚至不会显示弹出窗口。如果我可以显示弹出窗口,然后渲染图像,那就没问题了。您可以在我的 Google 代码存储库。
我已经实现了缓存,因此在第一次加载后,它将从内存或磁盘中加载单个图像,但第一次加载每个单元可能需要 2-4 秒。
我考虑实现的事情包括,在应用程序加载时弹出组合框,以便强制它渲染图像。这在我运行的测试中似乎不起作用。
我还尝试创建一个不可见的 CairoContext 和表面,但我要求它是 gtk.gdk.CairoContext,我认为如果没有实际的小部件就无法启动它。我有可能在屏幕外的小部件中渲染它,但我不确定这是否是一个好主意,甚至可能。
I have implemented a custom CellRenderer in PyGTK that can take longer to render than is ideal. There can be multiple images that have to be scaled, so when the user clicks on the ComboBox, it won't even show the popup until the rendering is completed. If I can show the popup, and then render the image, that would be fine. You can look at it on my Google Code Repository.
I have implemented caching, so that after it loads the first time, it will load from a single image from memory or disk, but the first time it loads can take 2-4 seconds per cell.
The things that I have thought of implementing, include, pop up the combobox when the application loads, so that it forces it to render the image. This does not seem to be working in the tests I have run.
I have also tried to create a CairoContext and surface that is not visible, but I require it to be a gtk.gdk.CairoContext, which I don't think can be initiated without an actual widget. There's a possibility that I could render this in a widget offscreen, but I'm not sure if that's a good idea, or even possible.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我使用了一个在屏幕加载后使用idle_add渲染的Pixmap,因为它不会初始化窗口,直到它被渲染在屏幕上的窗口内。您可以在 themeselect.py 中找到代码。查看 load_theme_thumbs() 和 _get_pixmap()。
I used a Pixmap that was rendered using idle_add once the screen loaded, since it would not initialize the window until it was rendered inside a window on screen. You can find the code in themeselect.py. Look at load_theme_thumbs(), and _get_pixmap().
正如您提到的,我认为将其渲染到屏幕外并没有什么坏处,并且出于类似的原因我也这样做了。除非你正在做一些非常奇怪的事情,否则这应该是可能的。
I see no harm in rendering it offscreen, as you mentioned, and I've done so for similar reasons. It should be possible unless you're doing something very odd.