Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prime out essential interface attributes before impl initialization #3071

Merged
merged 8 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/3071.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Essential attributes on the widgets' interface are now primed out before initialization of widgets' impl.
4 changes: 2 additions & 2 deletions core/src/toga/widgets/canvas/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ def __init__(
:param on_alt_release: Initial :any:`on_alt_release` handler.
:param on_alt_drag: Initial :any:`on_alt_drag` handler.
"""
super().__init__(id=id, style=style)

self._context = Context(canvas=self)

super().__init__(id=id, style=style)

# Set all the properties
self.on_resize = on_resize
self.on_press = on_press
Expand Down
4 changes: 2 additions & 2 deletions core/src/toga/widgets/numberinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ def __init__(
:param on_change: A handler that will be invoked when the value of the widget
changes.
"""
super().__init__(id=id, style=style)

# The initial setting of min requires calling get_value(),
# which in turn interrogates min. Prime those values with
# an empty starting value
Expand All @@ -118,6 +116,8 @@ def __init__(

self.on_change = None

super().__init__(id=id, style=style)

self.readonly = readonly
self.step = step
self.min = min
Expand Down
3 changes: 2 additions & 1 deletion core/src/toga/widgets/optioncontainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,10 +393,11 @@ def __init__(
<OptionContainerContentT>` to display in the OptionContainer.
:param on_select: Initial :any:`on_select` handler.
"""
super().__init__(id=id, style=style)
self._content = OptionList(self)
self.on_select = None

super().__init__(id=id, style=style)

if content is not None:
for item in content:
if isinstance(item, OptionItem):
Expand Down
3 changes: 2 additions & 1 deletion core/src/toga/widgets/scrollcontainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ def __init__(
:param on_scroll: Initial :any:`on_scroll` handler.
:param content: The content to display in the scroll window.
"""
super().__init__(id=id, style=style)

self._content: Widget | None = None
self.on_scroll = None

super().__init__(id=id, style=style)

# Set all attributes
self.vertical = vertical
self.horizontal = horizontal
Expand Down
3 changes: 2 additions & 1 deletion core/src/toga/widgets/selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,14 @@ def __init__(
:param on_change: Initial :any:`on_change` handler.
:param enabled: Whether the user can interact with the widget.
"""
super().__init__(id=id, style=style)

self._items: SourceT | ListSource

self.on_change = None # needed for _impl initialization

self._accessor = accessor
super().__init__(id=id, style=style)

self.items = items
if value:
self.value = value
Expand Down
2 changes: 1 addition & 1 deletion core/src/toga/widgets/splitcontainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ def __init__(
:param content: Initial :any:`SplitContainer content <SplitContainerContentT>`
of the container. Defaults to both panels being empty.
"""
super().__init__(id=id, style=style)
self._content: list[SplitContainerContentT] = [None, None]
super().__init__(id=id, style=style)

if content:
self.content = content
Expand Down
Loading