beeware / toga

A Python native, OS native GUI toolkit.
https://toga.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
4.39k stars 684 forks source link

Add content argument to WebView instantiation #2851

Open hyuri opened 2 months ago

hyuri commented 2 months ago

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

freakboy3742 commented 2 months ago

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 commented 2 months ago

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.

anneyshas commented 1 month ago

Currently working on this!