Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from PyQt4 import QtCore, QtGui, QtWebKit
- import Part
- import FreeCADGui, FreeCAD
- html = """
- <HTML>
- <HEAD>
- <TITLE>Test Input</TITLE>
- <SCRIPT LANGUAGE="JavaScript">
- function testResults (form) {
- var lenVar = form.boxlength.value;
- var widthVar = form.boxwidth.value;
- var heightVar = form.boxheight.value;
- pyObj.newBox(lenVar,widthVar,heightVar);
- }</SCRIPT>
- </HEAD>
- <BODY>
- <FORM NAME="myform" ACTION="" METHOD="GET">
- <table> <TR>
- <TH align=right>Box Length:
- <TD><INPUT TYPE="text" NAME="boxlength" VALUE=""><TR>
- <TH align=right>Box Width:
- <TD><INPUT TYPE="text" NAME="boxwidth" VALUE=""><TR>
- <TH align=right>Box Height:
- <TD><INPUT TYPE="text" NAME="boxheight" VALUE=""><TR> </table>
- <INPUT TYPE="button" NAME="button" Value="Draw Box" onClick="testResults(this.form)">
- </FORM> </BODY> </HTML>
- """
- class TestClass(QtCore.QObject):
- @QtCore.pyqtSlot(str,str,str)
- def newBox(self, msg1,msg2,msg3):
- l = float(msg1); w= float(msg2);h = float(msg3)
- box1 = Part.makeBox(l,w,h)
- Part.show(box1)
- def getMainWindow():
- "returns the main window"
- # using QtGui.qApp.activeWindow() isn't very reliable because if another
- # widget than the mainwindow is active (e.g. a dialog) the wrong widget is
- # returned
- toplevel = QtGui.qApp.topLevelWidgets()
- for i in toplevel:
- if i.metaObject().className() == "Gui::MainWindow":
- return i
- raise Exception("No main window found")
- def getComboView(mw):
- dw=mw.findChildren(QtGui.QDockWidget)
- for i in dw:
- if str(i.objectName()) == "Combo View":
- return i.findChild(QtGui.QTabWidget)
- raise Exception("No tab widget found")
- myObj = TestClass()
- a = QtGui.qApp
- mw = getMainWindow()
- tab = getComboView(getMainWindow())
- tab2 = QtGui.QTabWidget(parent = mw)
- web = QtWebKit.QWebView(tab2)
- tab.addTab(tab2,"DrawBox")
- v= web
- #m.move(0,0)
- #m.resize(200,200)
- v.setHtml(html)
- curr1 = v.page()
- frame1 = curr1.currentFrame()
- frame1.addToJavaScriptWindowObject("pyObj", myObj)
Add Comment
Please, Sign In to add comment