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 content argument to WebView instantiation #2851

Open
hyuri opened this issue Sep 16, 2024 · 3 comments
Open

Add content argument to WebView instantiation #2851

hyuri opened this issue Sep 16, 2024 · 3 comments
Labels
enhancement New features, or improvements to existing features. good first issue Is this your first time contributing? This could be a good place to start!

Comments

@hyuri
Copy link

hyuri commented Sep 16, 2024

What is the problem or limitation you are having?

Similar to #2307

Right now, unlike with URL, to create a WebView and set [HTML] content to it, we have to do it in two steps:

web_view = toga.WebView()

web_view.set_content("", html_content)

Describe the solution you'd like

WebView already allows passing a URL during instantiation, so why not allow passing "content" as well? That way we can do it in one step, and be consistent with MainWindow and ScrollContainer:

web_view = toga.WebView(content=html_content)

Describe alternatives you've considered

None

Additional context

No response

@hyuri hyuri added the enhancement New features, or improvements to existing features. label Sep 16, 2024
@freakboy3742
Copy link
Member

To clarify - the API for webview isn't:

web_view.set_content = ("", html_content)

it's

web_view.set_content("", html_content)

The difference is critical - it's a method invocation with 2 arguments, not a single assignment of a tuple. We need 2 arguments to set static "non-URL" content.

That said - URL and content based initialisation are mutually exclusive, so we could use the interpretation that if content is specified, URL is the used as the root URL for the raw content.

@hyuri
Copy link
Author

hyuri commented Sep 16, 2024

To clarify - the API for webview isn't: [...]

Sorry, that was a typo. Fixed.

That said - URL and content based initialisation are mutually exclusive, so we could use the interpretation that if content is specified, URL is the used as the root URL for the raw content.

Makes sense. With a note about that in the docs, for extra clarity, sounds pretty reasonable.

@freakboy3742 freakboy3742 added the good first issue Is this your first time contributing? This could be a good place to start! label Sep 16, 2024
@anneyshas
Copy link

Currently working on this!

anneyshas added a commit to anneyshas/toga that referenced this issue Oct 27, 2024
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. good first issue Is this your first time contributing? This could be a good place to start!
Projects
None yet
Development

No branches or pull requests

3 participants