Active Topics

 


Reply
Thread Tools
Posts: 18 | Thanked: 2 times | Joined on Aug 2010
#1
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's Avatar
Posts: 1,637 | Thanked: 4,424 times | Joined on Apr 2009 @ Germany
#2
Can you post the error message?
And it looks like the function definition has
wrong indentation.

nicolai
 
Posts: 18 | Thanked: 2 times | Joined on Aug 2010
#3
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.
 
Posts: 18 | Thanked: 2 times | Joined on Aug 2010
#4
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?
 
Posts: 17 | Thanked: 4 times | Joined on Jan 2010 @ Finland
#5
Originally Posted by Dimand View Post
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??
 
Posts: 18 | Thanked: 2 times | Joined on Aug 2010
#6
I typed the name error out and forgot the caps.
It is still caps in my code.

Should i use http instead?
 
nicolai's Avatar
Posts: 1,637 | Thanked: 4,424 times | Joined on Apr 2009 @ Germany
#7
Missing import statement?
Something like
from PyQt4.QtNetwork import QNetworkAccessManager

nicolai
 
Posts: 18 | Thanked: 2 times | Joined on Aug 2010
#8
Originally Posted by nicolai View Post
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.
 
Posts: 18 | Thanked: 2 times | Joined on Aug 2010
#9
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?
 
Posts: 3,319 | Thanked: 5,610 times | Joined on Aug 2008 @ Finland
#10
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)
__________________
Blogging about mobile linux - The Penguin Moves!
Maintainer of PyQt (see introduction and docs), AppWatch, QuickBrownFox, etc
 
Reply


 
Forum Jump


All times are GMT. The time now is 02:40.