From 72bffa68a70957f1205ed7e3daa9786e55360831 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 3 Jul 2018 09:49:00 +0530 Subject: [PATCH] Add page setup UI --- src/calibre/srv/convert.py | 11 +++++++++++ src/pyj/book_list/conversion_widgets.pyj | 20 +++++++++++++++++--- src/pyj/book_list/convert_book.pyj | 4 +++- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/calibre/srv/convert.py b/src/calibre/srv/convert.py index ed05ef9b51..babb2ba25a 100644 --- a/src/calibre/srv/convert.py +++ b/src/calibre/srv/convert.py @@ -9,6 +9,7 @@ import shutil import tempfile from threading import Lock +from calibre.customize.ui import input_profiles, output_profiles from calibre.db.errors import NoSuchBook from calibre.srv.changes import formats_added from calibre.srv.errors import BookNotFound, HTTPNotFound @@ -241,6 +242,15 @@ def get_conversion_options(input_fmt, output_fmt, book_id, db): return ans +def profiles(): + ans = getattr(profiles, 'ans', None) + if ans is None: + 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()} + return ans + + @endpoint('/conversion/book-data/{book_id}', postprocess=json, types={'book_id': int}) def conversion_data(ctx, rd, book_id): from calibre.ebooks.conversion.config import ( @@ -263,6 +273,7 @@ def conversion_data(ctx, rd, book_id): ans = { 'input_formats': [x.upper() for x in input_formats], 'output_formats': output_formats, + 'profiles': profiles(), 'conversion_options': get_conversion_options(input_fmt, output_formats[0], book_id, db), 'title': db.field_for('title', book_id), 'authors': db.field_for('authors', book_id), diff --git a/src/pyj/book_list/conversion_widgets.pyj b/src/pyj/book_list/conversion_widgets.pyj index 51d0752609..90c09eb3e2 100644 --- a/src/pyj/book_list/conversion_widgets.pyj +++ b/src/pyj/book_list/conversion_widgets.pyj @@ -26,7 +26,7 @@ add_extra_css(def(): # globals {{{ container_id = None -get_option_value = get_option_default_value = is_option_disabled = get_option_help = None +get_option_value = get_option_default_value = is_option_disabled = get_option_help = profiles = None entry_points = {} registry = {} listeners = {} @@ -277,9 +277,23 @@ def heuristics(container): add(checkbox, 'fix_indents', _('Replace entity indents with CSS indents')) # }}} -def create_option_group(group_name, 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 +# Page setup {{{ +@ep +def page_setup(container): + 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)) + g.appendChild(float_spin('margin_top', _('Top page margin'), unit='pt', step=0.1, min=-1, max=200)) + 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(choices('output_profile', _('&Output profile:'), {name: profiles.output[name].name for name in profiles.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_ + profiles = profiles_ registry = {} listeners = {} container_id = ensure_id(container) diff --git a/src/pyj/book_list/convert_book.pyj b/src/pyj/book_list/convert_book.pyj index 24e02c16a2..b2ca401204 100644 --- a/src/pyj/book_list/convert_book.pyj +++ b/src/pyj/book_list/convert_book.pyj @@ -328,7 +328,9 @@ def create_configure_group_markup(): _('Configuring {} settings').format(conversion_data.configuring_group_title))) panel = E.div() container.appendChild(panel) - create_option_group(conversion_data.configuring_group, container, get_option_value, get_option_default_value, is_option_disabled, get_option_help) + create_option_group( + conversion_data.configuring_group, conversion_data.profiles, container, + get_option_value, get_option_default_value, is_option_disabled, get_option_help) return ans, init