Menú

Mostrar Mensajes

Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.

Mostrar Mensajes Menú

Temas - n1co

#1
Scripting / [SOLUCIONADO]WebKit Python PyQt4
28 Febrero 2011, 20:02 PM

Hola a todos. Tengo un problemita, quiero hacer una app que pueda cargar varias paginas, la idea es que cargue una pagina en esta ventana de webkit, y al pasar un tiempo determinado por ejemplo 5 min o 10 seg lo que sea, cargue otra, el problema es que si yo hago un metodo que cargue varias paginas, solo veo cargarse la ultima que pongo, no las anteriores, esto me suena a un problema de eventos pero no he encontrado la info que necesito en internet. Espero que alguien me pueda ayudar, dejo el codigo aquí.

Muchas gracias



Código (python) [Seleccionar]

# -*- coding: utf-8 -*-
import sys

from PyQt4 import QtCore, QtGui, QtWebKit
from httpWidget import Ui_HttpWidget

class httpWidget(QtGui.QWidget):
def __init__(self, parent=None):
super(httpWidget, self).__init__(parent)
self.ui = Ui_HttpWidget()
self.ui.setupUi(self)

# set margins
l = self.layout()
l.setMargin(0)
self.ui.horizontalLayout.setMargin(5)

# set the default
url = 'http://localhost:8080'
self.ui.url.setText(url)

# load page
self.ui.webView.setUrl(QtCore.QUrl(url))

# history buttons:
self.ui.back.setEnabled(False)
self.ui.next.setEnabled(False)

QtCore.QObject.connect(self.ui.back,QtCore.SIGNAL("clicked()"), self.back)
QtCore.QObject.connect(self.ui.next,QtCore.SIGNAL("clicked()"), self.next)
QtCore.QObject.connect(self.ui.url,QtCore.SIGNAL("returnPressed()"), self.url_changed)
QtCore.QObject.connect(self.ui.webView,QtCore.SIGNAL("linkClicked (const QUrl&)"), self.link_clicked)
QtCore.QObject.connect(self.ui.webView,QtCore.SIGNAL("urlChanged (const QUrl&)"), self.link_clicked)
QtCore.QObject.connect(self.ui.webView,QtCore.SIGNAL("loadProgress (int)"), self.load_progress)
QtCore.QObject.connect(self.ui.webView,QtCore.SIGNAL("titleChanged (const QString&)"), self.title_changed)
QtCore.QObject.connect(self.ui.reload,QtCore.SIGNAL("clicked()"), self.reload_page)
QtCore.QObject.connect(self.ui.stop,QtCore.SIGNAL("clicked()"), self.stop_page)

QtCore.QMetaObject.connectSlotsByName(self)

def url_changed(self):
"""
Url have been changed by user
"""
page = self.ui.webView.page()
history = page.history()
if history.canGoBack():
self.ui.back.setEnabled(True)
else:
self.ui.back.setEnabled(False)
if history.canGoForward():
self.ui.next.setEnabled(True)
else:
self.ui.next.setEnabled(False)

url = self.ui.url.text()
self.ui.webView.setUrl(QtCore.QUrl(url))

def stop_page(self):
"""
Stop loading the page
"""
self.ui.webView.stop()

def title_changed(self, title):
"""
Web page title changed - change the tab name
"""
self.setWindowTitle(title)

def reload_page(self):
"""
Reload the web page
"""
self.ui.webView.setUrl(QtCore.QUrl(self.ui.url.text()))

def link_clicked(self, url):
"""
Update the URL if a link on a web page is clicked
"""
page = self.ui.webView.page()
history = page.history()
if history.canGoBack():
self.ui.back.setEnabled(True)
else:
self.ui.back.setEnabled(False)
if history.canGoForward():
self.ui.next.setEnabled(True)
else:
self.ui.next.setEnabled(False)

self.ui.url.setText(url.toString())

def load_progress(self, load):
"""
Page load progress
"""
if load == 100:
self.ui.stop.setEnabled(False)
else:
self.ui.stop.setEnabled(True)

def back(self):
"""
Back button clicked, go one page back
"""
page = self.ui.webView.page()
history = page.history()
history.back()
if history.canGoBack():
self.ui.back.setEnabled(True)
else:
self.ui.back.setEnabled(False)

def next(self):
"""
Next button clicked, go to next page
"""
page = self.ui.webView.page()
history = page.history()
history.forward()
if history.canGoForward():
self.ui.next.setEnabled(True)
else:
self.ui.next.setEnabled(False)

if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
myapp = httpWidget()
myapp.show()
sys.exit(app.exec_())