Very Simple Web Browser On PyQt4 and WebKit

I have been experimenting with Qt and one of the most powerful collection of widgets that it have: The QtWebKit.

The QtWebKit is a implementation of Webkit for the Qt Widgets interface. It can render web pages as well as run javascript and It have the possibility to be included in a desktop application.

In this case I used it to develop a very simple but functional web browser.
(I will publish a more complete web browser using this component in shortly).
In the mean time, Enjoy the code!

"""
    ********************* VerySimpleWebBrowser ************************

    This is a Very Simple Web Browser implemented over Qt and QtWebKit.

    author: Juan Manuel Garcia <jmg.utn@gmail.com>

    *******************************************************************
"""

import sys
from PyQt4 import QtCore, QtGui, QtWebKit

class Browser(QtGui.QMainWindow):

    def __init__(self):
        """
            Initialize the browser GUI and connect the events
        """

        QtGui.QMainWindow.__init__(self)
        self.resize(800,600)
        self.centralwidget = QtGui.QWidget(self)

        self.mainLayout = QtGui.QHBoxLayout(self.centralwidget)
        self.mainLayout.setSpacing(0)
        self.mainLayout.setMargin(1)

        self.frame = QtGui.QFrame(self.centralwidget)

        self.gridLayout = QtGui.QVBoxLayout(self.frame)
        self.gridLayout.setMargin(0)
        self.gridLayout.setSpacing(0)

        self.horizontalLayout = QtGui.QHBoxLayout()
        self.tb_url = QtGui.QLineEdit(self.frame)
        self.bt_back = QtGui.QPushButton(self.frame)
        self.bt_ahead = QtGui.QPushButton(self.frame)

        self.bt_back.setIcon(QtGui.QIcon().fromTheme("go-previous"))
        self.bt_ahead.setIcon(QtGui.QIcon().fromTheme("go-next"))

        self.horizontalLayout.addWidget(self.bt_back)
        self.horizontalLayout.addWidget(self.bt_ahead)
        self.horizontalLayout.addWidget(self.tb_url)
        self.gridLayout.addLayout(self.horizontalLayout)

        self.html = QtWebKit.QWebView()
        self.gridLayout.addWidget(self.html)
        self.mainLayout.addWidget(self.frame)
        self.setCentralWidget(self.centralwidget)

        self.connect(self.tb_url, QtCore.SIGNAL("returnPressed()"), self.browse)
        self.connect(self.bt_back, QtCore.SIGNAL("clicked()"), self.html.back)
        self.connect(self.bt_ahead, QtCore.SIGNAL("clicked()"), self.html.forward)

        self.default_url = "https://codescience.wordpress.com/"
        self.tb_url.setText(self.default_url)
        self.browse()

    def browse(self):
        """
            Make a web browse on a specific url and show the page on the
            Webview widget.
        """

        url = self.tb_url.text() if self.tb_url.text() else self.default_url
        self.html.load(QtCore.QUrl(url))
        self.html.show()

if __name__ == "__main__":

    app = QtGui.QApplication(sys.argv)
    main = Browser()
    main.show()
    sys.exit(app.exec_())

Or download from:

http://www.binpress.com/app/verysimplewebbrowser/279

Regards,

Juan Manuel

Advertisements

Simple, Fuly-Functional Web Browser On PyQt4

Finally here’s the new app. A Simple, fully-functional web browser that runs over PyQ4 and WebKit.

I was delighted with the beautiful of Qt interfaces and the powerfull of the embeed component, WebKit. These ones, combined in a well designed python code gives as result, my new app.

This application have the most of the common and basics features of a web browser. You can browse the internet like using FireFox or Google Chrome. And the most important, you can extend the program and do whatever you want with the user requests, pages and every stuff on the web. Think about how powerfull is that. There’s a lot of things you can do using this app as the base.

Features:

  • Fully-functional web browser
  • Multiple tabs
  • Standard Web Browser Command Buttons
  • Standard Web Browser Shortcuts
  • Smart Http pages completition
  • Well designed / Very Extensible
An assortment of snapshots:

Dependencies:

  • python
  • python-qt4
Check Out From:

http://www.binpress.com/app/simple-web-browser/260