[PyQt] Link between a QWebViev and a JavaScript program

projetmbc projetmbc at club-internet.fr
Mon Apr 20 09:34:03 BST 2009


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.

-------------- next part --------------
# -*- 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_())



More information about the PyQt mailing list