/usr/lib/python2.6/idlelib
NameSizeModeActions
Icons/-0755rm
aboutDialog.py68250644editdlrm
aboutDialog.pyc69370644editdlrm
aboutDialog.pyo69370644editdlrm
AutoComplete.py90610644editdlrm
AutoComplete.pyc79970644editdlrm
AutoComplete.pyo79970644editdlrm
AutoCompleteWindow.py172010644editdlrm
AutoCompleteWindow.pyc125440644editdlrm
AutoCompleteWindow.pyo124810644editdlrm
AutoExpand.py24830644editdlrm
AutoExpand.pyc25750644editdlrm
AutoExpand.pyo25750644editdlrm
Bindings.py35020644editdlrm
Bindings.pyc50620644editdlrm
Bindings.pyo50620644editdlrm
CallTips.py76080644editdlrm
CallTips.pyc102190644editdlrm
CallTips.pyo102190644editdlrm
CallTipWindow.py59240644editdlrm
CallTipWindow.pyc61890644editdlrm
CallTipWindow.pyo61890644editdlrm
ChangeLog563930644editdlrm
ClassBrowser.py63690644editdlrm
ClassBrowser.pyc91600644editdlrm
ClassBrowser.pyo91600644editdlrm
CodeContext.py83470644editdlrm
CodeContext.pyc67130644editdlrm
CodeContext.pyo66670644editdlrm
ColorDelegator.py101500644editdlrm
ColorDelegator.pyc89420644editdlrm
ColorDelegator.pyo89420644editdlrm
config-extensions.def26970644editdlrm
config-highlight.def17400644editdlrm
config-keys.def75170644editdlrm
config-main.def25120644editdlrm
configDialog.py532290644editdlrm
configDialog.pyc448280644editdlrm
configDialog.pyo448280644editdlrm
configHandler.py288030644editdlrm
configHandler.pyc272680644editdlrm
configHandler.pyo272680644editdlrm
configHelpSourceEdit.py66800644editdlrm
configHelpSourceEdit.pyc67310644editdlrm
configHelpSourceEdit.pyo67310644editdlrm
configSectionNameDialog.py37200644editdlrm
configSectionNameDialog.pyc43050644editdlrm
configSectionNameDialog.pyo43050644editdlrm
CREDITS.txt18560644editdlrm
Debugger.py158180644editdlrm
Debugger.pyc169860644editdlrm
Debugger.pyo169860644editdlrm
Delegator.py8310644editdlrm
Delegator.pyc16070644editdlrm
Delegator.pyo16070644editdlrm
dynOptionMenuWidget.py13020644editdlrm
dynOptionMenuWidget.pyc16990644editdlrm
dynOptionMenuWidget.pyo16990644editdlrm
EditorWindow.py597340644editdlrm
EditorWindow.pyc527690644editdlrm
EditorWindow.pyo526660644editdlrm
extend.txt36520644editdlrm
FileList.py36600644editdlrm
FileList.pyc39880644editdlrm
FileList.pyo39530644editdlrm
FormatParagraph.py57340644editdlrm
FormatParagraph.pyc48030644editdlrm
FormatParagraph.pyo48030644editdlrm
GrepDialog.py40520644editdlrm
GrepDialog.pyc50370644editdlrm
GrepDialog.pyo50370644editdlrm
help.txt112230644editdlrm
HISTORY.txt103170644editdlrm
HyperParser.py103100644editdlrm
HyperParser.pyc66200644editdlrm
HyperParser.pyo66200644editdlrm
idle.py6640644editdlrm
idle.pyc5940644editdlrm
idle.pyo5940644editdlrm
idle.pyw6640644editdlrm
IdleHistory.py31450644editdlrm
IdleHistory.pyc32130644editdlrm
IdleHistory.pyo32130644editdlrm
idlever.py230644editdlrm
idlever.pyc1570644editdlrm
idlever.pyo1570644editdlrm
IOBinding.py209720644editdlrm
IOBinding.pyc177130644editdlrm
IOBinding.pyo177130644editdlrm
keybindingDialog.py124070644editdlrm
keybindingDialog.pyc123840644editdlrm
keybindingDialog.pyo123840644editdlrm
macosxSupport.py47240644editdlrm
macosxSupport.pyc48640644editdlrm
macosxSupport.pyo48640644editdlrm
MultiCall.py174700644editdlrm
MultiCall.pyc161420644editdlrm
MultiCall.pyo160660644editdlrm
MultiStatusBar.py7890644editdlrm
MultiStatusBar.pyc15380644editdlrm
MultiStatusBar.pyo15380644editdlrm
NEWS.txt271650644editdlrm
ObjectBrowser.py41560644editdlrm
ObjectBrowser.pyc66910644editdlrm
ObjectBrowser.pyo66910644editdlrm
OutputWindow.py43920644editdlrm
OutputWindow.pyc49900644editdlrm
OutputWindow.pyo49900644editdlrm
ParenMatch.py66270644editdlrm
ParenMatch.pyc69730644editdlrm
ParenMatch.pyo69730644editdlrm
PathBrowser.py26460644editdlrm
PathBrowser.pyc41350644editdlrm
PathBrowser.pyo41350644editdlrm
Percolator.py26160644editdlrm
Percolator.pyc36340644editdlrm
Percolator.pyo34400644editdlrm
PyParse.py195100644editdlrm
PyParse.pyc101790644editdlrm
PyParse.pyo97110644editdlrm
PyShell.py519090644editdlrm
PyShell.pyc464940644editdlrm
PyShell.pyo463930644editdlrm
README.txt26230644editdlrm
RemoteDebugger.py116600644editdlrm
RemoteDebugger.pyc162900644editdlrm
RemoteDebugger.pyo161350644editdlrm
RemoteObjectBrowser.py9420644editdlrm
RemoteObjectBrowser.pyc21470644editdlrm
RemoteObjectBrowser.pyo21470644editdlrm
ReplaceDialog.py51340644editdlrm
ReplaceDialog.pyc59540644editdlrm
ReplaceDialog.pyo59540644editdlrm
rpc.py202150644editdlrm
rpc.pyc218190644editdlrm
rpc.pyo217090644editdlrm
run.py113370644editdlrm
run.pyc121640644editdlrm
run.pyo121640644editdlrm
ScriptBinding.py77830644editdlrm
ScriptBinding.pyc75850644editdlrm
ScriptBinding.pyo75850644editdlrm
ScrolledList.py39950644editdlrm
ScrolledList.pyc61470644editdlrm
ScrolledList.pyo61470644editdlrm
SearchDialog.py20400644editdlrm
SearchDialog.pyc30060644editdlrm
SearchDialog.pyo30060644editdlrm
SearchDialogBase.py43850644editdlrm
SearchDialogBase.pyc54920644editdlrm
SearchDialogBase.pyo54920644editdlrm
SearchEngine.py67310644editdlrm
SearchEngine.pyc72150644editdlrm
SearchEngine.pyo72150644editdlrm
StackViewer.py38570644editdlrm
StackViewer.pyc59160644editdlrm
StackViewer.pyo59160644editdlrm
tabbedpages.py181880644editdlrm
tabbedpages.pyc180850644editdlrm
tabbedpages.pyo180850644editdlrm
textView.py32460644editdlrm
textView.pyc39650644editdlrm
textView.pyo39650644editdlrm
TODO.txt84780644editdlrm
ToolTip.py27360644editdlrm
ToolTip.pyc41260644editdlrm
ToolTip.pyo41260644editdlrm
TreeWidget.py152370644editdlrm
TreeWidget.pyc179060644editdlrm
TreeWidget.pyo179060644editdlrm
UndoDelegator.py102770644editdlrm
UndoDelegator.pyc125500644editdlrm
UndoDelegator.pyo125500644editdlrm
WidgetRedirector.py44760644editdlrm
WidgetRedirector.pyc53380644editdlrm
WidgetRedirector.pyo53380644editdlrm
WindowList.py24730644editdlrm
WindowList.pyc36240644editdlrm
WindowList.pyo36240644editdlrm
ZoomHeight.py13070644editdlrm
ZoomHeight.pyc16510644editdlrm
ZoomHeight.pyo16510644editdlrm
__init__.py370644editdlrm
__init__.pyc1250644editdlrm
__init__.pyo1250644editdlrm
Edit: /usr/lib/python2.6/idlelib/UndoDelegator.py (10277B)
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 main(): from idlelib.Percolator import Percolator root = Tk() root.wm_protocol("WM_DELETE_WINDOW", root.quit) text = Text() text.pack() text.focus_set() p = Percolator(text) d = UndoDelegator() p.insertfilter(d) root.mainloop() if __name__ == "__main__": main()