AttributeError: 'ExampleApp' object has no attribute 'browse_folder' - python

from PyQt4 import QtGui
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import sys
import ADJ_Search
import os
from selenium import webdriver
from selenium.webdriver.support.ui import Select
import webbrowser
class ExampleApp(QtGui.QMainWindow, ADJ_Search.Ui_MainWindow):
def __init__(self):
super(self.__class__, self).__init__()
self.setupUi(self)
self.Chose_File_Button.clicked.connect(self.browse_folder)
self.List_Search_Button.clicked.connect(self.search_list)
def browse_folder(self):
self.List_ADJ_View.clear()
dlg = QFileDialog()
dlg.setFileMode(QFileDialog.AnyFile)
directory = QStringList()
if dlg.exec_():
directory = dlg.selectedFiles()
f = open(directory[0], 'r')
with f:
data = f.readlines()
for ADJ in data:
self.List_ADJ_View.addItem(ADJ.strip())
print ADJ.strip()
def search_list(self):
self.List_ADJ_View.clear()
print ''
def main():
app = QtGui.QApplication(sys.argv)
form = ExampleApp()
form.show()
app.exec_()
if __name__=='__main__':
main()
Error:
Error:Traceback (most recent call last):
File "temperary.py", line 45, in <module>
File "temperary.py", line 40, in main
form = ExampleApp()
File "temperary.py", line 15, in __init__
self.Chose_File_Button.clicked.connect(self.browse_folder)
AttributeError: 'ExampleApp' object has no attribute 'browse_folder'
Please help me to see why it always come out this error, also 'search_list' has this kind of error too. What do you think is causing it?

Related

Type Error: argument 1 has unexpected type 'QPushButton'

I wrote this codes:
import sys
import os
from PyQt5 import QtWidgets
class Notepad(QtWidgets.QWidget):
def __init__(self):
super().__init__()
self.init_ui()
def init_ui(self):
self.yazi_alani = QtWidgets.QTextEdit()
self.temizle = QtWidgets.QPushButton("Temizle")
self.kaydet = QtWidgets.QPushButton("Kaydet")
self.dosya_ac = QtWidgets.QPushButton("Dosya Aç")
v_box = QtWidgets.QVBoxLayout()
v_box.addWidget(self.yazi_alani)
v_box.addWidget(self.temizle)
v_box.addWidget(self.kaydet)
v_box.addWidget(self.dosya_ac)
self.setLayout(v_box)
self.setWindowTitle("Barış'ın Notepad Programı")
self.setGeometry(200,200,800,600)
self.temizle.clicked.connect(self.temizle)
self.kaydet.clicked.connect(self.kaydet)
self.dosya_ac.clicked.connect(self.dosya_ac)
self.show()
def temizle(self):
self.yazi_alani.clear()
def kaydet(self):
dosya_ismi = QtWidgets.QFileDialog.getSaveFileName(self,"Dosya Kaydet",os.getenv("HOME"))
with open (dosya_ismi[0],"w",encoding="utf-8") as file:
file.write(self.yazi_alani.toPlainText())
def dosya_ac(self):
dosya_ismi = QtWidgets.QFileDialog(self, "Dosya Aç", os.getenv("HOME"))
with open(dosya_ismi[0],"r",encoding="utf-8") as file:
self.yazi_alani.setText(file.read())
app = QtWidgets.QApplication(sys.argv)
pencere = Notepad()
sys.exit(app.exec())
I got this error:
Traceback (most recent call last):
File "C:/Users/noikp/Desktop/PyQt5 projem.py", line 41, in <module>
pencere = Pencere()
File "C:/Users/noikp/Desktop/PyQt5 projem.py", line 8, in __init__
self.init_ui()
File "C:/Users/noikp/Desktop/PyQt5 projem.py", line 28, in init_ui
self.temizle.clicked.connect(self.temizle)
TypeError: argument 1 has unexpected type 'QPushButton'
How can I solve this error?
It may be good if you answer fast...
pythonerrors
python
error
errors
errorrr
python3-x
You should rename your buttons or funcions.
You've got here method Notepad.temizle() AND button Notepad.temizle
So when you expect to send a message, instead you send a button, which is typeError
Also I can see the same error with other methods

How to display SQL data into GUI list widget?

I was wondering how to display information from an database table onto a listwidget or something similar. This is for a flashcard app, and the one questions is supposed to show at a time. Then when the click to reveal button is clicked the corresponding answer is supposed to show, but at the moment nothing is shown in the list widgets.
I don't understand why nothing is being shown in the GUI.
Here is my Code -
from PyQt4 import QtGui
from PyQt4 import QtCore
import sys
import flashcard
import os
import sqlite3
class FlashCardApp(QtGui.QMainWindow, flashcard.Ui_MainWindow):
def __init__(self):
super(self.__class__,self).__init__()
self.setupUi(self)
self.questions = []
self.answers = []
self.currentQ = 0
self.RevealAnswerBtn.clicked.connect(self.disA)
def dispQ(self):
print("display question {}".format(self.currentQ+1))
self.listQuestionWidget.clear()
if self.questions:
self.listQuestionWidget.addItem(self.questions[self.currentQ])
def disA(self):
self.listAnswerWidget.clear()
if self.answers:
self.listAnswerWidget.addItem(self.answers[self.currentQ])
def setData (self, questions, answers):
self.questions = questions
self.answers = answers
def run(self):
print ("start")
self.currentQ = 0
self.dispQ()
def main():
questions = []
answers = []
connection = sqlite3.connect("login.db")
c = connection.cursor()
c.execute ("SELECT Question FROM Flashcards")
resultq = c.fetchall()
questions.append(resultq)
c.execute ("SELECT Answer FROM Flashcards")
resulta = c.fetchall()
answers.append(resulta)
connection.close()
app = QtGui.QApplication(sys.argv)
form = FlashCardApp()
form.setData(questions,answers)
form.run()
form.show()
app.exec_()
if __name__ == '__main__':
main()
but then i get this error -
Traceback (most recent call last):
File "C:/Users/joe gorsuch/OneDrive/A-Level/Computer Science/Computer Science Project/Program/Login Form/Ui/1.py", line 68, in <module>
main()
File "C:/Users/joe gorsuch/OneDrive/A-Level/Computer Science/Computer Science Project/Program/Login Form/Ui/1.py", line 63, in main
form.run()
File "C:/Users/joe gorsuch/OneDrive/A-Level/Computer Science/Computer Science Project/Program/Login Form/Ui/1.py", line 41, in run
self.dispQ()
File "C:/Users/joe gorsuch/OneDrive/A-Level/Computer Science/Computer Science Project/Program/Login Form/Ui/1.py", line 25, in dispQ
self.listQuestionWidget.addItem(self.questions[self.currentQ])
TypeError: arguments did not match any overloaded call:
QListWidget.addItem(QListWidgetItem): argument 1 has unexpected type 'list'
QListWidget.addItem(str): argument 1 has unexpected type 'list'

Python Crash Course, Testing Your Code example

This is to test the class; however, I am getting an error and I do not know how to fix it.
import unittest
from name_function import get_formatted_name
class NamesTestCase(unittest.TestCase):
"""Tests for 'name_function.py'"""
def test_first_last_name(self):
"""Do names like 'Mark James' work?"""
formatted_name = get_formatted_name('mark','James')
self.assertEqual(formatted_name,'Mark James')
unittest.main()
Here's the class that is being tested.
def get_formatted_name(first, last):
"""This is where the name is formatted correctly"""
full_name = first + " " + last
return full_name.title()
The error I am getting is this:
/Desktop/python_work/test_name_function.py", line 1, in <module>
import unittest
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/unittest/__init__.py", line 58, in <module>
from .result import TestResult
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/unittest/result.py", line 5, in <module>
import traceback
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/traceback.py", line 3, in <module>
import linecache
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/linecache.py", line 10, in <module>
import tokenize
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/tokenize.py", line 96, in <module>
class TokenInfo(collections.namedtuple('TokenInfo', 'type string start end line')):
AttributeError: 'module' object has no attribute 'namedtuple'
Anyone have a clue?
I believe you need to add if 'name' == 'main':
unittest.main() to your code.
The below code should fix the error -
import unittest
from name_function import get_formatted_name
class NamesTestCase(unittest.TestCase):
"""Tests for 'name_function.py'"""
def test_first_last_name(self):
"""Do names like 'Mark James' work?"""
formatted_name = get_formatted_name('mark','James')
self.assertEqual(formatted_name,'Mark James')
if '__name__' == '__main__':
unittest.main()

pyforms cannot import conf from pysettings

This is my python file:
import pyforms
import pyside
from pyforms import BaseWidget
from pyforms.Controls import ControlText
from pyforms.Controls import ControlButton
class SimpleExample1(BaseWidget):
def __init__(self):
super(SimpleExample1,self).__init__('Simple example 1')
#Definition of the forms fields
self._firstname = ControlText('First name', 'Default value')
self._middlename = ControlText('Middle name')
self._lastname = ControlText('Lastname name')
self._fullname = ControlText('Full name')
self._button = ControlButton('Press this button')
#Define the button action
self._button.value = self.__buttonAction
def __buttonAction(self):
"""Button action event"""
self._fullname.value = self._firstname.value +" "+ self._middlename.value + \
" "+ self._lastname.value
#Execute the application
if __name__ == "__main__":
pyforms.startApp( SimpleExample1 )
And I got an error in the __init__.py file:
Traceback (most recent call last):
File "C:\Python27\Ashish\pyforms\1.py", line 1, in <module>
import pyforms
File "C:\Python27\lib\site-packages\pyforms\__init__.py", line 4, in <module>
from pysettings import conf;
ImportError: No module named pysettings
Here is my __init__.py:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import logging
from pysettings import conf;
conf += 'pyforms.gui.settings'
__author__ = "Ricardo Ribeiro"
__credits__ = ["Ricardo Ribeiro"]
__license__ = "MIT"
__version__ = '0.1.7.3'
__maintainer__ = "Ricardo Ribeiro"
__email__ = "ricardojvr#gmail.com"
__status__ = "Production"
logger = logging.getLogger(__name__)
if conf.PYFORMS_MODE in ['GUI', 'GUI-OPENCSP']:
from pyforms.gui import Controls
from pyforms.gui.BaseWidget import BaseWidget
if conf.PYFORMS_MODE in ['GUI-OPENCSP']:
from pyforms.gui.appmanager import startApp
else:
from pyforms.gui.standaloneManager import startApp
elif conf.PYFORMS_MODE in ['TERMINAL']:
from pyforms.terminal import Controls
from pyforms.terminal.BaseWidget import BaseWidget
from pyforms.terminal.appmanager import startApp
elif conf.PYFORMS_MODE in ['WEB']:
from pyforms_web.web import Controls
from pyforms_web.web.BaseWidget import BaseWidget
from pyforms_web.web.appmanager import startApp
You will need to download and install pysettings from https://github.com/UmSenhorQualquer/pysettings/tree/92bde8c680bc0a00ae97cc09bd4dab1b697d6ed2

Python does not detect soundtouch elements (bpmdetect and pitch) in gst-plugins-bad

I have installed gstreamer, gst-plugins-bad and its python bindings.
The following code selects a song from a given directory and plays it.
import pygst
pygst.require("0.10")
import gst
import pygtk
import gtk
import os
class Main:
def __init__(self):
self.pipeline = gst.Pipeline("mypipeline")
self.musicFiles = os.listdir("musicFiles")
self.currentSong = self.musicFiles[0]
self.findFile = gst.element_factory_make("filesrc", "file")
self.findFile.set_property("location", "musicFiles/" + self.currentSong)
self.pipeline.add(self.findFile)
self.mad = gst.element_factory_make("mad", "mad")
self.pipeline.add(self.mad)
self.findFile.link(self.mad)
self.audioconvert = gst.element_factory_make("audioconvert", "convert")
self.pipeline.add(self.audioconvert)
self.mad.link(self.audioconvert)
self.audioresample = gst.element_factory_make("audioresample", "resample")
self.pipeline.add(self.audioresample)
self.audioconvert.link(self.audioresample)
self.getbpm = gst.element_factory_make("bpmdetect", "bpm")
self.pipeline.add(self.getbpm)
self.audioresample.link(self.getbpm)
self.sink = gst.element_factory_make("playsink", "sink")
self.pipeline.add(self.sink)
self.audioresample.link(self.sink)
self.pipeline.set_state(gst.STATE_PLAYING)
start=Main()
gtk.main()
However, when I try to create the bpmdetect element, it gives the following error:
Traceback (most recent call last):
File "/Users/shubhitsingh/Desktop/Stuff/COLLEGE/US/Carnegie Mellon/Fall '12/15-112/Term Project/Practice/gstreamertutorial-1.py", line 49, in <module>
start=Main()
File "/Users/shubhitsingh/Desktop/Stuff/COLLEGE/US/Carnegie Mellon/Fall '12/15-112/Term Project/Practice/gstreamertutorial-1.py", line 37, in __init__
self.getbpm = gst.element_factory_make("bpmdetect", "bpm")
ElementNotFoundError: bpmdetect
Other elements from gst-plugins-bad can be created without problems. Its just the two elements under soundtouch (bpmdetect and pitch) that cannot be created. Help?

Categories

Resources