def _restoreState(self, state): ''' @param: state QByteArray ''' stream = QDataStream(state) if stream.atEnd(): return version = -1 historyIndex = -1 databases = False localStorage = False cache = False cookies = False version = stream.readInt() if version != self._s_stateDataVersoin: return historyIndex = stream.readInt() databases = stream.readBool() localStorage = stream.readBool() cache = stream.readBool() cookies = stream.readBool() if historyIndex != -1: self._ui.history.setChecked(True) self._ui.historyLength.setEnabled(True) self._ui.historyLength.setCurrentIndex(historyIndex) self._ui.databases.setChecked(databases) self._ui.localStorage.setChecked(localStorage) self._ui.cache.setChecked(cache) self._ui.cookies.setChecked(cookies)
def __setstate__(self, state): stream = QDataStream(state) self.windows = stream.readQVariant() assert (type(self.windows) == list) version = stream.readInt() if version >= 1: self.crashedSession = stream.readQVariant() if version >= 2: self.closedWindows = stream.readQVariant()
def restoreState(self, state): ''' @param: state QByteArray ''' stream = QDataStream(state) version = stream.readInt() if version < 1: return self._closedWindows.clear() windowCount = stream.readInt() for idx in range(windowCount): window = self.Window() window.windowState = stream.readQVariant() if not window.isValid(): continue window.icon = window.windowState.tabs[0].icon window.title = window.windowState.tabs[0].title self._closedWindows.append(window)
def createFromFile(cls, fpath): ''' @param: fpath QString @return: data RestoreData ''' data = RestoreData() if not QFile.exists(fpath): return data recoveryFile = QFile(fpath) if not recoveryFile.open(QIODevice.ReadOnly): return data stream = QDataStream(recoveryFile) version = stream.readInt() if version == const.sessionVersion: byteData = stream.readBytes() data = pickle.loads(byteData) else: print('WARNING: Unsupported session file version', version, 'path', fpath) return data
return result def __setstate__(self, state): print('__setstate__') for key, val in state.items(): if key == 'test1': self.test1 = QUrl.fromEncoded(val) else: setattr(self, key, val) if argv[1] == 'dump': data = QByteArray() ds = QDataStream(data, QIODevice.WriteOnly) ds.writeInt(1) obj = ObjType() ds.writeQVariant([obj, obj]) print(data) with open('test.dat', 'wb') as fp: fp.write(data) elif argv[1] == 'load': with open('test.dat', 'rb') as fp: data = fp.read() dsOut = QDataStream(QByteArray(data)) ver = dsOut.readInt() lst = dsOut.readQVariant() print(lst[0].test1) print(lst) else: raise RuntimeError('action should be dump or load')