Advertisement
danfalck

Untitled

Apr 8th, 2012
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.16 KB | None | 0 0
  1. import sys
  2. from PyQt4 import QtCore, QtGui, QtWebKit
  3. import WebGui
  4.  
  5. """Html snippet."""
  6. html = """
  7. <html><body>
  8.  <center>
  9.  <script language="JavaScript">
  10.    document.write('<p>Python ' + pyObj.pyVersion + '</p>')
  11.  </script>
  12.  <button onClick="pyObj.showMessage('Hello from WebKit')">Press me</button>
  13.  </center>
  14. </body></html>
  15. """
  16.  
  17. class StupidClass(QtCore.QObject):
  18.     """Simple class with one slot and one read-only property."""
  19.  
  20.     @QtCore.pyqtSlot(str)
  21.     def showMessage(self, msg):
  22.         """Open a message box and display the specified message."""
  23.         QtGui.QMessageBox.information(None, "Info", msg)
  24.  
  25.     def _pyVersion(self):
  26.         """Return the Python version."""
  27.         return sys.version
  28.  
  29.     """Python interpreter version property."""
  30.     pyVersion = QtCore.pyqtProperty(str, fget=_pyVersion)
  31.  
  32.  
  33. myObj = StupidClass()
  34.  
  35. a = QtGui.qApp
  36. mw = a.activeWindow()
  37. v= mw.findChild(QtWebKit.QWebFrame)
  38. #v.page().currentFrame().addToJavaScriptWindowObject('pyObj', myObj)
  39. #v.addToJavaScriptWindowObject('pyObj', myObj)
  40. v.setHtml(html)
  41. curr1 = v.page()
  42. frame1 = curr1.currentFrame()
  43. frame1.addToJavaScriptWindowObject("pyObj", myObj)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement