Пример #1
0
    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()
Пример #2
0
 def __setstate__(self, state):
     for key, val in state.items():
         if key == 'url':
             self.__dict__[key] = QUrl.fromEncoded(val)
         elif key == 'icon':
             ds = QDataStream(QByteArray(val))
             self.__dict__[key] = ds.readQVariant()
         else:
             self.__dict__[key] = val
    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)
Пример #4
0
        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')
Пример #5
0
 def clearRestoreData(self):
     crashedSession = QByteArray(self._data.crashedSession)
     self._data.clear()
     stream = QDataStream(crashedSession, QIODevice.ReadOnly)
     self._data = stream.readQVariant()