Allow passing importable file formats as arguments to ebook-edit

This commit is contained in:
Kovid Goyal 2014-02-27 18:53:51 +05:30
parent 33a2a38cd7
commit 5081bb93f1
4 changed files with 17 additions and 5 deletions

View File

@ -15,6 +15,8 @@ from calibre.ebooks.epub import initialize_container
from calibre.utils.logging import default_log
IMPORTABLE = {'htm', 'xhtml', 'html', 'xhtm', 'docx'}
def auto_fill_manifest(container):
manifest_id_map = container.manifest_id_map
manifest_name_map = {v:k for k, v in manifest_id_map.iteritems()}

View File

@ -167,10 +167,12 @@ class Boss(QObject):
create_book(d.mi, path, fmt=fmt)
self.open_book(path=path)
def import_book(self):
def import_book(self, path=None):
if not self._check_before_open():
return
d = ImportForeign(self.gui)
if hasattr(path, 'rstrip'):
d.set_src(os.path.abspath(path))
if d.exec_() == d.Accepted:
from calibre.ebooks.oeb.polish.import_book import import_book_as_epub
src, dest = d.data
@ -192,6 +194,9 @@ class Boss(QObject):
ext = path.rpartition('.')[-1].upper()
if ext not in SUPPORTED:
from calibre.ebooks.oeb.polish.import_book import IMPORTABLE
if ext.lower() in IMPORTABLE:
return self.import_book(path)
return error_dialog(self.gui, _('Unsupported format'),
_('Tweaking is only supported for books in the %s formats.'
' Convert your book to one of these formats first.') % _(' and ').join(sorted(SUPPORTED)),

View File

@ -189,11 +189,15 @@ class ImportForeign(Dialog): # {{{
l.addRow(self.bb)
def choose_source(self):
from calibre.ebooks.oeb.polish.import_book import IMPORTABLE
path = choose_files(self, 'edit-book-choose-file-to-import', _('Choose file'), filters=[
(_('HTML or DOCX files'), ['htm', 'html', 'xhtml', 'xhtm', 'docx'])], select_only_single_file=True)
(_('Importable files'), list(IMPORTABLE))], select_only_single_file=True)
if path:
self.src.setText(path[0])
self.dest.setText(self.data[1])
self.set_src(path[0])
def set_src(self, path):
self.src.setText(path)
self.dest.setText(self.data[1])
def choose_destination(self):
path = choose_save_file(self, 'edit-book-destination-for-generated-epub', _('Choose destination'), filters=[

View File

@ -549,11 +549,12 @@ class PostInstall:
from calibre.utils.smtp import option_parser as smtp_op
from calibre.library.server.main import option_parser as serv_op
from calibre.ebooks.oeb.polish.main import option_parser as polish_op, SUPPORTED
from calibre.ebooks.oeb.polish.import_book import IMPORTABLE
from calibre.debug import option_parser as debug_op
from calibre.ebooks import BOOK_EXTENSIONS
from calibre.customize.ui import available_input_formats
input_formats = sorted(all_input_formats())
tweak_formats = sorted(x.lower() for x in SUPPORTED)
tweak_formats = sorted(x.lower() for x in SUPPORTED|IMPORTABLE)
zsh = ZshCompleter(self.opts)
bc = os.path.join(os.path.dirname(self.opts.staging_sharedir),
'bash-completion')