Example #1
0
 def create_client(self):
     self.client = SocketClientFactory(self.on_client_connect_success,
                                       self.on_client_connect_fail,
                                       self.on_client_receive)
 def create_client(self):
     self.client = SocketClientFactory(
         self.on_client_connect_success, self.on_client_connect_fail, self.on_client_receive
     )
Example #3
0
class SampleGUIClientWindow(QMainWindow):
    def __init__(self, reactor, parent=None):
        super(SampleGUIClientWindow, self).__init__(parent)
        self.reactor = reactor

        self.create_main_frame()
        self.create_client()
        self.create_timer()

    def create_main_frame(self):
        self.circle_widget = CircleWidget()
        self.doit_button = QPushButton('Do it!')
        self.doit_button.clicked.connect(self.on_doit)
        self.log_widget = LogWidget()

        hbox = QHBoxLayout()
        hbox.addWidget(self.circle_widget)
        hbox.addWidget(self.doit_button)
        hbox.addWidget(self.log_widget)

        main_frame = QWidget()
        main_frame.setLayout(hbox)

        self.setCentralWidget(main_frame)

    def create_timer(self):
        self.circle_timer = QTimer(self)
        self.circle_timer.timeout.connect(self.circle_widget.next)
        self.circle_timer.start(25)

    def create_client(self):
        self.client = SocketClientFactory(self.on_client_connect_success,
                                          self.on_client_connect_fail,
                                          self.on_client_receive)

    def on_doit(self):
        self.log('Connecting...')
        # When the connection is made, self.client calls the on_client_connect
        # callback.
        #
        self.connection = self.reactor.connectTCP(SERVER_HOST, SERVER_PORT,
                                                  self.client)

    def on_client_connect_success(self):
        self.log('Connected to server. Sending...')
        self.client.send_msg('hello')

    def on_client_connect_fail(self, reason):
        # reason is a twisted.python.failure.Failure  object
        self.log('Connection failed: %s' % reason.getErrorMessage())

    def on_client_receive(self, msg):
        self.log('Client reply: %s' % msg)
        self.log('Disconnecting...')
        self.connection.disconnect()

    def log(self, msg):
        timestamp = '[%010.3f]' % time.clock()
        self.log_widget.append(timestamp + ' ' + str(msg))

    def closeEvent(self, e):
        self.reactor.stop()
class SampleGUIClientWindow(QMainWindow):
    def __init__(self, reactor, parent=None):
        super(SampleGUIClientWindow, self).__init__(parent)
        self.reactor = reactor

        self.create_main_frame()
        self.create_client()
        self.create_timer()

    def create_main_frame(self):
        self.circle_widget = CircleWidget()
        self.doit_button = QPushButton("Do it!")
        self.doit_button.clicked.connect(self.on_doit)
        self.log_widget = LogWidget()

        hbox = QHBoxLayout()
        hbox.addWidget(self.circle_widget)
        hbox.addWidget(self.doit_button)
        hbox.addWidget(self.log_widget)

        main_frame = QWidget()
        main_frame.setLayout(hbox)

        self.setCentralWidget(main_frame)

    def create_timer(self):
        self.circle_timer = QTimer(self)
        self.circle_timer.timeout.connect(self.circle_widget.next)
        self.circle_timer.start(25)

    def create_client(self):
        self.client = SocketClientFactory(
            self.on_client_connect_success, self.on_client_connect_fail, self.on_client_receive
        )

    def on_doit(self):
        self.log("Connecting...")
        # When the connection is made, self.client calls the on_client_connect
        # callback.
        #
        self.connection = self.reactor.connectTCP(SERVER_HOST, SERVER_PORT, self.client)

    def on_client_connect_success(self):
        self.log("Connected to server. Sending...")
        self.client.send_msg("hello")

    def on_client_connect_fail(self, reason):
        # reason is a twisted.python.failure.Failure  object
        self.log("Connection failed: %s" % reason.getErrorMessage())

    def on_client_receive(self, msg):
        self.log("Client reply: %s" % msg)
        self.log("Disconnecting...")
        self.connection.disconnect()

    def log(self, msg):
        timestamp = "[%010.3f]" % time.clock()
        self.log_widget.append(timestamp + " " + str(msg))

    def closeEvent(self, e):
        self.reactor.stop()