[PyQt] QWebEnginePage API for callbacks

David Cortesi davecortesi at gmail.com
Tue Jan 6 03:59:13 GMT 2015


On Mon, Jan 5, 2015 at 3:26 PM, Andreas Pakulat <apaku at gmx.de> wrote:

>
> I'm a bit at a loss what to do following a call to such a method. What is
>> the best way to "idle" until the callback comes? n.b. I don't see any
>> WebEngine specific guidance at the PyQt5 doc [2].
>>
>
> I'd say just as all other callbacks in Qt (i.e. signal/slots), return
> control to the qt event loop.
>

Could you clarify a bit? The doc [1] for QWebEnginePage.toPlainText() will
at some unknown future time call my callback passing the text of the page.
But I would make that call in some code that needs that text -- to write it
to a file, say. So in a custom class based on QWebEngineView, I capture the
^S key, perhaps, for Save. I put a findSaveDialog and get a path string and
open a text stream for output. Then...

    self.page().toPlainText( lambda s : self.save_plain_text = s )
    # Here --  twiddle my thumbs until I can...
    output_stream << self.save_plain_text

Is this the kind of thing you have in mind?

    self.save_plain_text = None
    self.page().toPlainText( lambda s : self.save_plain_text = s )
    while self.save_plain_text is None : QCoreApplication.processEvents()
    output_stream << self.save_plain_text
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20150105/981e48f3/attachment.html>


More information about the PyQt mailing list