Thanks Justin, really helps but I'm still confused. This is how far I got before running into questionmarks.
http://pastebin.com/E6evz8EC from functools import partial from PyQt4 import QtNetwork from PyQt4.QtGui import * class Server(QWidget): def __init__(self, parent=None): super(Server, self).__init__(parent) label = QLabel("Message", self) field = QLineEdit(self) field.setEnabled(False) field.setObjectName('Field') layout = QVBoxLayout(self) layout.addWidget(label) layout.addWidget(field) self.server = QtNetwork.QLocalServer() self.server.newConnection.connect(self.handle_connection) self.server.listen('myLocalSocket') def handle_connection(self): print "Handling connection" conn = self.server.nextPendingConnection() conn.readyRead.connect(partial(self.read_connection, conn)) def read_connection(self, conn): print "Reading connection" data = conn.readAll() field = self.findChild(QLineEdit, 'Field') field.setText(data) class Client(QLineEdit): def __init__(self, parent=None): super(Client, self).__init__(parent) self.returnPressed.connect(lambda: self.send(self.text())) def send(self, message): sock = QtNetwork.QLocalSocket() sock.connectToServer('myLocalSocket') sock.write('foo\n') if __name__ == '__main__': import sys app = QApplication(sys.argv) server = Server() server.show() client = Client() client.show() sys.exit(app.exec_()) On 22 July 2013 21:32, Justin Israel <[email protected]> wrote: > Here is a quick example using Qt classes: > > ### > from functools import partial > from PySide import QtNetwork > > def handleConn(): > conn = s.nextPendingConnection() > conn.readyRead.connect(partial(readConn, conn)) > > def readConn(conn): > data = conn.readAll() > print "Read:", data > > > # Make a server > server = QtNetwork.QLocalServer() > server.newConnection.connect(handleConn) > server.listen('myLocalSocket') > > # Make client > sock = QtNetwork.QLocalSocket() > sock.connectToServer('myLocalSocket') > sock.write('foo\n') > ### > > You create a QLocalServer which uses local named sockets. Then you tell it > to listen. It uses the event loop to wait for connections. > When a connection from a client comes in, the handleConn() is called. It > accepts the connection and then connects it to another slot that will wait > for data. This is all using signal/slots. > When the client writes data, the slot will be called. > > If you take this example and work up a test with it, I can help you > further from your code. > > > On Jul 23, 2013, at 7:49 AM, Marcus Ottosson wrote: > > > I came across this thread > > > https://groups.google.com/d/msg/python_inside_maya/ycSqonujjJ8/bRPEnQAGE1cJ > > > > ..but am not that familiar enough with network programming to understand > exactly what is going on. My problem seems similar, I want an externally > running PyQt application to get sent information from Maya. I'm trying to > setup a server within the PyQt app, but can't get around how to make it > concurrent. > > > > Could I get a simplified example of how does could be achieved? > > > > I made an example app here: http://pastebin.com/caRJX8qD > > Whenever the current node changes, I'd like this gui do show me the name > of that node via it's set(node) method. > > > > Any ideas? > > > > -- > > You received this message because you are subscribed to the Google > Groups "Python Programming for Autodesk Maya" group. > > To unsubscribe from this group and stop receiving emails from it, send > an email to [email protected]. > > To post to this group, send email to [email protected] > . > > For more options, visit https://groups.google.com/groups/opt_out. > > > > > > -- > You received this message because you are subscribed to the Google Groups > "Python Programming for Autodesk Maya" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > For more options, visit https://groups.google.com/groups/opt_out. > > > -- You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
