undo/redo functionality for arbitrary python classes
Project description
undoredo
--------
undo/redo functionality for arbitrary python classes
Supports Python 3. Might work in Python 2.
> Author: Ross Anderson ([rosshamish](https://github.com/rosshamish))
### Installation
```
pip install undoredo
```
### Usage
Any class can gain undo/redo functionality by doing the following:
- keep around an instance of UndoManager
- annotate undoable methods with the @undoable decorator
- implement do(), undo(), and redo() methods as shown in the following example
- implement copy(), and restore(obj) methods
- where copy() returns a copy of the object (probably a deep copy)
- where restore(obj) restores the calling object to the state of the passed object
### Example
```
import undoredo
class Counter(object):
def __init__(self, value=0):
self.undo_mgr = undoredo.UndoManager()
self.value = value
@undoredo.undoable
def increment(self):
self.value += 1
@undoredo.undoable
def decrement(self):
self.value -= 1
def do(self, command):
return self.undo_mgr.do(command)
def undo(self):
return self.undo_mgr.undo()
def redo(self):
return self.undo_mgr.redo()
def copy(self):
return Counter(self.value)
def restore(self, counter):
self.value = counter.value
c = Counter(0) # 0
c.increment() # 1
c.increment() # 2
c.undo() # 1
c.redo() # 2
```
### License
GPLv3
--------
undo/redo functionality for arbitrary python classes
Supports Python 3. Might work in Python 2.
> Author: Ross Anderson ([rosshamish](https://github.com/rosshamish))
### Installation
```
pip install undoredo
```
### Usage
Any class can gain undo/redo functionality by doing the following:
- keep around an instance of UndoManager
- annotate undoable methods with the @undoable decorator
- implement do(), undo(), and redo() methods as shown in the following example
- implement copy(), and restore(obj) methods
- where copy() returns a copy of the object (probably a deep copy)
- where restore(obj) restores the calling object to the state of the passed object
### Example
```
import undoredo
class Counter(object):
def __init__(self, value=0):
self.undo_mgr = undoredo.UndoManager()
self.value = value
@undoredo.undoable
def increment(self):
self.value += 1
@undoredo.undoable
def decrement(self):
self.value -= 1
def do(self, command):
return self.undo_mgr.do(command)
def undo(self):
return self.undo_mgr.undo()
def redo(self):
return self.undo_mgr.redo()
def copy(self):
return Counter(self.value)
def restore(self, counter):
self.value = counter.value
c = Counter(0) # 0
c.increment() # 1
c.increment() # 2
c.undo() # 1
c.redo() # 2
```
### License
GPLv3
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
undoredo-0.1.4.tar.gz
(2.5 kB
view details)
File details
Details for the file undoredo-0.1.4.tar.gz
.
File metadata
- Download URL: undoredo-0.1.4.tar.gz
- Upload date:
- Size: 2.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | abc1839ebf3aab3cdd5353595ad87875fd98d3f520843326720241f022fd07f9 |
|
MD5 | 162fef737c3f448a13c442ef767ad99f |
|
BLAKE2b-256 | 13d25522e7e9ef97b4673633f960f147b1630ec50e7a88a7dbfcda8a759db68a |