Esempio n. 1
0
    def _connect_signals(self):
        """Method used to connect the signals."""

        App._connect_signals(self)

        # Connecting socket signals
        self.__tcpSocket.error.connect(self.__display_error)
        self.__tcpSocket.readyRead.connect(self.__read_message)

        # Connecting the socket when requested
        self._window.set_connection_infos.connect(
            lambda x: self.connect_to_server(*x))

        # Connecting the bar names request
        self._window.get_bar_names.connect(
            lambda: self.encode_message(action="LA"))

        # Setting the bar name when requested
        self._window.set_bar_name.connect(self.__set_name)

        # Connecting the preferences
        self._window.ask_preferences.connect(
            lambda: self.fill_preferences.emit((self.__tcpSocket.peerAddress(
            ).toString(), self.__tcpSocket.peerPort()), self._name))

        # Connecting the send message signal
        self._window.send_message.connect(
            lambda x: self.encode_message(action="ME", message=x))

        # Connecting the send urgent message signal
        self._window.send_message_urgent.connect(
            lambda x: self.encode_message(action="UR", message=x))

        # Connecting the drink orders
        self._window.order_drink.connect(self.__order_drink)

        # Connecting the cancellation of an order
        self._window.cancel_order.connect(
            lambda x: print("Cancelling sale '{}'".format(x)))
        self._window.cancel_order.connect(
            lambda x: self.encode_message(action="AR", sale_id=x))

        # Connecting the refuel complete signal
        self._window.refuel_completed.connect(
            lambda d, q, i: self.encode_message(
                action="RE", key=d, quantity=q, id=i))

        # Connecting for the connection dialog
        self._window.request_connection_infos.connect(
            lambda: self.open_connection_dialog.emit([[
                self.__tcpSocket.peerAddress().toString(),
                self.__tcpSocket.state() == QAbstractSocket.ConnectedState
            ]]))