From 5773b12c6e5497b05138402abe7d0cc9311d3625 Mon Sep 17 00:00:00 2001 From: Vishal Pankaj Chandratreya <19171016+tfpf@users.noreply.github.com> Date: Sun, 9 Mar 2025 01:06:15 +0530 Subject: [PATCH 1/3] Simplified the scrolling method selector --- src/ScrollableContainers/_tk.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/ScrollableContainers/_tk.py b/src/ScrollableContainers/_tk.py index ee1d9cd..91d941d 100644 --- a/src/ScrollableContainers/_tk.py +++ b/src/ScrollableContainers/_tk.py @@ -216,18 +216,22 @@ def _scroll_viewport(self, event: tk.Event): :param event: Scroll event. """ - # Select which method to call based on whether Shift was held down. - # This is indicated by the LSB of the state. - callee = self._xview if event.state & 1 else self._yview match _system: case "Linux" if event.num == 4: - callee(tk.SCROLL, -1, tk.UNITS) + scroll_amount = -1 case "Linux" if event.num == 5: - callee(tk.SCROLL, 1, tk.UNITS) + scroll_amount = 1 case "Darwin": - callee(tk.SCROLL, -event.delta, tk.UNITS) + scroll_amount = -event.delta case "Windows": - callee(tk.SCROLL, -event.delta // 120, tk.UNITS) + scroll_amount = -event.delta // 120 case _: message = f"event {event.num} on OS {_system!r} is not supported" raise ValueError(message) + + # Select the method to call based on whether Shift was held down. This + # is indicated by the LSB of the state. + if event.state & 1: + self._xview(tk.SCROLL, scroll_amount, tk.UNITS) + else: + self._yview(tk.SCROLL, scroll_amount, tk.UNITS) From 207b6f4719dc65e516932cb9ae230b250fc386d5 Mon Sep 17 00:00:00 2001 From: Vishal Pankaj Chandratreya <19171016+tfpf@users.noreply.github.com> Date: Sun, 9 Mar 2025 01:48:21 +0530 Subject: [PATCH 2/3] `s/scroll_amount/amount/` just for fun --- src/ScrollableContainers/_tk.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ScrollableContainers/_tk.py b/src/ScrollableContainers/_tk.py index 91d941d..b8cdf44 100644 --- a/src/ScrollableContainers/_tk.py +++ b/src/ScrollableContainers/_tk.py @@ -218,13 +218,13 @@ def _scroll_viewport(self, event: tk.Event): """ match _system: case "Linux" if event.num == 4: - scroll_amount = -1 + amount = -1 case "Linux" if event.num == 5: - scroll_amount = 1 + amount = 1 case "Darwin": - scroll_amount = -event.delta + amount = -event.delta case "Windows": - scroll_amount = -event.delta // 120 + amount = -event.delta // 120 case _: message = f"event {event.num} on OS {_system!r} is not supported" raise ValueError(message) @@ -232,6 +232,6 @@ def _scroll_viewport(self, event: tk.Event): # Select the method to call based on whether Shift was held down. This # is indicated by the LSB of the state. if event.state & 1: - self._xview(tk.SCROLL, scroll_amount, tk.UNITS) + self._xview(tk.SCROLL, amount, tk.UNITS) else: - self._yview(tk.SCROLL, scroll_amount, tk.UNITS) + self._yview(tk.SCROLL, amount, tk.UNITS) From a3ac7edf475aa650184e148c546caf7a2eb28d18 Mon Sep 17 00:00:00 2001 From: Vishal Pankaj Chandratreya <19171016+tfpf@users.noreply.github.com> Date: Sun, 9 Mar 2025 01:49:25 +0530 Subject: [PATCH 3/3] Ignore `.idea` --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index b83c549..0388aa1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /dist/ +/.idea/ /.vscode/ __pycache__