def __init__(self, url, demo_type): QtCore.QObject.__init__(self) if demo_type.lower() == "insite": self.dataIF = DataInterface.InsiteDataInterface() elif demo_type.lower() == "d3": self.dataIF = DataInterface.D3DataInterface() else: self.dataIF = DataInterface.DataInterface() self.dataIF.dataChanged.connect(self.testFun) self.dataIF.loadData() self.wvwm = WebViewWindowMediator(WebViewWindow.Ui_WebViewWindow(), None) if demo_type.lower() == "insite": self.wvwm.setTitle("InSite") elif demo_type.lower() == "d3": self.wvwm.setTitle("Delv - Dynamic Linked Visualizations") self.wvwm.resize(1600,1400) self.wvwm.connectSignal("elementSelected",self.elementSelected) self.wvwm.connectLoadFinished(self.loadFinished) self.wvwm.connectWindowCleared(self.onWindowCleared) self.connect(self,QtCore.SIGNAL("testEventForPython"),self.testFun) self.connect(self, QtCore.SIGNAL("sketchesLoaded"),self.onSketchesLoaded) if url: self.wvwm.load(url)
class MainWindow(QtCore.QObject): #class MainWindow(): def __init__(self, url, demo_type): QtCore.QObject.__init__(self) if demo_type.lower() == "insite": self.dataIF = DataInterface.InsiteDataInterface() elif demo_type.lower() == "d3": self.dataIF = DataInterface.D3DataInterface() else: self.dataIF = DataInterface.DataInterface() self.dataIF.dataChanged.connect(self.testFun) self.dataIF.loadData() self.wvwm = WebViewWindowMediator(WebViewWindow.Ui_WebViewWindow(), None) if demo_type.lower() == "insite": self.wvwm.setTitle("InSite") elif demo_type.lower() == "d3": self.wvwm.setTitle("Delv - Dynamic Linked Visualizations") self.wvwm.resize(1600,1400) self.wvwm.connectSignal("elementSelected",self.elementSelected) self.wvwm.connectLoadFinished(self.loadFinished) self.wvwm.connectWindowCleared(self.onWindowCleared) self.connect(self,QtCore.SIGNAL("testEventForPython"),self.testFun) self.connect(self, QtCore.SIGNAL("sketchesLoaded"),self.onSketchesLoaded) if url: self.wvwm.load(url) def onWindowCleared(self): self.wvwm.exposeToJavaScript("QtWin", self) # self.wvwm.exposeToJavaScript() self.wvwm.exposeToJavaScript("dataIF",self.dataIF) def load(self, url): self.wvwm.load(url) def show(self): self.wvwm.show() @QtCore.pyqtSlot(str, str) def emitEvent(self, event, args): self.emit(QtCore.SIGNAL(event), args) def testFun(self, details): print "testFun received event with details:", details @QtCore.pyqtSlot(str) def onSketchesLoaded(self, invoker): print "MainWindow.onSketchesLoaded", invoker self.dataIF.triggerDataLoaded(invoker) def loadFinished(self, success): print "MainWindow.loadFinished" self.wvwm.evaluateJavaScript("delv.connectToQt();") # self.wvwm.resize(1600,1400) # can't load data until processing sketches have been loaded, so wait for onSketchesLoaded to be triggered instead def elementSelected(self, element, event): print "PyQt MainWindow received elementSelected" name = str(element.attribute("id")) # js = """ # var svgNS = "http://www.w3.org/2000/svg"; # var curElement = document.getElementById("%s"); # var bb = curElement.getBBox(); # var rect = document.createElementNS(svgNS, "rect"); # rect.setAttribute("id", "bboxRect") # rect.setAttribute("x", bb.x); # rect.setAttribute("y", bb.y); # rect.setAttribute("width", bb.width); # rect.setAttribute("height", bb.height); # rect.setAttribute("stroke", "black"); # rect.setAttribute("stroke-opacity", "1"); # curElement.appendChild(rect); # """ % (str(name)) # result = self.wvwm.evaluateJavaScript(js) print "name: ", name