From 32e1f6b78140c8e636c746d49263491ed9ac3748 Mon Sep 17 00:00:00 2001 From: Urban Wallasch Date: Mon, 3 May 2021 10:25:23 +0200 Subject: [PATCH] * Improved scrolling, Up/Down/PgUp/PgDn/Home/End keys work as long as window has focus. --- ffpreview.py | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/ffpreview.py b/ffpreview.py index 46f50ff..fa5cd97 100755 --- a/ffpreview.py +++ b/ffpreview.py @@ -284,30 +284,43 @@ scrollframe.bind( canvas.create_window((0, 0), window=scrollframe, anchor='nw') canvas.configure(yscrollcommand=scrollbar.set) +def page_scroll(event): + if event.keysym == 'Next': + canvas.yview_scroll(1, 'pages') + if event.keysym == 'Prior': + canvas.yview_scroll(-1, 'pages') + +def home_end_scroll(event): + if event.keysym == 'Home': + canvas.yview_moveto(0) + if event.keysym == 'End': + canvas.yview_moveto(1) + def mouse_wheel(event): - direction = 0 if event.num == 5 or event.delta == -120 or event.keysym == 'Down': - direction = 1 + canvas.yview_scroll(1, 'units') if event.num == 4 or event.delta == 120 or event.keysym == 'Up': - direction = -1 - canvas.yview_scroll(direction, 'units') + canvas.yview_scroll(-1, 'units') def bind_mousewheel(event): canvas.bind_all('', mouse_wheel) # Windows mouse wheel event canvas.bind_all('', mouse_wheel) # Linux mouse wheel event (Up) canvas.bind_all('', mouse_wheel) # Linux mouse wheel event (Down) - canvas.bind_all('', mouse_wheel) # Cursor up key - canvas.bind_all('', mouse_wheel) # Cursor down key def unbind_mousewheel(event): canvas.unbind_all('') canvas.unbind_all('') canvas.unbind_all('') - canvas.unbind_all('') - canvas.unbind_all('') scrollframe.bind('', bind_mousewheel) scrollframe.bind('', unbind_mousewheel) +canvas.bind_all('', mouse_wheel) # CursorUp key +canvas.bind_all('', mouse_wheel) # CursorDown key +canvas.bind_all('', home_end_scroll) # Home key +canvas.bind_all('', home_end_scroll) # End key +canvas.bind_all('', page_scroll) # PageUp key +canvas.bind_all('', page_scroll) # PageDn key + ############################################################ # rebuild thumbnails and index, if necessary @@ -368,6 +381,7 @@ try: if x == cfg.grid_columns: x = 0; y += 1 root.update() + canvas.configure(yscrollincrement=tlabel.winfo_height()) except Exception as e: eprint(str(e)) exit(2) -- 2.30.2