/opt/alt/python27/lib64/python2.7/idlelib
NameSizeModeActions
Icons/-0755rm
idle_test/-0755rm
aboutDialog.py70140644editdlrm
aboutDialog.pyc70170644editdlrm
aboutDialog.pyo70170644editdlrm
AutoComplete.py89640644editdlrm
AutoComplete.pyc81810644editdlrm
AutoComplete.pyo81810644editdlrm
AutoCompleteWindow.py173180644editdlrm
AutoCompleteWindow.pyc127140644editdlrm
AutoCompleteWindow.pyo126550644editdlrm
AutoExpand.py33950644editdlrm
AutoExpand.pyc35800644editdlrm
AutoExpand.pyo35800644editdlrm
Bindings.py29760644editdlrm
Bindings.pyc47080644editdlrm
Bindings.pyo47080644editdlrm
CallTips.py77400644editdlrm
CallTips.pyc83540644editdlrm
CallTips.pyo83540644editdlrm
CallTipWindow.py60650644editdlrm
CallTipWindow.pyc62920644editdlrm
CallTipWindow.pyo62920644editdlrm
ChangeLog563930644editdlrm
ClassBrowser.py69990644editdlrm
ClassBrowser.pyc98900644editdlrm
ClassBrowser.pyo98900644editdlrm
CodeContext.py83420644editdlrm
CodeContext.pyc67880644editdlrm
CodeContext.pyo67440644editdlrm
ColorDelegator.py97620644editdlrm
ColorDelegator.pyc91190644editdlrm
ColorDelegator.pyo91190644editdlrm
config-extensions.def29650644editdlrm
config-highlight.def25150644editdlrm
config-keys.def77770644editdlrm
config-main.def25610644editdlrm
configDialog.py659580644editdlrm
configDialog.pyc544350644editdlrm
configDialog.pyo544350644editdlrm
configHandler.py324850644editdlrm
configHandler.pyc299850644editdlrm
configHandler.pyo299850644editdlrm
configHelpSourceEdit.py66860644editdlrm
configHelpSourceEdit.pyc67120644editdlrm
configHelpSourceEdit.pyo67120644editdlrm
configSectionNameDialog.py40400644editdlrm
configSectionNameDialog.pyc45100644editdlrm
configSectionNameDialog.pyo45100644editdlrm
CREDITS.txt18660644editdlrm
Debugger.py182360644editdlrm
Debugger.pyc181440644editdlrm
Debugger.pyo181440644editdlrm
Delegator.py6650644editdlrm
Delegator.pyc13460644editdlrm
Delegator.pyo13460644editdlrm
dynOptionMenuWidget.py19840644editdlrm
dynOptionMenuWidget.pyc28680644editdlrm
dynOptionMenuWidget.pyo28680644editdlrm
EditorWindow.py654980644editdlrm
EditorWindow.pyc585220644editdlrm
EditorWindow.pyo584200644editdlrm
extend.txt36420644editdlrm
FileList.py37180644editdlrm
FileList.pyc41680644editdlrm
FileList.pyo41350644editdlrm
FormatParagraph.py72870644editdlrm
FormatParagraph.pyc73110644editdlrm
FormatParagraph.pyo73110644editdlrm
GrepDialog.py51450644editdlrm
GrepDialog.pyc66070644editdlrm
GrepDialog.pyo66070644editdlrm
help.html424140644editdlrm
help.py110350644editdlrm
help.pyc125430644editdlrm
help.pyo125430644editdlrm
help.txt121440644editdlrm
HISTORY.txt103170644editdlrm
HyperParser.py104970644editdlrm
HyperParser.pyc68030644editdlrm
HyperParser.pyo68030644editdlrm
idle.py4530644editdlrm
idle.pyc4230644editdlrm
idle.pyo4230644editdlrm
idle.pyw5630644editdlrm
IdleHistory.py40520644editdlrm
IdleHistory.pyc41510644editdlrm
IdleHistory.pyo41510644editdlrm
idlever.py4150644editdlrm
idlever.pyc5910644editdlrm
idlever.pyo5910644editdlrm
IOBinding.py219110644editdlrm
IOBinding.pyc190680644editdlrm
IOBinding.pyo190680644editdlrm
keybindingDialog.py124680644editdlrm
keybindingDialog.pyc123680644editdlrm
keybindingDialog.pyo123680644editdlrm
macosxSupport.py84350644editdlrm
macosxSupport.pyc85850644editdlrm
macosxSupport.pyo84470644editdlrm
MultiCall.py177010644editdlrm
MultiCall.pyc167930644editdlrm
MultiCall.pyo167190644editdlrm
MultiStatusBar.py13480644editdlrm
MultiStatusBar.pyc23570644editdlrm
MultiStatusBar.pyo23570644editdlrm
NEWS.txt472470644editdlrm
ObjectBrowser.py43760644editdlrm
ObjectBrowser.pyc74310644editdlrm
ObjectBrowser.pyo74310644editdlrm
OutputWindow.py45760644editdlrm
OutputWindow.pyc54270644editdlrm
OutputWindow.pyo54270644editdlrm
ParenMatch.py67140644editdlrm
ParenMatch.pyc73500644editdlrm
ParenMatch.pyo73500644editdlrm
PathBrowser.py30090644editdlrm
PathBrowser.pyc46810644editdlrm
PathBrowser.pyo46810644editdlrm
Percolator.py32220644editdlrm
Percolator.pyc48030644editdlrm
Percolator.pyo46190644editdlrm
PyParse.py195100644editdlrm
PyParse.pyc102260644editdlrm
PyParse.pyo97880644editdlrm
PyShell.py588590755editdlrm
PyShell.pyc542690644editdlrm
PyShell.pyo541670644editdlrm
README.txt78900644editdlrm
RemoteDebugger.py116320644editdlrm
RemoteDebugger.pyc171310644editdlrm
RemoteDebugger.pyo169770644editdlrm
RemoteObjectBrowser.py9420644editdlrm
RemoteObjectBrowser.pyc22800644editdlrm
RemoteObjectBrowser.pyo22800644editdlrm
ReplaceDialog.py66390644editdlrm
ReplaceDialog.pyc80160644editdlrm
ReplaceDialog.pyo80160644editdlrm
rpc.py201500644editdlrm
rpc.pyc224950644editdlrm
rpc.pyo223890644editdlrm
RstripExtension.py10500644editdlrm
RstripExtension.pyc16650644editdlrm
RstripExtension.pyo16650644editdlrm
run.py129170644editdlrm
run.pyc137700644editdlrm
run.pyo137120644editdlrm
ScriptBinding.py84590644editdlrm
ScriptBinding.pyc83700644editdlrm
ScriptBinding.pyo83700644editdlrm
ScrolledList.py43730644editdlrm
ScrolledList.pyc67680644editdlrm
ScrolledList.pyo67680644editdlrm
SearchDialog.py26300644editdlrm
SearchDialog.pyc41390644editdlrm
SearchDialog.pyo41390644editdlrm
SearchDialogBase.py70940644editdlrm
SearchDialogBase.pyc86310644editdlrm
SearchDialogBase.pyo86310644editdlrm
SearchEngine.py74630644editdlrm
SearchEngine.pyc85750644editdlrm
SearchEngine.pyo85750644editdlrm
StackViewer.py44310644editdlrm
StackViewer.pyc66770644editdlrm
StackViewer.pyo66770644editdlrm
tabbedpages.py184390644editdlrm
tabbedpages.pyc190810644editdlrm
tabbedpages.pyo190810644editdlrm
textView.py35200644editdlrm
textView.pyc41160644editdlrm
textView.pyo41160644editdlrm
TODO.txt84780644editdlrm
ToolTip.py31730644editdlrm
ToolTip.pyc48900644editdlrm
ToolTip.pyo48900644editdlrm
TreeWidget.py150370644editdlrm
TreeWidget.pyc183830644editdlrm
TreeWidget.pyo183830644editdlrm
UndoDelegator.py107870644editdlrm
UndoDelegator.pyc142180644editdlrm
UndoDelegator.pyo142180644editdlrm
WidgetRedirector.py69060644editdlrm
WidgetRedirector.pyc79510644editdlrm
WidgetRedirector.pyo79510644editdlrm
WindowList.py24730644editdlrm
WindowList.pyc38310644editdlrm
WindowList.pyo38310644editdlrm
ZoomHeight.py13000644editdlrm
ZoomHeight.pyc17110644editdlrm
ZoomHeight.pyo17110644editdlrm
__init__.py2880644editdlrm
__init__.pyc4440644editdlrm
__init__.pyo4440644editdlrm
Edit: /opt/alt/python27/lib64/python2.7/idlelib/UndoDelegator.py (10787B)
import string from Tkinter import * from idlelib.Delegator import Delegator #$ event <> #$ win #$ unix #$ event <> #$ win #$ unix #$ event <> #$ win #$ unix class UndoDelegator(Delegator): max_undo = 1000 def __init__(self): Delegator.__init__(self) self.reset_undo() def setdelegate(self, delegate): if self.delegate is not None: self.unbind("<>") self.unbind("<>") self.unbind("<>") Delegator.setdelegate(self, delegate) if delegate is not None: self.bind("<>", self.undo_event) self.bind("<>", self.redo_event) self.bind("<>", self.dump_event) def dump_event(self, event): from pprint import pprint pprint(self.undolist[:self.pointer]) print "pointer:", self.pointer, print "saved:", self.saved, print "can_merge:", self.can_merge, print "get_saved():", self.get_saved() pprint(self.undolist[self.pointer:]) return "break" def reset_undo(self): self.was_saved = -1 self.pointer = 0 self.undolist = [] self.undoblock = 0 # or a CommandSequence instance self.set_saved(1) def set_saved(self, flag): if flag: self.saved = self.pointer else: self.saved = -1 self.can_merge = False self.check_saved() def get_saved(self): return self.saved == self.pointer saved_change_hook = None def set_saved_change_hook(self, hook): self.saved_change_hook = hook was_saved = -1 def check_saved(self): is_saved = self.get_saved() if is_saved != self.was_saved: self.was_saved = is_saved if self.saved_change_hook: self.saved_change_hook() def insert(self, index, chars, tags=None): self.addcmd(InsertCommand(index, chars, tags)) def delete(self, index1, index2=None): self.addcmd(DeleteCommand(index1, index2)) # Clients should call undo_block_start() and undo_block_stop() # around a sequence of editing cmds to be treated as a unit by # undo & redo. Nested matching calls are OK, and the inner calls # then act like nops. OK too if no editing cmds, or only one # editing cmd, is issued in between: if no cmds, the whole # sequence has no effect; and if only one cmd, that cmd is entered # directly into the undo list, as if undo_block_xxx hadn't been # called. The intent of all that is to make this scheme easy # to use: all the client has to worry about is making sure each # _start() call is matched by a _stop() call. def undo_block_start(self): if self.undoblock == 0: self.undoblock = CommandSequence() self.undoblock.bump_depth() def undo_block_stop(self): if self.undoblock.bump_depth(-1) == 0: cmd = self.undoblock self.undoblock = 0 if len(cmd) > 0: if len(cmd) == 1: # no need to wrap a single cmd cmd = cmd.getcmd(0) # this blk of cmds, or single cmd, has already # been done, so don't execute it again self.addcmd(cmd, 0) def addcmd(self, cmd, execute=True): if execute: cmd.do(self.delegate) if self.undoblock != 0: self.undoblock.append(cmd) return if self.can_merge and self.pointer > 0: lastcmd = self.undolist[self.pointer-1] if lastcmd.merge(cmd): return self.undolist[self.pointer:] = [cmd] if self.saved > self.pointer: self.saved = -1 self.pointer = self.pointer + 1 if len(self.undolist) > self.max_undo: ##print "truncating undo list" del self.undolist[0] self.pointer = self.pointer - 1 if self.saved >= 0: self.saved = self.saved - 1 self.can_merge = True self.check_saved() def undo_event(self, event): if self.pointer == 0: self.bell() return "break" cmd = self.undolist[self.pointer - 1] cmd.undo(self.delegate) self.pointer = self.pointer - 1 self.can_merge = False self.check_saved() return "break" def redo_event(self, event): if self.pointer >= len(self.undolist): self.bell() return "break" cmd = self.undolist[self.pointer] cmd.redo(self.delegate) self.pointer = self.pointer + 1 self.can_merge = False self.check_saved() return "break" class Command: # Base class for Undoable commands tags = None def __init__(self, index1, index2, chars, tags=None): self.marks_before = {} self.marks_after = {} self.index1 = index1 self.index2 = index2 self.chars = chars if tags: self.tags = tags def __repr__(self): s = self.__class__.__name__ t = (self.index1, self.index2, self.chars, self.tags) if self.tags is None: t = t[:-1] return s + repr(t) def do(self, text): pass def redo(self, text): pass def undo(self, text): pass def merge(self, cmd): return 0 def save_marks(self, text): marks = {} for name in text.mark_names(): if name != "insert" and name != "current": marks[name] = text.index(name) return marks def set_marks(self, text, marks): for name, index in marks.items(): text.mark_set(name, index) class InsertCommand(Command): # Undoable insert command def __init__(self, index1, chars, tags=None): Command.__init__(self, index1, None, chars, tags) def do(self, text): self.marks_before = self.save_marks(text) self.index1 = text.index(self.index1) if text.compare(self.index1, ">", "end-1c"): # Insert before the final newline self.index1 = text.index("end-1c") text.insert(self.index1, self.chars, self.tags) self.index2 = text.index("%s+%dc" % (self.index1, len(self.chars))) self.marks_after = self.save_marks(text) ##sys.__stderr__.write("do: %s\n" % self) def redo(self, text): text.mark_set('insert', self.index1) text.insert(self.index1, self.chars, self.tags) self.set_marks(text, self.marks_after) text.see('insert') ##sys.__stderr__.write("redo: %s\n" % self) def undo(self, text): text.mark_set('insert', self.index1) text.delete(self.index1, self.index2) self.set_marks(text, self.marks_before) text.see('insert') ##sys.__stderr__.write("undo: %s\n" % self) def merge(self, cmd): if self.__class__ is not cmd.__class__: return False if self.index2 != cmd.index1: return False if self.tags != cmd.tags: return False if len(cmd.chars) != 1: return False if self.chars and \ self.classify(self.chars[-1]) != self.classify(cmd.chars): return False self.index2 = cmd.index2 self.chars = self.chars + cmd.chars return True alphanumeric = string.ascii_letters + string.digits + "_" def classify(self, c): if c in self.alphanumeric: return "alphanumeric" if c == "\n": return "newline" return "punctuation" class DeleteCommand(Command): # Undoable delete command def __init__(self, index1, index2=None): Command.__init__(self, index1, index2, None, None) def do(self, text): self.marks_before = self.save_marks(text) self.index1 = text.index(self.index1) if self.index2: self.index2 = text.index(self.index2) else: self.index2 = text.index(self.index1 + " +1c") if text.compare(self.index2, ">", "end-1c"): # Don't delete the final newline self.index2 = text.index("end-1c") self.chars = text.get(self.index1, self.index2) text.delete(self.index1, self.index2) self.marks_after = self.save_marks(text) ##sys.__stderr__.write("do: %s\n" % self) def redo(self, text): text.mark_set('insert', self.index1) text.delete(self.index1, self.index2) self.set_marks(text, self.marks_after) text.see('insert') ##sys.__stderr__.write("redo: %s\n" % self) def undo(self, text): text.mark_set('insert', self.index1) text.insert(self.index1, self.chars) self.set_marks(text, self.marks_before) text.see('insert') ##sys.__stderr__.write("undo: %s\n" % self) class CommandSequence(Command): # Wrapper for a sequence of undoable cmds to be undone/redone # as a unit def __init__(self): self.cmds = [] self.depth = 0 def __repr__(self): s = self.__class__.__name__ strs = [] for cmd in self.cmds: strs.append(" %r" % (cmd,)) return s + "(\n" + ",\n".join(strs) + "\n)" def __len__(self): return len(self.cmds) def append(self, cmd): self.cmds.append(cmd) def getcmd(self, i): return self.cmds[i] def redo(self, text): for cmd in self.cmds: cmd.redo(text) def undo(self, text): cmds = self.cmds[:] cmds.reverse() for cmd in cmds: cmd.undo(text) def bump_depth(self, incr=1): self.depth = self.depth + incr return self.depth def _undo_delegator(parent): from idlelib.Percolator import Percolator root = Tk() root.title("Test UndoDelegator") width, height, x, y = list(map(int, re.split('[x+]', parent.geometry()))) root.geometry("+%d+%d"%(x, y + 150)) text = Text(root) text.config(height=10) text.pack() text.focus_set() p = Percolator(text) d = UndoDelegator() p.insertfilter(d) undo = Button(root, text="Undo", command=lambda:d.undo_event(None)) undo.pack(side='left') redo = Button(root, text="Redo", command=lambda:d.redo_event(None)) redo.pack(side='left') dump = Button(root, text="Dump", command=lambda:d.dump_event(None)) dump.pack(side='left') root.mainloop() if __name__ == "__main__": from idlelib.idle_test.htest import run run(_undo_delegator)