Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
PySide/WebKit/Javascript
import sys
from PySide.QtCore import QObject, Slot
from PySide.QtGui import QApplication
from PySide.QtWebKit import QWebView
html = """
<html>
<body>
<h1>Hello!</h1><br>
<h2><a href="#" onclick="printer.text('Message from QWebView')">QObject Test</a></h2>
<h2><a href="#" onclick="alert('Javascript works!')">JS test</a></h2>
</body>
</html>
"""
class ConsolePrinter(QObject):
def __init__(self, parent=None):
super(ConsolePrinter, self).__init__(parent)
@Slot(str)
def text(self, message):
print message
if __name__ == '__main__':
app = QApplication(sys.argv)
view = QWebView()
frame = view.page().mainFrame()
printer = ConsolePrinter()
view.setHtml(html)
frame.addToJavaScriptWindowObject('printer', printer)
frame.evaluateJavaScript("alert('Hello');")
frame.evaluateJavaScript("printer.text('Goooooooooo!');")
view.show()
app.exec_()
@tao4yu

This comment has been minimized.

Show comment Hide comment
@tao4yu

tao4yu Oct 31, 2013

great! Thks!

tao4yu commented Oct 31, 2013

great! Thks!

@hit9

This comment has been minimized.

Show comment Hide comment
@hit9

hit9 May 27, 2014

cool!

hit9 commented May 27, 2014

cool!

@berndhahnebach

This comment has been minimized.

Show comment Hide comment
@berndhahnebach

berndhahnebach Nov 30, 2017

Great! many many thanks from me too. Der Wartburgritter

Great! many many thanks from me too. Der Wartburgritter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment