ok i have found a similar project which i do believe is dead now ... but the guy has made a browser with tabs and alot of other goodies heres the code
#!/usr/bin/env python
# Copyright (c) 2009 Harrison Erd
#
# This software is provided 'as-is', without any express or implied
# warranty. In no event will the authors be held liable for any damages
# arising from the use of this software.
#
# Permission is granted to anyone to use this software for any purpose,
# including commercial applications, and to alter it and redistribute it
# freely, subject to the following restrictions:
#
# 1. The origin of this software must not be misrepresented; you must not
# claim that you wrote the original software. If you use this software
# in a product, an acknowledgment in the product documentation would be
# appreciated but is not required.
#
# 2. Altered source versions must be plainly marked as such, and must not be
# misrepresented as being the original software.
#
# 3. This notice may not be removed or altered from any source
# distribution.
# fastPATX by PATX | Driver: Neil Wallace
# Version Evergreen | Questions? patx44@gmail.com
import sys
import urllib
from PyQt4 import QtCore, QtGui, QtWebKit
class patx_tab(QtGui.QWidget):
def __init__(self, index, parent=None):
super(QtGui.QWidget, self).__init__(parent)
self.mainUi = parent
self.index = index
print "making new tab with index",index
self.browser = QtWebKit.QWebView(self)
self.connect(self.browser, QtCore.SIGNAL('linkClicked (const QUrl&)'),
self.updateLineEdit)
self.connect(self.browser, QtCore.SIGNAL('urlChanged (const QUrl&)'),
self.updateLineEdit)
self.connect(self.browser, QtCore.SIGNAL('loadStarted ()'),
self.loadStarted)
self.connect(self.browser, QtCore.SIGNAL('loadFinished (bool)'),
self.loadFinished)
self.current_url = QtCore.QUrl("http://www.google.com/")
self.browser.setUrl(self.current_url)
self.horizontalLayout = QtGui.QHBoxLayout(self)
self.horizontalLayout.addWidget(self.browser)
def GoLink(self, url):
self.current_url = url
self.browser.load(url)
page = self.browser.page()
page.setLinkDelegationPolicy(QtWebKit.QWebPage.DelegateAllLinks)
def loadStarted(self):
print "loading page...",
def loadFinished(self,arg):
print "load finished...",
if arg:
print "sucess"
self.mainUi.tabWidget.setTabText(self.index, self.browser.title())
else:
print "failed"
self.tellFailLoad()
def updateLineEdit(self,url):
self.current_url = url
if self.index == self.mainUi.tabWidget.currentIndex():
self.mainUi.updateLineEdit(url)
def tellFailLoad(self):
self.browser.setHtml('<p>This page could not be rendered/loaded.</p>')
class fastpatx(QtGui.QMainWindow):
def __init__(self, parent=None):
super(QtGui.QMainWindow, self).__init__(parent)
self.resize(800, 600)
centralwidget = QtGui.QWidget(self)
self.toolbar = QtGui.QToolBar(centralwidget)
self.lineEdit = QtGui.QLineEdit(centralwidget)
self.GoButton = QtGui.QPushButton(centralwidget)
self.tabWidget = QtGui.QTabWidget(centralwidget)
self.tabWidget.setElideMode(QtCore.Qt.ElideRight)
self.tb = self.tabWidget.tabBar()
self.tb.hide()
self.addNewTab()
gridLayout = QtGui.QGridLayout(centralwidget)
gridLayout.setObjectName("gridLayout")
gridLayout.setSpacing(3)
gridLayout.setContentsMargins(3,3,3,3)
gridLayout.addWidget(self.toolbar, 0, 0, 1, 2)
gridLayout.addWidget(self.tabWidget, 2, 0, 1, 2)
gridLayout.addWidget(self.lineEdit, 1, 0, 1, 1)
gridLayout.addWidget(self.GoButton, 1, 1, 1, 1)
self.setCentralWidget(centralwidget)
menubar = QtGui.QMenuBar(self)
menubar.setGeometry(QtCore.QRect(0, 0, 800, 23))
self.setMenuBar(menubar)
self.statusbar = QtGui.QStatusBar(self)
self.setStatusBar(self.statusbar)
self.add_labels()
self.homeButton = QtGui.QPushButton('Home')
self.goBck = QtGui.QPushButton('Go Back')
self.srcButton = QtGui.QPushButton('View Source')
self.bookmark = QtGui.QPushButton('Bookmark Page')
self.bookmarks = QtGui.QPushButton('Your Bookmarks')
self.downloadb = QtGui.QPushButton('Download Page')
self.addTabBtn = QtGui.QPushButton('New Tab')
self.delTabBtn = QtGui.QPushButton('Close Tab')
self.fpAbout = QtGui.QPushButton('About')
self.goFwd = QtGui.QPushButton('Go Forward')
self.toolbar.addWidget(self.homeButton)
self.toolbar.addWidget(self.goBck)
self.toolbar.addWidget(self.goFwd)
self.toolbar.addWidget(self.bookmark)
self.toolbar.addWidget(self.bookmarks)
self.toolbar.addWidget(self.srcButton)
self.toolbar.addWidget(self.downloadb)
self.toolbar.addWidget(self.addTabBtn)
self.toolbar.addWidget(self.delTabBtn)
self.toolbar.addWidget(self.fpAbout)
self.connect(self.lineEdit,
QtCore.SIGNAL('returnPressed()'), self.lineEdited)
self.connect(self.GoButton,
QtCore.SIGNAL('clicked()'), self.lineEdited)
self.connect(self.tabWidget,
QtCore.SIGNAL('currentChanged(int)'), self.tabChanged)
self.connect(self.homeButton, QtCore.SIGNAL('clicked()'),
self.goHome)
self.connect(self.srcButton, QtCore.SIGNAL('clicked()'),
self.viewSrc)
self.connect(self.bookmark, QtCore.SIGNAL('clicked()'),
self.bookmarkfun)
self.connect(self.bookmarks, QtCore.SIGNAL('clicked()'),
self.bookmarksfun)
self.connect(self.downloadb, QtCore.SIGNAL('clicked()'),
self.offerDownload)
self.connect(self.addTabBtn, QtCore.SIGNAL('clicked()'),
self.addNewTab)
self.connect(self.delTabBtn, QtCore.SIGNAL('clicked()'),
self.delOldTab)
self.connect(self.goFwd, QtCore.SIGNAL('clicked()'),
self.goForward)
self.connect(self.goBck, QtCore.SIGNAL('clicked()'),
self.goBack)
self.connect(self.fpAbout, QtCore.SIGNAL('clicked()'),
self.About)
def goForward(self):
self.currentBrowser().forward()
def goBack(self):
self.currentBrowser().back()
def About(self):
QtGui.QMessageBox.information(self, "fastPATX",'''
<p><a href="http://patx.me/fastpatx">fastPATX - Evergreen</a></p>
<p>Owner: Harrison Erd ([url=http://www.patx.me]www.patx.me[/url])</p>
<p>Driver: Neil Wallace (rowinggolfer.blogspot.com)</p>
<p>License: Zlib (http://patx.me/publications)</p>
<p>Current Version Codename: Evergreen</p>
''')
def add_labels(self):
self.setWindowTitle("fastPATX")
self.GoButton.setText("Go")
def currentBrowser(self):
widget = self.tabWidget.currentWidget()
if widget is not None:
return widget.browser
def addNewTab(self):
i = self.renumberTabs()
newtab = patx_tab(i, self)
self.tabWidget.addTab(newtab, '(untitled)')
self.tabWidget.setCurrentWidget(newtab)
if self.tabWidget.count() > 1:
self.tb.show()
def renumberTabs(self):
i = 0
while i < self.tabWidget.count():
self.tabWidget.widget(i).index = i
i += 1
return i
def tabChanged(self, index):
self.updateLineEdit(self.tabWidget.currentWidget().current_url)
def delOldTab(self):
if self.tabWidget.count() == 1:
return
widget = self.tabWidget.currentWidget()
if widget is not None:
self.tabWidget.removeTab(self.tabWidget.indexOf(widget))
widget.deleteLater()
if self.renumberTabs() < 2:
self.tb.hide()
def bookmarksfun(self):
try:
bookread = open("fastpatx_faves.txt", 'r')
self.currentBrowser().setHtml(bookread.read())
bookread.close()
except IOError, e:
self.currentBrowser().setHtml("Favourites file not found.")
def bookmarkfun(self):
link1 = '<a href="'
link2 = '">%s</a><br>'%self.lineEdit.text()
bookurl = ("%s%s%s"%(link1,self.lineEdit.text(),link2)).encode('ascii')
hpaste = open('fastpatx_faves.txt', 'a').write('%s'%(bookurl))
bookwn = QtGui.QMessageBox.question(self,"fastPATX",
"The page has been bookmarked.",
QtGui.QMessageBox.Ok)
def viewSrc(self):
html = self.currentBrowser().page().mainFrame().toHtml()
dialog = QtGui.QDialog(self)
text = QtGui.QPlainTextEdit(dialog)
text.setPlainText(html)
ok = QtGui.QPushButton(dialog)
ok.setText('&Ok')
ok.setDefault(True)
self.connect(ok, QtCore.SIGNAL('clicked()'),
dialog.accept)
layout = QtGui.QVBoxLayout()
layout.addWidget(text)
layout.addWidget(ok)
dialog.setLayout(layout)
dialog.exec_()
def goHome(self):
self.currentBrowser().setUrl(QtCore.QUrl("http://www.google.com"))
def offerDownload(self):
result=QtGui.QMessageBox.question(self,"Download File",
"Download File <br />%s"%self.urlString,
QtGui.QMessageBox.Yes,QtGui.QMessageBox.No)
if result == QtGui.QMessageBox.Yes:
url = str(self.lineEdit.text())
filename, headers = urllib.urlretrieve(url)
print "Downloaded: %s - Location: %s" % (url, filename)
QtGui.QMessageBox.information(self,"fastPATX",
"""
<title>Downloads</title> <h1>Downloading your file to %s...</h1><hr>
<h2>Info on fastPATX Downloads:</h2>
If you wish to view this file go to %s. If you wish to save the file
go to %s and save, otherwise when browser is exited, you will lose the
file.<hr>Powered by <a href="http://patx.me/projects">fastPATX</a>.
"""%(filename,filename,filename))
def lineEdited(self):
self.tabWidget.currentWidget().GoLink(QtCore.QUrl(self.lineEdit.text()))
def updateLineEdit(self,url):
self.lineEdit.setText(url.toString())
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
ui = fastpatx()
ui.show()
sys.exit(app.exec_())
ive run it and it works well ... altho it uses QT dependencies ... im sure it will be a help to go forward with
Kori