Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Software > Calibre > Plugins

Notices

Reply
 
Thread Tools Search this Thread
Old 12-15-2010, 11:02 AM   #16
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,826
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Quote:
Originally Posted by chaley View Post
Wouldn't it be even faster if the method took a list of names and returned a dict {name: file_contents, }? That would permit the zip to be opened once to retrieve all the resources. Instead of ValueError, it could return {name: None} if it can't find a particular resource.
Done.
kovidgoyal is offline   Reply With Quote
Old 12-15-2010, 12:09 PM   #17
kiwidude
Calibre Plugins 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,635
Karma: 2162064
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
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
Old 12-15-2010, 12:17 PM   #18
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 11,728
Karma: 6690881
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by kiwidude View Post
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)
Given the new list interface, the problem becomes much more tractable. You load the icons you need from the zip into the dict. Some might not be there. You then loop through the items you need using a simple if x in list: test. If they is in the dict, cool. If not, you use the file approach. That lets the customizers put their icons in the local resources/images directory (or a subdir if they want to). There is almost zero time penalty because the zip scan was done once and you would need to open the files anyway.
Quote:
And yeah as Chaley says if you have a lot of icons you are opening/closing the zip a lot of times.
Problem gone with list interface.
chaley is offline   Reply With Quote
Old 12-15-2010, 12:18 PM   #19
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,826
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
I'm happy with the approach. I've already fixed the multiple open problem. Feel free to update your plugin after the next release.
kovidgoyal is offline   Reply With Quote
Old 12-15-2010, 12:28 PM   #20
kiwidude
Calibre Plugins 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,635
Karma: 2162064
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
Thanks Chaley/Kovid, I'll give that a go, looks more optimised. I do like the idea of being able to distribute a plugin that is just one zip the user never has to open. It should work nicely and much prefer as you say a test for presence in a dictionary over catching errors.
kiwidude is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
New Plugin Type Idea: Library Plugin cgranade Plugins 3 09-15-2010 12:11 PM
Multicomputer Sync users - Do you sync the Config directory? Starson17 Calibre 4 07-29-2010 01:07 AM
How do I Create a Python Plugin? Sydney's Mom Plugins 25 01-27-2010 06:26 AM
How do I do create a directory on a PRS-500? JSWolf Calibre 5 11-25-2009 11:53 AM
Statusbar config? tselling PocketBook 0 11-13-2009 10:47 AM


All times are GMT -4. The time now is 09:30 AM.


MobileRead.com is a privately owned, operated and funded community.