2019-09-01 14:34:00 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
#
|
2019-09-09 10:46:52 +00:00
|
|
|
# CanvasJournal.py
|
2019-09-04 14:23:59 +00:00
|
|
|
# Copyright (c) 2018, 2019 Lucio Andrés Illanes Albornoz <lucio@lucioillanes.de>
|
2019-09-01 14:34:00 +00:00
|
|
|
#
|
|
|
|
|
2019-09-03 16:58:50 +00:00
|
|
|
class CanvasJournal():
|
libcanvas/Canvas.py:dispatchPatchSingle(): cloned from dispatchPatch().
lib{canvas/Canvas{,Journal},gui/GuiCanvasPanel}.py: replace dirtyJournal & pushDeltas() w/ explicit {begin,end}().
libgui/GuiCanvasPanel.py:applyTool(): updated.
libgui/GuiCanvasPanel.py:dispatchPatchSingle(): cloned from dispatchPatch().
libtools/Tool{,Circle,Fill,Line,Rect,Select{,Clone,Move},Text}.py:on{Mouse,Keyboard}Event(): return rc, dirty.
libtools/ToolSelect{Clone,Move}.py:onSelectEvent(): return rc, dirty.
2019-09-09 16:43:33 +00:00
|
|
|
# {{{ begin(self)
|
|
|
|
def begin(self):
|
2019-09-12 14:24:53 +00:00
|
|
|
deltaItem = [[], []]; self.patchesUndo.insert(self.patchesUndoLevel, deltaItem);
|
libcanvas/Canvas.py:dispatchPatchSingle(): cloned from dispatchPatch().
lib{canvas/Canvas{,Journal},gui/GuiCanvasPanel}.py: replace dirtyJournal & pushDeltas() w/ explicit {begin,end}().
libgui/GuiCanvasPanel.py:applyTool(): updated.
libgui/GuiCanvasPanel.py:dispatchPatchSingle(): cloned from dispatchPatch().
libtools/Tool{,Circle,Fill,Line,Rect,Select{,Clone,Move},Text}.py:on{Mouse,Keyboard}Event(): return rc, dirty.
libtools/ToolSelect{Clone,Move}.py:onSelectEvent(): return rc, dirty.
2019-09-09 16:43:33 +00:00
|
|
|
# }}}
|
|
|
|
# {{{ end(self)
|
|
|
|
def end(self):
|
2019-09-12 14:24:53 +00:00
|
|
|
if self.patchesUndo[self.patchesUndoLevel] == [[], []]:
|
|
|
|
del self.patchesUndo[self.patchesUndoLevel]
|
2019-09-12 14:39:17 +00:00
|
|
|
else:
|
|
|
|
if self.patchesUndoLevel > 0:
|
|
|
|
del self.patchesUndo[:self.patchesUndoLevel]; self.patchesUndoLevel = 0;
|
libcanvas/Canvas.py:dispatchPatchSingle(): cloned from dispatchPatch().
lib{canvas/Canvas{,Journal},gui/GuiCanvasPanel}.py: replace dirtyJournal & pushDeltas() w/ explicit {begin,end}().
libgui/GuiCanvasPanel.py:applyTool(): updated.
libgui/GuiCanvasPanel.py:dispatchPatchSingle(): cloned from dispatchPatch().
libtools/Tool{,Circle,Fill,Line,Rect,Select{,Clone,Move},Text}.py:on{Mouse,Keyboard}Event(): return rc, dirty.
libtools/ToolSelect{Clone,Move}.py:onSelectEvent(): return rc, dirty.
2019-09-09 16:43:33 +00:00
|
|
|
# }}}
|
2019-09-08 16:08:04 +00:00
|
|
|
# {{{ popCursor(self)
|
2019-09-01 14:34:00 +00:00
|
|
|
def popCursor(self):
|
|
|
|
if len(self.patchesCursor):
|
2019-09-06 08:29:45 +00:00
|
|
|
patchesCursor = self.patchesCursor; self.patchesCursor = [];
|
2019-09-01 14:34:00 +00:00
|
|
|
return patchesCursor
|
|
|
|
else:
|
|
|
|
return []
|
|
|
|
# }}}
|
2019-09-08 16:08:04 +00:00
|
|
|
# {{{ popRedo(self)
|
2019-09-01 14:34:00 +00:00
|
|
|
def popRedo(self):
|
|
|
|
if self.patchesUndoLevel > 0:
|
2019-09-06 08:29:45 +00:00
|
|
|
self.patchesUndoLevel -= 1; patches = self.patchesUndo[self.patchesUndoLevel];
|
2019-09-01 14:34:00 +00:00
|
|
|
return patches[1]
|
|
|
|
else:
|
|
|
|
return []
|
|
|
|
# }}}
|
2019-09-08 16:08:04 +00:00
|
|
|
# {{{ popUndo(self)
|
2019-09-01 14:34:00 +00:00
|
|
|
def popUndo(self):
|
|
|
|
if self.patchesUndo[self.patchesUndoLevel] != None:
|
2019-09-06 08:29:45 +00:00
|
|
|
patches = self.patchesUndo[self.patchesUndoLevel]; self.patchesUndoLevel += 1;
|
2019-09-01 14:34:00 +00:00
|
|
|
return patches[0]
|
|
|
|
else:
|
|
|
|
return []
|
|
|
|
# }}}
|
2019-09-08 16:08:04 +00:00
|
|
|
# {{{ pushCursor(self, patches)
|
2019-09-01 14:34:00 +00:00
|
|
|
def pushCursor(self, patches):
|
|
|
|
self.patchesCursor.append(patches)
|
|
|
|
# }}}
|
2019-09-08 16:08:04 +00:00
|
|
|
# {{{ resetCursor(self)
|
2019-09-01 14:34:00 +00:00
|
|
|
def resetCursor(self):
|
|
|
|
if self.patchesCursor != None:
|
|
|
|
self.patchesCursor.clear()
|
|
|
|
self.patchesCursor = []
|
|
|
|
# }}}
|
2019-09-08 16:08:04 +00:00
|
|
|
# {{{ resetUndo(self)
|
2019-09-01 14:34:00 +00:00
|
|
|
def resetUndo(self):
|
|
|
|
if self.patchesUndo != None:
|
|
|
|
self.patchesUndo.clear()
|
|
|
|
self.patchesUndo = [None]; self.patchesUndoLevel = 0;
|
|
|
|
# }}}
|
2019-09-08 16:08:04 +00:00
|
|
|
# {{{ updateCurrentDeltas(self, redoPatches, undoPatches)
|
2019-09-06 08:29:45 +00:00
|
|
|
def updateCurrentDeltas(self, redoPatches, undoPatches):
|
2019-09-12 14:24:53 +00:00
|
|
|
self.patchesUndo[self.patchesUndoLevel][0].append(undoPatches)
|
|
|
|
self.patchesUndo[self.patchesUndoLevel][1].append(redoPatches)
|
2019-09-01 14:34:00 +00:00
|
|
|
# }}}
|
|
|
|
|
|
|
|
# {{{ __del__(self): destructor method
|
|
|
|
def __del__(self):
|
|
|
|
self.resetCursor(); self.resetUndo();
|
|
|
|
# }}}
|
|
|
|
|
|
|
|
#
|
|
|
|
# __init__(self): initialisation method
|
|
|
|
def __init__(self):
|
2019-09-04 13:52:54 +00:00
|
|
|
self.patchesCursor, self.patchesUndo, self. patchesUndoLevel = None, None, None
|
2019-09-01 14:34:00 +00:00
|
|
|
self.resetCursor(); self.resetUndo();
|
|
|
|
|
|
|
|
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|