Merge from trunk

This commit is contained in:
Charles Haley 2010-09-09 11:25:34 +01:00
commit a20a9ad3fa
11 changed files with 73 additions and 29 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 161 B

After

Width:  |  Height:  |  Size: 13 KiB

View File

@ -82,7 +82,7 @@ class ITUNES(DriverBase):
''' '''
name = 'Apple device interface' name = 'Apple device interface'
gui_name = 'Apple device' gui_name = _('Apple device')
icon = I('devices/ipad.png') icon = I('devices/ipad.png')
description = _('Communicate with iTunes/iBooks.') description = _('Communicate with iTunes/iBooks.')
supported_platforms = ['osx','windows'] supported_platforms = ['osx','windows']

View File

@ -138,3 +138,11 @@ def check_ebook_format(stream, current_guess):
stream.seek(0) stream.seek(0)
return ans return ans
def calibre_cover(title, author_string, series_string=None,
output_format='jpg', title_size=46, author_size=36):
from calibre.utils.magick.draw import create_cover_page, TextLine
lines = [TextLine(title, title_size), TextLine(author_string, author_size)]
if series_string:
lines.append(TextLine(series_string, author_size))
return create_cover_page(lines, I('library.png'), output_format='jpg')

View File

@ -70,7 +70,7 @@ class ArchiveExtract(FileTypePlugin):
fname = fnames[0] fname = fnames[0]
ext = os.path.splitext(fname)[1][1:] ext = os.path.splitext(fname)[1][1:]
if ext.lower() not in ('lit', 'epub', 'mobi', 'prc', 'rtf', 'pdf', if ext.lower() not in ('lit', 'epub', 'mobi', 'prc', 'rtf', 'pdf',
'mp3', 'pdb', 'azw', 'azw1'): 'mp3', 'pdb', 'azw', 'azw1', 'fb2'):
return archive return archive
of = self.temporary_file('_archive_extract.'+ext) of = self.temporary_file('_archive_extract.'+ext)

View File

@ -89,19 +89,22 @@ class CoverManager(object):
''' '''
Create a generic cover for books that dont have a cover Create a generic cover for books that dont have a cover
''' '''
from calibre.ebooks.metadata import authors_to_string from calibre.ebooks.metadata import authors_to_string, fmt_sidx
if self.no_default_cover: if self.no_default_cover:
return None return None
self.log('Generating default cover') self.log('Generating default cover')
m = self.oeb.metadata m = self.oeb.metadata
title = unicode(m.title[0]) title = unicode(m.title[0])
authors = [unicode(x) for x in m.creator if x.role == 'aut'] authors = [unicode(x) for x in m.creator if x.role == 'aut']
series_string = None
if m.series and m.series_index:
series_string = _('Book %s of %s')%(
fmt_sidx(m.series_index[0], use_roman=True), m.series[0])
try: try:
from calibre.utils.magick.draw import create_cover_page, TextLine from calibre.ebooks import calibre_cover
lines = [TextLine(title, 44), TextLine(authors_to_string(authors), img_data = calibre_cover(title, authors_to_string(authors),
32)] series_string=series_string)
img_data = create_cover_page(lines, I('library.png'))
id, href = self.oeb.manifest.generate('cover_image', id, href = self.oeb.manifest.generate('cover_image',
'cover_image.jpg') 'cover_image.jpg')
item = self.oeb.manifest.add(id, href, guess_type('t.jpg')[0], item = self.oeb.manifest.add(id, href, guess_type('t.jpg')[0],

View File

@ -58,7 +58,8 @@ class BulkConfig(Config):
output_path = 'dummy.'+output_format output_path = 'dummy.'+output_format
log = Log() log = Log()
log.outputs = [] log.outputs = []
self.plumber = Plumber(input_path, output_path, log) self.plumber = Plumber(input_path, output_path, log,
merge_plugin_recs=False)
def widget_factory(cls): def widget_factory(cls):
return cls(self.stack, self.plumber.get_option_by_name, return cls(self.stack, self.plumber.get_option_by_name,

View File

@ -144,15 +144,23 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog):
self.cover_data = cover self.cover_data = cover
def generate_cover(self, *args): def generate_cover(self, *args):
from calibre.utils.magick.draw import create_cover_page, TextLine from calibre.ebooks import calibre_cover
from calibre.ebooks.metadata import fmt_sidx
from calibre.gui2 import config
title = unicode(self.title.text()).strip() title = unicode(self.title.text()).strip()
author = unicode(self.authors.text()).strip() author = unicode(self.authors.text()).strip()
if not title or not author: if not title or not author:
return error_dialog(self, _('Specify title and author'), return error_dialog(self, _('Specify title and author'),
_('You must specify a title and author before generating ' _('You must specify a title and author before generating '
'a cover'), show=True) 'a cover'), show=True)
lines = [TextLine(title, 44), TextLine(author, 32)] series = unicode(self.series.text()).strip()
self.cover_data = create_cover_page(lines, I('library.png')) series_string = None
if series:
series_string = _('Book %s of %s')%(
fmt_sidx(self.series_index.value(),
use_roman=config['use_roman_numerals_for_series_number']), series)
self.cover_data = calibre_cover(title, author,
series_string=series_string)
pix = QPixmap() pix = QPixmap()
pix.loadFromData(self.cover_data) pix.loadFromData(self.cover_data)
self.cover.setPixmap(pix) self.cover.setPixmap(pix)

View File

@ -215,6 +215,7 @@ class ToolBar(QToolBar): # {{{
self.location_manager.locations_changed.connect(self.build_bar) self.location_manager.locations_changed.connect(self.build_bar)
donate.setAutoRaise(True) donate.setAutoRaise(True)
donate.setCursor(Qt.PointingHandCursor) donate.setCursor(Qt.PointingHandCursor)
self.added_actions = []
self.build_bar() self.build_bar()
self.preferred_width = self.sizeHint().width() self.preferred_width = self.sizeHint().width()
@ -237,7 +238,13 @@ class ToolBar(QToolBar): # {{{
actions = '-device' if showing_device else '' actions = '-device' if showing_device else ''
actions = gprefs['action-layout-toolbar'+actions] actions = gprefs['action-layout-toolbar'+actions]
for ac in self.added_actions:
m = ac.menu()
if m is not None:
m.setVisible(False)
self.clear() self.clear()
self.added_actions = []
for what in actions: for what in actions:
if what is None: if what is None:
@ -245,6 +252,7 @@ class ToolBar(QToolBar): # {{{
elif what == 'Location Manager': elif what == 'Location Manager':
for ac in self.location_manager.available_actions: for ac in self.location_manager.available_actions:
self.addAction(ac) self.addAction(ac)
self.added_actions.append(ac)
self.setup_tool_button(ac, QToolButton.MenuButtonPopup) self.setup_tool_button(ac, QToolButton.MenuButtonPopup)
elif what == 'Donate': elif what == 'Donate':
self.d_widget = QWidget() self.d_widget = QWidget()
@ -255,6 +263,7 @@ class ToolBar(QToolBar): # {{{
elif what in self.gui.iactions: elif what in self.gui.iactions:
action = self.gui.iactions[what] action = self.gui.iactions[what]
self.addAction(action.qaction) self.addAction(action.qaction)
self.added_actions.append(action.qaction)
self.setup_tool_button(action.qaction, action.popup_type) self.setup_tool_button(action.qaction, action.popup_type)
def setup_tool_button(self, ac, menu_mode=None): def setup_tool_button(self, ac, menu_mode=None):

View File

@ -173,6 +173,7 @@ class EbookViewer(MainWindow, Ui_EbookViewer):
self.pending_anchor = None self.pending_anchor = None
self.pending_reference = None self.pending_reference = None
self.pending_bookmark = None self.pending_bookmark = None
self.existing_bookmarks= []
self.selected_text = None self.selected_text = None
self.read_settings() self.read_settings()
self.dictionary_box.hide() self.dictionary_box.hide()
@ -415,15 +416,6 @@ class EbookViewer(MainWindow, Ui_EbookViewer):
self.action_font_size_smaller.setEnabled(self.view.multiplier() > 0.2) self.action_font_size_smaller.setEnabled(self.view.multiplier() > 0.2)
self.set_page_number(frac) self.set_page_number(frac)
def bookmark(self, *args):
title, ok = QInputDialog.getText(self, _('Add bookmark'), _('Enter title for bookmark:'))
title = unicode(title).strip()
if ok and title:
pos = self.view.bookmark()
bookmark = '%d#%s'%(self.current_index, pos)
self.iterator.add_bookmark((title, bookmark))
self.set_bookmarks(self.iterator.bookmarks)
def find(self, text, repeat=False, backwards=False): def find(self, text, repeat=False, backwards=False):
if not text: if not text:
@ -539,15 +531,34 @@ class EbookViewer(MainWindow, Ui_EbookViewer):
getattr(self, o).setEnabled(False) getattr(self, o).setEnabled(False)
self.setCursor(Qt.BusyCursor) self.setCursor(Qt.BusyCursor)
def bookmark(self, *args):
num = 1
bm = None
while True:
bm = _('Bookmark #%d')%num
if bm not in self.existing_bookmarks:
break
num += 1
title, ok = QInputDialog.getText(self, _('Add bookmark'),
_('Enter title for bookmark:'), text=bm)
title = unicode(title).strip()
if ok and title:
pos = self.view.bookmark()
bookmark = '%d#%s'%(self.current_index, pos)
self.iterator.add_bookmark((title, bookmark))
self.set_bookmarks(self.iterator.bookmarks)
def set_bookmarks(self, bookmarks): def set_bookmarks(self, bookmarks):
self.bookmarks_menu.clear() self.bookmarks_menu.clear()
self.bookmarks_menu.addAction(_("Manage Bookmarks"), self.manage_bookmarks) self.bookmarks_menu.addAction(_("Manage Bookmarks"), self.manage_bookmarks)
self.bookmarks_menu.addSeparator() self.bookmarks_menu.addSeparator()
current_page = None current_page = None
self.existing_bookmarks = []
for bm in bookmarks: for bm in bookmarks:
if bm[0] == 'calibre_current_page_bookmark': if bm[0] == 'calibre_current_page_bookmark':
current_page = bm current_page = bm
else: else:
self.existing_bookmarks.append(bm[0])
self.bookmarks_menu.addAction(bm[0], partial(self.goto_bookmark, bm)) self.bookmarks_menu.addAction(bm[0], partial(self.goto_bookmark, bm))
return current_page return current_page

View File

@ -165,11 +165,16 @@ def create_cover_page(top_lines, logo_path, width=590, height=750,
top = height - lheight - 10 top = height - lheight - 10
canvas.compose(vanity, left, top) canvas.compose(vanity, left, top)
available = (width, int(top - bottom)-20)
if available[1] > 40:
logo = Image() logo = Image()
logo.open(logo_path) logo.open(logo_path)
lwidth, lheight = logo.size 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.)) left = int(max(0, (width - lwidth)/2.))
top = max(int((height - lheight)/2.), bottom+20) top = bottom+10
canvas.compose(logo, left, top) canvas.compose(logo, left, top)
return canvas.export(output_format) return canvas.export(output_format)

View File

@ -1018,12 +1018,11 @@ class BasicNewsRecipe(Recipe):
Create a generic cover for recipes that dont have a cover Create a generic cover for recipes that dont have a cover
''' '''
try: try:
from calibre.utils.magick.draw import create_cover_page, TextLine from calibre.ebooks import calibre_cover
title = self.title if isinstance(self.title, unicode) else \ title = self.title if isinstance(self.title, unicode) else \
self.title.decode(preferred_encoding, 'replace') self.title.decode(preferred_encoding, 'replace')
date = strftime(self.timefmt) date = strftime(self.timefmt)
lines = [TextLine(title, 44), TextLine(date, 32)] img_data = calibre_cover(title, date)
img_data = create_cover_page(lines, I('library.png'), output_format='jpg')
cover_file.write(img_data) cover_file.write(img_data)
cover_file.flush() cover_file.flush()
except: except: