mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Profiles basically work in standalone viewer
This commit is contained in:
parent
43338d6123
commit
d016186860
@ -695,6 +695,8 @@ class WebView(RestartingWebEngineView):
|
|||||||
self.standalone_misc_settings_changed.emit()
|
self.standalone_misc_settings_changed.emit()
|
||||||
elif key != '*':
|
elif key != '*':
|
||||||
sd = vprefs['session_data']
|
sd = vprefs['session_data']
|
||||||
|
changed = sd.get(key) == val
|
||||||
|
if changed:
|
||||||
sd[key] = val
|
sd[key] = val
|
||||||
vprefs['session_data'] = sd
|
vprefs['session_data'] = sd
|
||||||
if key in ('standalone_font_settings', 'base_font_size'):
|
if key in ('standalone_font_settings', 'base_font_size'):
|
||||||
|
@ -540,10 +540,13 @@ class PrefsOverlay: # {{{
|
|||||||
def on_container_click(self, evt):
|
def on_container_click(self, evt):
|
||||||
pass # Dont allow panel to be closed by a click
|
pass # Dont allow panel to be closed by a click
|
||||||
|
|
||||||
|
def create_panel_impl(self, container):
|
||||||
|
return create_prefs_panel(container, self.overlay.hide_current_panel, self.on_change)
|
||||||
|
|
||||||
def show(self, container):
|
def show(self, container):
|
||||||
self.changes_occurred = False
|
self.changes_occurred = False
|
||||||
container.style.backgroundColor = get_color('window-background')
|
container.style.backgroundColor = get_color('window-background')
|
||||||
self.prefs = create_prefs_panel(container, self.overlay.hide_current_panel, self.on_change)
|
self.prefs = self.create_panel_impl(container)
|
||||||
|
|
||||||
def on_change(self):
|
def on_change(self):
|
||||||
self.changes_occurred = True
|
self.changes_occurred = True
|
||||||
@ -556,6 +559,11 @@ class PrefsOverlay: # {{{
|
|||||||
self.changes_occurred = False
|
self.changes_occurred = False
|
||||||
self.overlay.view.preferences_changed()
|
self.overlay.view.preferences_changed()
|
||||||
|
|
||||||
|
|
||||||
|
class ProfilesOverlay(PrefsOverlay):
|
||||||
|
def create_panel_impl(self, container):
|
||||||
|
return create_profiles_panel(container, self.overlay.hide_current_panel, self.on_change)
|
||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
class FontSizeOverlay: # {{{
|
class FontSizeOverlay: # {{{
|
||||||
@ -749,7 +757,7 @@ class Overlay:
|
|||||||
|
|
||||||
def show_profiles(self):
|
def show_profiles(self):
|
||||||
self.hide_current_panel()
|
self.hide_current_panel()
|
||||||
self.panels.push(TOCOverlay(self, create_profiles_panel.bind(None, self.hide_current_panel), _('Profiles')))
|
self.panels.push(ProfilesOverlay(self))
|
||||||
self.show_current_panel()
|
self.show_current_panel()
|
||||||
|
|
||||||
def show_goto(self):
|
def show_goto(self):
|
||||||
|
@ -10,7 +10,7 @@ from dom import clear, unique_id
|
|||||||
from gettext import gettext as _
|
from gettext import gettext as _
|
||||||
from modals import question_dialog
|
from modals import question_dialog
|
||||||
from read_book.globals import ui_operations
|
from read_book.globals import ui_operations
|
||||||
from session import settings_for_reader_profile
|
from session import apply_reader_profile, settings_for_reader_profile
|
||||||
from widgets import create_button
|
from widgets import create_button
|
||||||
|
|
||||||
|
|
||||||
@ -36,9 +36,12 @@ def use_profile(container_id, profile_name, profile_data):
|
|||||||
container = document.getElementById(container_id)
|
container = document.getElementById(container_id)
|
||||||
if not container:
|
if not container:
|
||||||
return
|
return
|
||||||
|
apply_reader_profile(get_session_data(), profile_data)
|
||||||
|
container.dispatchEvent(new Event('settings_changed'))
|
||||||
container.dispatchEvent(new Event('close_panel'))
|
container.dispatchEvent(new Event('close_panel'))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def delete_profile(container_id, profile_name):
|
def delete_profile(container_id, profile_name):
|
||||||
question_dialog(_('Are you sure?'), _('Are you sure you want to delete the saved profile named: {}?').format(profile_name),
|
question_dialog(_('Are you sure?'), _('Are you sure you want to delete the saved profile named: {}?').format(profile_name),
|
||||||
def (ok):
|
def (ok):
|
||||||
@ -84,9 +87,10 @@ def load_profiles(container_id):
|
|||||||
ui_operations.get_all_profiles(got_all_profiles.bind(None, container_id))
|
ui_operations.get_all_profiles(got_all_profiles.bind(None, container_id))
|
||||||
|
|
||||||
|
|
||||||
def create_profiles_panel(hide_panel, book, container, onclick):
|
def create_profiles_panel(container, hide_panel, on_change):
|
||||||
c = E.div(style='margin: 1rem', id=unique_id('placeholder-prefs'))
|
c = E.div(style='margin: 1rem', id=unique_id('placeholder-prefs'))
|
||||||
c.addEventListener('close_panel', def(): hide_panel();, False)
|
c.addEventListener('close_panel', def(): hide_panel();, False)
|
||||||
|
c.addEventListener('settings_changed', def(): on_change();, False)
|
||||||
container_id = c.id
|
container_id = c.id
|
||||||
a = E.div(
|
a = E.div(
|
||||||
style='display:flex',
|
style='display:flex',
|
||||||
|
@ -234,6 +234,21 @@ def get_subset_of_settings(sd, filter_func):
|
|||||||
ans[setting_name] = window.structuredClone(curval if is_set else metadata.default)
|
ans[setting_name] = window.structuredClone(curval if is_set else metadata.default)
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
|
def apply_profile(sd, profile, filter_func):
|
||||||
|
sentinel = {}
|
||||||
|
for setting_name in Object.keys(all_settings):
|
||||||
|
metadata = all_settings[setting_name]
|
||||||
|
curval = sd.get(setting_name, sentinel)
|
||||||
|
is_set = curval is not sentinel
|
||||||
|
if filter_func(setting_name, metadata, is_set, curval):
|
||||||
|
newval = None
|
||||||
|
if Object.prototype.hasOwnProperty.call(profile, setting_name):
|
||||||
|
newval = profile[setting_name]
|
||||||
|
if deep_eq(newval, metadata.default):
|
||||||
|
newval = None
|
||||||
|
sd.set(setting_name, window.structuredClone(newval))
|
||||||
|
|
||||||
|
|
||||||
standalone_reader_defaults = {
|
standalone_reader_defaults = {
|
||||||
'remember_window_geometry': False,
|
'remember_window_geometry': False,
|
||||||
'remember_last_read': True,
|
'remember_last_read': True,
|
||||||
@ -270,6 +285,12 @@ def settings_for_reader_profile(sd):
|
|||||||
return get_subset_of_settings(sd, filter_func)
|
return get_subset_of_settings(sd, filter_func)
|
||||||
|
|
||||||
|
|
||||||
|
def apply_reader_profile(sd, profile):
|
||||||
|
def filter_func(setting_name, metadata, is_set, curval):
|
||||||
|
return metadata.category is 'read_book'
|
||||||
|
apply_profile(sd, profile, filter_func)
|
||||||
|
|
||||||
|
|
||||||
default_interface_data = {
|
default_interface_data = {
|
||||||
'username': None,
|
'username': None,
|
||||||
'output_format': 'EPUB',
|
'output_format': 'EPUB',
|
||||||
|
@ -161,7 +161,7 @@ class SessionData:
|
|||||||
|
|
||||||
def set(self, key, val):
|
def set(self, key, val):
|
||||||
if val is None:
|
if val is None:
|
||||||
self.data[key] = session_defaults()[key]
|
self.data[key] = val = session_defaults()[key]
|
||||||
else:
|
else:
|
||||||
self.data[key] = val
|
self.data[key] = val
|
||||||
to_python.set_session_data(key, val)
|
to_python.set_session_data(key, val)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user