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

Provide a way for third-party widgets to register themselves #2928

Open
freakboy3742 opened this issue Oct 22, 2024 · 1 comment
Open

Provide a way for third-party widgets to register themselves #2928

freakboy3742 opened this issue Oct 22, 2024 · 1 comment
Labels
enhancement New features, or improvements to existing features.

Comments

@freakboy3742
Copy link
Member

What is the problem or limitation you are having?

Toga provides a list of built-in widgets; however, we hope to develop an ecosystem of third-party widgets.

Built-in widgets are able to from toga import SomeWidget, and the implementation of SomeWidget can call self.factory.SomeWidget() to instantiate a platform-specific implementation.

However, if a third-party widget requires a native implementation (e.g., a Cocoa wrapper, a Winforms wrapper etc), there's not currently any way to use that infrastructure to get a platform-specific implementation.

Describe the solution you'd like

It should be possible for a third-party package to define a widget that has platform-specific implementations.

Entry points should exist, both for defining the existence of a widget, and for registering platform-specific implementations of that widget. This way, installing a third-party widget package would make that widget available in the toga. namespace (or maybe in a toga.ext. extension namespace to prevent naming collisions), and third-party widgets could invoke self.factory.CustomWidget() to get the appropriate platform implementation.

In the best case, Toga would "eat its own dogfood", and use the same mechanisms for built-in widgets that third party widgets use.

Describe alternatives you've considered

If the entry-point approach is used, it may not be necessary to register the widgets, just the implementations. Requiring end users to say from toga_thirdparty import CustomWidget isn't unreasonable; the primary concern is that the implementation of CustomWidget needs to be able to invoke self.factory.CustomWidget() (or self.factory.toga_thirdparty.CustomWidget(), to ensure namespacing) to get a platform-specific implementation of the widget).

As an alternative to entry points, Toga's widget factory could include a mechanism for third-party widgets to register themselves on import. The end result is much the same; the only difference is where the registration process occurs.

Additional context

This has been a long-standing need, but came up recently in the context of #2927.

We're already using entry points to register backends; the interface that toga cocoa uses to register itself with toga core is accessible to third parties. Extending this to include widgets (or other platform-specific features) would make sense.

This should be accompanied by documentation that provides a "sample" third-party widget. This documentation should also encourage users to use the togax namespace, rather than the toga namespace for third-party widgets registered on PyPI.

@freakboy3742 freakboy3742 added the enhancement New features, or improvements to existing features. label Oct 22, 2024
@freakboy3742
Copy link
Member Author

See also #2687 - import_backend() may be a natural place to have fallback logic for third-party backends.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New features, or improvements to existing features.
Projects
None yet
Development

No branches or pull requests

1 participant