mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 02:34:06 -04:00
Move definition of valid_empty_formats to a better location
This commit is contained in:
parent
1c945b2d19
commit
2168bb9102
@ -24,6 +24,8 @@ from calibre.utils.localization import lang_as_iso639_1
|
||||
from calibre.utils.logging import DevNull
|
||||
from calibre.utils.zipfile import ZipFile, ZIP_STORED
|
||||
|
||||
valid_empty_formats = {'epub', 'txt', 'docx', 'azw3'}
|
||||
|
||||
def create_toc(mi, opf, html_name, lang):
|
||||
uuid = ''
|
||||
for u in opf.xpath('//*[@id="uuid_id"]'):
|
||||
@ -34,7 +36,9 @@ def create_toc(mi, opf, html_name, lang):
|
||||
|
||||
def create_book(mi, path, fmt='epub', opf_name='metadata.opf', html_name='start.xhtml', toc_name='toc.ncx'):
|
||||
''' Create an empty book in the specified format at the specified location. '''
|
||||
if fmt not in ['epub', 'azw3']:
|
||||
if fmt not in valid_empty_formats:
|
||||
raise ValueError('Cannot create empty book in the %s format' % fmt)
|
||||
if fmt not in {'epub', 'azw3'}:
|
||||
return
|
||||
path = os.path.abspath(path)
|
||||
lang = 'und'
|
||||
|
@ -14,7 +14,7 @@ from PyQt5.Qt import QPixmap, QTimer
|
||||
from calibre import as_unicode
|
||||
from calibre.gui2 import (error_dialog, choose_files, choose_dir,
|
||||
warning_dialog, info_dialog, gprefs)
|
||||
from calibre.gui2.dialogs.add_empty_book import AddEmptyBookDialog, valid_empty_formats
|
||||
from calibre.gui2.dialogs.add_empty_book import AddEmptyBookDialog
|
||||
from calibre.gui2.dialogs.confirm_delete import confirm
|
||||
from calibre.gui2.dialogs.progress import ProgressDialog
|
||||
from calibre.gui2.widgets import IMAGE_EXTENSIONS
|
||||
@ -79,6 +79,7 @@ class AddAction(InterfaceAction):
|
||||
ma('add-formats', _('Add files to selected book records'),
|
||||
triggered=self.add_formats, shortcut='Shift+A')
|
||||
arm = self.add_archive_menu = self.add_menu.addMenu(_('Add an empty file to selected book records'))
|
||||
from calibre.ebooks.oeb.polish.create import valid_empty_formats
|
||||
for fmt in sorted(valid_empty_formats):
|
||||
self.create_menu_action(arm, 'add-empty-' + fmt,
|
||||
_('Add empty {}').format(fmt.upper())).triggered.connect(
|
||||
|
@ -12,7 +12,6 @@ from calibre.gui2.complete2 import EditWithComplete
|
||||
from calibre.utils.config import tweaks
|
||||
from calibre.gui2 import gprefs
|
||||
|
||||
valid_empty_formats = {'epub', 'txt', 'docx', 'azw3'}
|
||||
|
||||
class AddEmptyBookDialog(QDialog):
|
||||
|
||||
@ -81,6 +80,7 @@ class AddEmptyBookDialog(QDialog):
|
||||
self.format_label = QLabel(_('Also create an empty ebook in format:'))
|
||||
self._layout.addWidget(self.format_label, 8, 0, 1, 2)
|
||||
c = self.format_value = QComboBox(self)
|
||||
from calibre.ebooks.oeb.polish.create import valid_empty_formats
|
||||
possible_formats = [''] + sorted(x.upper() for x in valid_empty_formats)
|
||||
c.addItems(possible_formats)
|
||||
c.setToolTip(_('Also create an empty book format file that you can subsequently edit'))
|
||||
|
Loading…
x
Reference in New Issue
Block a user