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


Python QtCore.QDataStream类代码示例

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


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

示例1: load

 def load(self):
     exception = None
     fh = None
     try:
         if self.filename.isEmpty():
             raise IOError, "no filename specified for loading"
         fh = QFile(self.filename)
         if not fh.open(QIODevice.ReadOnly):
             raise IOError, unicode(fh.errorString())
         stream = QDataStream(fh)
         magic = stream.readInt32()
         if magic != MAGIC_NUMBER:
             raise IOError, "unrecognized file type"
         fileVersion = stream.readInt16()
         if fileVersion != FILE_VERSION:
             raise IOError, "unrecognized file type version"
         self.ships = []
         while not stream.atEnd():
             name = QString()
             owner = QString()
             country = QString()
             description = QString()
             stream >> name >> owner >> country >> description
             teu = stream.readInt32()
             self.ships.append(Ship(name, owner, country, teu,
                                    description))
             self.owners.add(unicode(owner))
             self.countries.add(unicode(country))
         self.dirty = False
     except IOError, e:
         exception = e
开发者ID:DaoQiu,项目名称:VimProject,代码行数:31,代码来源:ships_ans.py

示例2: test_dropping_the_data_emits_the_signal

    def test_dropping_the_data_emits_the_signal(self):
        mw = self._get_one()
        self.assertEqual(mw.supportedDropActions(),
                         Qt.CopyAction)
        self.assertIn('application/vnd.re-eat.recipe', mw.mimeTypes())
        assert mw.viewport().acceptDrops()

        mw.recipeAdded = DummySignal()

        mimeData = QMimeData()
        encodedData = QByteArray()
        stream = QDataStream(encodedData, QIODevice.WriteOnly)
        stream.writeInt(1)
        stream.writeInt(2)
        mimeData.setData('application/vnd.re-eat.recipe', encodedData)

        mw.dropMimeData(0, mimeData, Qt.CopyAction)
        self.assertListEqual(mw.recipeAdded.received,
                             [(1, mw.date, mw.index),
                              (2, mw.date, mw.index)])

        mw.recipeMoved = DummySignal()
        mimeData = QMimeData()
        encodedData = QByteArray()
        stream = QDataStream(encodedData, QIODevice.WriteOnly)
        stream.writeInt(42)
        stream.writeQVariant(datetime.date.today())
        stream.writeInt(2)
        mimeData.setData('application/vnd.re-eat.meal_recipe', encodedData)

        mw.dropMimeData(0, mimeData, Qt.CopyAction)
        self.assertListEqual(mw.recipeMoved.received,
                             [(42, datetime.date.today(), 2, mw.date, mw.index)])
开发者ID:madjar,项目名称:re-eat,代码行数:33,代码来源:test_meals.py

示例3: open_to_stream

def open_to_stream(filename, mode, stream_version=QDataStream.Qt_4_5):
    file = QFile(filename)
    file.open(mode)

    stream = QDataStream(file)
    stream.setVersion(stream_version)
    return FileStream(file, stream)
开发者ID:nattofriends,项目名称:qbtrule,代码行数:7,代码来源:qbtrule.py

示例4: open

 def open(self):
     self.offerSave()
     path = (QFileInfo(self.filename).path()
             if not self.filename.isEmpty() else ".")
     fname = QFileDialog.getOpenFileName(self,
             "Page Designer - Open", path,
             "Page Designer Files (*.pgd)")
     if fname.isEmpty():
         return
     self.filename = fname
     fh = None
     try:
         fh = QFile(self.filename)
         if not fh.open(QIODevice.ReadOnly):
             raise IOError, unicode(fh.errorString())
         items = self.scene.items()
         while items:
             item = items.pop()
             self.scene.removeItem(item)
             del item
         self.addBorders()
         stream = QDataStream(fh)
         stream.setVersion(QDataStream.Qt_4_2)
         magic = stream.readInt32()
         if magic != MagicNumber:
             raise IOError, "not a valid .pgd file"
         fileVersion = stream.readInt16()
         if fileVersion != FileVersion:
             raise IOError, "unrecognised .pgd file version"
         while not fh.atEnd():
             self.readItemFromStream(stream)
     except IOError, e:
         QMessageBox.warning(self, "Page Designer -- Open Error",
                 "Failed to open {0}: {1}".format(self.filename, e))
开发者ID:pyros2097,项目名称:SabelIDE,代码行数:34,代码来源:level.py

示例5: read_project

def read_project(settings, openFileName):
    """ Toplevel reader routine. """

    status = None
    handle = None
    try:
        handle = QFile(openFileName)
        if not handle.open(QIODevice.ReadOnly):
            raise IOError(handle.errorString())

        stream = QDataStream(handle)

        # check header
        magic = stream.readInt32()
        if magic != MAGIC_NUMBER:
            status = ("Unrecognized file type - \n{0}\nis not "
                           "a sconcho spf file!").format(openFileName)
            raise IOError(status)

        version = stream.readInt32()
        stream.setVersion(QDataStream.Qt_4_5)

        # initialize API specific entries
        repeatLegends = {}
        rowRepeats = []
        textItems = []
        rowLabels = {}
        columnLabels = {}

        if version == 1:
            (patternGridItems, legendItems, colors, activeSymbol, 
             patternRepeats) = read_API_1_version(stream, settings)

        elif version == 2:
             (patternGridItems, legendItems, colors, activeSymbol, 
             patternRepeats, repeatLegends, rowRepeats, textItems) = \
                     read_API_2_version(stream, settings)
        elif version == 3:
             (patternGridItems, legendItems, colors, activeSymbol, 
             patternRepeats, repeatLegends, rowRepeats, textItems,
             rowLabels, columnLabels) = \
                     read_API_3_version(stream, settings)
        else:
            raise IOError("unsupported API version")
            

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

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

    return (True, None, patternGridItems, legendItems, colors, 
            activeSymbol, patternRepeats, repeatLegends, rowRepeats,
            textItems, rowLabels, columnLabels)
开发者ID:MissLitchi,项目名称:sconcho,代码行数:59,代码来源:io.py

示例6: mimeData

 def mimeData(self, items):
     mimeData = QMimeData()
     encodedData = QByteArray()
     stream = QDataStream(encodedData, QIODevice.WriteOnly)
     for item in items:
         id = item.data(Qt.UserRole)
         stream.writeInt(id)
     mimeData.setData('application/vnd.re-eat.recipe', encodedData)
     return mimeData
开发者ID:madjar,项目名称:re-eat,代码行数:9,代码来源:recipes.py

示例7: saveQDataStream

 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,代码行数:27,代码来源:moviedata.py

示例8: save

 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,代码行数:25,代码来源:ships_ans.py

示例9: test_mime_data

    def test_mime_data(self):
        class DummyItem(object):
            def data(s, role):
                self.assertEqual(role, Qt.UserRole)
                return 42

        mw = self._get_one()
        data = mw.mimeData([DummyItem()]).data('application/vnd.re-eat.meal_recipe')
        stream = QDataStream(data, QIODevice.ReadOnly)
        self.assertEqual(stream.readInt(), 42)
        self.assertEqual(stream.readQVariant(), mw.date)
        self.assertEqual(stream.readInt(), mw.index)
开发者ID:madjar,项目名称:re-eat,代码行数:12,代码来源:test_meals.py

示例10: test_drag_information_are_correct

    def test_drag_information_are_correct(self):
        rw = RecipesWidget()
        self.assertIn('application/vnd.re-eat.recipe', rw.mimeTypes())

        items = [rw.item(i) for i in (0, 1)]
        ids = [item.data(Qt.UserRole) for item in items]
        data = rw.mimeData(items)
        stream = QDataStream(data.data('application/vnd.re-eat.recipe'))
        result = []
        while not stream.atEnd():
            result.append(stream.readInt())
        self.assertListEqual(result, ids)
开发者ID:madjar,项目名称:re-eat,代码行数:12,代码来源:test_recipes.py

示例11: mimeData

    def mimeData(self, indexes):
        mime_data = QMimeData()
        encoded_data = QByteArray()

        stream = QDataStream(encoded_data, QIODevice.WriteOnly)

        ref = self.get_current_branch() or self.get_remote_ref()
        for index in indexes:
            if index.isValid() and index.column() == 0:
                text = QString(ref.name + " ")
                text += QString(str(index.row()))
                stream.writeQString(text)

        mime_data.setData("application/vnd.text.list", encoded_data)
        return mime_data
开发者ID:mike-perdide,项目名称:gitbuster,代码行数:15,代码来源:q_git_model.py

示例12: dropMimeData

    def dropMimeData(self, index, data, action):
        if action == Qt.IgnoreAction:
            return True

        if data.hasFormat('application/vnd.re-eat.meal_recipe'):
            encodedData = data.data('application/vnd.re-eat.meal_recipe')
            stream = QDataStream(encodedData, QIODevice.ReadOnly)

            while not stream.atEnd():
                id = stream.readInt()
                date = stream.readQVariant()
                index = stream.readInt()
                self.recipeRemoved.emit(id, date, index)
            return True
        return False
开发者ID:madjar,项目名称:re-eat,代码行数:15,代码来源:recipes.py

示例13: _loadRulesByExport

 def _loadRulesByExport(self, e_file):
     qfile = QFile(e_file)
     if qfile.open(QIODevice.ReadOnly):
         inp = QDataStream(qfile)
         inp.setVersion(QDataStream.Qt_4_5)
         tmp = inp.readQVariantHash()
         #tmp = QVariant(inp)
         rules = self._loadRulesFromVariantHash(tmp) 
         qfile.close()
         #if (tmp.isEmpty())
         #return false;
         #qDebug("Processing was successful!");
         return rules
     else:
         print "error: file " + file + "not open"
         return None
开发者ID:varogami,项目名称:bt-tools,代码行数:16,代码来源:rssfilter_qbt.py

示例14: mimeData

    def mimeData(self, indexes):
        mimeData = QMimeData()
        encodedData = QByteArray()

        stream = QDataStream(encodedData, QIODevice.WriteOnly)

        for index in indexes:
            if not index.isValid():
                continue
            if not isinstance(index.internalPointer(), TableItem):
                continue
            table = self.getItem(index)
            stream.writeQString(table.mimeUri())

        mimeData.setData(self.QGIS_URI_MIME, encodedData)
        return mimeData
开发者ID:Br1ndavoine,项目名称:QGIS,代码行数:16,代码来源:db_model.py

示例15: run

 def run(self):
         fh = QFile(self.filename)
         fhlen = self._file_len(self.filename)
         if not fh.open(QIODevice.ReadOnly):
                 raise IOError, unicode(fh.errorString())
         self.data_block = {}
         stream = QDataStream(fh)
         stream.setVersion(QDataStream.Qt_4_2)
         magic = stream.readInt32()
         if magic != gMAGICNUM:
                 raise IOError, "not a valid .jd file"
         fileVersion = stream.readInt16()
         if fileVersion != gFILEVERSION:
                 raise IOError, "unrecognised .jd file version"
         while not fh.atEnd():
                 self._ReadItemFromStream(stream)
         
         self.emit(SIGNAL("PROJECTLOADERDONE(PyQt_PyObject)"), self.data_block)
开发者ID:redesigndavid,项目名称:Jay-Dee,代码行数:18,代码来源:jd_threads.py


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