mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Port the TB preferences panel
This commit is contained in:
parent
ca8fed1bd4
commit
9f83584025
@ -2,12 +2,14 @@
|
|||||||
# License: GPL v3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPL v3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
from __python__ import hash_literals
|
from __python__ import hash_literals
|
||||||
|
|
||||||
from dom import clear
|
from dom import clear, ensure_id
|
||||||
from elementmaker import E
|
from elementmaker import E
|
||||||
from book_list.globals import get_session_data
|
|
||||||
from widgets import create_button
|
from widgets import create_button
|
||||||
from gettext import gettext as _
|
from gettext import gettext as _
|
||||||
|
|
||||||
|
from book_list.globals import get_session_data
|
||||||
|
from book_list.top_bar import create_top_bar
|
||||||
|
from book_list.router import back
|
||||||
# from book_list.theme import get_font_size, get_color
|
# from book_list.theme import get_font_size, get_color
|
||||||
|
|
||||||
pp_counter = 0
|
pp_counter = 0
|
||||||
@ -169,73 +171,69 @@ class LineEdit(ConfigItem):
|
|||||||
def from_ui(self):
|
def from_ui(self):
|
||||||
return self.control.value or ''
|
return self.control.value or ''
|
||||||
|
|
||||||
class PrefsPanel:
|
state = {}
|
||||||
|
|
||||||
def __init__(self, interface_data, book_list_container):
|
def onfocus(name):
|
||||||
nonlocal iv_counter
|
return def(ev):
|
||||||
pp_counter += 1
|
c = document.getElementById(state.container_id)
|
||||||
self.container_id = 'prefs-panel-' + pp_counter
|
div = c.querySelector('div[data-name="{}"]'.format(name))
|
||||||
|
div.lastChild.style.display = 'block'
|
||||||
|
|
||||||
|
|
||||||
|
def create_prefs_widget(container, prefs_data):
|
||||||
|
nonlocal state
|
||||||
|
state = {}
|
||||||
|
state.container_id = ensure_id(container)
|
||||||
|
state.widgets = []
|
||||||
|
clear(container)
|
||||||
|
|
||||||
|
for item in prefs_data:
|
||||||
div = E.div(
|
div = E.div(
|
||||||
id=self.container_id, style='display:none',
|
style='margin-bottom:1ex; padding: 1ex 1em; border-bottom: solid 1px currentColor',
|
||||||
|
title=item.tooltip,
|
||||||
|
data_name=item.name,
|
||||||
|
E.div(),
|
||||||
|
E.div(
|
||||||
|
item.tooltip or '',
|
||||||
|
style='font-size:0.8rem; font-style: italic; margin-top:1ex; display:none'
|
||||||
|
)
|
||||||
)
|
)
|
||||||
book_list_container.appendChild(div)
|
container.appendChild(div)
|
||||||
self.widgets = []
|
val = get_session_data().get(item.name)
|
||||||
|
if item.from_storage:
|
||||||
@property
|
val = item.from_storage(val)
|
||||||
def container(self):
|
if item.choices:
|
||||||
return document.getElementById(self.container_id)
|
cls = Choices
|
||||||
|
elif val is True or val is False:
|
||||||
@property
|
cls = CheckBox
|
||||||
def is_visible(self):
|
elif jstype(val) is 'number':
|
||||||
self.container.style.display is 'block'
|
cls = SpinBox
|
||||||
|
else:
|
||||||
@is_visible.setter
|
cls = LineEdit
|
||||||
def is_visible(self, val):
|
state.widgets.push((new cls(item, div.firstChild, onfocus(item.name))).initialize())
|
||||||
self.container.style.display = 'block' if val else 'none'
|
if state.widgets.length:
|
||||||
|
container.appendChild(
|
||||||
def init(self, data):
|
E.div(
|
||||||
c = self.container
|
style='margin:1ex 1em; padding: 1em; text-align:center',
|
||||||
clear(c)
|
create_button(_('Restore default settings'), 'refresh', reset_to_defaults)
|
||||||
self.widgets = []
|
|
||||||
|
|
||||||
def onfocus(name):
|
|
||||||
return def(ev):
|
|
||||||
c = self.container
|
|
||||||
div = c.querySelector('div[data-name="{}"]'.format(name))
|
|
||||||
div.lastChild.style.display = 'block'
|
|
||||||
|
|
||||||
for item in data:
|
|
||||||
div = E.div(
|
|
||||||
style='margin-bottom:1ex; padding: 1ex 1em; border-bottom: solid 1px currentColor',
|
|
||||||
title=item.tooltip,
|
|
||||||
data_name=item.name,
|
|
||||||
E.div(),
|
|
||||||
E.div(
|
|
||||||
item.tooltip or '',
|
|
||||||
style='font-size:0.8rem; font-style: italic; margin-top:1ex; display:none'
|
|
||||||
)
|
|
||||||
)
|
|
||||||
c.appendChild(div)
|
|
||||||
val = get_session_data().get(item.name)
|
|
||||||
if item.from_storage:
|
|
||||||
val = item.from_storage(val)
|
|
||||||
if item.choices:
|
|
||||||
cls = Choices
|
|
||||||
elif val is True or val is False:
|
|
||||||
cls = CheckBox
|
|
||||||
elif jstype(val) is 'number':
|
|
||||||
cls = SpinBox
|
|
||||||
else:
|
|
||||||
cls = LineEdit
|
|
||||||
self.widgets.append((new cls(item, div.firstChild, onfocus(item.name))).initialize())
|
|
||||||
if self.widgets.length:
|
|
||||||
c.appendChild(
|
|
||||||
E.div(
|
|
||||||
style='margin:1ex 1em; padding: 1em; text-align:center',
|
|
||||||
create_button(_('Restore default settings'), 'refresh', self.reset_to_defaults.bind(self))
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
|
||||||
def reset_to_defaults(self):
|
|
||||||
for w in self.widgets:
|
def reset_to_defaults():
|
||||||
w.reset_to_default()
|
for w in state.widgets:
|
||||||
|
w.reset_to_default()
|
||||||
|
|
||||||
|
|
||||||
|
def prefs_panel_handler(title, get_prefs_data, on_close=None, icon='close'):
|
||||||
|
|
||||||
|
def close_action():
|
||||||
|
if on_close is not None:
|
||||||
|
on_close()
|
||||||
|
back()
|
||||||
|
|
||||||
|
return def init_prefs_panel(container_id): # noqa:unused-local
|
||||||
|
container = document.getElementById(container_id)
|
||||||
|
create_top_bar(container, title, action=close_action, icon=icon)
|
||||||
|
container.appendChild(E.div())
|
||||||
|
create_prefs_widget(container.lastChild, get_prefs_data())
|
||||||
|
@ -15,9 +15,10 @@ from session import get_interface_data
|
|||||||
from book_list.library_data import library_data, current_library_id
|
from book_list.library_data import library_data, current_library_id
|
||||||
from book_list.ui import show_panel
|
from book_list.ui import show_panel
|
||||||
from book_list.router import back
|
from book_list.router import back
|
||||||
from book_list.top_bar import create_top_bar
|
from book_list.top_bar import create_top_bar, add_button
|
||||||
from book_list.globals import get_session_data
|
from book_list.globals import get_session_data
|
||||||
from book_list.theme import get_color, get_font_size
|
from book_list.theme import get_color, get_font_size
|
||||||
|
from book_list.prefs import prefs_panel_handler
|
||||||
|
|
||||||
apply_search = None
|
apply_search = None
|
||||||
|
|
||||||
@ -413,16 +414,7 @@ def create_search_panel(container):
|
|||||||
refresh()
|
refresh()
|
||||||
|
|
||||||
|
|
||||||
|
# Tag browser prefrences {{{
|
||||||
def init(container_id):
|
|
||||||
if not library_data.sortable_fields:
|
|
||||||
show_panel('book_list', replace=True)
|
|
||||||
return
|
|
||||||
container = document.getElementById(container_id)
|
|
||||||
create_top_bar(container, title=_('Search for books'), action=back, icon='close')
|
|
||||||
container.appendChild(E.div(class_=CLASS_NAME))
|
|
||||||
create_search_panel(container.lastChild)
|
|
||||||
|
|
||||||
|
|
||||||
def get_prefs():
|
def get_prefs():
|
||||||
return [
|
return [
|
||||||
@ -476,3 +468,18 @@ def get_prefs():
|
|||||||
},
|
},
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def tb_config_panel_handler():
|
||||||
|
return prefs_panel_handler(_('Configure Tag Browser'), get_prefs)
|
||||||
|
# }}}
|
||||||
|
|
||||||
|
|
||||||
|
def init(container_id):
|
||||||
|
if not library_data.sortable_fields:
|
||||||
|
show_panel('book_list', replace=True)
|
||||||
|
return
|
||||||
|
container = document.getElementById(container_id)
|
||||||
|
create_top_bar(container, title=_('Search for books'), action=back, icon='close')
|
||||||
|
add_button(container, icon='cogs', action=show_panel.bind(None, 'book_list^search^prefs'), tooltip=_('Configure Tag Browser'))
|
||||||
|
container.appendChild(E.div(class_=CLASS_NAME))
|
||||||
|
create_search_panel(container.lastChild)
|
||||||
|
@ -20,7 +20,7 @@ from book_list.router import back
|
|||||||
from book_list.ui import set_panel_handler, show_panel
|
from book_list.ui import set_panel_handler, show_panel
|
||||||
from book_list.library_data import load_status, ensure_current_library_data, library_data, current_sorted_field, loaded_books_query, url_books_query, current_library_id
|
from book_list.library_data import load_status, ensure_current_library_data, library_data, current_sorted_field, loaded_books_query, url_books_query, current_library_id
|
||||||
from book_list.item_list import create_item_list, create_item
|
from book_list.item_list import create_item_list, create_item
|
||||||
from book_list.search import init as init_search_panel, set_apply_search
|
from book_list.search import init as init_search_panel, set_apply_search, tb_config_panel_handler
|
||||||
|
|
||||||
ALLOWED_MODES = {'cover_grid'}
|
ALLOWED_MODES = {'cover_grid'}
|
||||||
DEFAULT_MODE = 'cover_grid'
|
DEFAULT_MODE = 'cover_grid'
|
||||||
@ -267,4 +267,5 @@ def create_more_actions_panel(container_id):
|
|||||||
set_panel_handler('book_list', init)
|
set_panel_handler('book_list', init)
|
||||||
set_panel_handler('book_list^sort', create_sort_panel)
|
set_panel_handler('book_list^sort', create_sort_panel)
|
||||||
set_panel_handler('book_list^search', init_search_panel)
|
set_panel_handler('book_list^search', init_search_panel)
|
||||||
|
set_panel_handler('book_list^search^prefs', tb_config_panel_handler())
|
||||||
set_panel_handler('book_list^more_actions', create_more_actions_panel)
|
set_panel_handler('book_list^more_actions', create_more_actions_panel)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user