예제 #1
0
    def __init__(self, parent=None):
        super(proxies, self).__init__(parent)

        self.client = parent

        self.proxies = {}
        self.proxiesDestination = {}
        port = 12000
        errored = False
        for i in range(11) :
            port = port + 1
            self.proxies[i] = QtNetwork.QUdpSocket(self)
            if not self.proxies[i].bind(QtNetwork.QHostAddress.LocalHost, port) :
                self.__logger.warn("Can't bind socket %i" % i)
                errored = True
            else :
                self.__logger.info("binding socket %i on port %i" % (i, self.proxies[i].localPort()))
                self.proxies[i].readyRead.connect(functools.partial(self.processPendingDatagrams, i))
                self.proxiesDestination[i] = None
        if errored:
            QtGui.QMessageBox.warning(self.client, "Cannot use proxy server", "FAF is unable to bind the port <b>12000 to 12011 on TCP</b>.<br>Please check your firewall settings.<br><b>You may experience connections problems until it's fixed.</b>")
            
        self.proxySocket = QtNetwork.QTcpSocket(self)
        self.proxySocket.connected.connect(self.connectedProxy)
        self.proxySocket.readyRead.connect(self.readData)
        self.proxySocket.disconnected.connect(self.disconnectedFromProxy)
        
        self.blockSize = 0
        self.uid = None
        self.canClose = False
        self.testedPortsAmount = {}
        self.testedPorts = []
        self.testedLoopbackAmount = {}
        self.testedLoopback = []
        self.testing = False
예제 #2
0
    def __init__(self):

        self.kill_now = False

        self.pix_label = None

        super(SceneViewer, self).__init__()

        self.ns = "/art/interface/projected_gui/"

        self.server = rospy.get_param(self.ns + "scene_server")
        self.port = rospy.get_param(self.ns + "scene_server_port")
        rospy.loginfo("Server: " + self.server + ":" + str(self.port))

        self.show()

        self.pix_label = QtGui.QLabel(self)
        self.pix_label.setAlignment(QtCore.Qt.AlignHCenter
                                    | QtCore.Qt.AlignVCenter)

        self.pix_label.resize(self.size())
        self.pix_label.show()

        self.tcpSocket = QtNetwork.QTcpSocket(self)
        self.blockSize = 0
        self.tcpSocket.readyRead.connect(self.getScene)
        self.tcpSocket.error.connect(self.on_error)

        rospy.loginfo("Scene viewer ready")
예제 #3
0
 def setup_socket(self):
     self.blockSize = 0
     self.tcpSocket = QtNetwork.QTcpSocket(self)
     self.tcpSocket.readyRead.connect(self.readMessage)
     self.tcpSocket.connected.connect(self.on_connected)
     self.tcpSocket.error.connect(self.display_connect_error)
     self.tcpSocket.connectToHost(HOST, PORT)
예제 #4
0
    def __init__(self, parent, client, local_socket, testing, init_mode=1):
        QtCore.QObject.__init__(self)
        self.parent = parent
        self.inputSocket = local_socket
        self.client = client
        self.testing = testing

        # for unpacking FA protocol
        self.blockSizeFromServer = 0
        self.headerSizeRead = False
        self.headerRead = False
        self.chunkSizeRead = False
        self.fieldTypeRead = False
        self.fieldSizeRead = False
        self.blockSize = 0
        self.fieldSize = 0
        self.chunkSize = 0
        self.fieldType = 0
        self.chunks = []

        self.pingTimer = None
        self.init_mode = init_mode

        #self.inputSocket.setSocketOption(QtNetwork.QTcpSocket.KeepAliveOption, 1)
        self.inputSocket.readyRead.connect(self.readData)
        self.inputSocket.disconnected.connect(self.inputDisconnected)
        self.__logger.info("FA connected locally.")  
        

        # Open the relay socket to our server
        self.relaySocket = QtNetwork.QTcpSocket(self.parent)        
        self.relaySocket.setSocketOption(QtNetwork.QTcpSocket.KeepAliveOption, 1)
        self.relaySocket.connectToHost(FAF_SERVER_HOST, FAF_SERVER_PORT)
        self.relaySocket.connected.connect(self.on_connected)
        self.relaySocket.error.connect(self.on_error)
예제 #5
0
    def create_tcp_socket(self, address, port):

        # create the socket
        tcp_socket = QtNetwork.QTcpSocket(parent=self)

        self.tcp_sockets.append(tcp_socket)

        # we have a destination port and address -> connect!
        tcp_socket.connectToHost(address, port)

        try:
            if not tcp_socket.waitForConnected(self.DEFAULT_WAITING_TIME):
                log.error('no connection for address %s:%s' %
                          (address.toString(), port))
        except RuntimeError:
            return

        # connect with processing function
        tcp_socket.readyRead.connect(
            lambda: self.read_from_tcp_socket(tcp_socket))

        # if socket is disconnected, delete it later
        tcp_socket.disconnected.connect(tcp_socket.deleteLater)

        return tcp_socket
예제 #6
0
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)

        self.blockSize = 0
        self.tcpSocket = QtNetwork.QTcpSocket(self)
        self.tcpSocket.readyRead.connect(self.readSig)
        self.tcpSocket.connectToHost(QtNetwork.QHostAddress('127.0.0.1'), 5000)
예제 #7
0
def Do_DownloadData(strFile, isFin=False):
    strData = 'GET /userRpm/' + strFile + ' HTTP/1.1\r\n' \
     'Cookie: ' + conf__strCookie +  '\r\n' \
     'Referer: ' + conf__strLinkPrefix + 'MenuRpm.htm\r\n\r\n'
    print strData
    cachedData = []

    def on_ready_read():
        if client.bytesAvailable():
            print '-' * 50
            print 'on_ready_read()'
            print client.bytesAvailable(), 'read.'
            data = str(client.readAll())
            cachedData.append(data)
            print len(data), client.bytesAvailable()
            #print data
    def on_connected():
        client.writeData(strData)
        print 'connected.'

    def on_disconnect():
        print '-' * 50
        print 'on_disconnect()'
        print len(cachedData)
        print ''.join(cachedData)
        if isFin: exit(0)

    client = QtNetwork.QTcpSocket()
    client.readyRead.connect(on_ready_read)
    client.connected.connect(on_connected)
    client.disconnected.connect(on_disconnect)
    client.connectToHost(QtNetwork.QHostAddress('192.168.1.1'), 80)
예제 #8
0
    def __init__(self, parent, local_socket, *args, **kwargs):
        QtCore.QObject.__init__(self, *args, **kwargs)
        self.parent = parent
        self.inputSocket = local_socket
        self.inputSocket.setSocketOption(QtNetwork.QTcpSocket.KeepAliveOption,
                                         1)
        self.inputSocket.readyRead.connect(self.readDatas)
        self.inputSocket.disconnected.connect(self.inputDisconnected)
        self.__logger.info("FA connected locally.")

        #Create a file to write the replay data into
        self.replayData = QtCore.QByteArray()
        self.replayInfo = fa.instance.info

        # Open the relay socket to our server
        self.relaySocket = QtNetwork.QTcpSocket(self.parent)
        self.relaySocket.connectToHost(INTERNET_REPLAY_SERVER_HOST,
                                       INTERNET_REPLAY_SERVER_PORT)

        if util.settings.value("fa.live_replay",
                               DEFAULT_LIVE_REPLAY,
                               type=bool):
            if self.relaySocket.waitForConnected(
                    1000):  #Maybe make this asynchronous
                self.__logger.debug("internet replay server " +
                                    self.relaySocket.peerName() + ":" +
                                    str(self.relaySocket.peerPort()))
            else:
                self.__logger.error("no connection to internet replay server")
예제 #9
0
    def __init__(self, parent=None):
        super(DialogClient, self).__init__(parent)

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

        self.clientProgressBar = QtGui.QProgressBar()
        self.clientStatusLabel = QtGui.QLabel("Client 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.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.addStretch(1)
        mainLayout.addSpacing(10)
        mainLayout.addWidget(buttonBox)
        self.setLayout(mainLayout)

        self.setWindowTitle("Loopback")
예제 #10
0
    def __init__(self, name, socket, requester, *args, **kwargs):
        '''
        Constructor
        '''
        QtCore.QObject.__init__(self, *args, **kwargs)

        self.name = name

        logger = logging.getLogger("faf.secondaryServer.%s" % self.name)
        logger.info("Instanciating secondary server.")

        self.socketPort = socket
        self.requester = requester

        self.result = self.RESULT_NONE
        self.command = None
        self.message = None

        self.blockSize = 0
        self.serverSocket = QtNetwork.QTcpSocket()

        self.serverSocket.error.connect(self.handleServerError)
        self.serverSocket.readyRead.connect(self.readDataFromServer)
        self.serverSocket.disconnected.connect(self.disconnected)
        self.serverSocket.error.connect(self.errored)
        self.invisible = False
예제 #11
0
    def __init__(self, host='127.0.0.1', port=4567):
        super(_Connector, self).__init__()
        self.socket = QtNetwork.QTcpSocket()
        self.socket.readyRead.connect(self.__readReady)
        self.socket.connectToHost(host, port)
        if not self.socket.waitForConnected(1000):
            raise IOError("Could not connect to server!")
        self.socket.setSocketOption(QtNetwork.QAbstractSocket.LowDelayOption,
                                    1)
        self.next = 0
        self.queue = []
        self.buf = ''
        self.watchHandlers = {}
        self.watchIndications = []
        self.progressHandlers = []
        self.progressIndications = []
        self.recursion = 0

        self.watchReady.connect(self.__dispatchIndications,
                                QtCore.Qt.QueuedConnection)

        try:
            reply = self._rpc(_Connector.INIT_REQ, _Connector.INIT_CNF,
                              struct.pack('>L', 0))
            (version, self.maxPacketSize) = struct.unpack_from(
                '>LL', self._parseDirectResult(reply), 0)
            if version != 0:
                raise IOError("Unsupported protocol version!")
        except:
            self.socket.disconnectFromHost()
            raise
예제 #12
0
    def __init__(self, port):
        super(Listener, self).__init__()

        self.__tcpSocket = QtNetwork.QTcpSocket()
        self.__tcpSocket.connectToHost("localhost",9999)

        self.__tcpSocket.newConnection.connected(self.startListening)
예제 #13
0
    def __init__(self, parent=None):
        QtGui.QDialog.__init__(self, parent)

        self.hostLabel = QtGui.QLabel(self.tr("&Server name:"))
        self.portLabel = QtGui.QLabel(self.tr("S&erver port:"))

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

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

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

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

        self.quitButton = QtGui.QPushButton(self.tr("Quit"))

        self.timerId = -1
        self.blockSize = 0
        self.currentFortune = QtCore.QString()
        self.tcpSocket = QtNetwork.QTcpSocket(self)

        self.connect(self.hostLineEdit,
                     QtCore.SIGNAL("textChanged(const QString &)"),
                     self.enableGetFortuneButton)
        self.connect(self.portLineEdit,
                     QtCore.SIGNAL("textChanged(const QString &)"),
                     self.enableGetFortuneButton)
        self.connect(self.getFortuneButton, QtCore.SIGNAL("clicked()"),
                     self.requestNewFortune)
        self.connect(self.quitButton, QtCore.SIGNAL("clicked()"), self,
                     QtCore.SLOT("close()"))
        self.connect(self.tcpSocket, QtCore.SIGNAL("readyRead()"),
                     self.readFortune)
        self.connect(self.tcpSocket,
                     QtCore.SIGNAL("error(QAbstractSocket::SocketError)"),
                     self.displayError)

        buttonLayout = QtGui.QHBoxLayout()
        buttonLayout.addStretch(1)
        buttonLayout.addWidget(self.getFortuneButton)
        buttonLayout.addWidget(self.quitButton)

        mainLayout = QtGui.QGridLayout()
        mainLayout.addWidget(self.hostLabel, 0, 0)
        mainLayout.addWidget(self.hostLineEdit, 0, 1)
        mainLayout.addWidget(self.portLabel, 1, 0)
        mainLayout.addWidget(self.portLineEdit, 1, 1)
        mainLayout.addWidget(self.statusLabel, 2, 0, 1, 2)
        mainLayout.addLayout(buttonLayout, 3, 0, 1, 2)
        self.setLayout(mainLayout)

        self.setWindowTitle(self.tr("Fortune Client"))
        self.portLineEdit.setFocus()
예제 #14
0
    def __init__(self, host, port):
        super(Listener, self).__init__()

        self.__tcpSocket = QtNetwork.QTcpSocket()
        self.__tcpSocket.connectToHost(host, port)

        self.__tcpSocket.connected.connect(self.startListening)
        self.__tcpSocket.error.connect(self.notifyError)
예제 #15
0
    def __init__(self, client, *args, **kwargs):
        logger.debug("Lobby instantiating.")
        BaseClass.__init__(self, *args, **kwargs)

        self.setupUi(self)

        self.client = client
        #self.client.galacticwarTab.setStyleSheet(util.readstylesheet("galacticwar/galacticwar.css"))

        self.COLOR_FACTIONS = {}
        self.mapTransparency = 10
        self.AA = True
        self.rotation = True
        self.stars = 25

        self.GWOptions = GWOptions(self)
        self.GWOptions.loadSettings()

        self.client.galacticwarTab.layout().addWidget(self)

        self.downloader = QNetworkAccessManager(self)
        self.downloader.finished.connect(self.finishRequest)

        self.shaderlist = []
        self.texturelist = {}
        self.shaders = {}

        self.infoPanel = None
        self.OGLdisplay = None

        self.galaxy = Galaxy(self)
        self.channel = None

        self.initDone = False

        self.uid = None
        self.faction = None
        self.name = None
        self.rank = None
        self.credits = 0
        self.victories = 0
        self.enslavedBy = None

        self.attacks = {}

        self.state = ClientState.NONE

        ## Network initialization

        self.socket = QtNetwork.QTcpSocket()
        self.socket.readyRead.connect(self.readFromServer)
        self.socket.disconnected.connect(self.disconnectedFromServer)
        self.socket.error.connect(self.socketError)
        self.blockSize = 0

        self.progress = QtGui.QProgressDialog()
        self.progress.setMinimum(0)
        self.progress.setMaximum(0)
예제 #16
0
파일: server.py 프로젝트: AHAPX/kvartis
 def connectToServer(self):
     self.socket = QtNetwork.QTcpSocket()
     self.socket.connectToHost('localhost', 8765)
     self.label1.setText('Connect to server')
     self.button2.setText('Disconnect')
     QtCore.QObject.connect(self.socket, QtCore.SIGNAL('disconnected()'), self.disconnect)
     QtCore.QObject.connect(self.button2, QtCore.SIGNAL('clicked()'), self.disconnect)
     QtCore.QObject.connect(self.socket, QtCore.SIGNAL('readyRead()'), self.readMessage)
     self.edit1.setEnabled(True)
     self.button3.setEnabled(True)
예제 #17
0
    def __init__(self, client):
        super(BaseClass, self).__init__()

        self.setupUi(self)

        #self.replayVault.setVisible(False)
        self.client = client
        client.replaysTab.layout().addWidget(self)

        client.gameInfo.connect(self.processGameInfo)
        client.replayVault.connect(self.replayVault)

        self.onlineReplays = {}
        self.onlineTree.setItemDelegate(ReplayItemDelegate(self))
        self.replayDownload = QNetworkAccessManager()
        self.replayDownload.finished.connect(self.finishRequest)

        # sending request to replay vault
        self.searchButton.pressed.connect(self.searchVault)
        self.playerName.returnPressed.connect(self.searchVault)
        self.mapName.returnPressed.connect(self.searchVault)

        self.myTree.itemDoubleClicked.connect(self.myTreeDoubleClicked)
        self.myTree.itemPressed.connect(self.myTreePressed)
        self.myTree.header().setResizeMode(0,
                                           QtGui.QHeaderView.ResizeToContents)
        self.myTree.header().setResizeMode(1,
                                           QtGui.QHeaderView.ResizeToContents)
        self.myTree.header().setResizeMode(2, QtGui.QHeaderView.Stretch)
        self.myTree.header().setResizeMode(3,
                                           QtGui.QHeaderView.ResizeToContents)

        self.liveTree.itemDoubleClicked.connect(self.liveTreeDoubleClicked)
        self.liveTree.itemPressed.connect(self.liveTreePressed)
        self.liveTree.header().setResizeMode(
            0, QtGui.QHeaderView.ResizeToContents)
        self.liveTree.header().setResizeMode(1, QtGui.QHeaderView.Stretch)
        self.liveTree.header().setResizeMode(
            2, QtGui.QHeaderView.ResizeToContents)

        self.games = {}

        self.onlineTree.itemDoubleClicked.connect(self.onlineTreeDoubleClicked)
        self.onlineTree.itemPressed.connect(self.onlineTreeClicked)

        # replay vault connection to server
        self.searching = False
        self.blockSize = 0
        self.replayVaultSocket = QtNetwork.QTcpSocket()
        self.replayVaultSocket.error.connect(self.handleServerError)
        self.replayVaultSocket.readyRead.connect(self.readDataFromServer)
        self.replayVaultSocket.disconnected.connect(self.disconnected)
        self.replayVaultSocket.error.connect(self.errored)

        logger.info("Replays Widget instantiated.")
예제 #18
0
    def run(self):
        self.tcpSocket = QtNetwork.QTcpSocket()
        self.tcpSocket.readyRead.connect(self.readStream)
        self.rBuffer.readyRead.connect(self.sendBuff)
        if not self.tcpSocket.setSocketDescriptor(self.socketDescriptor):
            self.emit(QtCore.SIGNAL("error(int)"), tcpSocket.error())
            return

        self.sendMsg('server,new,%s' % self.clientID)

        self.exec_()
예제 #19
0
    def __init__(self, *args, **kwargs):
        QtGui.QMainWindow.__init__(self, *args, **kwargs)

        self.socket = QtNetwork.QTcpSocket()

        self.watcherThread = FileWatcherThread()


        self.setupGUI()

        self.watcherThread.fileChanged.connect(self.fileChanged)
예제 #20
0
 def run(self):
     """
   Main method that connects sockets on both sides and "merge" them
 """
     while True:
         if not self.remote_socket is None:
             del self.remote_socket
         if not self.local_socket is None:
             del self.local_socket
         self.remote_socket = QtNetwork.QTcpSocket(self)
         self.local_socket = QtNetwork.QTcpSocket(self)
         #connect to remote
         self.connectSocket(self.remote_socket, self.remote_hostname,
                            self.remote_port)
         #Connect to local only when remote is connected
         self.connectSocket(self.local_socket, self.local_hostname,
                            self.local_port)
         #plug them together...
         self.merger.mergeSockets(self.local_socket, self.remote_socket)
         gc.collect()
     pass
예제 #21
0
 def serverConnect(self):
     self.connButton.setText('Connecting...')
     self.connButton.setEnabled(False)
     self.tcpSocket = QtNetwork.QTcpSocket(self)
     self.tcpSocket.readyRead.connect(self.readStream)
     self.tcpSocket.connectToHost(self.specAddr.text(),
                                  self.specPort.text().toInt()[0])
     if not self.tcpSocket.waitForConnected(5000):
         print 'Failed to connect, error code:', self.tcpSocket.error()
         self.tcpSocket.close()
         self.close()
     self.connButton.setText('Connected')
     self.sendButton.setEnabled(True)
예제 #22
0
    def __init__(self):
        super(NGQManagerClient, self).__init__()

        self.socket = QtNetwork.QTcpSocket()
        self.socket.readyRead.connect(self.__readFromServer)
        self.socket.connected.connect(self.__connectEstablished)
        self.socket.disconnected.connect(self.__connectLost)
        self.socket.stateChanged.connect(self.__socetStateChange)

        self.__tryConnect()

        self.__qgisState = {}
        self.setQGISPID()
예제 #23
0
	def run(self):
		self.tcpSocket = QtNetwork.QTcpSocket()
		print "Connection Established"

		if not self.tcpSocket.setSocketDescriptor(self.socketDescriptor):
			self.emit(QtCore.SIGNAL("error(int)"), tcpSocket.error())
			print "Error on setSocketDescriptor"
			return

		#print "Initial Socket state:", self.tcpSocket.state()
		while self.tcpSocket.state() == 3:
			if self.WaitForAction() == 0:
				break
		print "Out of while loop"
예제 #24
0
    def __init__(self, parent=None):
        super(Client, self).__init__(parent)

        self.blockSize = 0
        self.currentFortune = ''

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

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

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

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

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

        quitButton = QtGui.QPushButton("Quit")

        buttonBox = QtGui.QDialogButtonBox()
        buttonBox.addButton(self.getFortuneButton,
                            QtGui.QDialogButtonBox.ActionRole)
        buttonBox.addButton(quitButton, QtGui.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 = QtGui.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()
예제 #25
0
    def __init__(self,
                 featured_mod,
                 version=None,
                 modversions=None,
                 sim=False,
                 silent=False,
                 *args,
                 **kwargs):
        """
        Constructor
        """
        QtCore.QObject.__init__(self, *args, **kwargs)

        self.filesToUpdate = []

        self.lastData = time.time()

        self.featured_mod = featured_mod
        self.version = version
        self.modversions = modversions

        self.sim = sim
        self.modpath = None

        self.blockSize = 0
        self.updateSocket = QtNetwork.QTcpSocket()
        self.updateSocket.setSocketOption(QtNetwork.QTcpSocket.KeepAliveOption,
                                          1)
        self.updateSocket.setSocketOption(QtNetwork.QTcpSocket.LowDelayOption,
                                          1)

        self.result = self.RESULT_NONE

        self.destination = None

        self.silent = silent
        self.progress = QtGui.QProgressDialog()
        if self.silent:
            self.progress.setCancelButton(None)
        else:
            self.progress.setCancelButtonText("Cancel")
        self.progress.setWindowFlags(QtCore.Qt.CustomizeWindowHint
                                     | QtCore.Qt.WindowTitleHint)
        self.progress.setAutoClose(False)
        self.progress.setAutoReset(False)
        self.progress.setModal(1)
        self.progress.setWindowTitle("Updating %s" %
                                     str(self.featured_mod).upper())

        self.bytesToSend = 0
예제 #26
0
    def __init__(self):
        QtCore.QObject.__init__(self)
        self.sock = QtNetwork.QTcpSocket()

        QtCore.QObject.connect(self.sock, QtCore.SIGNAL('connected()'),
                               self.socketConnected)
        QtCore.QObject.connect(
            self.sock, QtCore.SIGNAL('error(QAbstractSocket::SocketError)'),
            self.socketError)
        QtCore.QObject.connect(self.sock, QtCore.SIGNAL('readyRead()'),
                               self.socketRead)
        QtCore.QObject.connect(self.sock, QtCore.SIGNAL('disconnected()'),
                               self.disconnected)

        self.buffor = bytes()
    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()
예제 #29
0
    def __init__(self, host, port, parent=None):
        super(CEQRemoteControl, self).__init__(parent)
        self._host = host
        self._port = port
        self._socket = None
        if isNetworkImport:
            self._socket = QtNetwork.QTcpSocket(self)
            self._socket.error.connect(self.handleConnectionError)
            self._socket.stateChanged.connect(self.onConnectionStateChanged)
            self._socket.readyRead.connect(self.onReadyRead)

        self._maxConnectionAttempts = 5
        self._connectionAttempts = 0
        self._isAlwaysReconnect = False  #TODO: atronah: сделать интерфейс для изменения этого значения

        self._activateAfterConnect = False
        self._lastMessageTime = time.time()
예제 #30
0
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)

        self.setWindowTitle('simple Qt/Python application')
        #
        ##
        ### create widgets
        ##
        #
        self.editData = QtGui.QLineEdit(self)
        self.editData.setEnabled(False)

        self.editText = QtGui.QLineEdit(self)
        self.editText.setEnabled(False)

        buttonSend = QtGui.QPushButton(self.tr("&Send"), self)
        self.connect(buttonSend, QtCore.SIGNAL('clicked()'), self.slotSend)

        buttonExit = QtGui.QPushButton(self.tr("E&xit"), self)
        self.connect(buttonExit, QtCore.SIGNAL('clicked()'), self.slotClose)

        horLayout = QtGui.QHBoxLayout()

        horLayout.addWidget(self.editText)
        horLayout.addStretch()
        horLayout.addWidget(buttonSend)

        layout = QtGui.QVBoxLayout(self)

        layout.addWidget(self.editData)
        layout.addLayout(horLayout)
        layout.addStretch()
        layout.addWidget(buttonExit)
        #
        ##
        ### socket
        ##
        #
        self.socket = QtNetwork.QTcpSocket()
        self.connect(self.socket, QtCore.SIGNAL('connected()'),
                     self.slotConnected)
        self.connect(self.socket, QtCore.SIGNAL('disconnected()'),
                     self.slotDisconnected)
        self.connect(self.socket, QtCore.SIGNAL('readyRead()'), self.slotRead)

        self.socket.connectToHost('localhost', 7000)