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


Python QDataStream.atEnd方法代码示例

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


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

示例1: load

# 需要导入模块: from PyQt4.QtCore import QDataStream [as 别名]
# 或者: from PyQt4.QtCore.QDataStream import atEnd [as 别名]
 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,代码行数:33,代码来源:ships_ans.py

示例2: test_drag_information_are_correct

# 需要导入模块: from PyQt4.QtCore import QDataStream [as 别名]
# 或者: from PyQt4.QtCore.QDataStream import atEnd [as 别名]
    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,代码行数:14,代码来源:test_recipes.py

示例3: dropMimeData

# 需要导入模块: from PyQt4.QtCore import QDataStream [as 别名]
# 或者: from PyQt4.QtCore.QDataStream import atEnd [as 别名]
    def dropMimeData(self, index, data, action):
        if action == Qt.IgnoreAction:
            return True

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

            while not stream.atEnd():
                id = stream.readInt()
                self.recipeAdded.emit(id, self.date, self.index)
            return True
        elif 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.recipeMoved.emit(id, date, index, self.date, self.index)
            return True
        return False
开发者ID:madjar,项目名称:re-eat,代码行数:25,代码来源:meals.py

示例4: loadQDataStream

# 需要导入模块: from PyQt4.QtCore import QDataStream [as 别名]
# 或者: from PyQt4.QtCore.QDataStream import atEnd [as 别名]
 def loadQDataStream(self):
     error = None
     fh = None
     try:
         fh = QFile(self.__fname)
         if not fh.open(QIODevice.ReadOnly):
             raise IOError(str(fh.errorString()))
         stream = QDataStream(fh)
         magic = stream.readInt32()
         if magic != MovieContainer.MAGIC_NUMBER:
             raise IOError("unrecognized file type")
         version = stream.readInt32()
         if version < MovieContainer.OLD_FILE_VERSION:
             raise IOError("old and unreadable file format")
         elif version > MovieContainer.FILE_VERSION:
             raise IOError("new and unreadable file format")
         old = False
         if version == MovieContainer.OLD_FILE_VERSION:
             old = True
         stream.setVersion(QDataStream.Qt_4_2)
         self.clear(False)
         while not stream.atEnd():
             title = QString()
             acquired = QDate()
             location = QString()
             notes = QString()
             stream >> title
             year = stream.readInt16()
             minutes = stream.readInt16()
             if old:
                 stream >> acquired >> notes
             else:
                 stream >> acquired >> location >> notes
             self.add(Movie(title, year, minutes, acquired,
                            location, notes))
     except EnvironmentError as e:
         error = "Failed to load: {0}".format(e)
     finally:
         if fh is not None:
             fh.close()
         if error is not None:
             return False, error
         self.__dirty = False
         return True, "Loaded {0} movie records from {1}".format(
                 len(self.__movies),
                 QFileInfo(self.__fname).fileName())
开发者ID:hooloong,项目名称:gitpython,代码行数:48,代码来源:moviedata_ans.py

示例5: decode_data

# 需要导入模块: from PyQt4.QtCore import QDataStream [as 别名]
# 或者: from PyQt4.QtCore.QDataStream import atEnd [as 别名]
    def decode_data(self, bytearray):
        """Handle drag/drop data."""

        data = []
        item = {}

        ds = QDataStream(bytearray)
        while not ds.atEnd():

            row = ds.readInt32()
            column = ds.readInt32()

            map_items = ds.readInt32()
            for i in range(map_items):

                key = ds.readInt32()

                value = QVariant()
                ds >> value
                item[Qt.ItemDataRole(key)] = value

            data.append(item)

        return data
开发者ID:richardmurri,项目名称:Query-Browser,代码行数:26,代码来源:scene.py

示例6: load

# 需要导入模块: from PyQt4.QtCore import QDataStream [as 别名]
# 或者: from PyQt4.QtCore.QDataStream import atEnd [as 别名]
 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(str(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()
             ship = Ship(name, owner, country, teu, description)
             self.ships[id(ship)] = ship
             self.owners.add(str(owner))
             self.countries.add(str(country))
         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,代码行数:38,代码来源:ships.py

示例7: dropMimeData

# 需要导入模块: from PyQt4.QtCore import QDataStream [as 别名]
# 或者: from PyQt4.QtCore.QDataStream import atEnd [as 别名]
    def dropMimeData(self, mime_data, action, row, col_unused, parent_unused,
                     filling_empty_model=False):
        if action == Qt.IgnoreAction:
            return True

        if not mime_data.hasFormat("application/vnd.text.list"):
            return False

        if not filling_empty_model and row == self.rowCount():
            # It's forbidden to insert before the first commit (last row of the
            # model).
            return False

        if row != -1:
            begin_row = row
        else:
            return False

        encoded_data = mime_data.data("application/vnd.text.list")
        stream = QDataStream(encoded_data, QIODevice.ReadOnly)
        new_items = []
        rows = 0

        while not stream.atEnd():
            text = stream.readQString()
            item_branch, item_row_s = str(text).split(' ')

            new_items.append([int(item_row_s),])
            rows += 1

        # Now new_items contains 1 element lists with the row of the inserted
        # commit. We will complete these lists with the actual Commit object.
        # item_branch contains the name of the branch.

        for (branch, model) in self._all_models_dict.items():
            if branch.name == item_branch:
                item_model = model

        # We're going to store the data to be inserted in a dictionnary before
        # inserting the rows. This is to avoid problems when copying rows from
        # a model to somewhere above in the same model. The insertion of rows
        # causes a shift of all the rows, including the ones to be copied from.
        data_to_be_inserted = {}
        insert_row = begin_row
        for item in new_items:
            item_row = item[0]

            for column, field in enumerate(self.get_columns()):
                item_index = self.createIndex(item_row, column)
                data = item_model.data(item_index, Qt.EditRole)
                data_to_be_inserted[(insert_row, column)] = data

            insert_row += 1

        self.start_history_event()

        parents_col = self.get_columns().index("parents")
        children_col = self.get_columns().index("children")

        _row = begin_row
        for item in new_items:
            replaced_row = _row
            replaced_index = self.createIndex(replaced_row, 0)
            while self.is_deleted(replaced_index):
                replaced_row += 1
                replaced_index = self.createIndex(replaced_row, 0)
            replaced_commit = self.git_model.get_commits()[replaced_index.row()]

            new_parents = [replaced_commit,]
            new_children = list(self.git_model.c_data(replaced_commit,
                                                      "children"))

            self.insertRows(_row, 1, QModelIndex())

            for column, field in enumerate(self.get_columns()):
                index = self.createIndex(_row, column)
                self.setData(index, data_to_be_inserted[(_row, column)])

            self.setData(self.createIndex(_row, children_col), new_children)
            self.setData(self.createIndex(_row, parents_col), [replaced_commit,])

            this_commit = self.git_model.get_commits()[_row]
            # Updating parent's children and children parent's
            for child in new_children:
                row_of_child = self.git_model.row_of(child)
                _parents = list(self.git_model.c_data(child, "parents"))
                parents_position = _parents.index(replaced_commit)

                # Removing only the replaced commit from the parents
                _parents.pop(parents_position)
                _parents.insert(parents_position, this_commit)
                self.setData(self.createIndex(row_of_child, parents_col),
                             _parents)

            for parent in new_parents:
                row_of_parent = self.git_model.row_of(parent)
                self.setData(self.createIndex(row_of_parent, children_col),
                             [this_commit,])

            _row += 1
#.........这里部分代码省略.........
开发者ID:mike-perdide,项目名称:gitbuster,代码行数:103,代码来源:q_editable_git_model.py


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