-
-
Notifications
You must be signed in to change notification settings - Fork 791
Support instantializing WebView w/ static content. #3400
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
Conversation
|
@freakboy3742 |
freakboy3742
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The broad shape of this is correct, with one note inline about the organization of the test cases.
However, the specific details of the implementation isn't consistent with the specification described in the ticket. The ticket says:
if content is specified, URL is the used as the root URL for the raw content.
That is - myview = WebView(url=myurl, content=mycontent) should be the equivalent of myview = WebView(); myview.set_content(myurl, mycontent), with the same caveat that is URL is provided, it will be ignored on some platforms (as documented in set_content()).
core/src/toga/widgets/webview.py
Outdated
| an empty page will be displayed. | ||
| :param content: The static "non-URL" content to use for the WebView. | ||
| This supersedes the ``url`` parameter, since content and URL initialization | ||
| are mutually exclusive. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment will need to be updated to reflect the new behavior.
core/tests/widgets/test_webview.py
Outdated
| root_url="https://example.com", | ||
| content="<h1>Hello, World!</h1>", | ||
| ) | ||
| assert widget.url == "https://example.com" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My previous review said:
These two cases should be up around L55, after test_create_with_values - and should be named to match.
Also - the tests should pass before you request a review. This test has a fairly glaring error in it.
|
Oh, I'm sorry I missed that part. Will fix this evening (tomorrow in UTC+8).
…On Thu, May 1, 2025 at 10:23 PM Russell Keith-Magee < ***@***.***> wrote:
***@***.**** requested changes on this pull request.
------------------------------
In core/src/toga/widgets/webview.py
<#3400 (comment)>:
> @@ -42,6 +43,9 @@ def __init__(
will be applied to the widget.
:param url: The full URL to load in the WebView. If not provided,
an empty page will be displayed.
+ :param content: The static "non-URL" content to use for the WebView.
+ This supersedes the ``url`` parameter, since content and URL initialization
+ are mutually exclusive.
This comment will need to be updated to reflect the new behavior.
------------------------------
In core/tests/widgets/test_webview.py
<#3400 (comment)>:
> @@ -77,6 +77,19 @@ def test_webview_load_disabled(monkeypatch):
del DummyWebView.SUPPORTS_ON_WEBVIEW_LOAD
+def test_init_widget_with_content():
+ """Static HTML content can be loaded into the page at instantiation time."""
+ webview = toga.WebView(url="https://example.com", content="<h1>Hello, World!</h1>")
+
+ assert_action_performed_with(
+ webview,
+ "set content",
+ root_url="https://example.com",
+ content="<h1>Hello, World!</h1>",
+ )
+ assert widget.url == "https://example.com"
My previous review said:
These two cases should be up around L55, after test_create_with_values -
and should be named to match.
Also - the tests should *pass* before you request a review. This test has
a fairly glaring error in it.
—
Reply to this email directly, view it on GitHub
<#3400 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BRODAI6XZ6LV7UY5BNJH47D24LQJ7AVCNFSM6AAAAAB4IZ2WZOVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDQMJRGA4TQNRWHA>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
freakboy3742
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made a small tweak to the docstring, but otherwise, this looks good; thanks!
|
Thanks. At the risk of embarrassing myself for asking, besides reading existing ones and see how they're written, how does one get better at writing docstrings? |
Unfortunately, I'm not sure I have any better suggestions than "practice". Writing is hard; writing with someone else's "voice" is even harder. The good news is that docstrings are easy for an editor to fix, because they're always self-contained to a single line/paragraph; and, as with most writing, the first draft is the hard part. If you're able to contribute a first draft that is in the vicinity of what is needed, I don't consider it a problem at all that a reviewer will tweak the specific text. |
Correct. I'm about to have my first A- semester average in my life if I don't work on my English Language Arts course at my school a bit. I mean this is easier since it's nonfiction and fiction's even harder. |
Fix #2851.
PR Checklist: