LordOfTheDance
LordOfTheDance

Reputation: 11

Python Twisted sendLine()

No not you again.

Well anyway I've been struggling with this for quite some time. So basically I have my twisted application and now I'm writing a PyQt interface for it. There's only one thing I haven't been able to bridge between the Twisted script and the new interface yet. That's when a button is being pressed get Twisted to send some data via the sendLine() function.

We can't use.

QtCore.QObject.connect(self.pushButton_7, QtCore.SIGNAL("clicked()"),
           Twisted().Button_Clicked('abc'))


class Twisted(LineReceiver):

   def Button_Clicked(self,out):
        self.sendLine(out)

This results in:

File "/usr/lib/python2.6/dist-packages/twisted/protocols/basic.py", line 296, in sendLine
    return self.transport.write(line + self.delimiter)
AttributeError: 'NoneType' object has no attribute 'write'

Can anyone give an example of how we could send some data when a PyQt button has been pressed?

Thanks Bye!

Upvotes: 1

Views: 2056

Answers (1)

Glyph
Glyph

Reputation: 31860

You can't just instantiate Twisted() and then use it; it's a Protocol, and Protocols must be instantiated via a Factory, in response to either connecting a client or accepting an incoming connection as a server. The error that you're seeing is telling you that Twisted's transport doesn't exist at the point where the button is clicked, so there's nowhere to send the data.

Since I'm assuming you're writing a client, you probably want to read the Writing Clients tutorial.

Upvotes: 2

Related Questions