当前位置: 首页>>代码示例>>Python>>正文


Python QDataStream.setByteOrder方法代码示例

本文整理汇总了Python中PyQt4.QtCore.QDataStream.setByteOrder方法的典型用法代码示例。如果您正苦于以下问题:Python QDataStream.setByteOrder方法的具体用法?Python QDataStream.setByteOrder怎么用?Python QDataStream.setByteOrder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt4.QtCore.QDataStream的用法示例。


在下文中一共展示了QDataStream.setByteOrder方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: send

# 需要导入模块: from PyQt4.QtCore import QDataStream [as 别名]
# 或者: from PyQt4.QtCore.QDataStream import setByteOrder [as 别名]
    def send(self, command, *args):
        self._logger.info("GC<<: {}:{}".format(command, args))
        ds = QDataStream(self._socket)
        ds.setByteOrder(QDataStream.LittleEndian)

        # Header
        ds.writeUInt32(len(command))
        ds.writeRawData(command.encode())

        # Chunks
        ds.writeUInt32(len(args))

        for chunk in args:
            ds.writeRawData(self._packLuaVal(chunk))
开发者ID:Arkonen8,项目名称:client,代码行数:16,代码来源:game_connection.py

示例2: changeResolution

# 需要导入模块: from PyQt4.QtCore import QDataStream [as 别名]
# 或者: from PyQt4.QtCore.QDataStream import setByteOrder [as 别名]
    def changeResolution(self):
        fileName = QFileDialog.getOpenFileName(self, 'Load .prn file', directory=self.settings.value('unpacker/dir_open',QDir.currentPath()), filter='PRN files (*.prn *.bin);;All (*)')
        if not fileName:
            return
        file = QFile(fileName)
        if not file.open(QFile.ReadWrite):
            QMessageBox.warning(self, "Unpacker .prn", "Unable load file {}:\n{}.".format(fileName, file.errorString()))
            return
        self.settings.setValue('unpacker/dir_open', QFileInfo(file).path())
        data = QDataStream(file)
        data.setByteOrder(QDataStream.LittleEndian)
        headerVersion = data.readInt32()
        xdpi = data.readInt32()
        ydpi = data.readInt32()

        dialog = ChangeResolutionDialog(xdpi, ydpi, self)
        if dialog.exec_():
            file.seek(4)
            data.writeInt32(dialog.sbXdpi.value())
            data.writeInt32(dialog.sbYdpi.value())
            self.status.showMessage("Resolution changed successful", 7000)
        file.close()
开发者ID:filin86,项目名称:prncreator,代码行数:24,代码来源:main.py

示例3: _onReadyRead

# 需要导入模块: from PyQt4.QtCore import QDataStream [as 别名]
# 或者: from PyQt4.QtCore.QDataStream import setByteOrder [as 别名]
    def _onReadyRead(self):
        while self._socket.bytesAvailable() >= 4:
            ds = QDataStream(self._socket)
            ds.setByteOrder(QDataStream.LittleEndian)

            # Header packet
            if self.header is None:
                size, = unpack('=l', self._socket.peek(4))

                if self._socket.bytesAvailable() < size + 4:
                    return

                #Omit size
                ds.readUInt32()

                self.header = ds.readRawData(size).decode()

            # Chunks packet
            else:
                if self.nchunks == -1:
                    self.nchunks = ds.readUInt32()
                    self.chunks = []

                while len(self.chunks) < self.nchunks:
                    chunk = self._readLuaVal(ds)

                    if chunk is None:
                        return

                    self.chunks.append(chunk)

                # Packet pair reading done.
                self._logger.info("GC >> : %s : %s", self.header, self.chunks)
                self.messageReceived.emit(self.header, self.chunks)
                self.header = None
                self.nchunks = -1
                self.chunks = None
开发者ID:Arkonen8,项目名称:client,代码行数:39,代码来源:game_connection.py

示例4: unpackPrnFile

# 需要导入模块: from PyQt4.QtCore import QDataStream [as 别名]
# 或者: from PyQt4.QtCore.QDataStream import setByteOrder [as 别名]
    def unpackPrnFile(self):
        fileName = QFileDialog.getOpenFileName(self, 'Load .prn file', directory=self.settings.value('unpacker/dir_open',QDir.currentPath()), filter='PRN files (*.prn *.bin);;All (*)')
        if not fileName:
            return
        file = QFile(fileName)
        if not file.open(QFile.ReadOnly):
            QMessageBox.warning(self, "Unpacker .prn", "Unable load file {}:\n{}.".format(fileName, file.errorString()))
            return
        self.settings.setValue('unpacker/dir_open', QFileInfo(file).path())
        data = QDataStream(file)
        data.setByteOrder(QDataStream.LittleEndian)
        file_name = QFileInfo(file).fileName()

        headerVersion = int.from_bytes(data.readRawData(4), 'little', signed=False)
        self.status.showMessage("Header Type: {:#X}".format(headerVersion))

        if headerVersion == self.NEW_RIP_FILE:
            xdpi = data.readInt32()
            ydpi = data.readInt32()
            bpl = data.readInt32()
            imgh = data.readInt32()
            imgw = data.readInt32()
            ppw = data.readInt32()
            colnum = data.readInt32()
            bitsperdrop = data.readInt32()
            colorOrder = data.readRawData(16).decode().replace(chr(0), '')
            colorList = list(colorOrder)
            name = b'\xff\xfe' + data.readRawData(512)
            name = name.decode('utf-16').replace(chr(0), '')
            zero = data.readInt32()
        elif headerVersion == self.STD_RIP_FILE:
            xdpi = data.readInt32()
            ydpi = data.readInt32()
            bpl = data.readInt32()
            imgh = data.readInt32()
            imgw = data.readInt32()
            ppw = data.readInt32()
            colnum = data.readInt32()
            bitsperdrop = data.readInt32()
            if not bitsperdrop:
                QMessageBox.warning(self, "Unpacker .prn", "File format not supported")
                return
            colorOrder = data.readRawData(16).decode().replace(chr(0), '')
            colorList = list(colorOrder)
            zero = data.readInt32()
            name = 'Not used in this format'
        elif headerVersion == self.CALDERA_RIP_FILE:
            xdpi = data.readInt32()
            ydpi = data.readInt32()
            bpl = data.readInt32()
            imgh = data.readInt32()
            imgw = data.readInt32()
            ppw = data.readInt32()
            colnum = data.readInt32()
            bitsperdrop = data.readInt32()
            if not bitsperdrop:
                QMessageBox.warning(self, "Unpacker .prn", "File format not supported")
                return
            colorOrder = data.readRawData(16).decode().replace(chr(0), '')
            colorList = list(colorOrder)
            zero = data.readInt32()
            name = 'Not used in this format'
        else:
            QMessageBox.warning(self, "Unpacker .prn", "File format not supported")
            return

        colors = {}
        for color in colorList:
            colors[color] = {}
            for level in range(1, 2**bitsperdrop):
                colors[color][level] = QImage(imgw, imgh , QImage.Format_Mono)
                colors[color][level].setColor(0, qRgb(255, 255, 255))
                colors[color][level].setColor(1, qRgb(0, 0, 0))
                colors[color][level].fill(0)

        pd = QProgressDialog('Analyze file ...', 'Cancel', 0, imgh-1, self)
        pd.setWindowTitle('Analyze ...')
        pd.open()

        mask = 0xFF>>(8-bitsperdrop) # Получаем маску для текущего количества бит на каплю
        for row in range(imgh):
            for color in colorList:
                for bytenum in range(0, bpl, bitsperdrop): # Получаем номер байта, с которого будем читать
                    byte = int.from_bytes(data.readRawData(bitsperdrop), 'big')
                    for pix in range(8):
                        shift = (7 - pix)*bitsperdrop
                        pixel = (byte>>shift)&mask
                        if pixel > 0:
                            numofpix = 8*bytenum/bitsperdrop + pix
                            if numofpix < imgw:
                                colors[color][pixel].setPixel(numofpix, row, 1)
            pd.setValue(row)
            if pd.wasCanceled():
                pd.close()
                file.close()
                return
        pd.close()
        file.close()

        catalog = QFileDialog.getExistingDirectory(self, directory=self.settings.value('unpacker/dir_save',QDir.currentPath()))
#.........这里部分代码省略.........
开发者ID:filin86,项目名称:prncreator,代码行数:103,代码来源:main.py

示例5: MainWindow

# 需要导入模块: from PyQt4.QtCore import QDataStream [as 别名]
# 或者: from PyQt4.QtCore.QDataStream import setByteOrder [as 别名]

#.........这里部分代码省略.........
                if width != image.width():
                    QMessageBox.warning(self, "Error!", "Width of images does not match!")
                    return
            else:
                width = image.width()

            if height != 0:
                if height != image.height():
                    QMessageBox.warning(self, "Error!", "Height of images does not match!")
                    return
            else:
                height = image.height()

        fileName = QFileDialog.getSaveFileName(self, "Save .prn file", self.settings.value('directories/dir_save', QDir.currentPath()),
                "PRN Files (*.prn);;BIN Files (*.bin)")

        if not fileName:
            return

        file = QFile(fileName)
        if not file.open(QFile.WriteOnly):
            QMessageBox.warning(self, "Prn Creator", "Unable to write file {}:\n{}.".format(self.fileName, file.errorString()))
            return
        self.settings.setValue('directories/dir_save', QFileInfo(file).path())

        self.testName, status = QInputDialog.getText(self, "Test name", "Enter name of the test to write into file:", text="Test")

        if not status:
            QMessageBox.warning(self, "Prn Creator", "Name changed to 'Test'")
            self.testName = "Test"

        self.fileName = QFileInfo(file).fileName()
        self.out = QDataStream(file)
        self.out.setByteOrder(QDataStream.LittleEndian)

        colors = ''
        for color in images:
            colors+=color

        self.imgwidth = width
        self.imgheight = height
        self.bytesPerLine = int((self.gsLevel*self.imgwidth+31)/32)*4
        self.writeNewHeader(colors)

        pd = QProgressDialog('Writing file ...', 'Cancel', 0, self.imgheight-1, self)
        pd.setWindowTitle('Creating file...')
        pd.open()


        tmp = 0
        # Записывать данные будем построчно
        for row in range(self.imgheight):
            # обходим по порядку цветов, как расположены в файле
            for color in colors:
                # Добиваем строку до длины, кратной 32м байтам
                for column in range (int(self.bytesPerLine/self.gsLevel*8)):
                    shift = 7-column+int(column/8)*8
                    pixel = 0
                    # Упорядочиваем уровни (на всякий)
                    levels = sorted(list(images[color].keys()))
                    # Если изображение меньше длины строки, то
                    if column < self.imgwidth:
                        for level in levels:
                            # Выбираем максимальный уровень из тех, что указаны в данном пикселе на всех слоях
                            if images[color][level].pixel(column, row) == self.black:
                                pixel = level
开发者ID:filin86,项目名称:prncreator,代码行数:70,代码来源:main.py


注:本文中的PyQt4.QtCore.QDataStream.setByteOrder方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。