Add page setup UI

This commit is contained in:
Kovid Goyal 2018-07-03 09:49:00 +05:30
parent 7cf198ba53
commit 72bffa68a7
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 31 additions and 4 deletions

View File

@ -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),

View File

@ -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)

View File

@ -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