-1

-PyQt4 -Python 3.4.2

ive had a look through many different questions here and done research online.

Basicly what has happened is that when i click on the Reload button nothing happens. Even when i tried to get it to print('Reload') nothing appears on the console. This also happens with the forward and back button. This happens in the Reload Function, Forward Function and the Back Function towards the bottom of the code

Im very new to PyQt

By the way this code is no where near done and the gui was made in Qt designer and converted into a py file from a ui file

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'ApacheUI.ui'
#
# Created by: PyQt4 UI code generator 4.11.4
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui
from PyQt4 import QtWebKit

try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    def _fromUtf8(s):
        return s

try:
    _encoding = QtGui.QApplication.UnicodeUTF8
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig)

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName(_fromUtf8("MainWindow"))
        MainWindow.resize(720, 600)
        MainWindow.setAcceptDrops(False)
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap(_fromUtf8("Apache.ico")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        MainWindow.setWindowIcon(icon)
        MainWindow.setAutoFillBackground(False)
        MainWindow.setDocumentMode(False)
        MainWindow.setTabShape(QtGui.QTabWidget.Rounded)
        self.centralwidget = QtGui.QWidget(MainWindow)
        self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
        self.gridLayout = QtGui.QGridLayout(self.centralwidget)
        self.gridLayout.setObjectName(_fromUtf8("gridLayout"))

        self.Forward = QtGui.QPushButton(self.centralwidget)
        self.Forward.setObjectName(_fromUtf8("Forward"))
        self.Forward.clicked.connect(lambda: self.Forward)
        self.gridLayout.addWidget(self.Forward, 0, 1, 1, 1)

        self.Back = QtGui.QPushButton(self.centralwidget)
        self.Back.setObjectName(_fromUtf8("Back"))
        self.Back.clicked.connect(lambda: self.Back)
        self.gridLayout.addWidget(self.Back, 0, 0, 1, 1)

        self.Reload = QtGui.QPushButton(self.centralwidget)
        self.Reload.setObjectName(_fromUtf8("Reload"))
        self.Reload.clicked.connect(lambda: self.Reload)
        self.gridLayout.addWidget(self.Reload, 0, 2, 1, 1)

        self.enter = QtGui.QPushButton(self.centralwidget)
        self.gridLayout.addWidget(self.enter, 0, 0, 0, 0)
        self.enter.resize(0, 0)
        self.enter.clicked.connect(self.Enter)
        self.enter.setShortcut("Return")

        self.UrlBar = QtGui.QLineEdit(self.centralwidget)
        self.UrlBar.setObjectName(_fromUtf8("UrlBar"))
        self.gridLayout.addWidget(self.UrlBar, 0, 3, 1, 1)

        self.webView = QtWebKit.QWebView(self.centralwidget)
        self.webView.setUrl(QtCore.QUrl(_fromUtf8("about:blank")))
        self.webView.setObjectName(_fromUtf8("webView"))
        self.gridLayout.addWidget(self.webView, 1, 0, 1, 5)
        MainWindow.setCentralWidget(self.centralwidget)

        self.webView.urlChanged.connect(self.UrlChanged)

        self.menubar = QtGui.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 720, 21))
        self.menubar.setObjectName(_fromUtf8("menubar"))
        self.menuOptions = QtGui.QMenu(self.menubar)
        self.menuOptions.setObjectName(_fromUtf8("menuOptions"))
        self.menuSearch_Engine = QtGui.QMenu(self.menuOptions)
        self.menuSearch_Engine.setObjectName(_fromUtf8("menuSearch_Engine"))
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtGui.QStatusBar(MainWindow)
        self.statusbar.setObjectName(_fromUtf8("statusbar"))
        MainWindow.setStatusBar(self.statusbar)

        self.actionSettings = QtGui.QAction(MainWindow)
        self.actionSettings.setObjectName(_fromUtf8("actionSettings"))
        self.actionDuck_Duck_Go = QtGui.QAction(MainWindow)
        self.actionDuck_Duck_Go.setObjectName(_fromUtf8("actionDuck_Duck_Go"))
        self.actionGoogle = QtGui.QAction(MainWindow)
        self.actionGoogle.setObjectName(_fromUtf8("actionGoogle"))
        self.actionBing = QtGui.QAction(MainWindow)
        self.actionBing.setObjectName(_fromUtf8("actionBing"))
        self.actionQuora = QtGui.QAction(MainWindow)
        self.actionQuora.setObjectName(_fromUtf8("actionQuora"))
        self.actionDogpile = QtGui.QAction(MainWindow)
        self.actionDogpile.setObjectName(_fromUtf8("actionDogpile"))
        self.actionVimeo = QtGui.QAction(MainWindow)
        self.actionVimeo.setObjectName(_fromUtf8("actionVimeo"))
        self.actionBoardreader = QtGui.QAction(MainWindow)
        self.actionBoardreader.setObjectName(_fromUtf8("actionBoardreader"))
        self.actionAsk = QtGui.QAction(MainWindow)
        self.actionAsk.setObjectName(_fromUtf8("actionAsk"))
        self.actionSlide_Share = QtGui.QAction(MainWindow)
        self.actionSlide_Share.setObjectName(_fromUtf8("actionSlide_Share"))
        self.actionAddict_o_matic = QtGui.QAction(MainWindow)
        self.actionAddict_o_matic.setObjectName(_fromUtf8("actionAddict_o_matic"))
        self.actionCreative_Commons = QtGui.QAction(MainWindow)
        self.actionCreative_Commons.setObjectName(_fromUtf8("actionCreative_Commons"))
        self.actionGiphy = QtGui.QAction(MainWindow)
        self.actionGiphy.setObjectName(_fromUtf8("actionGiphy"))

        self.menuSearch_Engine.addAction(self.actionDuck_Duck_Go)
        self.menuSearch_Engine.addAction(self.actionGoogle)
        self.menuSearch_Engine.addAction(self.actionBing)
        self.menuSearch_Engine.addAction(self.actionQuora)
        self.menuSearch_Engine.addAction(self.actionDogpile)
        self.menuSearch_Engine.addAction(self.actionVimeo)
        self.menuSearch_Engine.addAction(self.actionBoardreader)
        self.menuSearch_Engine.addAction(self.actionAsk)
        self.menuSearch_Engine.addAction(self.actionSlide_Share)
        self.menuSearch_Engine.addAction(self.actionAddict_o_matic)
        self.menuSearch_Engine.addAction(self.actionCreative_Commons)
        self.menuSearch_Engine.addAction(self.actionGiphy)
        self.menuOptions.addAction(self.menuSearch_Engine.menuAction())
        self.menubar.addAction(self.menuOptions.menuAction())

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        MainWindow.setWindowTitle(_translate("MainWindow", "Apache", None))
        self.Forward.setText(_translate("MainWindow", ">", None))
        self.Back.setText(_translate("MainWindow", "<", None))
        self.Reload.setText(_translate("MainWindow", "↻", None))
        self.menuOptions.setTitle(_translate("MainWindow", "Options", None))
        self.menuSearch_Engine.setTitle(_translate("MainWindow", "Search Engine", None))
        self.actionSettings.setText(_translate("MainWindow", "Settings", None))
        self.actionDuck_Duck_Go.setText(_translate("MainWindow", "Duck Duck Go", None))
        self.actionGoogle.setText(_translate("MainWindow", "Google", None))
        self.actionBing.setText(_translate("MainWindow", "Bing", None))
        self.actionQuora.setText(_translate("MainWindow", "Quora", None))
        self.actionDogpile.setText(_translate("MainWindow", "Dogpile", None))
        self.actionVimeo.setText(_translate("MainWindow", "Vimeo", None))
        self.actionBoardreader.setText(_translate("MainWindow", "Boardreader", None))
        self.actionAsk.setText(_translate("MainWindow", "Ask", None))
        self.actionSlide_Share.setText(_translate("MainWindow", "Slide Share", None))
        self.actionAddict_o_matic.setText(_translate("MainWindow", "Addict-o-matic", None))
        self.actionCreative_Commons.setText(_translate("MainWindow", "Creative Commons", None))
        self.actionGiphy.setText(_translate("MainWindow", "Giphy", None))


    def WebPlayer(self):

        url = ""

        self.googleLink = 'https://www.google.com'
        self.duckduckgoLink = 'https://duckduckgo.com/'
        self.duckduckgoSearch = 'https://duckduckgo.com/?q='
        self.bingLink = 'https://www.bing.com/'
        self.quoraLink = 'https://www.quora.com/'
        self.dogpileLink = 'http://www.dogpile.com/'
        self.vimeoLink = 'https://vimeo.com/'
        self.boardreaderLink = 'https://www.boardreader.com/'
        self.askLink = 'http://www.ask.com/'
        self.slideshareLink = 'http://www.slideshare.net/'
        self.addictomaticLink = 'http://addictomatic.com/'
        self.creationcommonsLink = 'https://search.creativecommons.org/'
        self.giphyLink = 'http://giphy.com/'

        self.searchPage = self.duckduckgoLink
        self.searchEngine = self.duckduckgoSearch

    def Enter(self):
        global url

        url = self.UrlBar.text()

        http = "http://"
        www = "www."

        if www in url and http not in url:
            url = http + url

        elif "." not in url:
            url = self.searchEngine + url

        elif http in url and www not in url:
            url = url[:7] + www + url[7:]

        elif http and www not in url:
            url = http + www + url

        self.UrlBar.setText(url)

        self.webView.load(QtCore.QUrl(url))

    def Reload(self):
        self.web.reload()

    def Back(self):
        self.webView.back()

    def Forward(self):
        self.web.forward()

    def UrlChanged(self):
        self.UrlBar.setText(self.webView.url().toString())

if __name__ == "__main__":
    import sys
    app = QtGui.QApplication(sys.argv)
    MainWindow = QtGui.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())
  • Any reason you are using connect(lambda: self.Reload) rather than just connect(self.Reload)? – Hugh Fisher Jul 15 '16 at 12:33
  • Yes because of what was said on this question, http://stackoverflow.com/questions/10730131/create-dynamic-button-in-pyqt Without it i get an error: TypeError: connect() slot argument should be a callable or a signal, not 'QPushButton' – Ender_Guy562 Jul 15 '16 at 13:39

1 Answers1

0

Firstly, you're using the same name for the button and the slot, so when setupUi is called, the former will shadow the latter.

Secondly, the lambda does not actually call the slot, which explains why "nothing happens". Of course, you cannot really call it anyway, since it is being shadowed by something which is not callable (i.e. a reference to the push-button). Note that this also explains the error message you mentioned in the comments to your question.

I would suggest you rename all the slots to something like handleReload, handleForward, etc, so the names don't clash. You should then connect the slots like this:

    self.Forward.clicked.connect(self.handleForward)
ekhumoro
  • 115,249
  • 20
  • 229
  • 336