Skip to content

time travel python: undo/redo with inverse operations for list and dict

Notifications You must be signed in to change notification settings

jaymebrd/UndoPy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

UndoPy

UndoPy is a library providing persistent Undo/Redo for two python data structures namely list and dict.

Implementation

This method is implemented using principles of inverse computations

Usage

pip install undopy

Undo and Redo Example

>>> from UndoPy import UndoLog, undo_dict, undo_list
>>> t = UndoLog()
>>> d = undo_dict({1: "VU", 2: "UvA"})
>>> l = undo_list([1, 2, 3])
>>> t.add(d)
>>> t.add(l)
>>> l.append(1)
>>> d[3] = "CWI"
>>> l
[1, 2, 3, 1]
>>> d
{1: 'VU', 2: 'UvA', 3: 'CWI'}
>>> t.undo()
>>> d
{1: 'VU', 2: 'UvA'}
>>> t.undo()
>>> l
[1, 2, 3]
>>> t.redo()
>>> t.redo()
>>> l
[1, 2, 3, 1]
>>> d
{1: 'VU', 2: 'UvA', 3: 'CWI'}
>>> t.start_group("foo")
True
>>> d[42] = "student"
>>> del d[3]
>>> t.end_group("foo")
>>> d
{1: 'VU', 2: 'UvA', 42: 'student'}
>>> t.undo()
>>> d
{1: 'VU', 2: 'UvA', 3: 'CWI'}

About

time travel python: undo/redo with inverse operations for list and dict

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages