Re: [PyQt] QWebView.page() and setPage()

2013-02-05 Thread Detlev Offenbach


On Sunday 03 February 2013, 18:13:00 Jiangcheng Bao wrote:
> I am trying to store a current page held by QWebView away, then after
> loading and processing a different page, restore the previous page,
> without having to actually request it again, but it seems that by
> doing the following, the application lost my original page, and still
> gives me back the new one. Maybe because it is just a reference to the
> page itself. Is there anyway I can actually store that page and reuse
> it, just like a regular browser would cache the page and load it
> relatively quickly when you revisit it?
> 
> Thanks
> J
> 
> import sys
> from time import sleep
> 
> from PyQt4.QtGui import QApplication
> from PyQt4.QtCore import QUrl
> from PyQt4.QtWebKit import QWebView
> 
> class Browser(QWebView):
> 
> def __init__(self):
> QWebView.__init__(self)
> self.loadFinished.connect(self.load_finished)
> 
> def load_finished(self, ok):
> print('page title: ' + self.title())
> 
> if __name__ == '__main__':
> app = QApplication(sys.argv)
> browser = Browser()
> 
> browser.load(QUrl('http://www.google.com'))
> 
> # store this result away
> google_page = browser.page()

Did you try:
google_page = QWebPage(browser.page())

> print('current page: ' + browser.title())
> # now load a different page
> 
> browser.load(QUrl('http://www.yahoo.com'))
> print('some other page: ' + browser.title())
> 
> #if browser.page():
> #browser.page().setView(None)
> 
> # lets put back my old page
> browser.setPage(google_page)
> print('my original page: ' + browser.title())
> 
> exit(app.exec_())
> ___
> PyQt mailing listPyQt@riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Detlev
-- 
Detlev Offenbach
det...@die-offenbachs.de___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

[PyQt] QWebView.page() and setPage()

2013-02-03 Thread Jiangcheng Bao
I am trying to store a current page held by QWebView away, then after
loading and processing a different page, restore the previous page,
without having to actually request it again, but it seems that by
doing the following, the application lost my original page, and still
gives me back the new one. Maybe because it is just a reference to the
page itself. Is there anyway I can actually store that page and reuse
it, just like a regular browser would cache the page and load it
relatively quickly when you revisit it?

Thanks
J

import sys
from time import sleep

from PyQt4.QtGui import QApplication
from PyQt4.QtCore import QUrl
from PyQt4.QtWebKit import QWebView

class Browser(QWebView):

def __init__(self):
QWebView.__init__(self)
self.loadFinished.connect(self.load_finished)

def load_finished(self, ok):
print('page title: ' + self.title())

if __name__ == '__main__':
app = QApplication(sys.argv)
browser = Browser()

browser.load(QUrl('http://www.google.com'))

# store this result away
google_page = browser.page()
print('current page: ' + browser.title())
# now load a different page

browser.load(QUrl('http://www.yahoo.com'))
print('some other page: ' + browser.title())

#if browser.page():
#browser.page().setView(None)

# lets put back my old page
browser.setPage(google_page)
print('my original page: ' + browser.title())

exit(app.exec_())
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt