MobileRead Forums

MobileRead Forums (https://www.mobileread.com/forums/index.php)
-   Development (https://www.mobileread.com/forums/forumdisplay.php?f=240)
-   -   Calibre plugin image resources (https://www.mobileread.com/forums/showthread.php?t=266777)

jackie_w 10-26-2015 11:07 AM

Calibre plugin image resources
 
I'm trying to convert a Python script (run via calibre-debug -e) to a plugin and am having a bit of trouble translating the image processing.

In the script I was using:

Code:

dummyimg = Image()
dummyimg.open(path_to_img_on_PC)
dummyimg.size = (wid, hgt)
dummyimg.save(path_to_exploded_ebook_image)

In the plugin:
In previous plugins, using the 'copy-something-someone-else-did' method, I've used code in the genesis method like
Code:

self.icons = get_icons(['images/plugin_icon.png', 'images/pic1.png', ...])
to pass icons to the plugin, but this time the images are not going to be used as QIcons.

Does the way I pass the images to the plugin need to change in genesis or do I need a way of converting the QIcon() data from get_resources('images/pic1.png') to an instance of Image() ?

Advice, please :)

kovidgoyal 10-26-2015 12:01 PM

Use get_resources instead of get_icons that will get you the raw image data which you can use with the Image object as

img.load(data)

instead of image.open(data)

but if all you want to do is resize and save the image, the QIcon class is perfectly capable of doing that, like this

qicon.pixmap(width, height).save(path to file)

jackie_w 10-26-2015 12:16 PM

Looks easy enough. Thanks :)

jackie_w 10-26-2015 12:27 PM

Followup question...

get_resources is available to the top level main Class. If the main Class calls another Class which calls another Class ... etc

Is the get_resources() method still available to the lower level Classes?

kovidgoyal 10-26-2015 12:47 PM

yes, get_resources() is a global function, vaialbale throughout plugin code

jackie_w 10-27-2015 09:00 AM

Question re: calibre library paths.

When running a plugin from calibre library X, is there a way to query calibre for a list of other library paths it knows about?

I'm familiar with this for the current library path:
Code:

db = self.gui.current_db
currlib_path = db.library_path

I want to include a basic test to avoid saving a scrambled book anywhere inside the calibre library system.

kovidgoyal 10-27-2015 09:11 AM

self.gui.iactions['Choose Library'].stats.stats

jackie_w 10-27-2015 09:29 AM

Thanks :)

jackie_w 10-27-2015 01:31 PM

Back again ...

To date when I've wanted to include an ebook preview dialog I've used something like
Code:

webview = QWebView()

name = 'xyz'
webview.load(QUrl.fromLocalFile(container.name_path_map[name]))

or
Code:

webview.reload
I'm unsure whether the above are suitable on anything other than Windows.

Since I'm trying to do things 'the calibre way' in this little exercise, please can you advise whether I should be doing something different.

Thanks in advance :)

kovidgoyal 10-27-2015 02:40 PM

That's fine. Although, you should be using name_to_abspath() rather than name_path_map.

jackie_w 10-27-2015 03:01 PM

OK, will do. Thanks :)


All times are GMT -4. The time now is 08:29 PM.

Powered by: vBulletin
Copyright ©2000 - 3.8.5, Jelsoft Enterprises Ltd.
MobileRead.com is a privately owned, operated and funded community.