summaryrefslogtreecommitdiffstats
path: root/Lib/idlelib/Percolator.py
diff options
context:
space:
mode:
authorDavid Scherer <dscherer@cmu.edu>2000-08-15 01:13:23 (GMT)
committerDavid Scherer <dscherer@cmu.edu>2000-08-15 01:13:23 (GMT)
commit7aced17437a6b05bc4b0b5ff93aa6a5d3a374d68 (patch)
treece0576a16111fd86ac5f56ff4ec1500f29c4f8db /Lib/idlelib/Percolator.py
parent33a6da9971a923ceaaee1406d0feaa64b8d1759a (diff)
downloadcpython-7aced17437a6b05bc4b0b5ff93aa6a5d3a374d68.zip
cpython-7aced17437a6b05bc4b0b5ff93aa6a5d3a374d68.tar.gz
cpython-7aced17437a6b05bc4b0b5ff93aa6a5d3a374d68.tar.bz2
Initial revision
Diffstat (limited to 'Lib/idlelib/Percolator.py')
-rw-r--r--Lib/idlelib/Percolator.py85
1 files changed, 85 insertions, 0 deletions
diff --git a/Lib/idlelib/Percolator.py b/Lib/idlelib/Percolator.py
new file mode 100644
index 0000000..9def5f4
--- /dev/null
+++ b/Lib/idlelib/Percolator.py
@@ -0,0 +1,85 @@
+from WidgetRedirector import WidgetRedirector
+from Delegator import Delegator
+
+class Percolator:
+
+ def __init__(self, text):
+ # XXX would be nice to inherit from Delegator
+ self.text = text
+ self.redir = WidgetRedirector(text)
+ self.top = self.bottom = Delegator(text)
+ self.bottom.insert = self.redir.register("insert", self.insert)
+ self.bottom.delete = self.redir.register("delete", self.delete)
+ self.filters = []
+
+ def close(self):
+ while self.top is not self.bottom:
+ self.removefilter(self.top)
+ self.top = None
+ self.bottom.setdelegate(None); self.bottom = None
+ self.redir.close(); self.redir = None
+ self.text = None
+
+ def insert(self, index, chars, tags=None):
+ # Could go away if inheriting from Delegator
+ self.top.insert(index, chars, tags)
+
+ def delete(self, index1, index2=None):
+ # Could go away if inheriting from Delegator
+ self.top.delete(index1, index2)
+
+ def insertfilter(self, filter):
+ # Perhaps rename to pushfilter()?
+ assert isinstance(filter, Delegator)
+ assert filter.delegate is None
+ filter.setdelegate(self.top)
+ self.top = filter
+
+ def removefilter(self, filter):
+ # XXX Perhaps should only support popfilter()?
+ assert isinstance(filter, Delegator)
+ assert filter.delegate is not None
+ f = self.top
+ if f is filter:
+ self.top = filter.delegate
+ filter.setdelegate(None)
+ else:
+ while f.delegate is not filter:
+ assert f is not self.bottom
+ f.resetcache()
+ f = f.delegate
+ f.setdelegate(filter.delegate)
+ filter.setdelegate(None)
+
+
+def main():
+ class Tracer(Delegator):
+ def __init__(self, name):
+ self.name = name
+ Delegator.__init__(self, None)
+ def insert(self, *args):
+ print self.name, ": insert", args
+ apply(self.delegate.insert, args)
+ def delete(self, *args):
+ print self.name, ": delete", args
+ apply(self.delegate.delete, args)
+ from Tkinter import *
+ root = Tk()
+ root.wm_protocol("WM_DELETE_WINDOW", root.quit)
+ text = Text()
+ text.pack()
+ text.focus_set()
+ p = Percolator(text)
+ t1 = Tracer("t1")
+ t2 = Tracer("t2")
+ p.insertfilter(t1)
+ p.insertfilter(t2)
+ root.mainloop()
+ p.removefilter(t2)
+ root.mainloop()
+ p.insertfilter(t2)
+ p.removefilter(t1)
+ root.mainloop()
+
+if __name__ == "__main__":
+ main()