You are not logged in.

1

Saturday, March 6th 2010, 6:59pm

window.open from QWebKit using pyqt

Dear all,


I've been trying to use QWebKit with pyqt as a front-end for the installable version of a web-application. In a few cases, I need to open pop-ups with window.open from Java-Script.

Below is the HTML code of my testing web-page [1], whereas the Javascript Alert works fine, but it fails to open a new window, even though I tried to set the respective property in the settings object [2].

What am I doing wrong?

Cheers,
Chris
soramimo has attached the following files:
  • test2_html.txt (274 Byte - 48 times downloaded - latest: Sep 6th 2010, 8:33pm)
  • webkit_py.txt (466 Byte - 44 times downloaded - latest: Aug 19th 2010, 10:31pm)

2

Sunday, March 7th 2010, 6:17am

Fighting fire with fire.
Three can keep a secret if two of them are dead.

3

Monday, March 15th 2010, 6:58pm

overriding createWindow

Hi Messenger,


thanks a lot for your reply! I tried the following (python not php):

PHP Source code

1
2
3
4
5
class CoolWebView(QWebView):

        def createWindow(selfwebWindowType):
            web QWebView()
            return web



If I understand the docs correctly, I should create a new instance of QWebView and return it.
Unfortunately, I get a segfaut, when executing window.open from Java-Script.

Then, I tried to specify the current QWebView as parent of the new one, as follows:

PHP Source code

1
2
3
4
5
class CoolWebView(QWebView):

        def createWindow(selfwebWindowType):
            web QWebView(self)  #THIS IS DIFFERENT
            return web


This fixed the segfault, but then nothing happens. No new window comes up :(.

Any Ideas?

Best,
Chris
soramimo has attached the following files:
  • webkit2_py.txt (617 Byte - 28 times downloaded - latest: Today, 3:15pm)
  • segfault.txt (4.26 kB - 21 times downloaded - latest: Sep 5th 2010, 6:00am)

This post has been edited 1 times, last edit by "soramimo" (Mar 15th 2010, 7:37pm)


4

Tuesday, March 16th 2010, 6:03am

I think always is necessary to take special care about objects lifetime.

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# -*- coding: utf-8 -*-
 #!/usr/bin/env python

import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtWebKit import *

class CustomWebView(QWebView):
	def __init__(self, parent = None):
		print("CustomWebView ctor")
		QWebView.__init__(self, parent)
	def createWindow(self, webWindowType):
		print("createWindow")
		self.view = CustomWebView()
		self.view.show()
		return self.view

app = QApplication(sys.argv)
web = CustomWebView()
#QWebView()
web.settings().setAttribute(QWebSettings.JavascriptEnabled, True)
web.settings().setAttribute(QWebSettings.JavascriptCanOpenWindows, True)
web.settings().setAttribute(QWebSettings.JavascriptCanAccessClipboard, True)
web.load(QUrl("test2.html"))
web.show()
sys.exit(app.exec_())

self.view stores new instance of CustomWebView in a variable. If you click a button twice you will see as previous (not stored any more) object is "auto" destroyed.
Fighting fire with fire.
Three can keep a secret if two of them are dead.

5

Tuesday, March 16th 2010, 4:51pm

Solved

Hi Messenger,


Thanks so much, it worked! Problem solved.


Best,
Chris

Rate this thread