From 4c1032ba5c4b1a6e961ab94044aabdee1e33f234 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 28 Dec 2019 21:14:38 +0530 Subject: [PATCH] A toolbar button for auto-scrolling --- imgsrc/auto-scroll.svg | 58 ++++++++++++++++++++++++++++ resources/images/auto-scroll.png | Bin 0 -> 822 bytes src/calibre/gui2/viewer/toolbars.py | 10 +++++ src/calibre/gui2/viewer/web_view.py | 3 ++ src/pyj/read_book/view.pyj | 4 ++ src/pyj/viewer-main.pyj | 2 + 6 files changed, 77 insertions(+) create mode 100644 imgsrc/auto-scroll.svg create mode 100644 resources/images/auto-scroll.png diff --git a/imgsrc/auto-scroll.svg b/imgsrc/auto-scroll.svg new file mode 100644 index 0000000000..122f305418 --- /dev/null +++ b/imgsrc/auto-scroll.svg @@ -0,0 +1,58 @@ + + + + + + image/svg+xml + + + + + + + + + diff --git a/resources/images/auto-scroll.png b/resources/images/auto-scroll.png new file mode 100644 index 0000000000000000000000000000000000000000..11671ff1581b8e0d3189c114a1d1336ef0c8119d GIT binary patch literal 822 zcmeAS@N?(olHy`uVBq!ia0vp^4Is?H3?#oinD`S&tq$-BaRt&0{~1D8g=#lk)m{}U zm3GE>v#)j*knLc+%0+LTo6bgO^^LB&YuuCzu4u1yRVu!!z0O5U619Pu| z#Mim%tOp_&APMARC4+snN`S64FA4GsW?*DyW8>oD;o%n(m(sAdwz0AI^^1szjEj#i zC@3r}nmTp+p1phb?K^bn#KlWjuHE?Z`}dzefB!ygU+&1jz{Kq7;uunK>+Q9hPKOKx z+#YVyQd*(Wt=%0ZB6_iD=J$Fd?JkoG%U&)q-aGTZ-CsVTt@G3;pG+~D>7xdsB2Q@@ z4wSCmX1ijkvVVK?9=D--KmW^xc+@uz{jiiH`Q}D zClp^he!qEP(2b_G>#vwvB`n#%8W`VufpIzGCWp_>X8(jr?3MU8?eDzHP^z=NNv1Z$ zah=^Fg>?I3$9Hwdn3(K?89V1MY&fx9&*9(A6KfkTY_GCdng6jO$zD|9doTyv{f-Sk z*xF9|x7_%{(si-_=!(B?t8;V=emo63eD}S6!Zi~Si9gSH#A?I$f9GU)fBcsAd#zum zR{#BfIc`q>y+e!R!!3X8X1&$!_vcUc{jCeOvux1o_f4`pp z1;%8C*G(?+2|au}m|rtB^P9hDcy(plfhYc}e|QJ%@3+(Zsit;k|JQl^v30y}xL(xk zX7akftl^r!{(^63S;g1uKfkhXr-OWNe!Roe+hP}fma$IR=gYWuew@SG<)RmUKV#y% zA9CQax_H6Q#DmE(jPvE=54=1s`r+4a);o0(3-+&k^?rV7f8ww64ZlCn=GyUR36q`u zzJ|;F+7G^d=ic%6E>m5+zQ&<`F_Fjl++Cl{S&ssZVMz%3&K0xrvSuYL_P~)i=Nqp` WRj1OV%&KXi4B+YN=d#Wzp$Py=r+tM0 literal 0 HcmV?d00001 diff --git a/src/calibre/gui2/viewer/toolbars.py b/src/calibre/gui2/viewer/toolbars.py index af345ff2ac..aae4f10409 100644 --- a/src/calibre/gui2/viewer/toolbars.py +++ b/src/calibre/gui2/viewer/toolbars.py @@ -55,6 +55,7 @@ def all_actions(): 'bookmarks': Action('bookmarks.png', _('Bookmarks'), 'toggle_bookmarks'), 'inspector': Action('debug.png', _('Inspector'), 'toggle_inspector'), 'reference': Action('reference.png', _('Toggle Reference mode'), 'toggle_reference_mode'), + 'autoscroll': Action('auto-scroll.png', _('Toggle auto-scrolling'), 'toggle_autoscroll'), 'lookup': Action('generic-library.png', _('Lookup words'), 'toggle_lookup'), 'chrome': Action('tweaks.png', _('Show viewer controls'), 'show_chrome'), 'mode': Action('scroll.png', _('Toggle paged mode'), 'toggle_paged_mode'), @@ -128,6 +129,7 @@ class ActionsToolBar(ToolBar): web_view.paged_mode_changed.connect(self.update_mode_action) web_view.reference_mode_changed.connect(self.update_reference_mode_action) web_view.standalone_misc_settings_changed.connect(self.update_visibility) + web_view.autoscroll_state_changed.connect(self.update_autoscroll_action) web_view.customize_toolbar.connect(self.customize, type=Qt.QueuedConnection) self.back_action = page.action(QWebEnginePage.Back) @@ -163,6 +165,9 @@ class ActionsToolBar(ToolBar): a.setCheckable(True) self.inspector_action = a = shortcut_action('inspector') a.setCheckable(True) + self.autoscroll_action = a = shortcut_action('autoscroll') + a.setCheckable(True) + self.update_autoscroll_action(False) self.chrome_action = shortcut_action('chrome') self.mode_action = a = shortcut_action('mode') @@ -195,6 +200,11 @@ class ActionsToolBar(ToolBar): a.setChecked(True) a.setToolTip(_('Switch to paged mode -- where the text is broken into pages')) + def update_autoscroll_action(self, active): + self.autoscroll_action.setChecked(active) + self.autoscroll_action.setToolTip( + _('Turn off auto-scrolling') if active else _('Turn on auto-scrolling')) + def update_reference_mode_action(self, enabled): self.reference_action.setChecked(enabled) diff --git a/src/calibre/gui2/viewer/web_view.py b/src/calibre/gui2/viewer/web_view.py index acf0a137c8..1d351ef6ec 100644 --- a/src/calibre/gui2/viewer/web_view.py +++ b/src/calibre/gui2/viewer/web_view.py @@ -247,6 +247,7 @@ class ViewerBridge(Bridge): report_cfi = from_js(object, object) ask_for_open = from_js(object) selection_changed = from_js(object) + autoscroll_state_changed = from_js(object) copy_selection = from_js(object) view_image = from_js(object) copy_image = from_js(object) @@ -416,6 +417,7 @@ class WebView(RestartingWebEngineView): toggle_full_screen = pyqtSignal() ask_for_open = pyqtSignal(object) selection_changed = pyqtSignal(object) + autoscroll_state_changed = pyqtSignal(object) view_image = pyqtSignal(object) copy_image = pyqtSignal(object) overlay_visibility_changed = pyqtSignal(object) @@ -455,6 +457,7 @@ class WebView(RestartingWebEngineView): self.bridge.toggle_full_screen.connect(self.toggle_full_screen) self.bridge.ask_for_open.connect(self.ask_for_open) self.bridge.selection_changed.connect(self.selection_changed) + self.bridge.autoscroll_state_changed.connect(self.autoscroll_state_changed) self.bridge.view_image.connect(self.view_image) self.bridge.copy_image.connect(self.copy_image) self.bridge.overlay_visibility_changed.connect(self.overlay_visibility_changed) diff --git a/src/pyj/read_book/view.pyj b/src/pyj/read_book/view.pyj index e976d58667..dc05a9b350 100644 --- a/src/pyj/read_book/view.pyj +++ b/src/pyj/read_book/view.pyj @@ -203,6 +203,8 @@ class View: handlers = { 'autoscroll_state_changed': def(data): self.autoscroll_active = v'!!data.running' + if ui_operations.autoscroll_state_changed: + ui_operations.autoscroll_state_changed(self.autoscroll_active) , 'bump_font_size': self.bump_font_size, 'content_loaded': self.on_content_loaded, @@ -417,6 +419,8 @@ class View: self.update_scroll_speed(SCROLL_SPEED_STEP) elif data.name is 'scrollspeed_decrease': self.update_scroll_speed(-SCROLL_SPEED_STEP) + elif data.name is 'toggle_autoscroll': + self.toggle_autoscroll() def on_selection_change(self, data): self.currently_showing.selected_text = data.text diff --git a/src/pyj/viewer-main.pyj b/src/pyj/viewer-main.pyj index 26d9167a35..fb87a39bf9 100644 --- a/src/pyj/viewer-main.pyj +++ b/src/pyj/viewer-main.pyj @@ -384,6 +384,8 @@ if window is window.top: to_python.clear_history() ui_operations.customize_toolbar = def(): to_python.customize_toolbar() + ui_operations.autoscroll_state_changed = def(active): + to_python.autoscroll_state_changed(active) document.body.appendChild(E.div(id='view')) window.onerror = onerror