From f7eef4f54cee5bba4037dc353568ca726694557c Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 3 Jul 2018 10:04:31 +0530 Subject: [PATCH] Show profile descriptions --- src/calibre/srv/convert.py | 13 +++++++++++-- src/pyj/book_list/conversion_widgets.pyj | 13 +++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/calibre/srv/convert.py b/src/calibre/srv/convert.py index babb2ba25a..ef0b73fe14 100644 --- a/src/calibre/srv/convert.py +++ b/src/calibre/srv/convert.py @@ -245,9 +245,18 @@ def get_conversion_options(input_fmt, output_fmt, book_id, db): def profiles(): ans = getattr(profiles, 'ans', None) if ans is None: + def desc(profile): + w, h = profile.screen_size + if w >= 10000: + ss = _('unlimited') + else: + ss = _('%(width)d x %(height)d pixels') % dict(width=w, height=h) + ss = _('Screen size: %s') % ss + return {'name': profile.name, 'description': ('%s [%s]' % (profile.description, ss))} + ans = profiles.ans = {} - ans['input'] = {p.short_name: {'name': p.name} for p in input_profiles()} - ans['output'] = {p.short_name: {'name': p.name} for p in output_profiles()} + ans['input'] = {p.short_name: desc(p) for p in input_profiles()} + ans['output'] = {p.short_name: desc(p) for p in output_profiles()} return ans diff --git a/src/pyj/book_list/conversion_widgets.pyj b/src/pyj/book_list/conversion_widgets.pyj index 90c09eb3e2..71a789f348 100644 --- a/src/pyj/book_list/conversion_widgets.pyj +++ b/src/pyj/book_list/conversion_widgets.pyj @@ -20,6 +20,7 @@ add_extra_css(def(): style += build_rule(sel + '.simple-group > label > *', display='table-cell', padding_bottom='1ex', padding_right='1rem') style += build_rule(sel + 'label.vertical', display='block') style += build_rule(sel + 'label.vertical > *', display='block', padding_bottom='1ex', padding_right='1rem') + style += build_rule(sel + '[data-profile]', margin_left='2em', text_indent='-2em', font_size='smaller', margin_bottom='1ex') return style ) @@ -280,6 +281,15 @@ def heuristics(container): # Page setup {{{ @ep def page_setup(container): + def show_profile_desc(name): + profile = get(name) + data = profiles.input if name is 'input_profile' else profiles.output + profile = data[profile] + container_for_option(name).parentNode.querySelector('[data-profile="{}"'.format( + 'input' if name is 'input_profile' else 'output')).textContent = indent + profile.description + + add_listener('input_profile', show_profile_desc) + add_listener('output_profile', show_profile_desc) g = E.div(class_='simple-group') container.appendChild(g) g.appendChild(float_spin('margin_left', _('Left page margin'), unit='pt', step=0.1, min=-1, max=200)) @@ -287,9 +297,12 @@ def page_setup(container): g.appendChild(float_spin('margin_right', _('Right page margin'), unit='pt', step=0.1, min=-1, max=200)) g.appendChild(float_spin('margin_bottom', _('Bottom page margin'), unit='pt', step=0.1, min=-1, max=200)) g.appendChild(choices('input_profile', _('&Input profile:'), {name: profiles.input[name].name for name in profiles.input})) + g.appendChild(E.div(data_profile='input')) g.appendChild(choices('output_profile', _('&Output profile:'), {name: profiles.output[name].name for name in profiles.output})) + g.appendChild(E.div(data_profile='output')) # }}} + def create_option_group(group_name, profiles_, container, get_option_value_, get_option_default_value_, is_option_disabled_, get_option_help_): nonlocal get_option_value, get_option_default_value, is_option_disabled, container_id, registry, listeners, get_option_help, profiles get_option_value, get_option_default_value, is_option_disabled, get_option_help = get_option_value_, get_option_default_value_, is_option_disabled_, get_option_help_