[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&nbsp;: 
  <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>">&lt;bjtexas@swbell.net&gt;</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 &amp; 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>-------%&lt;-----------------<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>&nbsp;&nbsp;&nbsp; def 
  setupUi(self, WebDlg):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  WebDlg.resize(671, 588)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  WebDlg.setWindowTitle("GeoTag")<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  self.gridLayout = 
  QtGui.QGridLayout(WebDlg)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  self.verticalLayout = 
  QtGui.QVBoxLayout()<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.webView 
  = QtWebKit.QWebView(WebDlg)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  self.verticalLayout.addWidget(self.webView)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
  self.horizontalLayout_2 = 
  QtGui.QHBoxLayout()<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  self.horizontalLayout = 
  QtGui.QHBoxLayout()<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  self.link_led = 
  QtGui.QLineEdit(WebDlg)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  self.link_led.setMinimumSize(QtCore.QSize(400, 
  0))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  self.horizontalLayout.addWidget(self.link_led)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
  self.get_coord_btn = 
  QtGui.QToolButton(WebDlg)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  self.get_coord_btn.setText("Get 
  coord.")<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  self.horizontalLayout.addWidget(self.get_coord_btn)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
  self.progressBar = 
  QtGui.QProgressBar(WebDlg)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  self.progressBar.setProperty("value", 
  0)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  self.progressBar.setTextVisible(False)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
  self.horizontalLayout.addWidget(self.progressBar)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
  self.close_btn = 
  QtGui.QPushButton(WebDlg)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  self.close_btn.setText("Close")<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  self.horizontalLayout.addWidget(self.close_btn)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
  self.verticalLayout.addLayout(self.horizontalLayout)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
  self.gridLayout.addLayout(self.verticalLayout, 0, 0, 1, 
  1)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.webPage = 
  QtWebKit.QWebPage()<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  self.webView.setPage(self.webPage)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  self.webView.settings().setAttribute(QtWebKit.QWebSettings.PluginsEnabled, 
  True)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  self.webView.loadProgress.connect(self.progress)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
  self.webView.urlChanged.connect(self.set_link)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
  self.webPage.contentsChanged.connect(self.pos_changed)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
  frame = self.webPage.mainFrame()<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  self.get_coord_btn.clicked.connect(self.pos_changed)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
  self.close_btn.clicked.connect(WebDlg.accept)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
  QtCore.QMetaObject.connectSlotsByName(WebDlg)<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
  self.set_link("mapViewer.html")<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  self.load_page()<BR><BR>&nbsp;&nbsp;&nbsp; def set_link(self, 
  url):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if not isinstance(url, 
  str):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  url = url.toString()<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  self.link_led.setText(url)<BR><BR>&nbsp;&nbsp;&nbsp; def 
  load_page(self):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; url = 
  str(self.link_led.text())<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  self.webView.setUrl(QtCore.QUrl(url))<BR><BR>&nbsp;&nbsp;&nbsp; def 
  progress(self, val):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  self.progressBar.setValue(val)<BR><BR>&nbsp;&nbsp;&nbsp; def 
  resize_event(self, event):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print 
  "Geometry %s" % 
  self.webView.geometry()<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  QtWebKit.QWebView.resizeEvent(self.webView, event)<BR><BR>&nbsp;&nbsp;&nbsp; 
  def pos_changed(self, event):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  frame = self.webPage.mainFrame()<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  document = 
  frame.documentElement()<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; datas = 
  document.findAll("div")<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print 
  "found %s 'div'" % datas.count()<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  dat = 
  frame.findFirstElement("div#latlon")<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  print dat, dat.toPlainText()<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  dat.setFocus()<BR><BR>if __name__ == "__main__":<BR>&nbsp;&nbsp;&nbsp; import 
  sys<BR>&nbsp;&nbsp;&nbsp; app = 
  QtGui.QApplication(sys.argv)<BR>&nbsp;&nbsp;&nbsp; WebDlg = 
  QtGui.QDialog()<BR>&nbsp;&nbsp;&nbsp; ui = WebDialog()<BR>&nbsp;&nbsp;&nbsp; 
  ui.setupUi(WebDlg)<BR>&nbsp;&nbsp;&nbsp; WebDlg.show()<BR>&nbsp;&nbsp;&nbsp; 
  sys.exit(app.exec_())<BR><BR>----%&lt;-------------------------<BR>and the 
  javascript<BR><BR>mapViewer.html<BR>-----%&lt;-------------------------<BR><BR>&lt;!DOCTYPE \
  html&gt;<BR>&lt;html&gt;<BR>&lt;head&gt;<BR>&lt;meta name="viewport" 
  content="initial-scale=1.0, user-scalable=no" /&gt;<BR>&lt;style 
  type="text/css"&gt;<BR>&nbsp; html { height: 100% }<BR>&nbsp; body { height: 
  100%; margin: 0px; padding: 0px }<BR>&nbsp; #map_canvas { height: 100% 
  }<BR>&lt;/style&gt;<BR>&lt;script type="text/javascript"<BR>&nbsp;&nbsp;&nbsp; 
  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>&gt;<BR>&lt;/script&gt;<BR>&lt;script \
  type="text/javascript"&gt;<BR><BR><BR>&nbsp; function updateLatLonFields(lat, 
  lon) {<BR>&nbsp;&nbsp;&nbsp; document.getElementById("latlon").innerHTML = lat 
  + ', ' + lon;<BR>&nbsp; }<BR><BR>&nbsp; function initialize() 
  {<BR>&nbsp;&nbsp;&nbsp; var latlng = new google.maps.LatLng(-34.397, 
  150.644);<BR>&nbsp;&nbsp;&nbsp; var myOptions = 
  {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; zoom: 8,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  center: latlng,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mapTypeId: 
  google.maps.MapTypeId.ROADMAP<BR>&nbsp;&nbsp;&nbsp; };<BR>&nbsp;&nbsp;&nbsp; 
  var map = new 
  google.maps.Map(document.getElementById("map_canvas"),<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
  myOptions);<BR><BR>&nbsp;&nbsp;&nbsp; 
  document.getElementById("latlon").innerHTML = latlng.lat() + ",&nbsp; " + 
  latlng.lng();<BR><BR>&nbsp;&nbsp;&nbsp; google.maps.event.addListener(map, 
  'bounds_changed', function() {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  var center = map.getCenter();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  updateLatLonFields(center.lat(), 
  center.lng());<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; });<BR><BR>&nbsp; 
  }<BR><BR>&lt;/script&gt;<BR>&lt;/head&gt;<BR>&lt;body 
  onload="initialize()"&gt;<BR>&nbsp; &lt;div id="map_canvas" style="width:100%; 
  height:100%"&gt;&lt;/div&gt;<BR>&nbsp; &lt;div 
  id="latlon"&gt;&lt;/div&gt;<BR>&lt;/body&gt;<BR>&lt;/html&gt;<BR><BR>--------%&lt;--------------------------------<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&nbsp;&nbsp;&nbsp; 
  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.&nbsp; 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>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial>Thanks for your response.</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial>Bob</FONT></DIV>
<DIV>&nbsp;</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