toga icon indicating copy to clipboard operation
toga copied to clipboard

Add content argument to WebView instantiation

Open hyuri opened this issue 1 year ago • 2 comments

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 avatar Sep 16 '24 07:09 hyuri

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.

freakboy3742 avatar Sep 16 '24 07:09 freakboy3742

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.

hyuri avatar Sep 16 '24 08:09 hyuri

Currently working on this!

anneyshas avatar Oct 26 '24 14:10 anneyshas

Hi! Last person working on this had not responded in 5 months... may I open a PR?

for anneyshas: you've done nothing wrong, I know that you (and pretty much other foss contributors) might have other things in their lifes, so I'm going to try to get this fixed.

johnzhou721 avatar May 01 '25 22:05 johnzhou721

@johnzhou721 I think it's safe to assume this is available to be worked on.

@anneyshas If you're still interested in working on this, let us know.

freakboy3742 avatar May 01 '25 22:05 freakboy3742