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.location \ << 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())
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())
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
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
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))