def requestStatus(self, avg_support = True):
        self.blockSize = 0
        self.socket.abort()

        block = QtCore.QByteArray()
        commStream = QtCore.QDataStream(block, QtCore.QIODevice.WriteOnly)
        commStream.setVersion(QtCore.QDataStream.Qt_4_0)
        commStream.writeUInt16(0)
        commStream.writeUInt16(self.STATUS_CMD)
        commStream.device().seek(0)
        commStream.writeUInt16(block.count() - 2)
        self.socket.connectToHost(self.ipAddress, self.portNumber)
        self.socket.waitForConnected(10)
        self.socket.write(block)
        self.socket.waitForReadyRead()
        inStream = QtCore.QDataStream(self.socket)
        inStream.setVersion(QtCore.QDataStream.Qt_4_0)

        if self.blockSize == 0:
            if self.socket.bytesAvailable() < 2:
                print("LVC: No Data Received...")
                return
            self.blockSize = inStream.readUInt16()
        self.framesLeft = inStream.readUInt16()
        self.fps = inStream.readUInt16()
        if avg_support:
            self.numAvgs_stat = inStream.readUInt16(); # new
        else:
            self.numAvgs_stat = 1;

        return (self.framesLeft, self.fps, self.numAvgs_stat);
Beispiel #2
0
    def loadFromMemory(self):
        """ This slot function is called in the second Dialog process, when the
        user presses the "Load Image from Shared Memory" button.  First, it
        attaches the process to the shared memory segment created by the first
        Dialog process.  Then it locks the segment for exclusive access, copies
        the image data from the segment into a QBuffer, and streams the QBuffer
        into a QImage.  Then it unlocks the shared memory segment, detaches
        from it, and finally displays the QImage in the Dialog.
        """

        if not self.sharedMemory.attach():
            self.ui.label.setText(
                "Unable to attach to shared memory segment.\nLoad an "
                "image first.")
            return

        buf = QtCore.QBuffer()
        ins = QtCore.QDataStream(buf)
        image = QtGui.QImage()

        self.sharedMemory.lock()
        buf.setData(self.sharedMemory.constData())
        buf.open(QtCore.QBuffer.ReadOnly)
        ins >> image
        self.sharedMemory.unlock()
        self.sharedMemory.detach()

        self.ui.label.setPixmap(QtGui.QPixmap.fromImage(image))
Beispiel #3
0
    def sendInstruction(self):
        block = QtCore.QByteArray()
        out = QtCore.QDataStream(block, QtCore.QIODevice.WriteOnly)
        out.setVersion(QtCore.QDataStream.Qt_4_0)
        out.writeUInt16(0)

        try:
            # Python v3.
            instruction = bytes(self.instruction, encoding='ascii')
        except:
            # Python v2.
            print("Error")

        out.writeString(instruction)
        out.device().seek(0)
        out.writeUInt16(block.size() - 2)

        clientConnection = self.tcpServer.nextPendingConnection()
        clientConnection.disconnected.connect(clientConnection.deleteLater)

        clientConnection.write(block)
        clientConnection.disconnectFromHost()

        if self.animation == 1:
            self.animation = 0
            self.updateInstruction()
    def dropEvent(self, ev):
        src = ev.source()

        if hasattr(src, 'implements') and src.implements('dock'):
            area = self.dropArea
            if area is None:
                return
            if area == 'center':
                area = 'above'
            self.area.moveDock(ev.source(), area, self)
            self.dropArea = None
            self.overlay.setDropArea(self.dropArea)

        elif ev.mimeData().hasFormat('captureName'):
            mime = ev.mimeData()
            itemData = mime.data('captureName')
            dataStream = QtCore.QDataStream(itemData,
                                            QtCore.QIODevice.ReadOnly)

            text = QtCore.QByteArray()
            offset = QtCore.QPoint()
            dataStream >> text >> offset

            self.captureDropped(str(ev.mimeData().text()))
            self.dropArea = None
            self.overlay.setDropArea(self.dropArea)
Beispiel #5
0
    def onDropEvent(self, event):
        if event.mimeData().hasFormat('application/x-text'):
            # decode drop stuff
            data = event.mimeData().data('application/x-text')
            stream = QtCore.QDataStream(data, QtCore.QIODevice.ReadOnly)
            dirName = QtCore.QString()
            nodeName = QtCore.QString()
            stream >> dirName
            stream >> nodeName
            event.setDropAction(QtCore.Qt.CopyAction)
            event.accept()

            # save dropPoint in scene space
            self.dropNodePoint = self.controller.gfxPanel.mapToScene(
                event.pos())

            # create an add node command and execute it
            from command.command import AddNodeCommand
            addNodeCommand = AddNodeCommand(self.controller.shaderLink,
                                            self.controller.gfxPanel,
                                            unicode(dirName),
                                            unicode(nodeName),
                                            self.dropNodePoint)
            self.controller.commandProcessor.executeCommand(addNodeCommand)
        else:
            event.ignore()
Beispiel #6
0
    def dropMimeData(self, data, action, row, column, parent):
        if not data.hasFormat('image/x-puzzle-piece'):
            return False

        if action == QtCore.Qt.IgnoreAction:
            return True

        if column > 0:
            return False

        if not parent.isValid():
            if row < 0:
                endRow = len(self.pixmaps)
            else:
                endRow = min(row, len(self.pixmaps))
        else:
            endRow = parent.row()

        encodedData = data.data('image/x-puzzle-piece')
        stream = QtCore.QDataStream(encodedData, QtCore.QIODevice.ReadOnly)

        while not stream.atEnd():
            pixmap = QtGui.QPixmap()
            location = QtGui.QPoint()
            stream >> pixmap >> location

            self.beginInsertRows(QtCore.QModelIndex(), endRow, endRow)
            self.pixmaps.insert(endRow, pixmap)
            self.locations.insert(endRow, location)
            self.endInsertRows()

            endRow += 1

        return True
    def mousePressEvent(self, event):
        child = self.childAt(event.pos())
        if not child:
            return

        pixmap = QtGui.QPixmap(child.pixmap())

        itemData = QtCore.QByteArray()
        dataStream = QtCore.QDataStream(itemData, QtCore.QIODevice.WriteOnly)
        dataStream << pixmap << QtCore.QPoint(event.pos() - child.pos())

        mimeData = QtCore.QMimeData()
        mimeData.setData('application/x-dnditemdata', itemData)

        drag = QtGui.QDrag(self)
        drag.setMimeData(mimeData)
        drag.setPixmap(pixmap)
        drag.setHotSpot(event.pos() - child.pos())

        tempPixmap = QtGui.QPixmap(pixmap)
        painter = QtGui.QPainter()
        painter.begin(tempPixmap)
        painter.fillRect(pixmap.rect(), QtGui.QColor(127, 127, 127, 127))
        painter.end()

        child.setPixmap(tempPixmap)

        if drag.exec_(QtCore.Qt.CopyAction | QtCore.Qt.MoveAction, QtCore.Qt.CopyAction) == QtCore.Qt.MoveAction:
            child.close()
        else:
            child.show()
            child.setPixmap(pixmap)
Beispiel #8
0
    def getScene(self):

        instr = QtCore.QDataStream(self.tcpSocket)
        instr.setVersion(QtCore.QDataStream.Qt_4_0)

        while not self.kill_now:

            if self.blockSize == 0:
                if self.tcpSocket.bytesAvailable() < 4:
                    return

                self.blockSize = instr.readUInt32()

            if self.tcpSocket.bytesAvailable() < self.blockSize:
                return

            self.blockSize = 0

            pix = QtGui.QImage()
            ba = QtCore.QByteArray()
            instr >> ba

            # skip this frame if there is another one in buffer
            if self.tcpSocket.bytesAvailable() > 0:
                rospy.loginfo("Frame dropped")
                continue

            # 16ms
            if not pix.loadFromData(ba, "JPG"):
                rospy.logerr("Failed to load image from received data")
                return

            self.get_image(pix)
    def readFortune(self):
        instr = QtCore.QDataStream(self.tcpSocket)
        instr.setVersion(QtCore.QDataStream.Qt_4_0)

        if self.blockSize == 0:
            if self.tcpSocket.bytesAvailable() < 2:
                return

            self.blockSize = instr.readUInt16()

        if self.tcpSocket.bytesAvailable() < self.blockSize:
            return

        nextFortune = instr.readString()

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

        if nextFortune == self.currentFortune:
            QtCore.QTimer.singleShot(0, self.requestNewFortune)
            return

        self.currentFortune = nextFortune
        self.statusLabel.setText(self.currentFortune)
        self.getFortuneButton.setEnabled(True)
Beispiel #10
0
    def startDrag(self, dropActions):
        item = self.currentItem()

        # check parent name and return if top level node
        if item.parent() == None:
            return

        # get dir name
        dirName = unicode(item.parent().text(0))

        # get node from library
        nodeName = unicode(item.text(0))

        # set custom data
        data = QtCore.QByteArray()
        stream = QtCore.QDataStream(data, QtCore.QIODevice.WriteOnly)
        stream << item.parent().text(0) << item.text(0)
        mimeData = QtCore.QMimeData()
        mimeData.setData('application/x-text', data)

        # set drag
        drag = QtGui.QDrag(self)
        drag.setMimeData(mimeData)
        drag.setPixmap(QtGui.QPixmap(':/node.png'))
        drag.start(QtCore.Qt.CopyAction)
Beispiel #11
0
    def readData(self):
        if self.proxySocket.isValid() :           
            if self.proxySocket.bytesAvailable() == 0 :
                return
            ins = QtCore.QDataStream(self.proxySocket)
            ins.setVersion(QtCore.QDataStream.Qt_4_2)
            while ins.atEnd() == False :                             
                if self.proxySocket.isValid() :
                    if self.blockSize == 0:
                        if self.proxySocket.isValid() :
                            if self.proxySocket.bytesAvailable() < 4:
                                return

                            self.blockSize = ins.readUInt32()
                        else :
                            return
        
                    if self.proxySocket.isValid() :
                        if self.proxySocket.bytesAvailable() < self.blockSize:
                            return

                    else :
                        return  
                    port = ins.readUInt16()
                    packet  = ins.readQVariant()
                    
                    self.tranfertToUdp(port, packet)
                    
                    self.blockSize = 0
      
                else : 
                    return    
            return                
Beispiel #12
0
    def writeToServer(self, action, *args, **kw):
        logger.debug(
            ("writeToServer(" + action + ", [" + ', '.join(args) + "])"))

        block = QtCore.QByteArray()
        out = QtCore.QDataStream(block, QtCore.QIODevice.ReadWrite)
        out.setVersion(QtCore.QDataStream.Qt_4_2)
        out.writeUInt32(0)
        out.writeQString(action)

        for arg in args:
            if type(arg) is IntType:
                out.writeInt(arg)
            elif isinstance(arg, basestring):
                out.writeQString(arg)
            elif type(arg) is FloatType:
                out.writeFloat(arg)
            elif type(arg) is ListType:
                out.writeQVariantList(arg)
            else:
                logger.warn("Uninterpreted Data Type: " + str(type(arg)) +
                            " of value: " + str(arg))
                out.writeQString(str(arg))

        out.device().seek(0)
        out.writeUInt32(block.size() - 4)

        self.bytesToSend = block.size() - 4
        self.replayVaultSocket.write(block)
    def SaveTools(self):
        try:
            if os.path.isfile(self.filepath):
                QtCore.QFile.remove(self.file) 
                      
            self.file.open(QtCore.QIODevice.WriteOnly)
            datastream = QtCore.QDataStream(self.file)
            count = self.MyToolsBars.topLevelItemCount()
            datastream.writeUInt32(count)
             
            for i in range(0, count):
                item = self.MyToolsBars.topLevelItem(i) 
                item.write(datastream)
                self.bar = None
                self.CreateToolBar(item)
                self.save_item(item, datastream)
 
            self.hasChanged = False
            self.file.close()
            # Restauramos la lista de herramientas de Qgis.
            state = self.saveWidgetState(self.ToolBars) 
            self.PopulateQgisTools()
            self.loadWidgetState(self.ToolBars, state)
            
            self.iface.messageBar().pushMessage("Info: ", "Save correctly.", level=QgsMessageBar.INFO, duration=3)  
            self.rename_btn.setEnabled(False)
            self.delete_btn.setEnabled(False) 
            self.restore = {}
                             
        except:
            self.iface.messageBar().pushMessage("Error: ", "Error save tools ", level=QgsMessageBar.CRITICAL, duration=3) 
        return
Beispiel #14
0
    def send_to_clients_evt(self):

        if len(self.connections) == 0:
            return

        # start = time.time()

        pix = QtGui.QImage(
            self.scene.width(),
            self.scene.height(),
            QtGui.QImage.Format_RGB888)
        painter = QtGui.QPainter(pix)
        painter.setRenderHint(QtGui.QPainter.Antialiasing)
        self.scene.render(painter)
        painter.end()
        pix = pix.mirrored()

        block = QtCore.QByteArray()
        out = QtCore.QDataStream(block, QtCore.QIODevice.WriteOnly)
        out.setVersion(QtCore.QDataStream.Qt_4_0)
        out.writeUInt32(0)

        img = QtCore.QByteArray()
        buffer = QtCore.QBuffer(img)
        buffer.open(QtCore.QIODevice.WriteOnly)
        pix.save(buffer, "JPG", 95)
        out << img

        out.device().seek(0)
        out.writeUInt32(block.size() - 4)

        # print block.size()

        for con in self.connections:
            con.write(block)
Beispiel #15
0
 def dropMimeData(self, QMimeData, Qt_DropAction, p_int, p_int_1,
                  QModelIndex):
     encodedData = QMimeData.data("joblist")
     dataStream = QtCore.QDataStream(encodedData, QtCore.QIODevice.ReadOnly)
     newItems = []
     while not dataStream.atEnd():
         # text=""
         # dataStream>>text
         # newItems<<text
         newItems += dataStream.readBytes().decode()
     rows = len(newItems)
     count = 0
     parentShift = 0
     newItems = sorted(newItems)
     if int(newItems[0]) < QModelIndex.row() and int(
             newItems[-1]) > QModelIndex.row():
         return False
     else:
         for row in newItems:
             row = int(row)
             if not QModelIndex.row(
             ) + parentShift == row + count + 1 and QModelIndex.isValid():
                 if QModelIndex.row() + parentShift < row + count:
                     self.moveRows(QtCore.QModelIndex(), row + count, 1,
                                   QtCore.QModelIndex(),
                                   QModelIndex.row() + parentShift)
                     parentShift += 1
                 else:
                     self.moveRows(QtCore.QModelIndex(), row + count, 1,
                                   QtCore.QModelIndex(),
                                   QModelIndex.row() + parentShift)
                     count -= 1
     return True
    def mimeData(self, indexes):
        """Returns an object that contains serialized items of data
        corresponding to the list of indexes specified.

        When a node is dragged the information required to drop it later
        on is encoded by this method and returned as a QMimeData object.

        :Parameter indexes: a list of indexes
        """

        mime_data = QtCore.QMimeData()
        encoded_data = QtCore.QByteArray()

        stream = QtCore.QDataStream(encoded_data, QtCore.QIODevice.WriteOnly)

        # Only one item selections are allowed in the tree of databases
        # view so indexes contains always one element
        for index in indexes:
            if index.isValid():
                filepath = self.data(index, QtCore.Qt.UserRole)
                nodepath = self.data(index, QtCore.Qt.UserRole + 1)
                row = unicode(index.row())
                stream.writeQString(filepath)
                stream.writeQString(nodepath)
                stream.writeQString(row)

                self.initial_parent = self.parent(index)

        mime_data.setData("application/x-dbstreemodeldatalist", encoded_data)
        return mime_data
Beispiel #17
0
    def dropEvent(self, event):
        if event.mimeData().hasFormat('image/x-puzzle-piece') and self.findPiece(self.targetSquare(event.pos())) == -1:
            pieceData = event.mimeData().data('image/x-puzzle-piece')
            dataStream = QtCore.QDataStream(pieceData, QtCore.QIODevice.ReadOnly)
            square = self.targetSquare(event.pos())
            pixmap = QtGui.QPixmap()
            location = QtCore.QPoint()
            dataStream >> pixmap >> location

            self.pieceLocations.append(location)
            self.piecePixmaps.append(pixmap)
            self.pieceRects.append(square)

            self.hightlightedRect = QtCore.QRect()
            self.update(square)

            event.setDropAction(QtCore.Qt.MoveAction)
            event.accept()

            if location == QtCore.QPoint(square.x() / 80, square.y() / 80):
                self.inPlace += 1
                if self.inPlace == 25:
                    self.puzzleCompleted.emit()
        else:
            self.highlightedRect = QtCore.QRect()
            event.ignore()
Beispiel #18
0
    def makeFromMimeData(mimeData):
        '''
      Creates a new ClusterNode object from the given QtCore.QMimeData object.
      '''
        assert mimeData.hasFormat(ClusterNode.sMimeType)

        node_data = mimeData.data(ClusterNode.sMimeType)
        data_stream = QtCore.QDataStream(node_data, QtCore.QIODevice.ReadOnly)

        # The MIME data for an ensemble node contains its XML element, its
        # state identifier, and its IP address. All of these are stored as
        # QtCore.QString instances.
        xml_elt = QtCore.QString()
        state = QtCore.QString()
        ip_addr = QtCore.QString()

        data_stream >> xml_elt >> state >> ip_addr

        if len(str(ip_addr)) == 0:
            ip_addr = None
        else:
            ip_addr = str(ip_addr)

        return ClusterNode(ET.fromstring(str(xml_elt)),
                           state.toInt()[0], ip_addr)
Beispiel #19
0
 def readData(self):
     instr = QtCore.QDataStream(self.connection)
     if self.connection.bytesAvailable >= 8:
         self.renderView.GetActiveCamera().Azimuth(instr.readDouble())
         if not self.timer.isActive():
             self.timer.start(30)
     if self.connection.bytesAvailable() >= 8:
         QtCore.QTimer.singleShot(30, self.readData)
Beispiel #20
0
    def receiveMessage(self):
        ins = QtCore.QDataStream(self.socket)
        ins.setVersion(QtCore.QDataStream.Qt_4_4)
        self.socket.bytesAvailable()

        result = QtCore.QByteArray()
        ins >> result
        self.hasRight = json.loads(forceString(result))
Beispiel #21
0
    def getScene(self):

        instr = QtCore.QDataStream(self.tcpSocket)
        instr.setVersion(QtCore.QDataStream.Qt_4_0)

        while True:

            if self.blockSize == 0:
                if self.tcpSocket.bytesAvailable() < 4:
                    return

                self.blockSize = instr.readUInt32()

            if self.tcpSocket.bytesAvailable() < self.blockSize:
                return

            self.blockSize = 0

            pix = QtGui.QImage()
            ba = QtCore.QByteArray()
            instr >> ba

            # skip this frame if there is another one in buffer
            if self.tcpSocket.bytesAvailable() > 0:
                rospy.logdebug("Frame dropped")
                continue

            # start = time.time()

            # 16ms
            if not pix.loadFromData(ba, "JPG"):
                rospy.logerr("Failed to load image from received data")
                return

            if self.calibrating or not self.projectors_calibrated or not self.maps_ready:
                return

            # 3ms
            img = pix.convertToFormat(QtGui.QImage.Format_ARGB32)
            v = qimage2ndarray.rgb_view(img)

            # TODO some further optimalization? this is about 30ms (with INTER_LINEAR)s...
            image_np = cv2.remap(v, self.map_x, self.map_y, cv2.INTER_LINEAR)

            # this is about 3ms
            height, width, channel = image_np.shape
            bytesPerLine = 3 * width
            image = QtGui.QPixmap.fromImage(
                QtGui.QImage(image_np.data, width, height, bytesPerLine,
                             QtGui.QImage.Format_RGB888))

            self.pix_label.setPixmap(image)
            self.update()

            # end = time.time()
            # rospy.logdebug("Frame loaded in: " + str(end-start))

            return
Beispiel #22
0
    def sendMessage(self):
        buf = QtCore.QBuffer()
        buf.open(QtCore.QBuffer.ReadWrite)
        out = QtCore.QDataStream(buf)
        out.setVersion(QtCore.QDataStream.Qt_4_4)

        out << QtCore.QByteArray(json.dumps(self.hasRight))
        self.serverSocket.write(buf.data().data())
        self.serverSocket.flush()
Beispiel #23
0
    def writeToServer(self, action, *args, **kw):
        '''
        This method is the workhorse of the client, and is used to send messages, queries and commands to the server.
        '''
        logger.debug("Client: " + action)

        block = QtCore.QByteArray()
        out = QtCore.QDataStream(block, QtCore.QIODevice.ReadWrite)
        out.setVersion(QtCore.QDataStream.Qt_4_2)

        out.writeUInt32(0)
        out.writeQString(action)

        for arg in args:
            if type(arg) is IntType:
                out.writeInt(arg)
            elif isinstance(arg, basestring):
                out.writeQString(arg)
            elif type(arg) is FloatType:
                out.writeFloat(arg)
            elif type(arg) is ListType:
                out.writeQVariantList(arg)
            elif type(arg) is DictType:
                out.writeQString(json.dumps(arg))
            elif type(arg) is QtCore.QFile:
                arg.open(QtCore.QIODevice.ReadOnly)
                fileDatas = QtCore.QByteArray(arg.readAll())
                #seems that that logger doesn't work
                #logger.debug("file size ", int(fileDatas.size()))
                out.writeInt(fileDatas.size())
                out.writeRawData(fileDatas)

                # This may take a while. We display the progress bar so the user get a feedback
                self.sendFile = True
                self.progress.setLabelText("Sending file to server")
                self.progress.setCancelButton(None)
                self.progress.setWindowFlags(QtCore.Qt.CustomizeWindowHint
                                             | QtCore.Qt.WindowTitleHint)
                self.progress.setAutoClose(True)
                self.progress.setMinimum(0)
                self.progress.setMaximum(100)
                self.progress.setModal(1)
                self.progress.setWindowTitle("Uploading in progress")

                self.progress.show()
                arg.close()
            else:
                logger.warn("Uninterpreted Data Type: " + str(type(arg)) +
                            " sent as str: " + str(arg))
                out.writeQString(str(arg))

        out.device().seek(0)
        out.writeUInt32(block.size() - 4)
        self.bytesToSend = block.size() - 4

        self.socket.write(block)
    def save(self, device):
        stream = QtCore.QDataStream(device)
        stream.writeQString(self.m_name)
        stream.writeInt(len(self.m_frames))

        for frame in self.m_frames:
            stream.writeInt(frame.nodeCount())

            for i in range(frame.nodeCount()):
                stream << frame.nodePos(i)
Beispiel #25
0
def sendMessage():
    global sock, timer

    bl = QtCore.QByteArray()
    out = QtCore.QDataStream(bl, QtCore.QIODevice.WriteOnly)
    out.writeDouble(10)

    sock.write(bl)

    timer.start(30)
Beispiel #26
0
 def accept(self):
     settings = QtCore.QSettings()
     for name in self.fontsDict.keys():
         font = self.fontsDict.get(name).font()
         arr = QtCore.QByteArray()
         buf = QtCore.QBuffer(arr)
         buf.open(QtCore.QIODevice.WriteOnly)
         QtCore.QDataStream(buf) << font
         settings.setValue(name, arr)
     settings.sync()
     super(FontSettingsDialog, self).accept()
Beispiel #27
0
    def unpackReplay(self,rfile):
        rfile = str(rfile)
        replay = open(rfile, "rb")
        if rfile.endswith(".fafreplay"):
            self.fafInfo = json.loads(replay.readline())
            self.unpackedFile = QtCore.qUncompress(QtCore.QByteArray.fromBase64(replay.read()))
            self.binary = QtCore.QDataStream(self.unpackedFile)
            self.binary.setByteOrder(QtCore.QDataStream.LittleEndian)
            self.binary.setFloatingPointPrecision(QtCore.QDataStream.SinglePrecision)

            #w = open("out.SCFAReplay","wb")
            #w.write(self.binary)
            #w.close()
        else:
            self.unpackedFile = QtCore.QByteArray(replay.read())
            self.binary = QtCore.QDataStream(self.unpackedFile)
            self.binary.setByteOrder(QtCore.QDataStream.LittleEndian)
            self.binary.setFloatingPointPrecision(QtCore.QDataStream.SinglePrecision)

        replay.close()
Beispiel #28
0
    def readDataFromServer(self):
        self.lastData = time.time()  # Keep resetting that timeout counter
        
        ins = QtCore.QDataStream(self.updateSocket)
        ins.setVersion(QtCore.QDataStream.Qt_4_2)

        while not ins.atEnd():
            #log("Bytes Available: %d" % self.updateSocket.bytesAvailable())                    

            # Nothing was read yet, commence a new block.
            if self.blockSize == 0:
                self.progress.reset()
                
                #wait for enough bytes to piece together block size information
                if self.updateSocket.bytesAvailable() < 4:                    
                    return 
                                
                self.blockSize = ins.readUInt32()
                
                if (self.blockSize > 65536):
                    self.progress.setLabelText("Downloading...")
                    self.progress.setValue(0)
                    self.progress.setMaximum(self.blockSize)
                else:
                    self.progress.setValue(0)
                    self.progress.setMinimum(0)
                    self.progress.setMaximum(0)
                            
            # Update our Gui at least once before proceeding (we might be receiving a huge file and this is not the first time we get here)   
            self.lastData = time.time()            
            QtGui.QApplication.processEvents()
                             
            #We have an incoming block, wait for enough bytes to accumulate                    
            if self.updateSocket.bytesAvailable() < self.blockSize:
                self.progress.setValue(self.updateSocket.bytesAvailable())
                return #until later, this slot is reentrant

            #Enough bytes accumulated. Carry on.
            self.progress.setValue(self.blockSize)
            
            # Update our Gui at least once before proceeding (we might have to write a big file)
            self.lastData = time.time()            
            QtGui.QApplication.processEvents()
                             
            # Find out what the server just sent us, and process it.
            action = ins.readQString()
            self.handleAction(self.blockSize, action, ins)

            # Prepare to read the next block
            self.blockSize = 0
            
            self.progress.setValue(0)
            self.progress.setMinimum(0)
            self.progress.setMaximum(0)
Beispiel #29
0
 def update_socket(self, socket):
     self.tcpSocket = socket
     self.tcpSocket.disconnected.connect(self.on_disconnect)
     self.tcpSocket.readyRead.connect(self.read)
     #Reading data
     self.blockSize = 0
     self.dataStream = QtCore.QDataStream(self.tcpSocket)
     self.dataStream.setVersion(QtCore.QDataStream.Qt_4_0)
     self.connected = True
     #send data if needed
     self.send_update_state()
     self.send_expDone()
     self.send_expFail()
Beispiel #30
0
    def mimeData(self, items):
        mimeData = QtGui.QTreeWidget.mimeData(self, items)
        encodedData = QtCore.QByteArray()
        stream = QtCore.QDataStream(encodedData, QtCore.QIODevice.WriteOnly)

        for item in items:
            if isinstance(item, GsLayerItem):
                layer = item.element
                uri = uri_utils.layerMimeUri(layer)
                stream.writeQString(uri)

        mimeData.setData(self.QGIS_URI_MIME, encodedData)
        return mimeData