31 |
31 |
32 When HexEditWidget loads data, HexEditChunks access them using a QIODevice |
32 When HexEditWidget loads data, HexEditChunks access them using a QIODevice |
33 interface. When the app uses a QByteArray or Python bytearray interface, |
33 interface. When the app uses a QByteArray or Python bytearray interface, |
34 QBuffer is used to provide again a QIODevice like interface. No data will |
34 QBuffer is used to provide again a QIODevice like interface. No data will |
35 be changed, therefore HexEditChunks opens the QIODevice in |
35 be changed, therefore HexEditChunks opens the QIODevice in |
36 QIODevice.ReadOnly mode. After every access HexEditChunks closes the |
36 QIODevice.OpenModeFlag.ReadOnly mode. After every access HexEditChunks |
37 QIODevice. That's why external applications can overwrite files while |
37 closes the QIODevice. That's why external applications can overwrite |
38 HexEditWidget shows them. |
38 files while HexEditWidget shows them. |
39 |
39 |
40 When the the user starts to edit the data, HexEditChunks creates a local |
40 When the the user starts to edit the data, HexEditChunks creates a local |
41 copy of a chunk of data (4 kilobytes) and notes all changes there. Parallel |
41 copy of a chunk of data (4 kilobytes) and notes all changes there. Parallel |
42 to that chunk, there is a second chunk, which keeps track of which bytes |
42 to that chunk, there is a second chunk, which keeps track of which bytes |
43 are changed and which are not. |
43 are changed and which are not. |
72 @type QIODevice |
72 @type QIODevice |
73 @return flag indicating successful operation |
73 @return flag indicating successful operation |
74 @rtype bool |
74 @rtype bool |
75 """ |
75 """ |
76 self.__ioDevice = ioDevice |
76 self.__ioDevice = ioDevice |
77 ok = self.__ioDevice.open(QIODevice.ReadOnly) |
77 ok = self.__ioDevice.open(QIODevice.OpenModeFlag.ReadOnly) |
78 if ok: |
78 if ok: |
79 # open successfully |
79 # open successfully |
80 self.__size = self.__ioDevice.size() |
80 self.__size = self.__ioDevice.size() |
81 self.__ioDevice.close() |
81 self.__ioDevice.close() |
82 else: |
82 else: |
117 if maxSize < 0: |
117 if maxSize < 0: |
118 maxSize = self.__size |
118 maxSize = self.__size |
119 elif (pos + maxSize) > self.__size: |
119 elif (pos + maxSize) > self.__size: |
120 maxSize = self.__size - pos |
120 maxSize = self.__size - pos |
121 |
121 |
122 self.__ioDevice.open(QIODevice.ReadOnly) |
122 self.__ioDevice.open(QIODevice.OpenModeFlag.ReadOnly) |
123 |
123 |
124 while maxSize > 0: |
124 while maxSize > 0: |
125 chunk.absPos = sys.maxsize |
125 chunk.absPos = sys.maxsize |
126 chunksLoopOngoing = True |
126 chunksLoopOngoing = True |
127 while chunkIdx < len(self.__chunks) and chunksLoopOngoing: |
127 while chunkIdx < len(self.__chunks) and chunksLoopOngoing: |
432 |
432 |
433 if foundIdx == -1: |
433 if foundIdx == -1: |
434 newChunk = HexEditChunk() |
434 newChunk = HexEditChunk() |
435 readAbsPos = absPos - ioDelta |
435 readAbsPos = absPos - ioDelta |
436 readPos = readAbsPos & self.READ_CHUNK_MASK |
436 readPos = readAbsPos & self.READ_CHUNK_MASK |
437 self.__ioDevice.open(QIODevice.ReadOnly) |
437 self.__ioDevice.open(QIODevice.OpenModeFlag.ReadOnly) |
438 self.__ioDevice.seek(readPos) |
438 self.__ioDevice.seek(readPos) |
439 newChunk.data = bytearray(self.__ioDevice.read(self.CHUNK_SIZE)) |
439 newChunk.data = bytearray(self.__ioDevice.read(self.CHUNK_SIZE)) |
440 self.__ioDevice.close() |
440 self.__ioDevice.close() |
441 newChunk.absPos = absPos - (readAbsPos - readPos) |
441 newChunk.absPos = absPos - (readAbsPos - readPos) |
442 newChunk.dataChanged = bytearray(len(newChunk.data)) |
442 newChunk.dataChanged = bytearray(len(newChunk.data)) |