View Single Post
Old 10-20-2012, 08:55 AM   #1
Buzzy
Junior Member
Buzzy began at the beginning.
 
Posts: 8
Karma: 10
Join Date: Oct 2012
Device: none
Help with plugin dev.

Hi,

I need some help with plugin development. Firstly, I'm not familiar with the intricacies of Python but I can't get any debugging output to appear using print, write or anything else, based on the suggestions in the plugin dev. pages on the calibre site. Not a character. I've stuck statements all over the code in places that are definitely being hit. What am I doing wrong? Do I need to redirect output somewhere specific. I'm running from the console using calibre-debug.

Secondly, I want to have my plugin generate its own cover and use it with the book it creates. I have that working but I can't find any way to prevent the default background texture from being drawn (which, I agree with comments elsewhere, isn't particularly nice). I've gone as far as to d/l the source and find where it's added but nothing I do anywhere stops it appearing. I've overridden the relevant functions, thus:

def calibre_cover(title, author_string, series_string=None, output_format='jpg', title_size=46, author_size=36, logo_path=None):
title = normalize(title)
author_string = normalize(author_string)
series_string = normalize(series_string)
# from calibre.utils.magick.draw import create_cover_page, TextLine
from calibre.utils.magick.draw import TextLine
lines = [TextLine(title, title_size), TextLine(author_string, author_size)]
if series_string:
lines.append(TextLine(series_string, author_size))
if logo_path is None:
logo_path = I('library.png')
return self.create_cover_page(lines, logo_path, output_format='jpg', texture_opacity=0.3, texture_data=I('add_book.png', data=False))

def create_cover_page(top_lines, logo_path, width=590, height=750, bgcolor='#ffffff', output_format='jpg', texture_data=None, texture_opacity=1.0):
'''
Create the standard calibre cover page and return it as a byte string in
the specified output_format.
'''
canvas = create_canvas(width, height, bgcolor)
if texture_data and hasattr(canvas, 'texture'):
texture = Image()
texture.load(texture_data)
texture.set_opacity(texture_opacity)
canvas.texture(texture)

bottom = 10
for line in top_lines:
twand = create_text_wand(line.font_size, font_path=line.font_path)
bottom = draw_centered_text(canvas, twand, line.text, bottom)
bottom += line.bottom_margin
bottom -= top_lines[-1].bottom_margin

foot_font = tweaks['generate_cover_foot_font']
if not foot_font:
foot_font = P('fonts/liberation/LiberationMono-Regular.ttf')
vanity = create_text_arc(__appname__ + ' ' + __version__, 24,
font=foot_font, bgcolor='#00000000')
lwidth, lheight = vanity.size
left = int(max(0, (width - lwidth)/2.))
top = height - lheight - 10
canvas.compose(vanity, left, top)

available = (width, int(top - bottom)-20)
if available[1] > 40:
logo = Image()
logo.open(logo_path)
lwidth, lheight = logo.size
scaled, lwidth, lheight = fit_image(lwidth, lheight, *available)
if scaled:
logo.size = (lwidth, lheight)
left = int(max(0, (width - lwidth)/2.))
top = bottom+10
extra = int((available[1] - lheight)/2.0)
if extra > 0:
top += extra
canvas.compose(logo, left, top)

return canvas.export(output_format)


I tried just using calibre_cover first and changing the values in the call to create_cover_page. Then I tried replacing create_cover_page. The thing just fails to use my cover at all and generates the default version,. I'm probably doing something silly but what? I've tried everything I can think of in the recipe and in main.py, including setting texture_data to none, changing opacity, disabling function calls, attempting to use a different texture as above, etc. Nothing works.

My plugin works well otherwise so it is called, it runs, it outputs, it's updated between runs, it lives and breathes and I disabled the related imports. It's more likely to be my lack of knowledge re: python and calibre, than something procedural. If we can fix point 1 that will undoubtedly help with point 2.

Thanks.
Buzzy is offline   Reply With Quote