def testQVariantListProperty(self): class Obj(object): list = ["foo", "bar", "baz"] obj = Obj() wrapper_dict = {} for name in ["list"]: getter = lambda arg=None, name=name: getattr(obj, name) wrapper_dict[name] = Property("QVariantList", getter) wrapper = type("PyObj", (QObject,), wrapper_dict) view = QWebView() frame = view.page().mainFrame() frame.addToJavaScriptWindowObject("py_obj", wrapper()) html = """ <html><body> <script type="text/javascript"> document.write(py_obj.list) </script> </body></html> """ view.setHtml(html) view.show() self.app.exec_()
def testQVariantListProperty(self): class Obj(object): list = ['foo', 'bar', 'baz'] obj = Obj() wrapper_dict = {} for name in ['list']: getter = lambda arg=None, name=name: getattr(obj, name) wrapper_dict[name] = Property('QVariantList', getter) wrapper = type('PyObj', (QObject, ), wrapper_dict) view = QWebView() frame = view.page().mainFrame() frame.addToJavaScriptWindowObject('py_obj', wrapper()) html = ''' <html><body> <script type="text/javascript"> document.write(py_obj.list) </script> </body></html> ''' view.setHtml(html) view.show() self.app.exec_()
def createWebView( nIndex ): global functionID global currentWebView functionID = nIndex currentWebView = QWebView() currentWebView._jsfuncs = JSFuncs() currentWebView.page().mainFrame().addToJavaScriptWindowObject("jsfuncs", currentWebView._jsfuncs) QObject.connect( currentWebView, QtCore.SIGNAL('loadFinished( bool )'), onLoadFinished ) currentWebView.load(PAGE_DATA % FUNCTIONS_LIST[ nIndex ]) currentWebView.show()
def testPlugin(self): view = QWebView() fac = PluginFactory() view.page().setPluginFactory(fac) QWebSettings.globalSettings().setAttribute(QWebSettings.PluginsEnabled, True) view.load(QUrl(os.path.join(os.path.abspath(os.path.dirname(__file__)), 'qmlplugin', 'index.html'))) view.resize(840, 600) view.show() QTimer.singleShot(500, self.app.quit) self.app.exec_()
def main(): app = QApplication([]) view = QWebView() fac = PluginFactory() view.page().setPluginFactory(fac) QWebSettings.globalSettings().setAttribute(QWebSettings.PluginsEnabled, True) view.load(QUrl(sys.argv[1])) view.resize(840, 600) view.show() return app.exec_()
def testPlugin(self): view = QWebView() fac = PluginFactory() view.page().setPluginFactory(fac) QWebSettings.globalSettings().setAttribute(QWebSettings.PluginsEnabled, True) view.load( QUrl( os.path.join(os.path.abspath(os.path.dirname(__file__)), 'qmlplugin', 'index.html'))) view.resize(840, 600) view.show() QTimer.singleShot(500, self.app.quit) self.app.exec_()