Skip to content

Commit 5773b12

Browse files
committed
Simplified the scrolling method selector
1 parent bf13a13 commit 5773b12

File tree

1 file changed

+11
-7
lines changed
  • src/ScrollableContainers

1 file changed

+11
-7
lines changed

src/ScrollableContainers/_tk.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -216,18 +216,22 @@ def _scroll_viewport(self, event: tk.Event):
216216
217217
:param event: Scroll event.
218218
"""
219-
# Select which method to call based on whether Shift was held down.
220-
# This is indicated by the LSB of the state.
221-
callee = self._xview if event.state & 1 else self._yview
222219
match _system:
223220
case "Linux" if event.num == 4:
224-
callee(tk.SCROLL, -1, tk.UNITS)
221+
scroll_amount = -1
225222
case "Linux" if event.num == 5:
226-
callee(tk.SCROLL, 1, tk.UNITS)
223+
scroll_amount = 1
227224
case "Darwin":
228-
callee(tk.SCROLL, -event.delta, tk.UNITS)
225+
scroll_amount = -event.delta
229226
case "Windows":
230-
callee(tk.SCROLL, -event.delta // 120, tk.UNITS)
227+
scroll_amount = -event.delta // 120
231228
case _:
232229
message = f"event {event.num} on OS {_system!r} is not supported"
233230
raise ValueError(message)
231+
232+
# Select the method to call based on whether Shift was held down. This
233+
# is indicated by the LSB of the state.
234+
if event.state & 1:
235+
self._xview(tk.SCROLL, scroll_amount, tk.UNITS)
236+
else:
237+
self._yview(tk.SCROLL, scroll_amount, tk.UNITS)

0 commit comments

Comments
 (0)