Skip to content

Commit

Permalink
Only check signature once; also only check for node name
Browse files Browse the repository at this point in the history
  • Loading branch information
HalfWhitt committed Dec 31, 2024
1 parent e4f0f84 commit 1ed6b0e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
34 changes: 23 additions & 11 deletions src/travertino/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,20 +172,32 @@ def refresh(self, viewport):
if self._root:
self._root.refresh(viewport)
else:
######################################################################
# 2024-12: Backwards compatibility for Toga <= 0.4.8
######################################################################
params = signature(self.style.layout).parameters
if len(params) == 1 or "_deprecated_usage" in params:
self.style.layout(viewport)
else:
self.style.layout(self, viewport)
######################################################################
# End backwards compatibility
######################################################################
self.style.layout(*self._layout_args(viewport))
if self.applicator:
self.applicator.set_bounds()

######################################################################
# 2024-12: Backwards compatibility for Toga <= 0.4.8
######################################################################

def _layout_args(self, viewport):
if "node" in signature(self.style.layout).parameters:
self.__class__._layout_args = self._layout_args_old
else:
self.__class__._layout_args = self._layout_args_new

return self._layout_args(viewport)

def _layout_args_new(self, viewport):
return (viewport,)

def _layout_args_old(self, viewport):
return self, viewport

######################################################################
# End backwards compatibility
######################################################################

def _set_root(self, node, root):
# Propagate a root node change through a tree.
node._root = root
Expand Down
9 changes: 1 addition & 8 deletions tests/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,6 @@ def layout(self, node, viewport):
super().layout(viewport)


class OldStyleDifferentName(Style):
# Just to be on the paranoid side, also test with a different parameter name, like
# this test used to have.
def layout(self, root, viewport):
super().layout(viewport)


@prep_style_class
class BrokenStyle(BaseStyle):
def reapply(self):
Expand Down Expand Up @@ -143,7 +136,7 @@ def test_create_node():
assert child3.root == new_node


@pytest.mark.parametrize("StyleClass", [Style, OldStyle, OldStyleDifferentName])
@pytest.mark.parametrize("StyleClass", [Style, OldStyle])
def test_refresh(StyleClass):
"""The layout can be refreshed, and the applicator invoked"""

Expand Down

0 comments on commit 1ed6b0e

Please sign in to comment.