Skip to content

Commit f9889c4

Browse files
authored
Type hints and other minor fixes (#9)
* Added information about `args` and `kwargs` of constructors * Double backticks in comments referencing code * Type hints * Ignore `.vscode`
1 parent 18dcb1a commit f9889c4

File tree

9 files changed

+32
-27
lines changed

9 files changed

+32
-27
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/dist/
2+
/.vscode/
23
__pycache__

examples/examples_ScrollableAreaQt5.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def grid_of_widgets(self, window):
1919
# Create a scrollable area.
2020
scrollable_area = ScrollableAreaQt5()
2121

22-
# Add widgets to the `area` attribute of the scrollable area, not to
22+
# Add widgets to the ``area`` attribute of the scrollable area, not to
2323
# the scrollable area itself.
2424
dim = 10
2525
grid_layout = QGridLayout(scrollable_area.area)

examples/examples_ScrollableAreaQt6.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def grid_of_widgets(self, window):
1919
# Create a scrollable area.
2020
scrollable_area = ScrollableAreaQt6()
2121

22-
# Add widgets to the `area` attribute of the scrollable area, not to
22+
# Add widgets to the ``area`` attribute of the scrollable area, not to
2323
# the scrollable area itself.
2424
dim = 10
2525
grid_layout = QGridLayout(scrollable_area.area)

examples/examples_ScrollableFrameTk.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ def grid_of_widgets(self, window):
1818
# Create a scrollable frame.
1919
scrollable_frame = ScrollableFrameTk(window)
2020

21-
# Add widgets to the `frame` attribute of the scrollable frame, not to
22-
# the scrollable frame itself.
21+
# Add widgets to the ``frame`` attribute of the scrollable frame, not
22+
# to the scrollable frame itself.
2323
dim = 10
2424
for i, j in itertools.product(range(dim), repeat=2):
2525
label = ttk.Label(scrollable_frame.frame, text=f"Label\n({i}, {j})")

examples/examples_ScrollablePanelWx.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ def grid_of_widgets(self, window):
1717
# Create a scrollable panel.
1818
scrollable_panel = ScrollablePanelWx(window)
1919

20-
# Add widgets to the `panel` attribute of the scrollable panel, not to
21-
# the scrollable panel itself.
20+
# Add widgets to the ``panel`` attribute of the scrollable panel, not
21+
# to the scrollable panel itself.
2222
dim = 10
2323
grid_sizer = wx.GridSizer(dim, dim, 20, 20)
2424
for i, j in itertools.product(range(dim), repeat=2):

src/ScrollableContainers/_qt5.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
class ScrollableAreaQt5(QScrollArea):
88
"""
99
Container with horizontal and vertical scrolling capabilities. Widgets must
10-
be added to its `area` attribute.
10+
be added to its ``area`` attribute. Constructor arguments are passed to the
11+
parent constructor.
1112
"""
1213

1314
def __init__(self, *args, **kwargs):

src/ScrollableContainers/_qt6.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
class ScrollableAreaQt6(QScrollArea):
88
"""
99
Container with horizontal and vertical scrolling capabilities. Widgets must
10-
be added to its `area` attribute.
10+
be added to its ``area`` attribute. Constructor arguments are passed to the
11+
parent constructor.
1112
"""
1213

1314
def __init__(self, *args, **kwargs):

src/ScrollableContainers/_tk.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
class ScrollableFrameTk(ttk.Frame):
1111
"""
1212
Container with horizontal and vertical scrolling capabilities. Widgets must
13-
be added to its `frame` attribute.
13+
be added to its ``frame`` attribute. Constructor arguments are passed to
14+
the parent constructor.
1415
"""
1516

1617
def __init__(self, *args, **kwargs):
@@ -45,16 +46,16 @@ def __init__(self, *args, **kwargs):
4546
self._canvas.xview_moveto(0.0)
4647
self._canvas.yview_moveto(0.0)
4748

48-
def _xview(self, *args, width=None):
49+
def _xview(self, *args, width: int | None = None):
4950
"""
5051
Called when a horizontal scroll is requested. Called by other callbacks
51-
(`_on_canvas_configure` and `_on_frame_configure`) whenever it is
52+
(``_on_canvas_configure`` and ``_on_frame_configure``) whenever it is
5253
necessary to horizontally realign the contents of the canvas. Scroll
5354
the view only if the contents are not completely visible. Otherwise,
5455
move the scrollbar to such a position that they are horizontally
5556
centred.
5657
57-
:param args: Tuple which can be passed to `tkinter.Canvas.xview`.
58+
:param args: Passed to ``tkinter.Canvas.xview``.
5859
:param width: Width of the canvas.
5960
"""
6061
if self._canvas.xview() != (0.0, 1.0):
@@ -73,12 +74,12 @@ def _yview(self, *args):
7374
Called when a vertical scroll is requested. Scroll the view only if the
7475
contents are not completely visible.
7576
76-
:param args: Tuple which can be passed to `tkinter.Canvas.yview`.
77+
:param args: Passed to ``tkinter.Canvas.yview``.
7778
"""
7879
if self._canvas.yview() != (0.0, 1.0):
7980
self._canvas.yview(*args)
8081

81-
def _on_canvas_configure(self, event):
82+
def _on_canvas_configure(self, event: tk.Event):
8283
"""
8384
Called when the canvas is resized. Update the scrollable region.
8485
@@ -87,22 +88,22 @@ def _on_canvas_configure(self, event):
8788
self._canvas.configure(scrollregion=self._canvas.bbox(tk.ALL))
8889
self._xview(tk.SCROLL, 0, tk.UNITS, width=event.width)
8990

90-
def _on_frame_configure(self, _=None):
91+
def _on_frame_configure(self, _event: tk.Event | None = None):
9192
"""
9293
Called when the frame is resized or the canvas is scrolled. Update the
9394
scrollable region.
9495
9596
This method is necessary to handle updates which may occur after the
9697
GUI loop has started.
9798
98-
:param _: Configure event.
99+
:param _event: Configure event.
99100
"""
100101
self._canvas.configure(scrollregion=self._canvas.bbox(tk.ALL))
101102
self._xview(tk.SCROLL, 0, tk.UNITS)
102103

103-
def _on_frame_expose(self, _=None):
104+
def _on_frame_expose(self, _event: tk.Event | None = None):
104105
"""
105-
Called when the frame becomes visible. Call `_on_frame_configure` and
106+
Called when the frame becomes visible. Call ``_on_frame_configure`` and
106107
then disable this callback.
107108
108109
This method is necessary because if a scrollable frame is put into,
@@ -112,34 +113,34 @@ def _on_frame_expose(self, _=None):
112113
because its frame configure events work differently.) Hence, I try to
113114
centre the contents again upon an expose event.
114115
115-
:param _: Expose event.
116+
:param _event: Expose event.
116117
"""
117118
self._on_frame_configure()
118119
self.frame.unbind("<Expose>", self._on_frame_expose_id)
119120

120-
def _on_canvas_enter(self, _=None):
121+
def _on_canvas_enter(self, _event: tk.Event | None = None):
121122
"""
122123
Called when the mouse pointer enters the canvas. Set up vertical
123124
scrolling with the mouse wheel.
124125
125-
:param _: Enter event.
126+
:param _event: Enter event.
126127
"""
127128
self.bind_all("<Button-4>", self._on_mouse_scroll)
128129
self.bind_all("<Button-5>", self._on_mouse_scroll)
129130
self.bind_all("<MouseWheel>", self._on_mouse_scroll)
130131

131-
def _on_canvas_leave(self, _=None):
132+
def _on_canvas_leave(self, _event: tk.Event | None = None):
132133
"""
133134
Called when the mouse pointer leaves the canvas. Unset vertical
134135
scrolling with the mouse wheel.
135136
136-
:param _: Leave event.
137+
:param _event: Leave event.
137138
"""
138139
self.unbind_all("<Button-4>")
139140
self.unbind_all("<Button-5>")
140141
self.unbind_all("<MouseWheel>")
141142

142-
def _on_mouse_scroll(self, event):
143+
def _on_mouse_scroll(self, event: tk.Event):
143144
"""
144145
Called when the mouse wheel is scrolled or a two-finger swipe gesture
145146
is performed on the touchpad. Ask to scroll the view horizontally if

src/ScrollableContainers/_wx.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
__all__ = ["ScrollablePanelWx"]
22

33
import wx
4-
from wx.lib import scrolledpanel
4+
from wx.lib.scrolledpanel import ScrolledPanel
55

66

7-
class ScrollablePanelWx(scrolledpanel.ScrolledPanel):
7+
class ScrollablePanelWx(ScrolledPanel):
88
"""
99
Container with horizontal and vertical scrolling capabilities. Widgets must
10-
be added to its `panel` attribute.
10+
be added to its ``panel`` attribute. Constructor arguments are passed to
11+
the parent constructor.
1112
"""
1213

1314
def __init__(self, *args, **kwargs):

0 commit comments

Comments
 (0)