src/eric7/HexEdit/HexEditUndoStack.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9473
3f23dbf37dbe
--- a/src/eric7/HexEdit/HexEditUndoStack.py	Wed Jul 13 11:16:20 2022 +0200
+++ b/src/eric7/HexEdit/HexEditUndoStack.py	Wed Jul 13 14:55:47 2022 +0200
@@ -16,6 +16,7 @@
     """
     Class implementing the edit commands.
     """
+
     INSERT = 0
     REMOVEAT = 1
     OVERWRITE = 2
@@ -25,10 +26,11 @@
     """
     Class implementing the Undo command.
     """
+
     def __init__(self, chunks, cmd, pos, newByte, parent=None):
         """
         Constructor
-        
+
         @param chunks reference to the data container
         @type HexEditChunks
         @param cmd edit command
@@ -41,15 +43,15 @@
         @type QUndoCommand
         """
         super().__init__(parent)
-        
+
         self.__chunks = chunks
         self._pos = pos
         self._newByte = newByte
         self._cmd = cmd
-        
+
         self.__wasChanged = False
         self.__oldByte = 0
-    
+
     def undo(self):
         """
         Public method to undo the command.
@@ -62,7 +64,7 @@
         elif self._cmd == HexEditCommand.REMOVEAT:
             self.__chunks.insert(self._pos, self.__oldByte)
             self.__chunks.setDataChanged(self._pos, self.__wasChanged)
-    
+
     def redo(self):
         """
         Public method to redo the command.
@@ -77,32 +79,32 @@
             self.__oldByte = self.__chunks[self._pos]
             self.__wasChanged = self.__chunks.dataChanged(self._pos)
             self.__chunks.removeAt(self._pos)
-    
+
     def mergeWith(self, command):
         """
         Public method to merge this command with another one.
-        
+
         @param command reference to the command to merge with
         @type QUndoCommand
         @return flag indicating a successful merge
         @rtype bool
         """
         result = False
-        
+
         if (
-            self._cmd != HexEditCommand.REMOVEAT and
-            command._cmd == HexEditCommand.OVERWRITE and
-            command._pos == self._pos
+            self._cmd != HexEditCommand.REMOVEAT
+            and command._cmd == HexEditCommand.OVERWRITE
+            and command._pos == self._pos
         ):
             self._newByte = command._newByte
             result = True
-        
+
         return result
-    
+
     def id(self):
         """
         Public method to get the ID of this undo command class.
-        
+
         @return ID of the undo command class
         @rtype int
         """
@@ -113,58 +115,59 @@
     """
     Class implementing an Undo stack for the hex edit widget.
     """
+
     def __init__(self, chunks, parent=None):
         """
         Constructor
-        
+
         @param chunks reference to the data container
         @type HexEditChunks
         @param parent reference to the parent object
         @type QObject
         """
         super().__init__(parent)
-        
+
         self.__chunks = chunks
         self.__parent = parent
-    
+
     def insert(self, pos, data):
         """
         Public method to insert a byte.
-        
+
         @param pos position to insert at
         @type int
         @param data byte to be inserted
         @type int (range 0 to 255)
         """
         if pos >= 0 and pos <= self.__chunks.size():
-            uc = HexEditUndoCommand(
-                self.__chunks, HexEditCommand.INSERT, pos, data)
+            uc = HexEditUndoCommand(self.__chunks, HexEditCommand.INSERT, pos, data)
             self.push(uc)
-    
+
     def insertByteArray(self, pos, byteArray):
         """
         Public method to insert bytes.
-        
+
         @param pos position to insert at
         @type int
         @param byteArray data to be inserted
         @type byteArray or QByteArray
         """
         ba = bytearray(byteArray)
-        
+
         if pos >= 0 and pos <= self.__chunks.size():
             txt = self.tr("Inserting %n byte(s)", "", len(ba))
             self.beginMacro(txt)
             for idx in range(len(ba)):
                 uc = HexEditUndoCommand(
-                    self.__chunks, HexEditCommand.INSERT, pos + idx, ba[idx])
+                    self.__chunks, HexEditCommand.INSERT, pos + idx, ba[idx]
+                )
                 self.push(uc)
             self.endMacro()
-    
+
     def removeAt(self, pos, length=1):
         """
         Public method to remove bytes.
-        
+
         @param pos position to remove bytes from
         @type int
         @param length amount of bytes to remove
@@ -172,36 +175,35 @@
         """
         if pos >= 0 and pos <= self.__chunks.size():
             if length == 1:
-                uc = HexEditUndoCommand(
-                    self.__chunks, HexEditCommand.REMOVEAT, pos, 0)
+                uc = HexEditUndoCommand(self.__chunks, HexEditCommand.REMOVEAT, pos, 0)
                 self.push(uc)
             else:
                 txt = self.tr("Deleting %n byte(s)", "", length)
                 self.beginMacro(txt)
                 for _cnt in range(length):
                     uc = HexEditUndoCommand(
-                        self.__chunks, HexEditCommand.REMOVEAT, pos, 0)
+                        self.__chunks, HexEditCommand.REMOVEAT, pos, 0
+                    )
                     self.push(uc)
                 self.endMacro()
-    
+
     def overwrite(self, pos, data):
         """
         Public method to replace a byte.
-        
+
         @param pos position to replace the byte at
         @type int
         @param data byte to replace with
         @type int (range 0 to 255)
         """
         if pos >= 0 and pos <= self.__chunks.size():
-            uc = HexEditUndoCommand(
-                self.__chunks, HexEditCommand.OVERWRITE, pos, data)
+            uc = HexEditUndoCommand(self.__chunks, HexEditCommand.OVERWRITE, pos, data)
             self.push(uc)
-    
+
     def overwriteByteArray(self, pos, length, byteArray):
         """
         Public method to replace bytes.
-        
+
         @param pos position to replace the bytes at
         @type int
         @param length amount of bytes to replace
@@ -210,7 +212,7 @@
         @type bytearray or QByteArray
         """
         ba = bytearray(byteArray)
-        
+
         if pos >= 0 and pos <= self.__chunks.size():
             txt = self.tr("Inserting %n byte(s)", "", len(ba))
             self.beginMacro(txt)

eric ide

mercurial