![]() |
#1 |
frumious Bandersnatch
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 7,543
Karma: 19001583
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
|
Using image in plugin code
In the Prince PDF plugin I use two small images in the "about" dialog (second screnshot in that thread). However, I just noticed it doesn't work. In fact, the images are not read from the plugin file, but from the current directory, so I only see the images if I launch calibre from the directory where I'm developing the plugin (that's why I thought it worked before).
What I want is using the images in HTML code, which currently looks something like this: Code:
<p style="margin:1em 0 0 0"><img src=":images/prince_icon.png"/> <i>Prince is copyrighted © YesLogic Pty. Ltd.</i></p> <p style="margin:0"><img src=":images/small_icon.png"/> This plugin is released under GPL v3.</p> |
![]() |
![]() |
![]() |
#2 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,157
Karma: 27110894
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
In what context are you using this HTML file? Just extract the images into a temp directory and use absolute paths to them, that way it will always work.
|
![]() |
![]() |
Advert | |
|
![]() |
#3 |
frumious Bandersnatch
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 7,543
Karma: 19001583
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
|
It's just the text for the "about" or "help" dialog (inside the plugin). I simply define a variable with the HTML code:
Code:
help_txt = _(''' <h3 style="text-align:center">The Prince PDF Plugin</h3> <p style="text-align:center"><i>Created by Jellby</i></p> ... <p style="margin:1em 0 0 0"><i><img src=":images/prince_icon.png"/> Prince is copyrighted © YesLogic Pty. Ltd.</i></p> <p style="margin:0"><img src=":images/small_icon.png"/> This plugin is released under GPL v3.</p> ''') Code:
QMessageBox.about(self, _('About the Prince PDF Plugin'), help_txt) |
![]() |
![]() |
![]() |
#4 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,157
Karma: 27110894
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Code:
from calibre.ptempfile import TemporaryDirectory with TemporaryDirectory('xxx') as tdir: for x in ('one.jpg', 'two.jpg'): with open(os.path.join(tdir, x) as f: f.write(get_resources('images/' + x)) about.exec_() |
![]() |
![]() |
![]() |
#5 | |
frumious Bandersnatch
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 7,543
Karma: 19001583
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
|
Quote:
Code:
with open(os.path.join(tdir, x),'w') as f: ![]() A minor, probably trivial question: How can I access the "version" defined in __init__ (or "name", or "author"...) from elsewhere inside the plugin code? |
|
![]() |
![]() |
Advert | |
|
![]() |
#6 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,157
Karma: 27110894
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
from calibre_plugins.<plugin_name> import version
|
![]() |
![]() |
![]() |
#7 |
frumious Bandersnatch
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 7,543
Karma: 19001583
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
|
That works for __copyright__, which is defined outside the class, but not for version, which is inside:
Code:
from __future__ import (unicode_literals, division, absolute_import, print_function) __license__ = 'GPL v3' __copyright__ = '2014, Jellby <jellby@yahoo.com>' __docformat__ = 'restructuredtext en' from calibre.customize import InterfaceActionBase load_translations() class PrincePDFPlugin(InterfaceActionBase): name = _('Prince PDF') description = _('Converts to PDF using the Prince software (third-party)') supported_platforms = ['linux', 'windows'] author = 'Jellby' version = (1, 1, 3) minimum_calibre_version = (1, 16, 0) actual_plugin = 'calibre_plugins.prince_pdf.ui:InterfacePlugin' ... I must be doing something wrong. Last edited by Jellby; 03-11-2014 at 02:51 PM. |
![]() |
![]() |
![]() |
#8 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,157
Karma: 27110894
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
So either define version outside the class like this
version = xxx class MyClass: version = version or import the class from calibre_plugins.plugin_name import MyClass version = MyClass.version |
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Plugin not customizable: Plugin: HTML Output does not need customization | flyingfoxlee | Conversion | 2 | 02-24-2012 02:24 AM |
[GUI Plugin] Plugin Updater **Deprecated** | kiwidude | Plugins | 159 | 06-19-2011 12:27 PM |
New Plugin Type Idea: Library Plugin | cgranade | Plugins | 3 | 09-15-2010 12:11 PM |
Let's create a source code repository for DR 800 related code? | jraf | iRex | 3 | 03-11-2010 12:26 PM |
iLiad Is source code of iLiad image viewer available? | ericshliao | iRex Developer's Corner | 1 | 01-16-2008 02:24 AM |