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

Add the ability to specify platform-specific icons #2260

Merged
merged 9 commits into from
Dec 16, 2023

Conversation

freakboy3742
Copy link
Member

#2259 revealed a need for platform specific icons, as the toolbar icon used for iOS is unlikely to be useful on other platforms. This problem has been seen in other forms - for example, the default .png icon is a useful size for GTK toolbars, but not for Android toolbars.

This PR makes icons a resource that is provided by the backend, rather than the core package; this avoids shipping .icns or .ico files on to platforms that can't use those files.

It also modifies the icon loading process to include a platform-specific filename suffix as part of the lookup scheme (so it will look for foobar-macOS.png before looking for foobar.png.

Builds on #2259 because it corrects the OptionContainer tests to avoid the use of the "-iOS" suffix.

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

@mhsmith
Copy link
Member

mhsmith commented Dec 13, 2023

I think this needs to be rebased again – it still contains all of #2259.

@freakboy3742
Copy link
Member Author

I think this needs to be rebased again – it still contains all of #2259.

Done.

Comment on lines 39 to 40
On GTK, Toga will look for (in order):
* ``myicon-linux-72.png``
Copy link
Member

Choose a reason for hiding this comment

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

RST requires a blank line before a list.

Suggested change
On GTK, Toga will look for (in order):
* ``myicon-linux-72.png``
On GTK, Toga will look for (in order):
* ``myicon-linux-72.png``

Comment on lines 42 to 50
def TOGA_ICON(cls) -> Icon:
return Icon("resources/toga", system=True)
return Icon("toga", system=True)

@cachedicon
def DEFAULT_ICON(cls) -> Icon:
return Icon("resources/toga", system=True)
return Icon("toga", system=True)

@cachedicon
def OPTION_CONTAINER_DEFAULT_TAB_ICON(cls) -> Icon:
Copy link
Member

Choose a reason for hiding this comment

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

These should have some docstrings, which should at least explain the distinction between TOGA_ICON and DEFAULT_ICON. If there isn't any distinction, maybe we should deprecate one of them.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed documenting these is desirable... is it possible? How do you docstring a constant?

Copy link
Member

Choose a reason for hiding this comment

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

Hm, I see these aren't normal @properties, so I'm not sure how Sphinx would deal with them. Maybe it could be done by making cachedicon copy the __doc__ attribute from the underlying method to itself. Or maybe we could use the #: syntax that works in Enums (e.g. in toga/core/src/toga/constants/__init__.py).

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh wait... these are properties... Forgot about that.

@mhsmith mhsmith merged commit 54c4f01 into beeware:main Dec 16, 2023
35 checks passed
@freakboy3742 freakboy3742 deleted the platform-icons branch December 17, 2023 02:22
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.

2 participants