<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
<title></title>
</head>
<body text="#000000" bgcolor="#ffffff">
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>
</body>
</html>