Advertisement
danfalck

Untitled

Apr 8th, 2012
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.65 KB | None | 0 0
  1. import sys
  2. from PyQt4 import QtCore, QtGui, QtWebKit
  3. import WebGui
  4. import Part
  5. import FreeCADGui, FreeCAD
  6.  
  7. """Html snippet."""
  8. html = """
  9. <html><body>
  10.  <center>
  11.  <script language="JavaScript">
  12.    document.write('<p>Python ' + pyObj.pyVersion + '</p>')
  13.  </script>
  14.  <button onClick="pyObj.showMessage('Hello from WebKit')">Press me</button>
  15.  
  16.  <table>
  17.    <TR>
  18.      <TH align=right>Box size:
  19.      <TD><input type=text name=size >
  20.  
  21.  <button onClick="pyObj.makeBox('a box should magically appear on the screen')">Make Box</button>
  22.  </center>
  23. </body></html>
  24. """
  25.  
  26. class StupidClass(QtCore.QObject):
  27.     """Simple class with one slot and one read-only property."""
  28.  
  29.     @QtCore.pyqtSlot(str)
  30.     def showMessage(self, msg):
  31.         """Open a message box and display the specified message."""
  32.         QtGui.QMessageBox.information(None, "Info", msg)
  33.  
  34.     @QtCore.pyqtSlot(str)
  35.     def makeBox(self, msg):
  36.         #boxsize = float(form['size'].value)
  37.         FreeCAD.Console.PrintMessage("I want a box to appear on the screen\n")
  38.         #FreeCAD.Console.PrintMessage("it is " + str(boxsize) + " big")
  39.         FreeCAD.ActiveDocument.addObject("Part::Box","Box")
  40.         FreeCAD.ActiveDocument.recompute()
  41.  
  42.  
  43.     def _pyVersion(self):
  44.         """Return the Python version."""
  45.         return sys.version
  46.  
  47.  
  48.  
  49.     """Python interpreter version property."""
  50.     pyVersion = QtCore.pyqtProperty(str, fget=_pyVersion)
  51.  
  52.  
  53. myObj = StupidClass()
  54.  
  55. a = QtGui.qApp
  56. mw = a.activeWindow()
  57. v= mw.findChild(QtWebKit.QWebFrame)
  58.  
  59. v.setHtml(html)
  60. curr1 = v.page()
  61. frame1 = curr1.currentFrame()
  62. frame1.addToJavaScriptWindowObject("pyObj", myObj)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement