danfalck

taskpanel with webkit in freecad

Apr 18th, 2012
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.07 KB | None | 0 0
  1. from PyQt4 import QtCore, QtGui, QtWebKit
  2. import Part
  3. import FreeCADGui, FreeCAD
  4.  
  5. html = """
  6. <HTML>
  7. <HEAD>
  8. <TITLE>Test Input</TITLE>
  9. <SCRIPT LANGUAGE="JavaScript">
  10. function testResults (form) {
  11.    var lenVar = form.boxlength.value;
  12.    var widthVar = form.boxwidth.value;
  13.    var heightVar = form.boxheight.value;
  14.    pyObj.newBox(lenVar,widthVar,heightVar);
  15. }</SCRIPT>
  16. </HEAD>
  17. <BODY>
  18. <FORM NAME="myform" ACTION="" METHOD="GET">
  19.  <table> <TR>
  20.      <TH align=right>Box Length:
  21.      <TD><INPUT TYPE="text" NAME="boxlength" VALUE=""><TR>
  22.      <TH align=right>Box Width:
  23.      <TD><INPUT TYPE="text" NAME="boxwidth" VALUE=""><TR>
  24.      <TH align=right>Box Height:
  25.      <TD><INPUT TYPE="text" NAME="boxheight" VALUE=""><TR> </table>
  26. <INPUT TYPE="button" NAME="button" Value="Draw Box" onClick="testResults(this.form)">
  27. </FORM> </BODY> </HTML>
  28. """
  29. class TestClass(QtCore.QObject):
  30.     @QtCore.pyqtSlot(str,str,str)
  31.     def newBox(self, msg1,msg2,msg3):
  32.         l = float(msg1); w= float(msg2);h = float(msg3)
  33.         box1 = Part.makeBox(l,w,h)
  34.         Part.show(box1)
  35.  
  36. def getMainWindow():
  37.     "returns the main window"
  38.     # using QtGui.qApp.activeWindow() isn't very reliable because if another
  39.     # widget than the mainwindow is active (e.g. a dialog) the wrong widget is
  40.     # returned
  41.     toplevel = QtGui.qApp.topLevelWidgets()
  42.     for i in toplevel:
  43.         if i.metaObject().className() == "Gui::MainWindow":
  44.             return i
  45.     raise Exception("No main window found")
  46.  
  47.  
  48.  
  49. def getComboView(mw):
  50.     dw=mw.findChildren(QtGui.QDockWidget)
  51.     for i in dw:
  52.         if str(i.objectName()) == "Combo View":
  53.             return i.findChild(QtGui.QTabWidget)
  54.     raise Exception("No tab widget found")
  55.  
  56.  
  57. myObj = TestClass()
  58.  
  59. a = QtGui.qApp
  60. mw = getMainWindow()
  61. tab = getComboView(getMainWindow())
  62.  
  63. tab2 = QtGui.QTabWidget(parent = mw)
  64. web = QtWebKit.QWebView(tab2)
  65. tab.addTab(tab2,"DrawBox")
  66.  
  67. v= web
  68. #m.move(0,0)
  69. #m.resize(200,200)
  70. v.setHtml(html)
  71. curr1 = v.page()
  72. frame1 = curr1.currentFrame()
  73. frame1.addToJavaScriptWindowObject("pyObj", myObj)
Add Comment
Please, Sign In to add comment