示例#1
0
    def __init__(self,
                 host: str,
                 port: int,
                 parent: Optional[QtCore.QObject] = None):
        """Initialise a new instance of the class."""
        super().__init__(parent)

        self.host: str = host
        self.port: int = port

        self.__accounts: Dict[int, CompetitorAccount] = dict()
        self.__now: float = 0.0
        self.__order_books: List[OrderBook] = list(
            OrderBook(i, 0.0, 0.0) for i in Instrument)
        self.__orders: Dict[int, Dict[int, Order]] = {0: dict()}
        self.__stop_later: bool = False
        self.__teams: Dict[int, str] = {0: ""}

        self.__ask_prices: List[int] = [0] * TOP_LEVEL_COUNT
        self.__ask_volumes: List[int] = [0] * TOP_LEVEL_COUNT
        self.__bid_prices: List[int] = [0] * TOP_LEVEL_COUNT
        self.__bid_volumes: List[int] = [0] * TOP_LEVEL_COUNT

        self.__socket = QtNetwork.QTcpSocket(self)
        self.__socket.connected.connect(self.on_connected)
        self.__socket.disconnected.connect(self.on_disconnected)
        self.__socket.errorOccurred.connect(self.on_error_occurred)
        self.__socket.readyRead.connect(self.on_data_received)
        self.__stream = QtCore.QDataStream(self.__socket)
示例#2
0
 def __init__(self):
     super(TclInterfaceHandler, self).__init__()
     self.operation = Operation.NONE
     self.frame_address = "00000000"
     self.frames = "1"
     self.tcpClientSocket = QtNetwork.QTcpSocket()
     self.tcpClientSocketStatus = SocketStatus.DISCONNECTED
     self.startVivado()
     return
示例#3
0
    def __init__(self, parent=None):
        super(TalkMainWindow, self).__init__(parent)
        self.ui = Ui_TalkWindow()
        self.ui.setupUi(self)
        self.ui.connectButton.clicked.connect(self.connect)

        self.socket = QtNetwork.QTcpSocket(self)
        self.socket.readyRead.connect(self.readData)
        self.socket.error.connect(self.displayError)
        self.connectState = False
示例#4
0
    def __init__(self, parent=None):
        super(Client, self).__init__(parent)

        self.blockSize = 0
        self.currentFortune = ''

        hostLabel = QtWidgets.QLabel("&Server name:")
        portLabel = QtWidgets.QLabel("S&erver port:")

        self.hostLineEdit = QtWidgets.QLineEdit('Localhost')
        self.portLineEdit = QtWidgets.QLineEdit()
        self.portLineEdit.setValidator(QtGui.QIntValidator(1, 65535, self))

        hostLabel.setBuddy(self.hostLineEdit)
        portLabel.setBuddy(self.portLineEdit)

        self.statusLabel = QtWidgets.QLabel(
            "This examples requires that you run "
            "the Fortune Server example as well.")

        self.getFortuneButton = QtWidgets.QPushButton("Get Fortune")
        self.getFortuneButton.setDefault(True)
        self.getFortuneButton.setEnabled(False)

        quitButton = QtWidgets.QPushButton("Quit")

        buttonBox = QtWidgets.QDialogButtonBox()
        buttonBox.addButton(self.getFortuneButton,
                            QtWidgets.QDialogButtonBox.ActionRole)
        buttonBox.addButton(quitButton, QtWidgets.QDialogButtonBox.RejectRole)

        self.tcpSocket = QtNetwork.QTcpSocket(self)

        self.hostLineEdit.textChanged.connect(self.enableGetFortuneButton)
        self.portLineEdit.textChanged.connect(self.enableGetFortuneButton)
        self.getFortuneButton.clicked.connect(self.requestNewFortune)
        quitButton.clicked.connect(self.close)
        self.tcpSocket.readyRead.connect(self.readFortune)
        self.tcpSocket.error.connect(self.displayError)

        mainLayout = QtWidgets.QGridLayout()
        mainLayout.addWidget(hostLabel, 0, 0)
        mainLayout.addWidget(self.hostLineEdit, 0, 1)
        mainLayout.addWidget(portLabel, 1, 0)
        mainLayout.addWidget(self.portLineEdit, 1, 1)
        mainLayout.addWidget(self.statusLabel, 2, 0, 1, 2)
        mainLayout.addWidget(buttonBox, 3, 0, 1, 2)
        self.setLayout(mainLayout)

        self.setWindowTitle("Fortune Client")
        self.portLineEdit.setFocus()
示例#5
0
    def __init__(self, host, port):
        self.socket = QtNetwork.QTcpSocket()
        self.socket.stateChanged.connect(self._on_socket_state_change)
        self.socket.readyRead.connect(self.read)
        self.socket.error.connect(self._on_error)
        self.socket.setSocketOption(QtNetwork.QTcpSocket.KeepAliveOption, 1)

        self._host = host
        self._port = port
        self.block_size = 0

        self._obs_state = BehaviorSubject(ConnectionState.DISCONNECTED)
        self.obs_state = self._obs_state.pipe(ops.distinct_until_changed())
        self.message_stream = Subject()
    def __init__(self, uifile):
        loader = QtUiTools.QUiLoader()
        self.ui = loader.load(uifile)
        self.connectButton = self.ui.findChild(QtWidgets.QWidget,
                                               "connectButton")
        self.talkMain = self.ui.findChild(QtWidgets.QWidget, "talkMain")
        self.messageEdit = self.ui.findChild(QtWidgets.QWidget, "messageEdit")
        self.sendButton = self.ui.findChild(QtWidgets.QWidget, "sendButton")

        self.connectButton.clicked.connect(self.connect)
        self.ui.closeEvent = self.closeEvent

        self.socket = QtNetwork.QTcpSocket(self.ui)
        self.socket.readyRead.connect(self.readData)
        self.socket.error.connect(self.displayError)
示例#7
0
    def run(self):
        tcpSocket = QtNetwork.QTcpSocket()
        if not tcpSocket.setSocketDescriptor(self.socketDescriptor):
            self.error.emit(tcpSocket.error())
            return

        block = QtCore.QByteArray()
        outstr = QtCore.QDataStream(block, QtCore.QIODevice.WriteOnly)
        outstr.setVersion(QtCore.QDataStream.Qt_4_0)
        outstr.writeUInt16(0)
        outstr.writeString(self.text)
        outstr.device().seek(0)
        outstr.writeUInt16(block.count() - 2)

        tcpSocket.write(block)
        tcpSocket.disconnectFromHost()
        tcpSocket.waitForDisconnected()
    def run(self):
        self.mutex.lock()
        serverName = self.hostName
        serverPort = self.port
        self.mutex.unlock()

        while not self.quit:
            Timeout = 5 * 1000

            socket = QtNetwork.QTcpSocket()
            socket.connectToHost(serverName, serverPort)

            if not socket.waitForConnected(Timeout):
                self.error.emit(socket.error(), socket.errorString())
                return

            while socket.bytesAvailable() < 2:
                if not socket.waitForReadyRead(Timeout):
                    self.error.emit(socket.error(), socket.errorString())
                    return

            instr = QtCore.QDataStream(socket)
            instr.setVersion(QtCore.QDataStream.Qt_4_0)
            blockSize = instr.readUInt16()

            while socket.bytesAvailable() < blockSize:
                if not socket.waitForReadyRead(Timeout):
                    self.error.emit(socket.error(), socket.errorString())
                    return

            self.mutex.lock()
            fortune = instr.readString()

            try:
                # Python v3.
                fortune = str(fortune, encoding='ascii')
            except TypeError:
                # Python v2.
                pass

            self.newFortune.emit(fortune)

            self.cond.wait(self.mutex)
            serverName = self.hostName
            serverPort = self.port
            self.mutex.unlock()
示例#9
0
    def __init__(self, parent=None):
        super(Dialog, self).__init__(parent)

        self.tcpServer = QtNetwork.QTcpServer()
        self.tcpClient = QtNetwork.QTcpSocket()
        self.bytesToWrite = 0
        self.bytesWritten = 0
        self.bytesReceived = 0

        self.clientProgressBar = QtGui.QProgressBar()
        self.clientStatusLabel = QtGui.QLabel("Client ready")
        self.serverProgressBar = QtGui.QProgressBar()
        self.serverStatusLabel = QtGui.QLabel("Server ready")

        self.startButton = QtGui.QPushButton("&Start")
        self.quitButton = QtGui.QPushButton("&Quit")

        buttonBox = QtGui.QDialogButtonBox()
        buttonBox.addButton(self.startButton,
                            QtGui.QDialogButtonBox.ActionRole)
        buttonBox.addButton(self.quitButton, QtGui.QDialogButtonBox.RejectRole)

        self.startButton.clicked.connect(self.start)
        self.quitButton.clicked.connect(self.close)
        self.tcpServer.newConnection.connect(self.acceptConnection)
        self.tcpClient.connected.connect(self.startTransfer)
        self.tcpClient.bytesWritten.connect(self.updateClientProgress)
        self.tcpClient.error.connect(self.displayError)

        mainLayout = QtGui.QVBoxLayout()
        mainLayout.addWidget(self.clientProgressBar)
        mainLayout.addWidget(self.clientStatusLabel)
        mainLayout.addWidget(self.serverProgressBar)
        mainLayout.addWidget(self.serverStatusLabel)
        mainLayout.addStretch(1)
        mainLayout.addSpacing(10)
        mainLayout.addWidget(buttonBox)
        self.setLayout(mainLayout)

        self.setWindowTitle("Loopback")
 def setUp(self):
     self.sock = QtNetwork.QTcpSocket()
     self.sock.connectToHost('127.0.0.1', 25)
示例#11
0
 def __init__(self):
     self._ip_address = None
     self._name = ""
     self._socket = QtNetwork.QTcpSocket()
     self._receiver = None
     self._sender = None
示例#12
0
 def connect_to_server(self):
     self.socket = QtNetwork.QTcpSocket()
     self.socket.connected.connect(self._handle_connected)
     self.socket.error.connect(self._handle_error)
     self.socket.connectToHost(self.server, vstreamer_utils.SERVER_PORT)
示例#13
0
 def __init__(self, ctx):
     QtCore.QObject.__init__(self)
     self.text=""
     self.socket = QtNetwork.QTcpSocket(ctx)
     self.socket.readyRead.connect(self.readData)
     self.socket.error.connect(self.displayError)