def main(): options = yield getStepperMotorOptions() url = yield getStepperMotorURL(options) StepperMotorClient.__ccname__ = '(%s) sm client' % options['name'] protocol = yield getProtocol(url) smc = StepperMotorClient(protocol) runConsoleClient( StepperMotorConsoleClient, smc )
def getProtocol(self,url,name=None): if url not in self.protocols: try: p = yield getProtocol(url) except Exception, e: QtGui.QMessageBox.information(self,'connect failed','could not connect to %s (%s)' % ('unnamed' if name is None else name,url)) raise e p.onClose = lambda a, b, c: self.onProtocolDisconnect(url) self.protocols[url] = p if url not in self.protocolActions: if name is None: name, ok = QtGui.QInputDialog.getText(self,'name connection','enter alias for %s' % url) name = name if ok else url a = self.protocolsMenu.addAction(name) a.triggered.connect(partial(self.getProtocol,url)) self.protocolActions[url] = a else: self.reconnected.emit(url) action = self.protocolActions[url] action.setEnabled(False)
def initializeConsoleClient(self): self.counter = 0 self.protocol = yield getProtocol(MESSAGE_SERVER)
from PySide import QtGui import qt4reactor app = QtGui.QApplication(sys.argv) qt4reactor.install() from twisted.internet import reactor from abclient import getProtocol from abbase import parseCommandLineURL from sitz import TEST_STEPPER_MOTOR_SERVER from functools import partial widget = QtGui.QWidget() button = QtGui.QPushButton('get commands',parent = widget) def onConnect(protocol): def onClick(): def onCommands(commands): QtGui.QMessageBox.information(widget,'commands','<br>'.join('%s: %s' %(name,desc) for name, desc in commands.items())) protocol.sendCommand('commands').addCallback(onCommands) button.clicked.connect(onClick) getProtocol(parseCommandLineURL()).addCallback(onConnect) widget.show() reactor.runReturn() app.exec_()
from abclient import getProtocol from abbase import parseCommandLineURL from sitz import TEST_STEPPER_MOTOR_SERVER from functools import partial widget = QtGui.QWidget() button = QtGui.QPushButton('get commands', parent=widget) def onConnect(protocol): def onClick(): def onCommands(commands): QtGui.QMessageBox.information( widget, 'commands', '<br>'.join('%s: %s' % (name, desc) for name, desc in commands.items())) protocol.sendCommand('commands').addCallback(onCommands) button.clicked.connect(onClick) getProtocol(parseCommandLineURL()).addCallback(onConnect) widget.show() reactor.runReturn() app.exec_()