Debian Codegraph @

src/pyj/read_book/prefs/misc.pyj

raw
1 # vim:fileencoding=utf-8
2 # License: GPL v3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
3 from __python__ import bound_methods, hash_literals
4
5 from elementmaker import E
6 from gettext import gettext as _
7
8 from book_list.globals import get_session_data
9 from dom import unique_id
10 from read_book.globals import ui_operations
11 from read_book.prefs.utils import create_button_box
12 from session import session_defaults, standalone_reader_defaults as DEFAULTS
13 from widgets import create_button
14
15 CONTAINER = unique_id('standalone-misc-settings')
16
17
18 def restore_defaults():
19 container = get_container()
20 for q in Object.keys(DEFAULTS):
21 control = container.querySelector(f'[name={q}]')
22 if jstype(DEFAULTS[q]) is 'boolean':
23 control.checked = DEFAULTS[q]
24 else:
25 control.value = DEFAULTS[q]
26 container.querySelector(f'[name=hide_tooltips]').checked = session_defaults().hide_tooltips
27
28
29 def get_container():
30 return document.getElementById(CONTAINER)
31
32
33 def create_misc_panel(container, apply_func, cancel_func):
34 container.appendChild(E.div(id=CONTAINER, style='margin: 1rem'))
35 container = container.lastChild
36 sd = get_session_data()
37 settings = sd.get('standalone_misc_settings')
38 settings.hide_tooltips = sd.get('hide_tooltips')
39
40 def cb(name, text):
41 ans = E.input(type='checkbox', name=name)
42 ans.checked = settings[name] if jstype(settings[name]) is 'boolean' else DEFAULTS[name]
43 return E.div(style='margin-top:1ex', E.label(ans, '\xa0' + text))
44
45 sai = E.input(name='sync_annots_user', type='text', title=_(
46 'The username of a Content server user that you want all annotations synced with.'
47 ' Use the special value * to sync with anonymous users'
48 ))
49 sai.value = settings.sync_annots_user if jstype(settings.sync_annots_user) is 'string' else DEFAULTS.sync_annots_user
50 sync_annots = E.div(
51 style='margin-top: 1ex; margin-left: 3px',
52 E.label(_('Sync bookmarks/highlights with Content server user:') + '\xa0', sai)
53 )
54
55 container.append(cb('remember_window_geometry', _('Remember last used window size and position')))
56 container.append(cb('show_actions_toolbar', _('Show a toolbar with the most useful actions')))
57 container.lastChild.append(E.span('\xa0'))
58 container.lastChild.append(
59 create_button(_('Customize toolbar'), action=ui_operations.customize_toolbar))
60 container.append(cb('show_actions_toolbar_in_fullscreen', _('Keep the toolbar in full screen mode (needs restart)')))
61 container.append(cb('remember_last_read', _('Remember current page when quitting')))
62 container.append(cb('restore_docks', _('Restore open panels such as Table of Contents, Search, etc. on restart')))
63 container.append(cb('save_annotations_in_ebook', _('Keep a copy of annotations/bookmarks in the e-book file, for easy sharing')))
64 container.append(sync_annots)
65 container.append(cb('singleinstance', _('Allow only a single instance of the viewer (needs restart)')))
66 container.append(cb('hide_tooltips', _('Hide mouse-over tooltips in the book text')))
67 container.append(cb('auto_hide_mouse', _('Auto hide the mouse cursor when unused for a few seconds')))
68
69 container.appendChild(create_button_box(restore_defaults, apply_func, cancel_func))
70
71
72 develop = create_misc_panel
73
74
75 def commit_misc(onchange):
76 sd = get_session_data()
77 container = get_container()
78 vals = {}
79 for q in Object.keys(DEFAULTS):
80 control = container.querySelector(f'[name={q}]')
81 if jstype(DEFAULTS[q]) is 'boolean':
82 val = control.checked
83 else:
84 val = control.value.strip()
85 if val is not DEFAULTS[q]:
86 vals[q] = val
87 sd.set('standalone_misc_settings', vals)
88 hide_tooltips = container.querySelector(f'[name=hide_tooltips]').checked
89 sd.set('hide_tooltips', None if hide_tooltips is session_defaults().hide_tooltips else hide_tooltips)
90 onchange()