Skip to content

Commit de045d8

Browse files
authored
Better typing for _xview, _yview, frame (#29)
* Read the arguments of `_xview` and `_yview` explicitly * Install Hatch globally * Install more dependencies using `pacman`
1 parent 082cfb8 commit de045d8

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

.github/workflows/build.yml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,17 @@ on: [push, workflow_dispatch]
33

44
jobs:
55
build:
6-
name: lint, install and package on amd64/archlinux:base
76
runs-on: ubuntu-22.04
87
container: amd64/archlinux:base
98
steps:
109
- uses: actions/checkout@v4
1110
- run: |
12-
pacman -Syu --needed --noconfirm python-pipx python-wxpython
13-
pipx install hatch
14-
pipx ensurepath
11+
pacman -Syu --needed --noconfirm python-pipx python-pyqt5 python-pyqt6 python-wxpython
12+
pipx install --global hatch
1513
name: Install dependencies
16-
# Use the full path because Hatch is not found for some reason.
17-
- run: ~/.local/bin/hatch fmt --check
14+
- run: hatch fmt --check
1815
name: Lint
19-
- run: ~/.local/bin/hatch -vv env create dev
16+
- run: hatch -vv env create dev
2017
name: Create editable installation
21-
- run: ~/.local/bin/hatch build
18+
- run: hatch build
2219
name: Package into tarball and wheel

src/ScrollableContainers/_tk.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def __init__(self, *args, **kwargs):
5757
self._canvas.yview_moveto(0.0)
5858

5959
@property
60-
def frame(self):
60+
def frame(self) -> ttk.Frame:
6161
return self._frame
6262

6363
def _show_scrollbars(self):
@@ -109,7 +109,7 @@ def _peek_scrollbars(self, _event: tk.Event | None = None):
109109
self._show_scrollbars()
110110
self._schedule_hide_scrollbars()
111111

112-
def _xview(self, *args, width: int | None = None):
112+
def _xview(self, action: str, fraction_or_amount: float, what: str | None = None, *, width: int | None = None):
113113
"""
114114
Called when a horizontal scroll is requested. Called by other callbacks
115115
(``_configure_viewport_explicit`` and ``_configure_viewport_implicit``)
@@ -118,11 +118,13 @@ def _xview(self, *args, width: int | None = None):
118118
horizontal dimension. Otherwise, horizontally centre the contents of
119119
the canvas.
120120
121-
:param args: Passed to ``tkinter.Canvas.xview``.
122-
:param width: Width of the canvas.
121+
:param action: First argument of ``tkinter.Canvas.xview``.
122+
:param fraction_or_amount: Second argument of ``tkinter.Canvas.xview``.
123+
:param what: Third argument of ``tkinter.Canvas.xview``.
124+
:param width: Width of the canvas. Will be queried if ``None``.
123125
"""
124126
if self._canvas.xview() != (0.0, 1.0):
125-
self._canvas.xview(*args)
127+
self._canvas.xview(action, fraction_or_amount, what)
126128
else:
127129
width = width or self._canvas.winfo_width()
128130

@@ -133,15 +135,17 @@ def _xview(self, *args, width: int | None = None):
133135
self._canvas.xview_moveto((1 - width / self._frame.winfo_width()) / 2)
134136
self._peek_scrollbars()
135137

136-
def _yview(self, *args):
138+
def _yview(self, action: str, fraction_or_amount: float, what: str | None = None):
137139
"""
138140
Called when a vertical scroll is requested. Scroll the viewport only if
139141
it does not show everything in the vertical dimension.
140142
141-
:param args: Passed to ``tkinter.Canvas.yview``.
143+
:param action: First argument of ``tkinter.Canvas.yview``.
144+
:param fraction_or_amount: Second argument of ``tkinter.Canvas.yview``.
145+
:param what: Third argument of ``tkinter.Canvas.yview``.
142146
"""
143147
if self._canvas.yview() != (0.0, 1.0):
144-
self._canvas.yview(*args)
148+
self._canvas.yview(action, fraction_or_amount, what)
145149
self._peek_scrollbars()
146150

147151
def _configure_viewport_explicit(self, event: tk.Event):

0 commit comments

Comments
 (0)