Python Forum
Thread Rating:
  • 2 Vote(s) - 3.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pyqt browser
#1
I came across making browser a few years ago. Never got into actual dev of it. But i kept it around. Sometimes i still go back and use this basic browser because i get sick of dealing with Chrome/Firefox BS, and sometimes they just seem faster, and sometimes i use it to bypass websites footprint of you being there numerous times. My wife uses this just to bypass store's receipt surveys to get unlimited discounts when they cut you off on other browsers. There is only a back /forward button, and URL bar, nothing else. Everyone i show it to says its much faster, and it surely feels it.

I figured if i found it useful, others might too. And should reside on a python forum (if it doesnt already?).

pyqt4
import sys
from PyQt4 import QtCore, QtGui, QtWebKit

class Browser(QtGui.QMainWindow):

   def __init__(self):
       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 = "http://www.google.com/webhp?complete=0&hl=en"
       self.tb_url.setText(self.default_url)
       self.browse()

   def browse(self):
       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_())
pyqt5
import sys
from PyQt5 import QtCore, QtGui, QtWebKitWidgets, QtWidgets
#requires package python-pyqt5.qtwebkit for QtWebKitWidgets

class Browser(QtWidgets.QMainWindow):

   def __init__(self):
       QtWidgets.QMainWindow.__init__(self)
       self.resize(800,600)
       self.centralwidget = QtWidgets.QWidget(self)

       self.mainLayout = QtWidgets.QHBoxLayout(self.centralwidget)
       self.mainLayout.setSpacing(0)
       self.mainLayout.setContentsMargins(1, 1, 1, 1)

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

       self.gridLayout = QtWidgets.QVBoxLayout(self.frame)
       self.gridLayout.setContentsMargins(0, 0, 0, 0)
       self.gridLayout.setSpacing(0)

       self.horizontalLayout = QtWidgets.QHBoxLayout()
       self.tb_url = QtWidgets.QLineEdit(self.frame)
       self.bt_back = QtWidgets.QPushButton(self.frame)
       self.bt_ahead = QtWidgets.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 = QtWebKitWidgets.QWebView()
       self.gridLayout.addWidget(self.html)
       self.mainLayout.addWidget(self.frame)
       self.setCentralWidget(self.centralwidget)

       self.tb_url.returnPressed.connect(self.browse)
       self.bt_back.clicked.connect(self.html.back)
       self.bt_ahead.clicked.connect(self.html.forward)

       self.default_url = "http://www.google.com/webhp?complete=0&hl=en"
       self.tb_url.setText(self.default_url)
       self.browse()

   def browse(self):
       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 = QtWidgets.QApplication(sys.argv)
   main = Browser()
   main.show()
sys.exit(app.exec_())
Recommended Tutorials:
Reply
#2
looks nice, but when i entered a URL (http://python-forum.io/) and pressed Enter, nothing happened.  i waited about a minute and it just stayed there. i tried again without the trailing '/' and the same thing.  then i tried https and then it worked ... got the home page after a couple seconds.  odd!

i was using the pyqt4 one since that is what i have on ubuntu 16.04.2 LTS.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#3
Yeah, you have to input the exact URL you plan on going to. There are no commodities programmed in.
Recommended Tutorials:
Reply
#4
(Jul-18-2017, 05:02 PM)metulburr Wrote: Yeah, you have to input the exact URL you plan on going to. There are no commodities programmed in.
so it doesn't do redirects.  hmmm.  it should at least try to react in some way to what it doesn't support.  still, this thing could be useful on those ƿгѲӥ sites with abusive code.
Output:
lt1/forums /home/forums 1> lynx -mime_header http://python-forum.io/ HTTP/1.1 301 Moved Permanently Date: Thu, 20 Jul 2017 03:09:19 GMT Server: Apache/2.4.7 (Ubuntu) Location: https://python-forum.io/ Content-Length: 312 Connection: close Content-Type: text/html; charset=iso-8859-1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>301 Moved Permanently</title> </head><body> <h1>Moved Permanently</h1> <p>The document has moved <a href="https://python-forum.io/">here</a>.</p> <hr> <address>Apache/2.4.7 (Ubuntu) Server at python-forum.io Port 80</address> </body></html> lt1/forums /home/forums 2>
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#5
You are welcome to add customization to it. I prefer less customization as it drags the browsers speed down. Currently as is, i use this when i want i get problems with Firefox/Chrome and just want a fast raw browser.
Recommended Tutorials:
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020