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

Make WebView.set_content()'s URL argument optional #2854

Open
hyuri opened this issue Sep 17, 2024 · 1 comment
Open

Make WebView.set_content()'s URL argument optional #2854

hyuri opened this issue Sep 17, 2024 · 1 comment
Labels
enhancement New features, or improvements to existing features.

Comments

@hyuri
Copy link

hyuri commented Sep 17, 2024

What is the problem or limitation you are having?

Currently, the url argument in set_content() is required. But it stands to reason that, if you are directly setting raw HTML content, that content doesn't have a URL associated with it.

What we can currently do is pass an empty string to url:
my_webview.set_content("", content=html_content)

But that's clunky.

Describe the solution you'd like

In the set_content() function, make the url argument optional.

Describe alternatives you've considered

Perhaps #2851 can make this issue obsolete.

Additional context

No response

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

Your assertion is incorrect - even if you don't specify a URL, a webview has a URL. That URL might be about:blank - but it's still a URL, and it can impact how page content is interpreted. GTK, iOS and macOS don't have an option to not specify a URL when loading content.

The closest we could do here would be to set it up such that mywebview.content = "<html>..." is an implicit call to mywebview.set_content("", "<html>...") - but the additional complication is that most web APIs don't provide a way to retrieve the page HTML content - so we need to define a setter, but without a getter.

Syntactically, that's not something Python allows - but I guess we could define the getter, but make it raise AttributeError so that it looks like it doesn't exist, and document that it's a write-only property, and advise that the setter is equivalent to set_content("", content).

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

2 participants