Re: Re: [PyQt] Link between a QWebViev and a JavaScript program
Marcell Mars a écrit : from PyQt4.QtCore import * from PyQt4.QtGui import * from PyQt4.QtWebKit import * myWebKit = QWebView() myWebKit.show() myWebKit.setUrl(QUrl("http://www.google.com";)) myWebKit.page().mainFrame().evaluateJavaScript(open('jquery.js').read()) myWebKit.page().mainFrame().evaluateJavaScript("""$(document).ready(function() { $("body").css("background", "#f00");});""") Indeed the line myWebKit.page().mainFrame().evaluateJavaScript("""$(document).ready(function() { $("body").css("background", "#f00");});""") must be changed to self.webView.page().mainFrame().evaluateJavaScript("""$("body").css("background", "#f00");""") With this modification, everything is ok. Thanks. Christophe. ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] Link between a QWebViev and a JavaScript program
I've forgot the gui file. Here is it. Christophe. : Marcell Mars a écrit : the simplest example of loading jquery.js (geti it from http://jqueryjs.googlecode.com/files/jquery-1.3.2.js and put it in the same directory with the snippet below) after loading html and then using jquery syntax to change the background color into red: run it in python interactive shell or better in ipython: from PyQt4.QtCore import * from PyQt4.QtGui import * from PyQt4.QtWebKit import * myWebKit = QWebView() myWebKit.show() myWebKit.setUrl(QUrl("http://www.google.com";)) myWebKit.page().mainFrame().evaluateJavaScript(open('jquery.js').read()) myWebKit.page().mainFrame().evaluateJavaScript("""$(document).ready(function() { $("body").css("background", "#f00");});""") Your example doesn't work for me. I've done the program given with tis message and the files which are ine the same folder. What's wrong ? Christophe. # -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'C:\Documents and Settings\Christophe\Mes documents\2,pyBaNaMa\Deb_PythonEtPyQT\CodesProjets\99-WebViev-JavaScript\JQueryTest.ui ' # # Created: Mon Apr 20 00:32:39 2009 # by: PyQt4 UI code generator 4.4.4 # # WARNING! All changes made in this file will be lost! from PyQt4 import QtCore, QtGui class Ui_dial_Projet2(object): def setupUi(self, dial_Projet2): dial_Projet2.setObjectName("dial_Projet2") dial_Projet2.resize(805, 639) dial_Projet2.setAutoFillBackground(True) self.verticalLayout = QtGui.QVBoxLayout(dial_Projet2) self.verticalLayout.setObjectName("verticalLayout") self.webView = QtWebKit.QWebView(dial_Projet2) self.webView.setUrl(QtCore.QUrl("http://www.google.com";)) self.webView.setObjectName("webView") self.verticalLayout.addWidget(self.webView) self.retranslateUi(dial_Projet2) QtCore.QMetaObject.connectSlotsByName(dial_Projet2) def retranslateUi(self, dial_Projet2): dial_Projet2.setWindowTitle(QtGui.QApplication.translate("dial_Projet2", "Projet n°2", None, QtGui.QApplication.UnicodeUTF8)) from PyQt4 import QtWebKit if __name__ == "__main__": import sys app = QtGui.QApplication(sys.argv) dial_Projet2 = QtGui.QDialog() ui = Ui_dial_Projet2() ui.setupUi(dial_Projet2) dial_Projet2.show() sys.exit(app.exec_()) ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] Link between a QWebViev and a JavaScript program
Marcell Mars a écrit : the simplest example of loading jquery.js (geti it from http://jqueryjs.googlecode.com/files/jquery-1.3.2.js and put it in the same directory with the snippet below) after loading html and then using jquery syntax to change the background color into red: run it in python interactive shell or better in ipython: from PyQt4.QtCore import * from PyQt4.QtGui import * from PyQt4.QtWebKit import * myWebKit = QWebView() myWebKit.show() myWebKit.setUrl(QUrl("http://www.google.com";)) myWebKit.page().mainFrame().evaluateJavaScript(open('jquery.js').read()) myWebKit.page().mainFrame().evaluateJavaScript("""$(document).ready(function() { $("body").css("background", "#f00");});""") Your example doesn't work for me. I've done the program given with tis message and the files which are ine the same folder. What's wrong ? Christophe. A simple test # -*- coding: utf-8 -*- #!/usr/bin/env python # Les lignes ci-dessus sont très importantes : #1°) La 1ère ligne indique le codage du fichier Python. #2°) La 2nde ligne est indispensable pour un bon fonctionnement sous Linux. # PRESENTATION : ce script montre comment créé un fichier au format HTML ou PDF. # AUTEUR : BAL Christophe # MAIL : projet...@club.fr # SITE : http://christophe_bal.club.fr/index.php # DATE DE CREATION : 24/06/2008 # DERNIERE MODIFICATION : 10/12/2008 # # TEST(S) EFFECTUE(S) : programme testé sous Windows XP avec succès. # On importe les bibliothèques que nous allons utiliser. import sys from PyQt4 import QtCore, QtGui from PyQt4 import QtWebKit # On importe notre boîte de dialogue. from JQueryTest import Ui_dial_Projet2 class dial_Projet2(QtGui.QDialog, Ui_dial_Projet2): def __init__(self): QtGui.QDialog.__init__(self) Ui_dial_Projet2.__init__(self) self.verticalLayout = QtGui.QVBoxLayout(self) self.verticalLayout.setObjectName("verticalLayout") self.webView = QtWebKit.QWebView(self) self.webView.setUrl(QtCore.QUrl("test.html")) self.webView.setObjectName("webView") self.verticalLayout.addWidget(self.webView) self.webView.page().mainFrame().evaluateJavaScript(open('jquery.js').read()) self.webView.page().mainFrame().evaluateJavaScript("""$(document).ready(function() { $("body").css("background", "#ff0");});""") if __name__ == "__main__": import sys app = QtGui.QApplication(sys.argv) testFichier = dial_Projet2() testFichier.show() sys.exit(app.exec_()) ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] Link between a QWebViev and a JavaScript program
David Boddie a écrit : The porting of the C++ Qt examples to Python has fallen behind since Qt 4.3 so there aren't any simple WebKit examples included with PyQt. I'm not lucky... :-\ David Boddie a écrit : The recent Monster Evolution experiments on Qt Labs include a Python version of a program that integrates with WebKit's JavaScript engine: http://labs.trolltech.com/blogs/2009/04/07/monster-evolution-in-qt-episode-2-attack-of-the-squirrelfish/ QWebFrame's addToJavaScriptWindowObject() method lets you insert an instance of a QObject subclass into the page. You can expose methods to JavaScript, but you have to declare them as slots with the @pyqtSignature() decorator. The example code can be found here: http://labs.trolltech.com/gitweb?p=GraphicsDojo;a=blob;f=webmonster/webmonster.py I'll study it as soon as possible... Thanks. Christophe. ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] Link between a QWebViev and a JavaScript program
On Sun Apr 19 20:51:49 BST 2009, projetmbc wrote: > Simon Edwards a écrit : > > projetmbc wrote: > >> I'm seeking for information about how to comunicate from PyQt with a > >> JavaScript program. > > > > QWebFrame's evaluateJavaScript() might be a start. > > Indeed I'm looking for a simple example rather than an abstract one. The porting of the C++ Qt examples to Python has fallen behind since Qt 4.3 so there aren't any simple WebKit examples included with PyQt. Still, the recent Monster Evolution experiments on Qt Labs include a Python version of a program that integrates with WebKit's JavaScript engine: http://labs.trolltech.com/blogs/2009/04/07/monster-evolution-in-qt-episode-2-attack-of-the-squirrelfish/ QWebFrame's addToJavaScriptWindowObject() method lets you insert an instance of a QObject subclass into the page. You can expose methods to JavaScript, but you have to declare them as slots with the @pyqtSignature() decorator. The example code can be found here: http://labs.trolltech.com/gitweb?p=GraphicsDojo;a=blob;f=webmonster/webmonster.py David ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] Link between a QWebViev and a JavaScript program
the simplest example of loading jquery.js (geti it from http://jqueryjs.googlecode.com/files/jquery-1.3.2.js and put it in the same directory with the snippet below) after loading html and then using jquery syntax to change the background color into red: run it in python interactive shell or better in ipython: from PyQt4.QtCore import * from PyQt4.QtGui import * from PyQt4.QtWebKit import * myWebKit = QWebView() myWebKit.show() myWebKit.setUrl(QUrl("http://www.google.com";)) myWebKit.page().mainFrame().evaluateJavaScript(open('jquery.js').read()) myWebKit.page().mainFrame().evaluateJavaScript("""$(document).ready(function() { $("body").css("background", "#f00");});""") ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] Link between a QWebViev and a JavaScript program
Simon Edwards a écrit : projetmbc wrote: I'm seeking for information about how to comunicate from PyQt with a JavaScript program. QWebFrame's evaluateJavaScript() might be a start. Indeed I'm looking for a simple example rather than an abstract one. Christophe. ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] Link between a QWebViev and a JavaScript program
Simon Edwards a écrit : projetmbc wrote: I'm seeking for information about how to comunicate from PyQt with a JavaScript program. QWebFrame's evaluateJavaScript() might be a start. I also found a whitepaper of QT. I'll try to test that. Thanks for showing me the direction. Christophe. ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] Link between a QWebViev and a JavaScript program
projetmbc wrote: I'm seeking for information about how to comunicate from PyQt with a JavaScript program. QWebFrame's evaluateJavaScript() might be a start. -- Simon Edwards | KDE-NL, Guidance tools, Guarddog Firewall si...@simonzone.com | http://www.simonzone.com/software/ Nijmegen, The Netherlands | "ZooTV? You made the right choice." ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt