mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-31 14:33:54 -04:00
Fix set_radio_group_value and make it re-useable
This commit is contained in:
parent
9b982d3f18
commit
3305fe4a14
@ -133,3 +133,12 @@ def add_extra_css(func):
|
|||||||
|
|
||||||
def get_widget_css():
|
def get_widget_css():
|
||||||
return extra_css.join('\n')
|
return extra_css.join('\n')
|
||||||
|
|
||||||
|
|
||||||
|
def set_radio_group_value(parent, name, val):
|
||||||
|
changed = False
|
||||||
|
for inp in parent.querySelectorAll(f'input[name={name}]'):
|
||||||
|
inp.checked = inp.value is val
|
||||||
|
changed = True
|
||||||
|
if not changed:
|
||||||
|
raise KeyError(f'No radio group with name={name} found')
|
||||||
|
@ -6,7 +6,10 @@ from elementmaker import E
|
|||||||
from gettext import gettext as _
|
from gettext import gettext as _
|
||||||
|
|
||||||
from book_list.globals import get_session_data
|
from book_list.globals import get_session_data
|
||||||
from dom import add_extra_css, build_rule, clear, set_css, svgicon, unique_id
|
from dom import (
|
||||||
|
add_extra_css, build_rule, clear, set_css, set_radio_group_value, svgicon,
|
||||||
|
unique_id
|
||||||
|
)
|
||||||
from modals import error_dialog
|
from modals import error_dialog
|
||||||
from read_book.globals import default_color_schemes, ui_operations
|
from read_book.globals import default_color_schemes, ui_operations
|
||||||
from read_book.prefs.utils import create_button_box
|
from read_book.prefs.utils import create_button_box
|
||||||
@ -39,11 +42,6 @@ def get_container():
|
|||||||
return document.getElementById(CONTAINER)
|
return document.getElementById(CONTAINER)
|
||||||
|
|
||||||
|
|
||||||
def set_radio_group_value(parent, name, val):
|
|
||||||
for inp in parent.querySelector(f'input[name={name}]'):
|
|
||||||
inp.checked = inp.value is val
|
|
||||||
|
|
||||||
|
|
||||||
def resolve_color_scheme(current_color_scheme):
|
def resolve_color_scheme(current_color_scheme):
|
||||||
sd = get_session_data()
|
sd = get_session_data()
|
||||||
cs = current_color_scheme or sd.get('current_color_scheme') or defaults.current_color_scheme
|
cs = current_color_scheme or sd.get('current_color_scheme') or defaults.current_color_scheme
|
||||||
@ -93,7 +91,7 @@ def edit_color_scheme(ev):
|
|||||||
for which in MARGINS:
|
for which in MARGINS:
|
||||||
attr = f'margin_{which}'
|
attr = f'margin_{which}'
|
||||||
val = scheme[attr]
|
val = scheme[attr]
|
||||||
set_radio_group_value(container, f'input[name={attr}_color_type]', 'custom' if val else 'default')
|
set_radio_group_value(container, f'{attr}_color_type', 'custom' if val else 'default')
|
||||||
if val:
|
if val:
|
||||||
bg, fg = val.split(':')
|
bg, fg = val.split(':')
|
||||||
container.querySelector(f'input[name={attr}_bg]').value = bg
|
container.querySelector(f'input[name={attr}_bg]').value = bg
|
||||||
|
Loading…
x
Reference in New Issue
Block a user