Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- from PyQt4.QtCore import *
- from PyQt4.QtNetwork import *
- # -*- coding: utf-8 -*-
- from PyQt4.QtCore import *
- from PyQt4.QtNetwork import *
- from PyQt4.QtGui import *
- from PyQt4.QtWebKit import *
- class BaseBrowser(QWidget):
- def __init__(self, parent = None):
- super(BaseBrowser, self).__init__(parent)
- self.__progress = 0
- QNetworkProxyFactory.setUseSystemConfiguration(True)
- self.webView = QWebView()
- self.webView.load(QUrl("http://www.yandex.ru"))
- self.connect(self.webView, SIGNAL("loadFinished(bool)"), self.adjustLocation)
- self.connect(self.webView, SIGNAL("titleChanged(QString)"), self.adjustTitle)
- self.connect(self.webView, SIGNAL("loadProgress(int)"), self.setProgress)
- self.connect(self.webView, SIGNAL("loadFinished(bool)"), self.finishLoading)
- self.locationEdit = QLineEdit()
- self.locationEdit.setSizePolicy(QSizePolicy.Expanding, self.locationEdit.sizePolicy().verticalPolicy())
- self.connect(self.locationEdit, SIGNAL("returnPressed()"), self.changeLocation)
- self.goButton = QPushButton("Go")
- self.connect(self.goButton, SIGNAL("clicked()"), self.changeLocation)
- self.layout = QGridLayout(self)
- self.layout.addWidget(self.locationEdit, 0, 0)
- self.layout.addWidget(self.goButton, 0, 1)
- self.layout.addWidget(self.webView, 1, 0, 1, 2)
- self.setLayout(self.layout)
- def adjustLocation(self):
- self.locationEdit.setText(self.webView.url().toString())
- def changeLocation(self):
- url = self.locationEdit.text()
- if url[0:7] != 'http://':
- url = 'http://' + url
- self.webView.load(QUrl(url))
- self.webView.setFocus()
- def adjustTitle(self):
- if self.__progress <= 0 or self.__progress >= 100:
- self.setWindowTitle(self.webView.title())
- else:
- self.setWindowTitle(QString("%1 (%2%)").arg(self.webView.title()).arg(self.__progress))
- def setProgress(self, p):
- self.__progress = p
- self.adjustTitle()
- def finishLoading(self):
- self.__progress = 100
- self.adjustTitle()
- if __name__ == "__main__":
- import sys
- app = QApplication(sys.argv)
- prog = BaseBrowser()
- prog.show()
- sys.exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement