diff --git a/src/calibre/gui2/viewer/config.py b/src/calibre/gui2/viewer/config.py index 5439cddad4..02ee94bcdb 100644 --- a/src/calibre/gui2/viewer/config.py +++ b/src/calibre/gui2/viewer/config.py @@ -111,6 +111,13 @@ def save_viewer_profile(profile_name, profile, *user_names: str): profile = json.loads(profile) if isinstance(profile, dict): profile['__timestamp__'] = isoformat(utcnow()) + from calibre.gui2.viewer.toolbars import current_actions, DEFAULT_ACTIONS + ca = current_actions() + s = {} + if ca != DEFAULT_ACTIONS: + s['toolbar-actions'] = ca + if s: + profile['__standalone_extra_settings__'] = s try: with open(os.path.join(viewer_config_dir, 'profiles.json'), 'rb') as f: raw = json.loads(f.read()) diff --git a/src/calibre/gui2/viewer/toolbars.py b/src/calibre/gui2/viewer/toolbars.py index 3fe1c1493f..5b0403f588 100644 --- a/src/calibre/gui2/viewer/toolbars.py +++ b/src/calibre/gui2/viewer/toolbars.py @@ -152,6 +152,7 @@ class ActionsToolBar(ToolBar): web_view.read_aloud_state_changed.connect(self.update_read_aloud_action) web_view.customize_toolbar.connect(self.customize, type=Qt.ConnectionType.QueuedConnection) web_view.view_created.connect(self.on_view_created) + web_view.change_toolbar_actions.connect(self.change_toolbar_actions) self.web_actions = {} self.back_action = a = shortcut_action('back') @@ -223,6 +224,13 @@ class ActionsToolBar(ToolBar): self.add_actions() + def change_toolbar_actions(self, toolbar_actions): + if toolbar_actions is None: + vprefs.__delitem__('actions-toolbar-actions') + else: + vprefs.set('actions-toolbar-actions', toolbar_actions) + self.add_actions() + def update_web_action(self): a = self.sender() for x, ac in self.web_actions.items(): diff --git a/src/calibre/gui2/viewer/web_view.py b/src/calibre/gui2/viewer/web_view.py index 86160761e0..ec91e08684 100644 --- a/src/calibre/gui2/viewer/web_view.py +++ b/src/calibre/gui2/viewer/web_view.py @@ -492,6 +492,7 @@ class WebView(RestartingWebEngineView): standalone_misc_settings_changed = pyqtSignal(object) view_created = pyqtSignal(object) content_file_changed = pyqtSignal(str) + change_toolbar_actions = pyqtSignal(object) def __init__(self, parent=None): self._host_widget = None @@ -581,6 +582,11 @@ class WebView(RestartingWebEngineView): self.execute_when_ready('profile_response', 'apply-profile', settings) elif which == 'request-save': self.execute_when_ready('profile_response', 'request-save', profile_name) + elif which == 'apply-profile-to-viewer-ui': + toolbar_actions = None + s = settings.get('__standalone_extra_settings__', {}) + toolbar_actions = s.get('toolbar-actions', None) + self.change_toolbar_actions.emit(toolbar_actions) def link_hovered(self, url): if url == 'javascript:void(0)': diff --git a/src/pyj/read_book/profiles.pyj b/src/pyj/read_book/profiles.pyj index e7800b7b11..1feffa5062 100644 --- a/src/pyj/read_book/profiles.pyj +++ b/src/pyj/read_book/profiles.pyj @@ -38,11 +38,12 @@ def use_profile(container_id, profile_name, profile_data): return sd = get_session_data() apply_reader_profile(sd, profile_data) + if ui_operations.apply_profile: + ui_operations.apply_profile(profile_data) container.dispatchEvent(new Event('settings_changed')) container.dispatchEvent(new Event('close_panel')) - 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), def (ok): diff --git a/src/pyj/viewer-main.pyj b/src/pyj/viewer-main.pyj index 4fddef9538..b9d3d91866 100644 --- a/src/pyj/viewer-main.pyj +++ b/src/pyj/viewer-main.pyj @@ -89,6 +89,7 @@ def profile_response(which, x): apply_reader_profile(sd, x) if view: view.preferences_changed() + ui_operations.apply_profile(x) elif which is 'request-save': sd = get_session_data() settings = settings_for_reader_profile(sd) @@ -371,6 +372,8 @@ if window is window.top: install(TRANSLATIONS_DATA) ui_operations.get_all_profiles = get_all_profiles ui_operations.save_profile = save_profile + ui_operations.apply_profile = def(profile): + to_python.profile_op('apply-profile-to-viewer-ui', "", profile) ui_operations.get_file = get_file ui_operations.get_url_for_book_file_name = get_url_for_book_file_name ui_operations.get_mathjax_files = get_mathjax_files