[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: Re: [PyQt] Are theer limits to the ability of QWebView to process
From: "BJ" <bjtexas () swbell ! net>
Date: 2011-07-26 21:26:15
Message-ID: 509C0CC960FD4F75AA45103397B8072F () BobPC
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
----- Original Message -----
From: Vincent Vande Vyvre
To: pyqt@riverbankcomputing.com
Sent: Saturday, July 23, 2011 12:12 AM
Subject: Re: [PyQt] Are theer limits to the ability of QWebView to process javascript?
Le 23/07/11 03:12, Phlip a écrit :
On Fri, Jul 22, 2011 at 1:14 PM, BJ <bjtexas@swbell.net> wrote:
I have a webpage containing quite a bit of javascript to display Google
Maps.
It seems to run well on IE and Firefox browsers but is unable to run in a
QWebView.
Can you report any error messages, or logging? Can you survey other
Ajax sites & see if any do or don't work?
Does any of the maps page show at all?
And recall that Google Maps depends on your cache to hold each
regional image tile. So does QWebView have, for example, a different
cache than real web browsers that use webkit?
This code is working:
-------%<-----------------
# -*- coding: utf-8 -*-
import sys
from PyQt4 import QtCore, QtGui
from PyQt4 import QtWebKit
class WebDialog(object):
def setupUi(self, WebDlg):
WebDlg.resize(671, 588)
WebDlg.setWindowTitle("GeoTag")
self.gridLayout = QtGui.QGridLayout(WebDlg)
self.verticalLayout = QtGui.QVBoxLayout()
self.webView = QtWebKit.QWebView(WebDlg)
self.verticalLayout.addWidget(self.webView)
self.horizontalLayout_2 = QtGui.QHBoxLayout()
self.horizontalLayout = QtGui.QHBoxLayout()
self.link_led = QtGui.QLineEdit(WebDlg)
self.link_led.setMinimumSize(QtCore.QSize(400, 0))
self.horizontalLayout.addWidget(self.link_led)
self.get_coord_btn = QtGui.QToolButton(WebDlg)
self.get_coord_btn.setText("Get coord.")
self.horizontalLayout.addWidget(self.get_coord_btn)
self.progressBar = QtGui.QProgressBar(WebDlg)
self.progressBar.setProperty("value", 0)
self.progressBar.setTextVisible(False)
self.horizontalLayout.addWidget(self.progressBar)
self.close_btn = QtGui.QPushButton(WebDlg)
self.close_btn.setText("Close")
self.horizontalLayout.addWidget(self.close_btn)
self.verticalLayout.addLayout(self.horizontalLayout)
self.gridLayout.addLayout(self.verticalLayout, 0, 0, 1, 1)
self.webPage = QtWebKit.QWebPage()
self.webView.setPage(self.webPage)
self.webView.settings().setAttribute(QtWebKit.QWebSettings.PluginsEnabled, True)
self.webView.loadProgress.connect(self.progress)
self.webView.urlChanged.connect(self.set_link)
self.webPage.contentsChanged.connect(self.pos_changed)
frame = self.webPage.mainFrame()
self.get_coord_btn.clicked.connect(self.pos_changed)
self.close_btn.clicked.connect(WebDlg.accept)
QtCore.QMetaObject.connectSlotsByName(WebDlg)
self.set_link("mapViewer.html")
self.load_page()
def set_link(self, url):
if not isinstance(url, str):
url = url.toString()
self.link_led.setText(url)
def load_page(self):
url = str(self.link_led.text())
self.webView.setUrl(QtCore.QUrl(url))
def progress(self, val):
self.progressBar.setValue(val)
def resize_event(self, event):
print "Geometry %s" % self.webView.geometry()
QtWebKit.QWebView.resizeEvent(self.webView, event)
def pos_changed(self, event):
frame = self.webPage.mainFrame()
document = frame.documentElement()
datas = document.findAll("div")
print "found %s 'div'" % datas.count()
dat = frame.findFirstElement("div#latlon")
print dat, dat.toPlainText()
dat.setFocus()
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
WebDlg = QtGui.QDialog()
ui = WebDialog()
ui.setupUi(WebDlg)
WebDlg.show()
sys.exit(app.exec_())
----%<-------------------------
and the javascript
mapViewer.html
-----%<-------------------------
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0px; padding: 0px }
#map_canvas { height: 100% }
</style>
<script type="text/javascript"
src="http://maps.google.com/maps/api/js?sensor=false">
</script>
<script type="text/javascript">
function updateLatLonFields(lat, lon) {
document.getElementById("latlon").innerHTML = lat + ', ' + lon;
}
function initialize() {
var latlng = new google.maps.LatLng(-34.397, 150.644);
var myOptions = {
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
document.getElementById("latlon").innerHTML = latlng.lat() + ", " + latlng.lng();
google.maps.event.addListener(map, 'bounds_changed', function() {
var center = map.getCenter();
updateLatLonFields(center.lat(), center.lng());
});
}
</script>
</head>
<body onload="initialize()">
<div id="map_canvas" style="width:100%; height:100%"></div>
<div id="latlon"></div>
</body>
</html>
--------%<--------------------------------
Same results with OpenStreetMap
Regards
--
Vincent V.V.
Oqapy . Qarte+7 . PaQager
------------------------------------------------------------------------------
_______________________________________________
PyQt mailing list PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Thanks for the example Vincent, I found my problem after looking at your
example. However there seems to be some functionality issues. I can't
pan with the cursor or get my infowindows to work.
Thanks for your response.
Bob
[Attachment #5 (text/html)]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE></TITLE>
<META content="text/html; charset=ISO-8859-1" http-equiv=Content-Type>
<META name=GENERATOR content="MSHTML 9.00.8112.16430">
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff text=#000000>
<BLOCKQUOTE
style="BORDER-LEFT: #000000 2px solid; PADDING-LEFT: 5px; PADDING-RIGHT: 0px; \
MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px"> <DIV style="FONT: 10pt arial">----- Original \
Message ----- </DIV> <DIV
style="FONT: 10pt arial; BACKGROUND: #e4e4e4; font-color: black"><B>From:</B>
<A title=vincent.vandevyvre@swing.be
href="mailto:vincent.vandevyvre@swing.be">Vincent Vande Vyvre</A> </DIV>
<DIV style="FONT: 10pt arial"><B>To:</B> <A title=pyqt@riverbankcomputing.com
href="mailto:pyqt@riverbankcomputing.com">pyqt@riverbankcomputing.com</A>
</DIV>
<DIV style="FONT: 10pt arial"><B>Sent:</B> Saturday, July 23, 2011 12:12
AM</DIV>
<DIV style="FONT: 10pt arial"><B>Subject:</B> Re: [PyQt] Are theer limits to
the ability of QWebView to process javascript?</DIV>
<DIV><BR></DIV>Le 23/07/11 03:12, Phlip a écrit :
<BLOCKQUOTE
cite=mid:CADC6JdSGTJbaZ9wboD2xC5AN6KkNNGX_ZhZz6ZD-PE1Q2-pd6w@mail.gmail.com
type="cite"><PRE wrap="">On Fri, Jul 22, 2011 at 1:14 PM, BJ <A \
class=moz-txt-link-rfc2396E \
href="mailto:bjtexas@swbell.net>"><bjtexas@swbell.net></A> wrote:
</PRE>
<BLOCKQUOTE type="cite"><PRE wrap="">I have a webpage containing quite a bit of \
javascript to display Google Maps.
It seems to run well on IE and Firefox browsers but is unable to run in a
QWebView.
</PRE></BLOCKQUOTE><PRE wrap="">Can you report any error messages, or logging? Can \
you survey other Ajax sites & see if any do or don't work?
Does any of the maps page show at all?
And recall that Google Maps depends on your cache to hold each
regional image tile. So does QWebView have, for example, a different
cache than real web browsers that use webkit?
</PRE></BLOCKQUOTE>This code is
working:<BR><BR>-------%<-----------------<BR># -*- coding: utf-8
-*-<BR><BR>import sys<BR><BR>from PyQt4 import QtCore, QtGui<BR>from PyQt4
import QtWebKit<BR><BR>class WebDialog(object):<BR> def
setupUi(self, WebDlg):<BR>
WebDlg.resize(671, 588)<BR>
WebDlg.setWindowTitle("GeoTag")<BR>
self.gridLayout =
QtGui.QGridLayout(WebDlg)<BR>
self.verticalLayout =
QtGui.QVBoxLayout()<BR> self.webView
= QtWebKit.QWebView(WebDlg)<BR>
self.verticalLayout.addWidget(self.webView)<BR> \
self.horizontalLayout_2 =
QtGui.QHBoxLayout()<BR>
self.horizontalLayout =
QtGui.QHBoxLayout()<BR>
self.link_led =
QtGui.QLineEdit(WebDlg)<BR>
self.link_led.setMinimumSize(QtCore.QSize(400,
0))<BR>
self.horizontalLayout.addWidget(self.link_led)<BR> \
self.get_coord_btn =
QtGui.QToolButton(WebDlg)<BR>
self.get_coord_btn.setText("Get
coord.")<BR>
self.horizontalLayout.addWidget(self.get_coord_btn)<BR> \
self.progressBar =
QtGui.QProgressBar(WebDlg)<BR>
self.progressBar.setProperty("value",
0)<BR>
self.progressBar.setTextVisible(False)<BR> \
self.horizontalLayout.addWidget(self.progressBar)<BR> \
self.close_btn =
QtGui.QPushButton(WebDlg)<BR>
self.close_btn.setText("Close")<BR>
self.horizontalLayout.addWidget(self.close_btn)<BR> \
self.verticalLayout.addLayout(self.horizontalLayout)<BR> \
self.gridLayout.addLayout(self.verticalLayout, 0, 0, 1,
1)<BR> self.webPage =
QtWebKit.QWebPage()<BR>
self.webView.setPage(self.webPage)
<BR>
self.webView.settings().setAttribute(QtWebKit.QWebSettings.PluginsEnabled,
True)<BR>
self.webView.loadProgress.connect(self.progress)<BR> \
self.webView.urlChanged.connect(self.set_link)<BR> \
self.webPage.contentsChanged.connect(self.pos_changed)<BR> \
frame = self.webPage.mainFrame()<BR>
self.get_coord_btn.clicked.connect(self.pos_changed)<BR> \
self.close_btn.clicked.connect(WebDlg.accept)<BR> \
QtCore.QMetaObject.connectSlotsByName(WebDlg)<BR><BR> \
self.set_link("mapViewer.html")<BR>
self.load_page()<BR><BR> def set_link(self,
url):<BR> if not isinstance(url,
str):<BR>
url = url.toString()<BR>
self.link_led.setText(url)<BR><BR> def
load_page(self):<BR> url =
str(self.link_led.text())<BR>
self.webView.setUrl(QtCore.QUrl(url))<BR><BR> def
progress(self, val):<BR>
self.progressBar.setValue(val)<BR><BR> def
resize_event(self, event):<BR> print
"Geometry %s" %
self.webView.geometry()<BR>
QtWebKit.QWebView.resizeEvent(self.webView, event)<BR><BR>
def pos_changed(self, event):<BR>
frame = self.webPage.mainFrame()<BR>
document =
frame.documentElement()<BR> datas =
document.findAll("div")<BR> print
"found %s 'div'" % datas.count()<BR>
dat =
frame.findFirstElement("div#latlon")<BR>
print dat, dat.toPlainText()<BR>
dat.setFocus()<BR><BR>if __name__ == "__main__":<BR> import
sys<BR> app =
QtGui.QApplication(sys.argv)<BR> WebDlg =
QtGui.QDialog()<BR> ui = WebDialog()<BR>
ui.setupUi(WebDlg)<BR> WebDlg.show()<BR>
sys.exit(app.exec_())<BR><BR>----%<-------------------------<BR>and the
javascript<BR><BR>mapViewer.html<BR>-----%<-------------------------<BR><BR><!DOCTYPE \
html><BR><html><BR><head><BR><meta name="viewport"
content="initial-scale=1.0, user-scalable=no" /><BR><style
type="text/css"><BR> html { height: 100% }<BR> body { height:
100%; margin: 0px; padding: 0px }<BR> #map_canvas { height: 100%
}<BR></style><BR><script type="text/javascript"<BR>
src=<A class=moz-txt-link-rfc2396E
href="http://maps.google.com/maps/api/js?sensor=false">"http://maps.google.com/maps/api/js?sensor=false"</A>><BR></script><BR><script \
type="text/javascript"><BR><BR><BR> function updateLatLonFields(lat,
lon) {<BR> document.getElementById("latlon").innerHTML = lat
+ ', ' + lon;<BR> }<BR><BR> function initialize()
{<BR> var latlng = new google.maps.LatLng(-34.397,
150.644);<BR> var myOptions =
{<BR> zoom: 8,<BR>
center: latlng,<BR> mapTypeId:
google.maps.MapTypeId.ROADMAP<BR> };<BR>
var map = new
google.maps.Map(document.getElementById("map_canvas"),<BR> \
myOptions);<BR><BR>
document.getElementById("latlon").innerHTML = latlng.lat() + ", " +
latlng.lng();<BR><BR> google.maps.event.addListener(map,
'bounds_changed', function() {<BR>
var center = map.getCenter();<BR>
updateLatLonFields(center.lat(),
center.lng());<BR> });<BR><BR>
}<BR><BR></script><BR></head><BR><body
onload="initialize()"><BR> <div id="map_canvas" style="width:100%;
height:100%"></div><BR> <div
id="latlon"></div><BR></body><BR></html><BR><BR>--------%<--------------------------------<BR><BR>Same \
results with OpenStreetMap<BR><BR>Regards<BR><BR><BR>
<DIV class=moz-signature>-- <BR>Vincent V.V.<BR><A
href="https://launchpad.net/oqapy">Oqapy</A> . <A
href="https://launchpad.net/qarte+7">Qarte+7</A> . <A
href="https://launchpad.net/paqager">PaQager</A></DIV>
<P>
<HR>
<P></P>_______________________________________________<BR>PyQt mailing
list
PyQt@riverbankcomputing.com<BR>http://www.riverbankcomputing.com/mailman/listinfo/pyqt</BLOCKQUOTE>
<DIV><FONT size=2 face=Arial>Thanks for the example Vincent, I found my problem
after looking at your</FONT></DIV>
<DIV><FONT size=2 face=Arial>example. However there seems to be some
functionality issues. I can't</FONT></DIV>
<DIV><FONT size=2 face=Arial>pan with the cursor or get my infowindows to
work.</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT> </DIV>
<DIV><FONT size=2 face=Arial>Thanks for your response.</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT> </DIV>
<DIV><FONT size=2 face=Arial>Bob</FONT></DIV>
<DIV> </DIV></BODY></HTML>
_______________________________________________
PyQt mailing list PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic