1
0
mirror of https://github.com/gryf/ebook-converter.git synced 2026-03-13 13:15:53 +01:00

Cleanup get_image_path usage.

This commit is contained in:
2020-04-12 19:32:51 +02:00
parent 5aa0b1a0eb
commit ea19d47ad1
6 changed files with 237 additions and 291 deletions

View File

@@ -1102,277 +1102,277 @@ plugins += [ActionAdd, ActionFetchAnnotations, ActionGenerateCatalog,
# Preferences Plugins {{{ # Preferences Plugins {{{
class LookAndFeel(PreferencesPlugin): # class LookAndFeel(PreferencesPlugin):
name = 'Look & Feel' # name = 'Look & Feel'
icon = I('lookfeel.png') # icon = I('lookfeel.png')
gui_name = _('Look & feel') # gui_name = _('Look & feel')
category = 'Interface' # category = 'Interface'
gui_category = _('Interface') # gui_category = _('Interface')
category_order = 1 # category_order = 1
name_order = 1 # name_order = 1
config_widget = 'ebook_converter.gui2.preferences.look_feel' # config_widget = 'ebook_converter.gui2.preferences.look_feel'
description = _('Adjust the look and feel of the calibre interface' # description = _('Adjust the look and feel of the calibre interface'
' to suit your tastes') # ' to suit your tastes')
class Behavior(PreferencesPlugin): # class Behavior(PreferencesPlugin):
name = 'Behavior' # name = 'Behavior'
icon = I('config.png') # icon = I('config.png')
gui_name = _('Behavior') # gui_name = _('Behavior')
category = 'Interface' # category = 'Interface'
gui_category = _('Interface') # gui_category = _('Interface')
category_order = 1 # category_order = 1
name_order = 2 # name_order = 2
config_widget = 'ebook_converter.gui2.preferences.behavior' # config_widget = 'ebook_converter.gui2.preferences.behavior'
description = _('Change the way calibre behaves') # description = _('Change the way calibre behaves')
class Columns(PreferencesPlugin): # class Columns(PreferencesPlugin):
name = 'Custom Columns' # name = 'Custom Columns'
icon = I('column.png') # icon = I('column.png')
gui_name = _('Add your own columns') # gui_name = _('Add your own columns')
category = 'Interface' # category = 'Interface'
gui_category = _('Interface') # gui_category = _('Interface')
category_order = 1 # category_order = 1
name_order = 3 # name_order = 3
config_widget = 'ebook_converter.gui2.preferences.columns' # config_widget = 'ebook_converter.gui2.preferences.columns'
description = _('Add/remove your own columns to the calibre book list') # description = _('Add/remove your own columns to the calibre book list')
class Toolbar(PreferencesPlugin): # class Toolbar(PreferencesPlugin):
name = 'Toolbar' # name = 'Toolbar'
icon = I('wizard.png') # icon = I('wizard.png')
gui_name = _('Toolbars & menus') # gui_name = _('Toolbars & menus')
category = 'Interface' # category = 'Interface'
gui_category = _('Interface') # gui_category = _('Interface')
category_order = 1 # category_order = 1
name_order = 4 # name_order = 4
config_widget = 'ebook_converter.gui2.preferences.toolbar' # config_widget = 'ebook_converter.gui2.preferences.toolbar'
description = _('Customize the toolbars and context menus, changing which' # description = _('Customize the toolbars and context menus, changing which'
' actions are available in each') # ' actions are available in each')
class Search(PreferencesPlugin): # class Search(PreferencesPlugin):
name = 'Search' # name = 'Search'
icon = I('search.png') # icon = I('search.png')
gui_name = _('Searching') # gui_name = _('Searching')
category = 'Interface' # category = 'Interface'
gui_category = _('Interface') # gui_category = _('Interface')
category_order = 1 # category_order = 1
name_order = 5 # name_order = 5
config_widget = 'ebook_converter.gui2.preferences.search' # config_widget = 'ebook_converter.gui2.preferences.search'
description = _('Customize the way searching for books works in calibre') # description = _('Customize the way searching for books works in calibre')
class InputOptions(PreferencesPlugin): # class InputOptions(PreferencesPlugin):
name = 'Input Options' # name = 'Input Options'
icon = I('arrow-down.png') # icon = I('arrow-down.png')
gui_name = _('Input options') # gui_name = _('Input options')
category = 'Conversion' # category = 'Conversion'
gui_category = _('Conversion') # gui_category = _('Conversion')
category_order = 2 # category_order = 2
name_order = 1 # name_order = 1
config_widget = 'ebook_converter.gui2.preferences.conversion:InputOptions' # config_widget = 'ebook_converter.gui2.preferences.conversion:InputOptions'
description = _('Set conversion options specific to each input format') # description = _('Set conversion options specific to each input format')
def create_widget(self, *args, **kwargs): # def create_widget(self, *args, **kwargs):
# The DOC Input plugin tries to override this # # The DOC Input plugin tries to override this
self.config_widget = 'ebook_converter.gui2.preferences.conversion:InputOptions' # self.config_widget = 'ebook_converter.gui2.preferences.conversion:InputOptions'
return PreferencesPlugin.create_widget(self, *args, **kwargs) # return PreferencesPlugin.create_widget(self, *args, **kwargs)
class CommonOptions(PreferencesPlugin): # class CommonOptions(PreferencesPlugin):
name = 'Common Options' # name = 'Common Options'
icon = I('convert.png') # icon = I('convert.png')
gui_name = _('Common options') # gui_name = _('Common options')
category = 'Conversion' # category = 'Conversion'
gui_category = _('Conversion') # gui_category = _('Conversion')
category_order = 2 # category_order = 2
name_order = 2 # name_order = 2
config_widget = 'ebook_converter.gui2.preferences.conversion:CommonOptions' # config_widget = 'ebook_converter.gui2.preferences.conversion:CommonOptions'
description = _('Set conversion options common to all formats') # description = _('Set conversion options common to all formats')
class OutputOptions(PreferencesPlugin): # class OutputOptions(PreferencesPlugin):
name = 'Output Options' # name = 'Output Options'
icon = I('arrow-up.png') # icon = I('arrow-up.png')
gui_name = _('Output options') # gui_name = _('Output options')
category = 'Conversion' # category = 'Conversion'
gui_category = _('Conversion') # gui_category = _('Conversion')
category_order = 2 # category_order = 2
name_order = 3 # name_order = 3
config_widget = 'ebook_converter.gui2.preferences.conversion:OutputOptions' # config_widget = 'ebook_converter.gui2.preferences.conversion:OutputOptions'
description = _('Set conversion options specific to each output format') # description = _('Set conversion options specific to each output format')
class Adding(PreferencesPlugin): # class Adding(PreferencesPlugin):
name = 'Adding' # name = 'Adding'
icon = I('add_book.png') # icon = I('add_book.png')
gui_name = _('Adding books') # gui_name = _('Adding books')
category = 'Import/Export' # category = 'Import/Export'
gui_category = _('Import/export') # gui_category = _('Import/export')
category_order = 3 # category_order = 3
name_order = 1 # name_order = 1
config_widget = 'ebook_converter.gui2.preferences.adding' # config_widget = 'ebook_converter.gui2.preferences.adding'
description = _('Control how calibre reads metadata from files when ' # description = _('Control how calibre reads metadata from files when '
'adding books') # 'adding books')
class Saving(PreferencesPlugin): # class Saving(PreferencesPlugin):
name = 'Saving' # name = 'Saving'
icon = I('save.png') # icon = I('save.png')
gui_name = _('Saving books to disk') # gui_name = _('Saving books to disk')
category = 'Import/Export' # category = 'Import/Export'
gui_category = _('Import/export') # gui_category = _('Import/export')
category_order = 3 # category_order = 3
name_order = 2 # name_order = 2
config_widget = 'ebook_converter.gui2.preferences.saving' # config_widget = 'ebook_converter.gui2.preferences.saving'
description = _('Control how calibre exports files from its database ' # description = _('Control how calibre exports files from its database '
'to disk when using Save to disk') # 'to disk when using Save to disk')
class Sending(PreferencesPlugin): # class Sending(PreferencesPlugin):
name = 'Sending' # name = 'Sending'
icon = I('sync.png') # icon = I('sync.png')
gui_name = _('Sending books to devices') # gui_name = _('Sending books to devices')
category = 'Import/Export' # category = 'Import/Export'
gui_category = _('Import/export') # gui_category = _('Import/export')
category_order = 3 # category_order = 3
name_order = 3 # name_order = 3
config_widget = 'ebook_converter.gui2.preferences.sending' # config_widget = 'ebook_converter.gui2.preferences.sending'
description = _('Control how calibre transfers files to your ' # description = _('Control how calibre transfers files to your '
'e-book reader') # 'e-book reader')
class Plugboard(PreferencesPlugin): # class Plugboard(PreferencesPlugin):
name = 'Plugboard' # name = 'Plugboard'
icon = I('plugboard.png') # icon = I('plugboard.png')
gui_name = _('Metadata plugboards') # gui_name = _('Metadata plugboards')
category = 'Import/Export' # category = 'Import/Export'
gui_category = _('Import/export') # gui_category = _('Import/export')
category_order = 3 # category_order = 3
name_order = 4 # name_order = 4
config_widget = 'ebook_converter.gui2.preferences.plugboard' # config_widget = 'ebook_converter.gui2.preferences.plugboard'
description = _('Change metadata fields before saving/sending') # description = _('Change metadata fields before saving/sending')
class TemplateFunctions(PreferencesPlugin): # class TemplateFunctions(PreferencesPlugin):
name = 'TemplateFunctions' # name = 'TemplateFunctions'
icon = I('template_funcs.png') # icon = I('template_funcs.png')
gui_name = _('Template functions') # gui_name = _('Template functions')
category = 'Advanced' # category = 'Advanced'
gui_category = _('Advanced') # gui_category = _('Advanced')
category_order = 5 # category_order = 5
name_order = 5 # name_order = 5
config_widget = 'ebook_converter.gui2.preferences.template_functions' # config_widget = 'ebook_converter.gui2.preferences.template_functions'
description = _('Create your own template functions') # description = _('Create your own template functions')
class Email(PreferencesPlugin): # class Email(PreferencesPlugin):
name = 'Email' # name = 'Email'
icon = I('mail.png') # icon = I('mail.png')
gui_name = _('Sharing books by email') # gui_name = _('Sharing books by email')
category = 'Sharing' # category = 'Sharing'
gui_category = _('Sharing') # gui_category = _('Sharing')
category_order = 4 # category_order = 4
name_order = 1 # name_order = 1
config_widget = 'ebook_converter.gui2.preferences.emailp' # config_widget = 'ebook_converter.gui2.preferences.emailp'
description = _('Setup sharing of books via email. Can be used ' # description = _('Setup sharing of books via email. Can be used '
'for automatic sending of downloaded news to your devices') # 'for automatic sending of downloaded news to your devices')
class Server(PreferencesPlugin): # class Server(PreferencesPlugin):
name = 'Server' # name = 'Server'
icon = I('network-server.png') # icon = I('network-server.png')
gui_name = _('Sharing over the net') # gui_name = _('Sharing over the net')
category = 'Sharing' # category = 'Sharing'
gui_category = _('Sharing') # gui_category = _('Sharing')
category_order = 4 # category_order = 4
name_order = 2 # name_order = 2
config_widget = 'ebook_converter.gui2.preferences.server' # config_widget = 'ebook_converter.gui2.preferences.server'
description = _('Setup the calibre Content server which will ' # description = _('Setup the calibre Content server which will '
'give you access to your calibre library from anywhere, ' # 'give you access to your calibre library from anywhere, '
'on any device, over the internet') # 'on any device, over the internet')
class MetadataSources(PreferencesPlugin): # class MetadataSources(PreferencesPlugin):
name = 'Metadata download' # name = 'Metadata download'
icon = I('download-metadata.png') # icon = I('download-metadata.png')
gui_name = _('Metadata download') # gui_name = _('Metadata download')
category = 'Sharing' # category = 'Sharing'
gui_category = _('Sharing') # gui_category = _('Sharing')
category_order = 4 # category_order = 4
name_order = 3 # name_order = 3
config_widget = 'ebook_converter.gui2.preferences.metadata_sources' # config_widget = 'ebook_converter.gui2.preferences.metadata_sources'
description = _('Control how calibre downloads e-book metadata from the net') # description = _('Control how calibre downloads e-book metadata from the net')
class IgnoredDevices(PreferencesPlugin): # class IgnoredDevices(PreferencesPlugin):
name = 'Ignored Devices' # name = 'Ignored Devices'
icon = I('reader.png') # icon = I('reader.png')
gui_name = _('Ignored devices') # gui_name = _('Ignored devices')
category = 'Sharing' # category = 'Sharing'
gui_category = _('Sharing') # gui_category = _('Sharing')
category_order = 4 # category_order = 4
name_order = 4 # name_order = 4
config_widget = 'ebook_converter.gui2.preferences.ignored_devices' # config_widget = 'ebook_converter.gui2.preferences.ignored_devices'
description = _('Control which devices calibre will ignore when they are connected ' # description = _('Control which devices calibre will ignore when they are connected '
'to the computer.') # 'to the computer.')
class Plugins(PreferencesPlugin): # class Plugins(PreferencesPlugin):
name = 'Plugins' # name = 'Plugins'
icon = I('plugins.png') # icon = I('plugins.png')
gui_name = _('Plugins') # gui_name = _('Plugins')
category = 'Advanced' # category = 'Advanced'
gui_category = _('Advanced') # gui_category = _('Advanced')
category_order = 5 # category_order = 5
name_order = 1 # name_order = 1
config_widget = 'ebook_converter.gui2.preferences.plugins' # config_widget = 'ebook_converter.gui2.preferences.plugins'
description = _('Add/remove/customize various bits of calibre ' # description = _('Add/remove/customize various bits of calibre '
'functionality') # 'functionality')
class Tweaks(PreferencesPlugin): # class Tweaks(PreferencesPlugin):
name = 'Tweaks' # name = 'Tweaks'
icon = I('tweaks.png') # icon = I('tweaks.png')
gui_name = _('Tweaks') # gui_name = _('Tweaks')
category = 'Advanced' # category = 'Advanced'
gui_category = _('Advanced') # gui_category = _('Advanced')
category_order = 5 # category_order = 5
name_order = 2 # name_order = 2
config_widget = 'ebook_converter.gui2.preferences.tweaks' # config_widget = 'ebook_converter.gui2.preferences.tweaks'
description = _('Fine tune how calibre behaves in various contexts') # description = _('Fine tune how calibre behaves in various contexts')
class Keyboard(PreferencesPlugin): # class Keyboard(PreferencesPlugin):
name = 'Keyboard' # name = 'Keyboard'
icon = I('keyboard-prefs.png') # icon = I('keyboard-prefs.png')
gui_name = _('Shortcuts') # gui_name = _('Shortcuts')
category = 'Advanced' # category = 'Advanced'
gui_category = _('Advanced') # gui_category = _('Advanced')
category_order = 5 # category_order = 5
name_order = 4 # name_order = 4
config_widget = 'ebook_converter.gui2.preferences.keyboard' # config_widget = 'ebook_converter.gui2.preferences.keyboard'
description = _('Customize the keyboard shortcuts used by calibre') # description = _('Customize the keyboard shortcuts used by calibre')
class Misc(PreferencesPlugin): # class Misc(PreferencesPlugin):
name = 'Misc' # name = 'Misc'
icon = I('exec.png') # icon = I('exec.png')
gui_name = _('Miscellaneous') # gui_name = _('Miscellaneous')
category = 'Advanced' # category = 'Advanced'
gui_category = _('Advanced') # gui_category = _('Advanced')
category_order = 5 # category_order = 5
name_order = 3 # name_order = 3
config_widget = 'ebook_converter.gui2.preferences.misc' # config_widget = 'ebook_converter.gui2.preferences.misc'
description = _('Miscellaneous advanced configuration') # description = _('Miscellaneous advanced configuration')
plugins += [LookAndFeel, Behavior, Columns, Toolbar, Search, InputOptions, # plugins += [LookAndFeel, Behavior, Columns, Toolbar, Search, InputOptions,
CommonOptions, OutputOptions, Adding, Saving, Sending, Plugboard, # CommonOptions, OutputOptions, Adding, Saving, Sending, Plugboard,
Email, Server, Plugins, Tweaks, Misc, TemplateFunctions, # Email, Server, Plugins, Tweaks, Misc, TemplateFunctions,
MetadataSources, Keyboard, IgnoredDevices] # MetadataSources, Keyboard, IgnoredDevices]
# }}} # }}}

View File

@@ -95,37 +95,6 @@ class DummyReporter(object):
pass pass
def gui_configuration_widget(name, parent, get_option_by_name,
get_option_help, db, book_id, for_output=True):
import importlib
def widget_factory(cls):
return cls(parent, get_option_by_name,
get_option_help, db, book_id)
if for_output:
try:
output_widget = importlib.import_module(
'ebook_converter.gui2.convert.'+name)
pw = output_widget.PluginWidget
pw.ICON = I('back.png')
pw.HELP = _('Options specific to the output format.')
return widget_factory(pw)
except ImportError:
pass
else:
try:
input_widget = importlib.import_module(
'ebook_converter.gui2.convert.'+name)
pw = input_widget.PluginWidget
pw.ICON = I('forward.png')
pw.HELP = _('Options specific to the input format.')
return widget_factory(pw)
except ImportError:
pass
return None
class InputFormatPlugin(Plugin): class InputFormatPlugin(Plugin):
''' '''
@@ -262,17 +231,6 @@ class InputFormatPlugin(Plugin):
''' '''
pass pass
def gui_configuration_widget(self, parent, get_option_by_name,
get_option_help, db, book_id=None):
'''
Called to create the widget used for configuring this plugin in the
calibre GUI. The widget must be an instance of the PluginWidget class.
See the builtin input plugins for examples.
'''
name = self.name.lower().replace(' ', '_')
return gui_configuration_widget(name, parent, get_option_by_name,
get_option_help, db, book_id, for_output=False)
class OutputFormatPlugin(Plugin): class OutputFormatPlugin(Plugin):
@@ -363,14 +321,3 @@ class OutputFormatPlugin(Plugin):
''' '''
pass pass
def gui_configuration_widget(self, parent, get_option_by_name,
get_option_help, db, book_id=None):
'''
Called to create the widget used for configuring this plugin in the
calibre GUI. The widget must be an instance of the PluginWidget class.
See the builtin output plugins for examples.
'''
name = self.name.lower().replace(' ', '_')
return gui_configuration_widget(name, parent, get_option_by_name,
get_option_help, db, book_id, for_output=True)

View File

@@ -66,7 +66,7 @@ class DevicePlugin(Plugin):
path_sep = os.sep path_sep = os.sep
#: Icon for this device #: Icon for this device
icon = I('reader.png') icon = None
# Encapsulates an annotation fetched from the device # Encapsulates an annotation fetched from the device
UserAnnotation = namedtuple('Annotation','type, value') UserAnnotation = namedtuple('Annotation','type, value')

View File

@@ -635,9 +635,8 @@ def read_custom_tweaks():
def default_tweaks_raw(): def default_tweaks_raw():
with open(pkg_resources.resource_filename('ebook_converter', return pkg_resources.resource_filename('ebook_converter',
'data/default_tweaks.py')) as f: 'data/default_tweaks.py')
return f.read().encode()
def read_tweaks(): def read_tweaks():

View File

@@ -626,10 +626,12 @@ def encode_jpeg(file_path, quality=80):
def test(): # {{{ def test(): # {{{
# TODO(gryf): move this test to separate file.
from ebook_converter.ptempfile import TemporaryDirectory from ebook_converter.ptempfile import TemporaryDirectory
from ebook_converter import CurrentDir from ebook_converter import CurrentDir
from glob import glob from glob import glob
img = image_from_data(I('lt.png', data=True, allow_user_override=False)) # TODO(gryf): make the sample image out of pillow or smth
# img = image_from_data(I('lt.png', data=True, allow_user_override=False))
with TemporaryDirectory() as tdir, CurrentDir(tdir): with TemporaryDirectory() as tdir, CurrentDir(tdir):
save_image(img, 'test.jpg') save_image(img, 'test.jpg')
ret = optimize_jpeg('test.jpg') ret = optimize_jpeg('test.jpg')
@@ -638,7 +640,9 @@ def test(): # {{{
ret = encode_jpeg('test.jpg') ret = encode_jpeg('test.jpg')
if ret is not None: if ret is not None:
raise SystemExit('encode_jpeg failed: %s' % ret) raise SystemExit('encode_jpeg failed: %s' % ret)
shutil.copyfile(I('lt.png'), 'test.png') # TODO(gryf): make the sample image out of pillow or smth. for sure
# tempfile would be better idea.
#shutil.copyfile(I('lt.png'), 'test.png')
ret = optimize_png('test.png') ret = optimize_png('test.png')
if ret is not None: if ret is not None:
raise SystemExit('optimize_png failed: %s' % ret) raise SystemExit('optimize_png failed: %s' % ret)

View File

@@ -98,7 +98,3 @@ def get_image_path(path, data=False, allow_user_override=True):
def set_data(path, data=None): def set_data(path, data=None):
return _resolver.set_data(path, data) return _resolver.set_data(path, data)
builtins.__dict__['P'] = get_path
builtins.__dict__['I'] = get_image_path