Commits

Yuya Nishihara committed 7e51f6e

pyqt: guitest: quick'n'dirty impl of remote execution

  • Participants
  • Parent commits 5bfe3b7

Comments (0)

Files changed (1)

pyqt/guitest/dialog.py

 import sys
 from PyQt4.QtGui import QApplication, QWidget, QIcon, QFont, QToolTip, QPushButton, QMessageBox, qApp
 from PyQt4.QtCore import QObject, QTimer, Qt, SIGNAL, SLOT
+from PyQt4.QtNetwork import QLocalServer
 from PyQt4.QtTest import QTest
 
 class MainWindow(QWidget):
     app = QApplication(sys.argv)
     w = MainWindow()
     w.show()
+    localns = locals()
 
-    # TODO by remote request
-    QTimer.singleShot(1000,
-                      lambda: QTest.mouseClick(w._quitButton, Qt.LeftButton))
+    # TODO clean up
+    server = QLocalServer()
+    def handleconnection():
+        sock = server.nextPendingConnection()
+        print 'connected'
+        def handlerequest():
+            # e.g. QTest.mouseClick(w._quitButton, Qt.LeftButton)
+            # TODO use pyro or something?
+            expr = str(sock.readAll())
+            print 'code:', expr
+            try:
+                print 'result:', eval(expr, globals(), localns)
+            except Exception, err:
+                print err
+        sock.readyRead.connect(handlerequest)
+
+    # TODO remove socket file if any
+    server.newConnection.connect(handleconnection)
+    server.listen('foo')
 
     return app.exec_()