View Single Post
Old 12-15-2010, 12:09 PM   #17
kiwidude
calibre/Sigil Developer
kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.
 
Posts: 4,224
Karma: 1334002
Join Date: Oct 2010
Location: London, UK
Device: Kindle Paperwhite 3G, iPad 3, iPad Air
Ok, I've given that method a go. I guess my head was still thinking about that config\resources\images directory and being able to make use of that. However I can see where you are coming from in terms of keeping the plugin completely self-contained even after "install".

Being in the resources directory did have a minor advantage in that it means that you can use self.create_action to create your menus since that just takes an icon name, however now you must pass None to that for the icon and then use a separate .setIcon call afterwards.

The other potential nasty with this approach is typified by the search the internet plugin where users can have custom images for when they add their own websites to the menu. That means either:
- they should manually add their images to the plugin zip file within the Calibre configuration folder (and remember to do that any time they upgrade the plugin). Don't like that idea.
- or I support them using the config/resources/images directory. In which case I have to trap ValueError since I don't know whether an icon will or won't be in the zip when building the menus with code like this:

Code:
                        actual_icon = None
                        try:
                            resource = self.load_resource(icon_name)
                            pixmap = QPixmap()
                            pixmap.loadFromData(resource)
                            actual_icon = QIcon(pixmap)
                        except ValueError:
                            actual_icon = QIcon(I(icon_name))
                        ac.setIcon(actual_icon)
And yeah as Chaley says if you have a lot of icons you are opening/closing the zip a lot of times.

I've written the code, and it works, but I won't publish it on the gui plugins thread until the next version of Calibre is out and you are 100% happy that this is the approach you want to take. I don't mind tweaking the plugin code further if anything is changed.

EDIT: Didn't see Kovid's post above that had made a further change to the API, let me give that a go...

Last edited by kiwidude; 12-15-2010 at 12:17 PM.
kiwidude is offline   Reply With Quote