Quantcast
Channel: Planet Python
Viewing all articles
Browse latest Browse all 22462

qutebrowser development blog: Day 7: Fixing things

$
0
0

Handling callbacks

I did a small experiment today, trying to make it easier to use QtWebEngine functions which expect a callback, like QWebEnginePage::runJavaScript.

Normally, you'd call such a function like this:

defcalc(view):defcb(data):print("data: {}".format(data))view.page().runJavaScript('1 + 1',cb)

What I wanted is to (ab)use Python's yield statement instead (as a coroutine), so I can yield a callback to call, and the rest of the function would run after it:

@wrap_cbdefcalc(view):data=yieldview.page().runJavaScript,'1 + 1'print("data: {}".format(data))

This worked fine, and the wrap_cb decorator looks like this:

defwrap_cb(func):@functools.wraps(func)definner(*args):gen=func(*args)arg=next(gen)def_send(*args):try:gen.send(*args)exceptStopIteration:passifcallable(arg):cb_func=argargs=[]else:cb_func,*args=argcb_func(*args,_send)returninner

In the end I ended up not using it though, because it felt like too much magic.

Definitely was an interesting experiment, and I'm a step closer wrapping my head around how coroutines work.

QtWebEngine branch

Yesterday, I branched off a qtwebengine branch, and started refactoring everything so there would be a clearly defined interface which hides the implementation details of a single tab in qutebrowser (QWebView or QWebEngineView).

This means even the current QtWebKit backend broke, which is why the work is still in a branch. I got both QtWebKit and QtWebEngine to run enough to show you a nice screenshot, but as soon as you do anything except opening an URL (like scrolling, or going back/forward) qutebrowser crashed.

Today I worked on getting everything running with QtWebKit first again, and expanding the API of a tab. Here's what's working so far:

  • Scrolling
  • Going back/forward
  • :debug-dump-page (needed for tests)
  • :jseval (needed for tests)
  • Caret browsing

Everything apart from that is either broken or untested - but it's a start!

Seeing the first tests pass definitely was a satisfying feeling :)


Viewing all articles
Browse latest Browse all 22462

Trending Articles