Skip to content

Future-proof Chart against changing Toga Widget initialization#194

Merged
freakboy3742 merged 11 commits into
beeware:mainfrom
HalfWhitt:future-proof-for-toga-widget-init
Apr 22, 2025
Merged

Future-proof Chart against changing Toga Widget initialization#194
freakboy3742 merged 11 commits into
beeware:mainfrom
HalfWhitt:future-proof-for-toga-widget-init

Conversation

@HalfWhitt
Copy link
Copy Markdown
Member

Updates Chart to play nice with the restructured Widget initialization in beeware/toga#2942, while staying backwards compatibile with Toga 0.4.8.

I realize that PR may or may not change significantly before merging; this is for its current form as of beeware/toga@c4db37f, and I can amend as needed.

PR Checklist:

  • All new features have been tested
  • All new features have been documented
  • I have read the CONTRIBUTING.md file
  • I will abide by the code of conduct

Copy link
Copy Markdown
Member

@freakboy3742 freakboy3742 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed this makes sense in the light of beeware/toga#2942 changes; one possible way to avoid the backwards incompatibility at all, plus any additional changes that are needed as a result of the final review state of beeware/toga#2942.

Comment thread src/toga_chart/chart.py Outdated
if not self._impl:
# Backwards compatibility for Toga 0.4.8, which does not call the _create()
# method in Widget.__init__()
self._create()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can also fix this by a toga dependency to toga-core>=0.4.8. It's an interesting omission that we don't currently have that dependency, only enforcing the toga-dummy requirement on developers.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh. Yeah. That is a good point! I'll just change it to that once we know for sure what the next version number is.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed the backwards compatibility shim and added the version requirement (which fails for now, of course, since Toga 0.5.0 doesn't exist).

@HalfWhitt HalfWhitt marked this pull request as draft November 29, 2024 04:46
@HalfWhitt
Copy link
Copy Markdown
Member Author

So this works with updated Toga now, but a Matplotlib change is an issue.

Looks like we're calling an internal method, _get_text_path_transform, which no longer exists:

if ismath:
path, transform = self._get_text_path_transform(
x, y, s, prop, angle, ismath
)
color = gc.get_rgb()
gc.set_linewidth(0.75)
self.draw_path(gc, path, transform, rgbFace=color)

I've not yet looked into it enough to know the best way to adapt.

(Strangely, even when I remove that call, I start seeing weird layout breaks from resizing, like in #191, but without any console errors. May or may not be caused by this same spot in the code, one way or another.)

@freakboy3742
Copy link
Copy Markdown
Member

So this works with updated Toga now, but a Matplotlib change is an issue.

Looks like we're calling an internal method, _get_text_path_transform, which no longer exists:

Looking at the PR that removed the method - the naive approach would seem to be _draw_text_as_path - the only complication is working out how to get a graphic context.

On a semi-related notes - I seem to recall hitting an issue with a matplotlib update a few months back that would cause issues when the chart is on option container and isn't visible. At the time, the "fix" was to pin an older version of matplotlib, but if we're updating the version, it might be worth checking this as well.

@HalfWhitt
Copy link
Copy Markdown
Member Author

Speaking of updating versions and matplotlib, shouldn't toga-chart declare a dependency on matplotlib, I imagine?

@freakboy3742
Copy link
Copy Markdown
Member

Speaking of updating versions and matplotlib, shouldn't toga-chart declare a dependency on matplotlib, I imagine?

Um... yes it should... how has that gone unnoticed?!

Looking through my archives, my demo projects using toga-chart have always declared the dependency on matplotlib, so it's always worked.

Comment thread pyproject.toml Outdated
@@ -47,6 +47,7 @@ dev = [
"setuptools_scm == 8.2.0",
"tox == 4.24.2",
"toga-dummy >= 0.4.0",
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can remove "toga-dummy >= 0.4.0", due to "toga-dummy >= 0.5.0, < 0.6.0",

Comment thread pyproject.toml
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that toga 0.5.0 is out, is there a reason to remove the range you had before? "toga >= 0.5.0, < 0.6.0",

@freakboy3742 freakboy3742 force-pushed the future-proof-for-toga-widget-init branch from 941910b to e198ad8 Compare April 22, 2025 06:59
@freakboy3742 freakboy3742 marked this pull request as ready for review April 22, 2025 07:00
Copy link
Copy Markdown
Member

@freakboy3742 freakboy3742 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've worked out the workaround for _get_text_path_transform - it turns out the _draw_text_as_path has always existed, and does what we need anyway.

I've also added in the dependency declarations for matplotlib and toga-core.

@freakboy3742 freakboy3742 merged commit 4ab282b into beeware:main Apr 22, 2025
@HalfWhitt
Copy link
Copy Markdown
Member Author

Thanks for handling this, Russ!

(I've been rather preoccupied the last couple of weeks, but I do still exist.) 😉

@HalfWhitt HalfWhitt deleted the future-proof-for-toga-widget-init branch April 22, 2025 11:40
@freakboy3742
Copy link
Copy Markdown
Member

Thanks for handling this, Russ!

No problem at all - I hit some issues updating some presentations for PyConUS, which forced the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants