Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../lib64/python2..../idlelib
File: Percolator.py
from idlelib.WidgetRedirector import WidgetRedirector
[0] Fix | Delete
from idlelib.Delegator import Delegator
[1] Fix | Delete
[2] Fix | Delete
class Percolator:
[3] Fix | Delete
[4] Fix | Delete
def __init__(self, text):
[5] Fix | Delete
# XXX would be nice to inherit from Delegator
[6] Fix | Delete
self.text = text
[7] Fix | Delete
self.redir = WidgetRedirector(text)
[8] Fix | Delete
self.top = self.bottom = Delegator(text)
[9] Fix | Delete
self.bottom.insert = self.redir.register("insert", self.insert)
[10] Fix | Delete
self.bottom.delete = self.redir.register("delete", self.delete)
[11] Fix | Delete
self.filters = []
[12] Fix | Delete
[13] Fix | Delete
def close(self):
[14] Fix | Delete
while self.top is not self.bottom:
[15] Fix | Delete
self.removefilter(self.top)
[16] Fix | Delete
self.top = None
[17] Fix | Delete
self.bottom.setdelegate(None); self.bottom = None
[18] Fix | Delete
self.redir.close(); self.redir = None
[19] Fix | Delete
self.text = None
[20] Fix | Delete
[21] Fix | Delete
def insert(self, index, chars, tags=None):
[22] Fix | Delete
# Could go away if inheriting from Delegator
[23] Fix | Delete
self.top.insert(index, chars, tags)
[24] Fix | Delete
[25] Fix | Delete
def delete(self, index1, index2=None):
[26] Fix | Delete
# Could go away if inheriting from Delegator
[27] Fix | Delete
self.top.delete(index1, index2)
[28] Fix | Delete
[29] Fix | Delete
def insertfilter(self, filter):
[30] Fix | Delete
# Perhaps rename to pushfilter()?
[31] Fix | Delete
assert isinstance(filter, Delegator)
[32] Fix | Delete
assert filter.delegate is None
[33] Fix | Delete
filter.setdelegate(self.top)
[34] Fix | Delete
self.top = filter
[35] Fix | Delete
[36] Fix | Delete
def removefilter(self, filter):
[37] Fix | Delete
# XXX Perhaps should only support popfilter()?
[38] Fix | Delete
assert isinstance(filter, Delegator)
[39] Fix | Delete
assert filter.delegate is not None
[40] Fix | Delete
f = self.top
[41] Fix | Delete
if f is filter:
[42] Fix | Delete
self.top = filter.delegate
[43] Fix | Delete
filter.setdelegate(None)
[44] Fix | Delete
else:
[45] Fix | Delete
while f.delegate is not filter:
[46] Fix | Delete
assert f is not self.bottom
[47] Fix | Delete
f.resetcache()
[48] Fix | Delete
f = f.delegate
[49] Fix | Delete
f.setdelegate(filter.delegate)
[50] Fix | Delete
filter.setdelegate(None)
[51] Fix | Delete
[52] Fix | Delete
[53] Fix | Delete
def _percolator(parent):
[54] Fix | Delete
import Tkinter as tk
[55] Fix | Delete
import re
[56] Fix | Delete
class Tracer(Delegator):
[57] Fix | Delete
def __init__(self, name):
[58] Fix | Delete
self.name = name
[59] Fix | Delete
Delegator.__init__(self, None)
[60] Fix | Delete
def insert(self, *args):
[61] Fix | Delete
print self.name, ": insert", args
[62] Fix | Delete
self.delegate.insert(*args)
[63] Fix | Delete
def delete(self, *args):
[64] Fix | Delete
print self.name, ": delete", args
[65] Fix | Delete
self.delegate.delete(*args)
[66] Fix | Delete
root = tk.Tk()
[67] Fix | Delete
root.title("Test Percolator")
[68] Fix | Delete
width, height, x, y = list(map(int, re.split('[x+]', parent.geometry())))
[69] Fix | Delete
root.geometry("+%d+%d"%(x, y + 150))
[70] Fix | Delete
text = tk.Text(root)
[71] Fix | Delete
p = Percolator(text)
[72] Fix | Delete
t1 = Tracer("t1")
[73] Fix | Delete
t2 = Tracer("t2")
[74] Fix | Delete
[75] Fix | Delete
def toggle1():
[76] Fix | Delete
if var1.get() == 0:
[77] Fix | Delete
var1.set(1)
[78] Fix | Delete
p.insertfilter(t1)
[79] Fix | Delete
elif var1.get() == 1:
[80] Fix | Delete
var1.set(0)
[81] Fix | Delete
p.removefilter(t1)
[82] Fix | Delete
[83] Fix | Delete
def toggle2():
[84] Fix | Delete
if var2.get() == 0:
[85] Fix | Delete
var2.set(1)
[86] Fix | Delete
p.insertfilter(t2)
[87] Fix | Delete
elif var2.get() == 1:
[88] Fix | Delete
var2.set(0)
[89] Fix | Delete
p.removefilter(t2)
[90] Fix | Delete
[91] Fix | Delete
text.pack()
[92] Fix | Delete
var1 = tk.IntVar()
[93] Fix | Delete
cb1 = tk.Checkbutton(root, text="Tracer1", command=toggle1, variable=var1)
[94] Fix | Delete
cb1.pack()
[95] Fix | Delete
var2 = tk.IntVar()
[96] Fix | Delete
cb2 = tk.Checkbutton(root, text="Tracer2", command=toggle2, variable=var2)
[97] Fix | Delete
cb2.pack()
[98] Fix | Delete
[99] Fix | Delete
if __name__ == "__main__":
[100] Fix | Delete
from idlelib.idle_test.htest import run
[101] Fix | Delete
run(_percolator)
[102] Fix | Delete
[103] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function