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


Python QDataStream.writeInt32方法代码示例

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


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

示例1: saveQDataStream

# 需要导入模块: from PyQt4.QtCore import QDataStream [as 别名]
# 或者: from PyQt4.QtCore.QDataStream import writeInt32 [as 别名]
 def saveQDataStream(self):
     error = None
     fh = None
     try:
         fh = QFile(self.__fname)
         if not fh.open(QIODevice.WriteOnly):
             raise IOError(str(fh.errorString()))
         stream = QDataStream(fh)
         stream.writeInt32(MovieContainer.MAGIC_NUMBER)
         stream.writeInt32(MovieContainer.FILE_VERSION)
         stream.setVersion(QDataStream.Qt_4_2)
         for key, movie in self.__movies:
             stream << movie.title
             stream.writeInt16(movie.year)
             stream.writeInt16(movie.minutes)
             stream << movie.acquired << movie.notes
     except EnvironmentError as e:
         error = "Failed to save: {0}".format(e)
     finally:
         if fh is not None:
             fh.close()
         if error is not None:
             return False, error
         self.__dirty = False
         return True, "Saved {0} movie records to {1}".format(
                 len(self.__movies),
                 QFileInfo(self.__fname).fileName())
开发者ID:hooloong,项目名称:gitpython,代码行数:29,代码来源:moviedata.py

示例2: save

# 需要导入模块: from PyQt4.QtCore import QDataStream [as 别名]
# 或者: from PyQt4.QtCore.QDataStream import writeInt32 [as 别名]
 def save(self):
     exception = None
     fh = None
     try:
         if self.filename.isEmpty():
             raise IOError("no filename specified for saving")
         fh = QFile(self.filename)
         if not fh.open(QIODevice.WriteOnly):
             raise IOError(str(fh.errorString()))
         stream = QDataStream(fh)
         stream.writeInt32(MAGIC_NUMBER)
         stream.writeInt16(FILE_VERSION)
         stream.setVersion(QDataStream.Qt_4_1)
         for ship in self.ships:
             stream << ship.name << ship.owner << ship.country \
                    << ship.description
             stream.writeInt32(ship.teu)
         self.dirty = False
     except IOError as e:
         exception = e
     finally:
         if fh is not None:
             fh.close()
         if exception is not None:
             raise exception
开发者ID:hooloong,项目名称:gitpython,代码行数:27,代码来源:ships_ans.py

示例3: save_project

# 需要导入模块: from PyQt4.QtCore import QDataStream [as 别名]
# 或者: from PyQt4.QtCore.QDataStream import writeInt32 [as 别名]
def save_project(canvas, colors, activeSymbol, settings, saveFileName):
    """ Toplevel writer routine. 

    """

    # prepare data structures
    patternGridItems = get_patternGridItems(canvas)
    legendItems = canvas.gridLegend.values()
    patternRepeats = get_patternRepeats(canvas)
    repeatLegends = canvas.repeatLegend
    rowRepeats = canvas.rowRepeatTracker
    rowLabels = canvas.rowLabels
    columnLabels = canvas.columnLabels
    textItems = canvas.canvasTextBoxes
    assert(len(patternRepeats) == len(repeatLegends))

    status = None
    handle = None
    try:
        handle = QFile(saveFileName)
        if not handle.open(QIODevice.WriteOnly | QIODevice.Truncate):
            raise IOError(unicode(handle.errorString()))

        stream = QDataStream(handle)

        # write header
        stream.writeInt32(MAGIC_NUMBER)
        stream.writeInt32(API_VERSION)
        stream.setVersion(QDataStream.Qt_4_5)

        # write content
        write_patternGridItems(stream, patternGridItems)
        write_legendItems(stream, legendItems)
        write_colors(stream, colors)
        write_active_symbol(stream, activeSymbol)
        write_patternRepeats(stream, patternRepeats)
        write_repeatLegends(stream, repeatLegends)
        write_rowRepeats(stream, rowRepeats)
        write_textItems(stream, textItems)
        write_row_labels(stream, rowLabels)
        write_column_labels(stream, columnLabels)
        write_settings(stream, settings)


    except (IOError, OSError) as e:
        status = "Failed to save: %s " % e

    finally:
        if handle is not None:
            handle.close()
        if status is not None:
            return (False, status)

    return (True, None)
开发者ID:MissLitchi,项目名称:sconcho,代码行数:56,代码来源:io.py

示例4: save

# 需要导入模块: from PyQt4.QtCore import QDataStream [as 别名]
# 或者: from PyQt4.QtCore.QDataStream import writeInt32 [as 别名]
 def save(self):
     exception = None
     fh = None
     try:
         if self.filename.isEmpty():
             raise IOError, "no filename specified for saving"
         fh = QFile(self.filename)
         if not fh.open(QIODevice.WriteOnly):
             raise IOError, unicode(fh.errorString())
         stream = QDataStream(fh)
         stream.writeInt32(MAGIC_NUMBER)
         stream.writeInt16(FILE_VERSION)
         stream.setVersion(QDataStream.Qt_4_1)
         for ship in self.ships.values():
             stream << ship.name << ship.owner << ship.country 
             stream << ship.description
             stream.writeInt32(ship.teu)
         self.dirty = False
     except IOError, err:
         exception = err
开发者ID:imagingearth,项目名称:PyQt4-Examples,代码行数:22,代码来源:ships.py

示例5: sendMessage

# 需要导入模块: from PyQt4.QtCore import QDataStream [as 别名]
# 或者: from PyQt4.QtCore.QDataStream import writeInt32 [as 别名]
    def sendMessage(self, msg, args, id = None):
        """Sends a message.

        msg -- The message type.
        args -- List of message arguments.
        id -- An optional socket descriptor. If specified, then the message will only be sent if this connection's socket descriptor matches id."""
        if id:
            if self.socketDescriptor() != id:
                return
        msg = Message.fromInt(msg)
        if not msg.validateArgs(args):
            log.warning("Message %d and args %s have invalid types. Message not sent.", msg, args)
            return
        if self.client:
            log.debug("Sending %s %s", msg, args)
        elif self.player and self.player.name:
            log.debug("Sending %s %s to %s", msg, args, self.player)
        else:
            log.debug("Sending %s %s to %s", msg, args, self.peerAddress().toString())
        data = QByteArray()
        stream = QDataStream(data, self.WriteOnly)
        stream.writeInt32(int(msg))
        for arg in args:
            if type(arg) == str:
                stream.writeInt32(len(arg))
                stream.writeRawData(arg)
            elif type(arg) == int:
                stream.writeInt32(arg)
            elif type(arg) == long:
                stream.writeInt64(arg)
        self.write(data)
        self.messageSent.emit(msg, args)
开发者ID:dhrosa,项目名称:empyre_old,代码行数:34,代码来源:network.py

示例6: changeResolution

# 需要导入模块: from PyQt4.QtCore import QDataStream [as 别名]
# 或者: from PyQt4.QtCore.QDataStream import writeInt32 [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

示例7: save

# 需要导入模块: from PyQt4.QtCore import QDataStream [as 别名]
# 或者: from PyQt4.QtCore.QDataStream import writeInt32 [as 别名]
 def save(self):
     if self.filename.isEmpty():
         path = "."
         fname = QFileDialog.getSaveFileName(self,
                 "Page Designer - Save As", path,
                 "Page Designer Files (*.pgd)")
         if fname.isEmpty():
             return
         self.filename = fname
     fh = None
     try:
         fh = QFile(self.filename)
         if not fh.open(QIODevice.WriteOnly):
             raise IOError, unicode(fh.errorString())
         self.scene.clearSelection()
         stream = QDataStream(fh)
         stream.setVersion(QDataStream.Qt_4_2)
         stream.writeInt32(MagicNumber)
         stream.writeInt16(FileVersion)
         for item in self.scene.items():
             self.writeItemToStream(stream, item)
     except IOError, e:
         QMessageBox.warning(self, "Page Designer -- Save Error",
                 "Failed to save {0}: {1}".format(self.filename, e))
开发者ID:pyros2097,项目名称:SabelIDE,代码行数:26,代码来源:level.py

示例8: MainWindow

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

#.........这里部分代码省略.........
                    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
                    tmp |= (pixel<<shift*self.gsLevel)
                    # Как только сдвиг обнулится, то записываем в файл
                    if not shift:
                        self.out.writeRawData(tmp.to_bytes(self.gsLevel, 'big'))
                        tmp=0
            pd.setValue(row)
            if pd.wasCanceled():
                pd.close()
                file.close()
                return
        pd.close()
        file.close()

        self.status.showMessage("File created successful", 7000)


    def writeNewHeader(self, colors):
        xdpi = int(self.xdpiCmbBox.currentText())
        ydpi = int(self.ydpiCmbBox.currentText())

        self.paperWidth = 0

        colorOrder = colors.encode()
        while len(colorOrder) < 16:
            colorOrder += bytes.fromhex('00')

        self.out.writeInt32(self.NEW_RIP_FILE)
        self.out.writeInt32(xdpi)
        self.out.writeInt32(ydpi)
        self.out.writeInt32(self.bytesPerLine)
        self.out.writeInt32(self.imgheight)
        self.out.writeInt32(self.imgwidth)
        self.out.writeInt32(self.paperWidth)
        self.out.writeInt32(len(colors))
        self.out.writeInt32(self.gsLevel)

        self.out.writeRawData(colorOrder)

        name = self.testName.encode(encoding='utf_16')[2:514] # Удаляем первые два байта сигнатуры UTF-16
        while len(name) < 256*2: # Дополняем до 256 символов WCHAR
            name += bytes.fromhex('00')
        self.out.writeRawData(name)

        self.out.writeInt32(0) # Зарезервировано

    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)
开发者ID:filin86,项目名称:prncreator,代码行数:70,代码来源:main.py


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