Code Monkey home page Code Monkey logo

aqwebengine's Introduction

aqwebengine

Qt QWebEngine on async steroids:

  • async versions of methods to load URL and set page html
  • async versions of methods to get page content as HTML and plain text
  • async method to call python from JS
  • async method to call JS from Python

Uses qasync as an engine to run PyQt/PySide2 asyncronously.

Examples

w = AQWebEngine()
...
await w.set_html_async('<b>Hello</b>, world!')
...
await w.load('https://www.example.com')
...
html = await w.to_html_async()  # get current page as HTML
...
text = await w.to_plain_text()  # get current page as plain text
...
await w.eval_js('function inc(x) { return x + 1; }')
result = await w.eval_js('inc(41)')
assert result == 42
...
def do_something(x):
    return x + 1
w.register_python_function('do_something', do_something)
result = await w.eval_js('qt.callPython("do_something", 41)')
assert result == 42

Python API

eval_js

Asynchronously evaluates the string argument as a JS expression. Returns result to the Python caller. JSError is raised if evaluation of JS expression throws an exception.

register_python_function

Registeres a python (sync or async) function to be callable from JS (see qt.callPython JS API below).

Python function should take a single JSON-serializable parameter.

Arguments:

  • function_name - the name of the function, as seen by JS
  • function - python function. Can be sync or async, should take a single JSON-serializable argument.

JS API

qt.callPython

Calls python host.

Arguments:

  • function_name - the name of the registered python function
  • (optional) args - any JSON-serializable value

Python function may return JSON-serializable value, that will be returned to the JS caller.

aqwebengine's People

Contributors

mkroutikov avatar

Watchers

David Nadeau avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.