UI for setting the read mode preference

This commit is contained in:
Kovid Goyal 2016-09-26 09:04:01 +05:30
parent f4b6f52efe
commit 6eac8fd175

View File

@ -9,6 +9,7 @@ from elementmaker import E
CONTAINER = unique_id('reader-page-layout')
MARGINS = unique_id('reader-page-margins')
READ_MODE = unique_id('read-mode')
add_extra_css(def():
sel = '#' + MARGINS
@ -21,13 +22,27 @@ def create_layout_panel(container):
container.appendChild(E.div(id=CONTAINER))
container = container.lastChild
sd = get_session_data()
container.appendChild(E.p(_('Change the page margins below'), style='margin:1ex 1em; padding: 1ex 0'))
container.appendChild(E.p(_('Change the page margins below'), style='margin:1ex 1rem; padding: 1ex 0'))
container.appendChild(E.table(id=MARGINS))
labels = {'top':_('Top:'), 'bottom':_('Bottom:'), 'left':_('Left:'), 'right':_('Right:')}
for which in 'top bottom left right'.split(' '):
container.lastChild.appendChild(E.tr(
E.td(labels[which]), E.td(E.input(type='number', min='0', step='1', name=which, value=str(sd.get('margin_'+which))))
))
container.appendChild(E.div(
_('Choose the page layout mode. In paged mode, the text is split up into individual pages, as in a paper book. In flow mode'
' text is presented as one long scrolling page, as in web browsers.'),
style='margin: 1ex 1rem; padding-top:1ex; border-top: solid 1px'))
container.appendChild(E.div(id=READ_MODE, style='margin: 1ex 1rem; display: flex; justify-content: space-between'))
rm = sd.get('read_mode')
rm = 'flow' if rm is 'flow' else 'paged'
def rb(name, text):
d = container.lastChild
d.appendChild(E.label(E.input(type='radio', name='page-layout-mode', checked=rm is name), text))
rb('paged', _('Paged mode'))
rb('flow', _('Flow mode'))
develop = create_layout_panel
@ -43,5 +58,12 @@ def commit_layout(onchange, container):
if val is not sd.get('margin_' + which):
was_changed = True
sd.set('margin_' + which, val)
rm = sd.get('read_mode')
rm = 'flow' if rm is 'flow' else 'paged'
crm = 'paged' if element(READ_MODE, 'input').checked else 'flow'
if rm is not crm:
was_changed = True
sd.set('read_mode', crm)
if was_changed:
onchange()