question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

webview.start() function

See original GitHub issue

I propose an alternative way to start a webview application

webview.start(title, html, css='', script='', js_api=None, options={})

would start a webview window with the given title and html. Optionally separate CSS and JS can be supplied as parameters (or embedded into the html). options would be a new dictionary with window specific options of create_window. start would be a single window blocking function, subsequent windows shall be opened using create_window.

All the building blocks are already in place, so the implementation should pose no challenges.

Comments are welcomed.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
shivaprsdcommented, Mar 27, 2018

Agreed. What I suggest is to merge the base_uri and transform_url functions into one; The later already does the protocol check, the former properly adds the path. The new function can be used by both create_window and load_html.

But about start it has occurred to me that this is in fact the best time for such a drastic change! What, other than a major release like 2.0, can be the best place to put it? 3.0 would be too late. I know, I said it, it’d be work. But I don’t think it would complicate the API; instead simplify it, if we do it properly. Here’s my idea:

  • GUI libraries want to run on the main thread. Fine. We’ll makecreate_window open windows only if we’re running; if we’re not running, we will postpone the call till start. I am imagining a global stack to which create_window pushes the ‘calls’ (store the window-specs) and start would execute one by one.
  • Obviously, start would not take any arguments. It would return nothing also. It has to be called from the main thread and it will block. All create_window calls, before or after start, will not block, but return the uid of the window.
  • API calls work the same way as before. They wait for _webview_ready.
  • Only start will _initialize_imports.

Now what all this means for the single-window app maker is just an extra call to start after their usual create_window:

import webview

if __name__ == '__main__':
    webview.create_window('Simple browser', 'http://www.flowrl.com')
    webview.start()

It would in no way complicate the API! It complicates our lives, of course. 🙃 I say do it now before the core code gets messier. I dare give it at least a try before 2.0. Another (not so attractive) option is to release a 1.9 with what we have now, and 2.0 later, with the task list mentioned in #197 including start.

1reaction
shivaprsdcommented, Mar 27, 2018

Now that’s much better, the two initial suggestions seemed far-fetched. But now how does start differ anyway from create_window? If we don’t want any options, both syntaxes are the same, which kind of defeats the purpose of introducing start, right?

Before this issue was opened, I had envisioned a start function but with a different objective: to actually start the application. Like the run function of most web-server frameworks. You can create all the windows you need with create_window and start your app when you’re done. So create_window would never block execution, and return the uids of all windows. To quote:

Do one thing, and do it well.

I had got this idea when I wrote the doc for multiple windows, realising how odd it was with only the initial call to create_window blocking and giving a special uid “master” to it and all that stuff. But I restrained from proposing it as implementing such a model would render us backward-incompatible. It would be also much work. But honestly now, that would have been a better purpose for the start function.

Read more comments on GitHub >

github_iconTop Results From Across the Web

API | pywebview
webview.​​ Start a GUI loop and display previously created windows. This function must be called from a main thread.
Read more >
webview.util.WebViewException: This function must be run ...
I am creating these to thread in my python program but they don't start , it says run then from main thread. i...
Read more >
WebView - Android Developers
Classes. ConversationStatus · ConversationStatus.Builder · PeopleManager. android.app.role. Overview. Classes. RoleManager. android.app.sdksandbox.
Read more >
Android WebView Example Tutorial - DigitalOcean
The onKeyDown() method has been overridden with an implementation that first checks if the WebView can go back. If the user has navigated...
Read more >
API | pywebview
Calling this function for the first time will start the application and block ... uid is the uid of the target window returned...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found