All pastes #1895050 Raw Edit

PyQt mini browser

public python v1 · immutable
#1895050 ·published 2010-07-05 17:45 UTC
rendered paste body
#!/usr/bin/env python# -*- coding: utf-8 -*-import sysfrom PyQt4 import QtGui, QtCore, QtWebKitDEFAULT_URL = 'http://www.google.com' # Change this as you Wishclass SimpleBrowser (QtGui.QMainWindow): # needs PyQt    def __init__(self, url):        QtGui.QMainWindow.__init__(self, None)        self.central=QtGui.QWidget(self)        self.layout=QtGui.QVBoxLayout(self.central)        self.setCentralWidget(self.central)        self.text=QtGui.QLineEdit()        self.browser=QtWebKit.QWebView()        self.layout.addWidget(self.text)        self.layout.addWidget(self.browser)        self.text.editingFinished.connect(self.changeUrl)        self.changeUrl(url)        self.browser.urlChanged.connect(self.updateUrl)        self.tools=self.addToolBar("Main Toolbar")        self.tools.show()        for a in [QtWebKit.QWebPage.Back, QtWebKit.QWebPage.Forward, QtWebKit.QWebPage.Stop, QtWebKit.QWebPage.Reload]:            self.tools.addAction(self.browser.pageAction(a))            def updateUrl(self, url=None):        if url:            self.text.setText(url.toString())    def changeUrl(self, url=None):        if url:            self.browser.setUrl(QtCore.QUrl(url))        if __name__ == '__main__':    if len(sys.argv) > 1:        url = sys.argv[1]    else:        url = DEFAULT_URL    app = QtGui.QApplication(sys.argv)    browser = SimpleBrowser(url)    browser.show()    app.exec_()