mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add settings elements to change scroll speeds
This commit is contained in:
parent
e028bbb3f6
commit
1ecf881cb4
@ -11,14 +11,22 @@ from read_book.prefs.utils import create_button_box
|
||||
from session import defaults
|
||||
|
||||
CONTAINER = unique_id('standalone-scrolling-settings')
|
||||
MIN_SCROLL_SPEED = 0.5
|
||||
MAX_SCROLL_SPEED = 5
|
||||
|
||||
# Scroll speeds in lines/sec
|
||||
MIN_SCROLL_SPEED_AUTO = 0.25
|
||||
MAX_SCROLL_SPEED_AUTO = 5
|
||||
|
||||
MIN_SCROLL_SPEED_SMOOTH = 10
|
||||
MAX_SCROLL_SPEED_SMOOTH = 50
|
||||
|
||||
def restore_defaults():
|
||||
container = get_container()
|
||||
for control in container.querySelectorAll('input[name]'):
|
||||
control.checked = defaults[control.getAttribute('name')]
|
||||
val = defaults[control.getAttribute('name')]
|
||||
if control.type is 'checkbox':
|
||||
control.checked = val
|
||||
else:
|
||||
control.valueAsNumber = val
|
||||
|
||||
|
||||
def get_container():
|
||||
@ -27,10 +35,10 @@ def get_container():
|
||||
|
||||
def change_scroll_speed(amt):
|
||||
sd = get_session_data()
|
||||
lps = sd.get('lines_per_sec_smooth')
|
||||
nlps = max(MIN_SCROLL_SPEED, min(lps + amt, MAX_SCROLL_SPEED))
|
||||
lps = sd.get('lines_per_sec_auto')
|
||||
nlps = max(MIN_SCROLL_SPEED_AUTO, min(lps + amt, MAX_SCROLL_SPEED_AUTO))
|
||||
if nlps != lps:
|
||||
sd.set('lines_per_sec_smooth', nlps)
|
||||
sd.set('lines_per_sec_auto', nlps)
|
||||
return nlps
|
||||
|
||||
|
||||
@ -45,16 +53,42 @@ def create_scrolling_panel(container, apply_func, cancel_func):
|
||||
ans.checked = True
|
||||
return E.div(style='margin-top:1ex', E.label(ans, '\xa0' + text))
|
||||
|
||||
container.appendChild(E.div(style='margin-top:1ex', _(
|
||||
'Control how mouse based scrolling works in paged mode')))
|
||||
def spinner(name, text, **kwargs):
|
||||
ans = E.input(type='number', name=name, id=name)
|
||||
for key, val in Object.entries(kwargs):
|
||||
ans[key] = val
|
||||
ans.valueAsNumber = sd.get(name) or defaults[name]
|
||||
return E.label("for"=name, text), ans
|
||||
|
||||
container.appendChild(E.div(style='margin-top:1ex', _('Control how mouse based scrolling works in paged mode')))
|
||||
container.appendChild(cb(
|
||||
'paged_wheel_scrolls_by_screen', _('Mouse wheel scrolls by screen fulls instead of pages')))
|
||||
container.appendChild(cb(
|
||||
'paged_margin_clicks_scroll_by_screen', _('Clicking on the margins scrolls by screen fulls instead of pages')))
|
||||
|
||||
container.appendChild(E.div(style='margin-top:1ex; border-top: solid 1px', '\xa0'))
|
||||
container.appendChild(cb(
|
||||
'book_scrollbar', _('Show a scrollbar')))
|
||||
container.appendChild(E.hr())
|
||||
container.appendChild(E.div(style='margin-top:1ex', _('Control how smooth scrolling works in flow mode')))
|
||||
container.appendChild(
|
||||
E.div(style='display:grid;margin-top:1ex;align-items:center;grid-template-columns:auto auto;grid-gap:1ex;justify-content:flex-start;',
|
||||
*spinner(
|
||||
'lines_per_sec_smooth',
|
||||
_('Smooth scrolling speed in lines/sec'),
|
||||
step=5,
|
||||
min=MIN_SCROLL_SPEED_SMOOTH,
|
||||
max=MAX_SCROLL_SPEED_SMOOTH
|
||||
),
|
||||
*spinner(
|
||||
'lines_per_sec_auto',
|
||||
_('Auto scrolling speed in lines/sec'),
|
||||
step=MIN_SCROLL_SPEED_AUTO,
|
||||
min=MIN_SCROLL_SPEED_AUTO,
|
||||
max=MAX_SCROLL_SPEED_AUTO
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
container.appendChild(E.hr())
|
||||
container.appendChild(cb('book_scrollbar', _('Show a scrollbar')))
|
||||
|
||||
container.appendChild(create_button_box(restore_defaults, apply_func, cancel_func))
|
||||
|
||||
@ -68,8 +102,8 @@ def commit_scrolling(onchange):
|
||||
changed = False
|
||||
for control in container.querySelectorAll('input[name]'):
|
||||
name = control.getAttribute('name')
|
||||
val = control.checked
|
||||
if val is not sd.get(name):
|
||||
val = control.checked if control.type is 'checkbox' else control.valueAsNumber
|
||||
if val is not sd.get(name) and control.validity.valid:
|
||||
sd.set(name, val)
|
||||
changed = True
|
||||
if changed:
|
||||
|
@ -23,7 +23,7 @@ from read_book.overlay import Overlay
|
||||
from read_book.prefs.colors import resolve_color_scheme
|
||||
from read_book.prefs.font_size import change_font_size_by
|
||||
from read_book.prefs.head_foot import render_head_foot
|
||||
from read_book.prefs.scrolling import change_scroll_speed, MIN_SCROLL_SPEED as SCROLL_SPEED_STEP
|
||||
from read_book.prefs.scrolling import change_scroll_speed, MIN_SCROLL_SPEED_AUTO as SCROLL_SPEED_STEP
|
||||
from read_book.resources import load_resources
|
||||
from read_book.search import SearchOverlay, find_in_spine
|
||||
from read_book.shortcuts import create_shortcut_map
|
||||
|
Loading…
x
Reference in New Issue
Block a user