cleanup
[pyside-example-qml-signalslot:qml-signalslot.git] / webkit.py
1 #!/usr/bin/env python
2 #-*- coding:utf-8 -*-
3
4
5 #  Set This value to 0 to test pyqt version
6 PYSIDE = 1
7
8
9 if PYSIDE:
10     from PySide.QtCore import *
11     from PySide.QtGui import *
12     from PySide.QtWebKit import *
13 else:
14     import sip
15     sip.setapi('QString', 2)
16     from PyQt4.QtCore import *
17     from PyQt4.QtGui import *
18     from PyQt4.QtWebKit import *
19     Slot=pyqtSlot
20 import sys
21
22
23 html='''
24 <html>
25 <head>
26 <script>
27 po.s1()
28 po.s2(42)
29 po.s3('Foo')
30 </script>
31 </head>
32 </html>
33 '''
34
35 class Po(QObject):
36     def __init__(self):
37         QObject.__init__(self)
38
39     @Slot()
40     def s1(self):
41         self._echo('S1: This is called without any argument')
42
43     @Slot(int)
44     def s2(self,i):
45         self._echo('S2: This is called with the number "%d"'%i)
46
47     @Slot(unicode)
48     def s3(self,s):
49         self._echo('S3: This is called with a string: %s'%s)
50
51     def _echo(self,s):
52         QMessageBox.information(None, "Info", s)
53         print s
54
55 app = QApplication(sys.argv)
56 po=Po()
57 web = QWebView()
58 web.show()
59 web.page().mainFrame().addToJavaScriptWindowObject("po", po)
60 web.setHtml(html)
61
62 sys.exit(app.exec_())
63