任意python类的撤消/重做功能
undoredo的Python项目详细描述
undo redo
--
任意python类的undo/redo功能
支持python 3可能在python 2中工作。
>;作者:ross anderson([rosshamish](https://github.com/rosshamish)作者:ross anderson([rosshamish](https://github.com/rosshamish)
`
` `
` `
` `
`
pip instainstall undo redo
/>
/>任何类都可以通过以下操作获得撤销/重做功能:
>
br/>/>-保留undomanager的一个实例
-使用@undotabable的undoable方法注释un是的decorator
-实现do()、undo()和redo()方法,如以下示例所示
-实现copy()和restore(obj)方法
-其中copy()返回对象的副本(可能是深层副本)
-其中restore(obj)将调用对象还原到传递对象的状态undoredo
类计数器(对象):
def\uu init(self,value=0):
self.undo\u 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,计数器:
self.value=counter.value
c=counter(0)0
c.increment()1
c.increment()2
c.undo()1
c.redo()2
````
--
任意python类的undo/redo功能
支持python 3可能在python 2中工作。
>;作者:ross anderson([rosshamish](https://github.com/rosshamish)作者:ross anderson([rosshamish](https://github.com/rosshamish)
`
` `
` `
` `
`
pip instainstall undo redo
/>
/>任何类都可以通过以下操作获得撤销/重做功能:
>
br/>/>-保留undomanager的一个实例
-使用@undotabable的undoable方法注释un是的decorator
-实现do()、undo()和redo()方法,如以下示例所示
-实现copy()和restore(obj)方法
-其中copy()返回对象的副本(可能是深层副本)
-其中restore(obj)将调用对象还原到传递对象的状态undoredo
类计数器(对象):
def\uu init(self,value=0):
self.undo\u 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,计数器:
self.value=counter.value
c=counter(0)0
c.increment()1
c.increment()2
c.undo()1
c.redo()2
````