maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   Request-Help pyqt attribute error. (https://talk.maemo.org/showthread.php?t=61579)

Dimand 2010-09-02 06:45

Request-Help pyqt attribute error.
 
I have been messing around with pyqt but i have hit a brick wall with this.

Basically, i used the designer to create a gui and the main code is the program, but i keep getting an attribute error when i try and make a function for some buton.

Code:

#!/usr/bin/python2.5
import sys
from PyQt4 import QtGui,QtCore
from sms_ui import *

class Awesome(QtGui.QMainWindow):
        def __init__(self, parent=None):
                #build parent user interface
                QtGui.QWidget.__init__(self, parent)
                self.ui = Ui_MainWindow()
                self.ui.setupUi(self)
                QtCore.QObject.connect(self.ui.btnSend, QtCore.SIGNAL('clicked()'), self.smsgo)

                def smsgo(self):
                                a=1

if __name__ == "__main__":
        #This function means this was run directly, not called from another python file.
        app = QtGui.QApplication(sys.argv)
        myapp = Awesome()
        myapp.show()
        sys.exit(app.exec_())

I cant see what is wrong here. if i remove

Code:

QtCore.QObject.connect(self.ui.btnSend, QtCore.SIGNAL('clicked()'), self.smsgo)

                def smsgo(self):
                                a=1

The GUI is fine. I have double checked the names of everything.

Any insight?

nicolai 2010-09-02 07:05

Re: Request-Help pyqt attribute error.
 
Can you post the error message?
And it looks like the function definition has
wrong indentation.

nicolai

Dimand 2010-09-02 07:11

Re: Request-Help pyqt attribute error.
 
Yes. That was it. :\

I am going to have to be careful about that.

Sorry to waste your time, though i'm sure i will have more problems soon enough.

Dimand 2010-09-02 11:11

Re: Request-Help pyqt attribute error.
 
Ok, I have a new question.

Here is my code snipit

Code:

manager = QNetworkAccessManager(self);
                connect(manager, SIGNAL(finished("QNetworkReply*")), self, SLOT(replyFinished("QNetworkReply*")));
                manager.post(QNetworkRequest(QUrl(sms)));

I get this error:
nameerror: global name 'Qnetworkaccessmanager' is not defined

The Qnetworkaccessmanager is defiantly confusing me a bit. Any hints in the right direction?

peppe78 2010-09-02 11:39

Re: Request-Help pyqt attribute error.
 
Quote:

Originally Posted by Dimand (Post 805097)
Ok, I have a new question.

Here is my code snipit

Code:

manager = QNetworkAccessManager(self);
                connect(manager, SIGNAL(finished("QNetworkReply*")), self, SLOT(replyFinished("QNetworkReply*")));
                manager.post(QNetworkRequest(QUrl(sms)));

I get this error:
nameerror: global name 'Qnetworkaccessmanager' is not defined

The Qnetworkaccessmanager is defiantly confusing me a bit. Any hints in the right direction?

check the Capitalizing?

'Qnetworkaccessmanager' => 'QNetworkAccessManager'

it's right here in the code but probably not in your
script, because in the nameerror only the first letter is a capital??

Dimand 2010-09-02 11:49

Re: Request-Help pyqt attribute error.
 
I typed the name error out and forgot the caps.
It is still caps in my code. :confused:

Should i use http instead?

nicolai 2010-09-02 11:54

Re: Request-Help pyqt attribute error.
 
Missing import statement?
Something like
from PyQt4.QtNetwork import QNetworkAccessManager

nicolai

Dimand 2010-09-02 11:59

Re: Request-Help pyqt attribute error.
 
Quote:

Originally Posted by nicolai (Post 805136)
Missing import statement?
Something like
from PyQt4.QtNetwork import QNetworkAccessManager

nicolai

I had
from PyQt4 import QtGui,QtCore,QtNetwork
seems i needed
from PyQt4.QtNetwork import QNetworkAccessManager
too.

now it is telling me connect is not defined, but i can probably work that out.

Dimand 2010-09-03 01:06

Re: Request-Help pyqt attribute error.
 
Ok, So i have a program that works.
It sends an sms through exetel

Code:

#!/usr/bin/python2.5
import sys
from PyQt4 import QtGui,QtCore,QtNetwork
from PyQt4.QtNetwork import QNetworkAccessManager
from sms2_ui import *

class MyForm(QtGui.QMainWindow):
        def __init__(self, parent=None):
                #build parent user interface
                QtGui.QWidget.__init__(self, parent)
                self.ui = Ui_MainWindow()
                self.ui.setupUi(self)
                QtCore.QCoreApplication.setOrganizationName("Dimand Corp")
                QtCore.QCoreApplication.setApplicationName("SMS Exetel")
                self.settings = QtCore.QSettings()

                #connect buttons
                QtCore.QObject.connect(self.ui.btnSMS, QtCore.SIGNAL('clicked()'), self.doAddNew)
                QtCore.QObject.connect(self.ui.actionFrom_2, QtCore.SIGNAL('triggered()'), self.doSetNum)
                QtCore.QObject.connect(self.ui.actionUsername_3, QtCore.SIGNAL('triggered()'), self.doSetName)
                QtCore.QObject.connect(self.ui.actionPassword_3, QtCore.SIGNAL('triggered()'), self.doSetPass)
                QtCore.QObject.connect(self.ui.actionQuit, QtCore.SIGNAL('triggered()'), QtGui.qApp, QtCore.SLOT('quit()'))

                #Create Sub's
        def doAddNew(self):
                msg = self.ui.plainTextEditSMS.toPlainText()
                user = self.settings.value("Username").toString()
                password = self.settings.value("Password").toString()
                fromnum = self.settings.value("FromNum").toString()
                sms = "https://smsgw.exetel.com.au/sendsms/api_sms.php?username="+ user + "&password=" + password + "&mobilenumber=" + self.ui.lineTo.displayText() + "&message=" + msg + "&sender=" + fromnum + "&messagetype=Text"
                self.manager = QNetworkAccessManager(self);
                #QtCore.QObject.connect(self.manager, QtCore.SIGNAL('finished("QNetworkReply*")'),self, QtCore.SLOT('finished("QNetworkReply*")'));
                self.manager.get(QtNetwork.QNetworkRequest(QtCore.QUrl(sms)));
                self.ui.lineTo.clear()
                self.ui.plainTextEditSMS.clear()

        def doSetNum(self):
                text, ok = QtGui.QInputDialog.getText(self, "Settings",
                "Send Number:", QtGui.QLineEdit.Normal,
                QtCore.QDir.home().dirName())
                if ok and text != '':
                        self.settings.setValue("FromNum", text)

        def doSetName(self):
                text, ok = QtGui.QInputDialog.getText(self, "Settings",
                "Username:", QtGui.QLineEdit.Normal,
                QtCore.QDir.home().dirName())
                if ok and text != '':
                        self.settings.setValue("Username", text)

        def doSetPass(self):
                text, ok = QtGui.QInputDialog.getText(self, "Settings",
                "Password:", QtGui.QLineEdit.Normal,
                QtCore.QDir.home().dirName())
                if ok and text != '':
                        self.settings.setValue("Password", text)

if __name__ == "__main__":
                #This function means this was run directly, not called from another python file.
                app = QtGui.QApplication(sys.argv)
                myapp = MyForm()
                myapp.show()
                sys.exit(app.exec_())

I would prefer not to have to run it from the terminal ever time though. how can i make it as a executable on my phone?

Also, I still cant figer out how to get a response back from the network access manager. (hence why the connect is commented out) Any ideas there?

attila77 2010-09-11 10:45

Re: Request-Help pyqt attribute error.
 
See http://wiki.maemo.org/Desktop_file_format

For the connect, off the top of my head:
self.connect(self.manager, QtCore.SIGNAL('finished("QNetworkReply*")'),self, lambda x: do_something_with_reply(x)));

(you don't need the lambda or the parameter if do_something_with_reply is a slot in a QObject or one of it's subclasses)


All times are GMT. The time now is 12:09.

vBulletin® Version 3.8.8