本文整理汇总了Python中PyQt4.QtCore.QDataStream.setVersion方法的典型用法代码示例。如果您正苦于以下问题:Python QDataStream.setVersion方法的具体用法?Python QDataStream.setVersion怎么用?Python QDataStream.setVersion使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtCore.QDataStream
的用法示例。
在下文中一共展示了QDataStream.setVersion方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save
# 需要导入模块: from PyQt4.QtCore import QDataStream [as 别名]
# 或者: from PyQt4.QtCore.QDataStream import setVersion [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
示例2: open
# 需要导入模块: from PyQt4.QtCore import QDataStream [as 别名]
# 或者: from PyQt4.QtCore.QDataStream import setVersion [as 别名]
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))
示例3: saveQDataStream
# 需要导入模块: from PyQt4.QtCore import QDataStream [as 别名]
# 或者: from PyQt4.QtCore.QDataStream import setVersion [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())
示例4: open_to_stream
# 需要导入模块: from PyQt4.QtCore import QDataStream [as 别名]
# 或者: from PyQt4.QtCore.QDataStream import setVersion [as 别名]
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)
示例5: read_project
# 需要导入模块: from PyQt4.QtCore import QDataStream [as 别名]
# 或者: from PyQt4.QtCore.QDataStream import setVersion [as 别名]
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)
示例6: save_project
# 需要导入模块: from PyQt4.QtCore import QDataStream [as 别名]
# 或者: from PyQt4.QtCore.QDataStream import setVersion [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)
示例7: _loadRulesByExport
# 需要导入模块: from PyQt4.QtCore import QDataStream [as 别名]
# 或者: from PyQt4.QtCore.QDataStream import setVersion [as 别名]
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
示例8: loadQDataStream
# 需要导入模块: from PyQt4.QtCore import QDataStream [as 别名]
# 或者: from PyQt4.QtCore.QDataStream import setVersion [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())
示例9: run
# 需要导入模块: from PyQt4.QtCore import QDataStream [as 别名]
# 或者: from PyQt4.QtCore.QDataStream import setVersion [as 别名]
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)
示例10: save
# 需要导入模块: from PyQt4.QtCore import QDataStream [as 别名]
# 或者: from PyQt4.QtCore.QDataStream import setVersion [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
示例11: save
# 需要导入模块: from PyQt4.QtCore import QDataStream [as 别名]
# 或者: from PyQt4.QtCore.QDataStream import setVersion [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))