Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../lib64/python2..../idlelib
File: MultiCall.py
"""
[0] Fix | Delete
MultiCall - a class which inherits its methods from a Tkinter widget (Text, for
[1] Fix | Delete
example), but enables multiple calls of functions per virtual event - all
[2] Fix | Delete
matching events will be called, not only the most specific one. This is done
[3] Fix | Delete
by wrapping the event functions - event_add, event_delete and event_info.
[4] Fix | Delete
MultiCall recognizes only a subset of legal event sequences. Sequences which
[5] Fix | Delete
are not recognized are treated by the original Tk handling mechanism. A
[6] Fix | Delete
more-specific event will be called before a less-specific event.
[7] Fix | Delete
[8] Fix | Delete
The recognized sequences are complete one-event sequences (no emacs-style
[9] Fix | Delete
Ctrl-X Ctrl-C, no shortcuts like <3>), for all types of events.
[10] Fix | Delete
Key/Button Press/Release events can have modifiers.
[11] Fix | Delete
The recognized modifiers are Shift, Control, Option and Command for Mac, and
[12] Fix | Delete
Control, Alt, Shift, Meta/M for other platforms.
[13] Fix | Delete
[14] Fix | Delete
For all events which were handled by MultiCall, a new member is added to the
[15] Fix | Delete
event instance passed to the binded functions - mc_type. This is one of the
[16] Fix | Delete
event type constants defined in this module (such as MC_KEYPRESS).
[17] Fix | Delete
For Key/Button events (which are handled by MultiCall and may receive
[18] Fix | Delete
modifiers), another member is added - mc_state. This member gives the state
[19] Fix | Delete
of the recognized modifiers, as a combination of the modifier constants
[20] Fix | Delete
also defined in this module (for example, MC_SHIFT).
[21] Fix | Delete
Using these members is absolutely portable.
[22] Fix | Delete
[23] Fix | Delete
The order by which events are called is defined by these rules:
[24] Fix | Delete
1. A more-specific event will be called before a less-specific event.
[25] Fix | Delete
2. A recently-binded event will be called before a previously-binded event,
[26] Fix | Delete
unless this conflicts with the first rule.
[27] Fix | Delete
Each function will be called at most once for each event.
[28] Fix | Delete
"""
[29] Fix | Delete
[30] Fix | Delete
import sys
[31] Fix | Delete
import string
[32] Fix | Delete
import re
[33] Fix | Delete
import Tkinter
[34] Fix | Delete
[35] Fix | Delete
# the event type constants, which define the meaning of mc_type
[36] Fix | Delete
MC_KEYPRESS=0; MC_KEYRELEASE=1; MC_BUTTONPRESS=2; MC_BUTTONRELEASE=3;
[37] Fix | Delete
MC_ACTIVATE=4; MC_CIRCULATE=5; MC_COLORMAP=6; MC_CONFIGURE=7;
[38] Fix | Delete
MC_DEACTIVATE=8; MC_DESTROY=9; MC_ENTER=10; MC_EXPOSE=11; MC_FOCUSIN=12;
[39] Fix | Delete
MC_FOCUSOUT=13; MC_GRAVITY=14; MC_LEAVE=15; MC_MAP=16; MC_MOTION=17;
[40] Fix | Delete
MC_MOUSEWHEEL=18; MC_PROPERTY=19; MC_REPARENT=20; MC_UNMAP=21; MC_VISIBILITY=22;
[41] Fix | Delete
# the modifier state constants, which define the meaning of mc_state
[42] Fix | Delete
MC_SHIFT = 1<<0; MC_CONTROL = 1<<2; MC_ALT = 1<<3; MC_META = 1<<5
[43] Fix | Delete
MC_OPTION = 1<<6; MC_COMMAND = 1<<7
[44] Fix | Delete
[45] Fix | Delete
# define the list of modifiers, to be used in complex event types.
[46] Fix | Delete
if sys.platform == "darwin":
[47] Fix | Delete
_modifiers = (("Shift",), ("Control",), ("Option",), ("Command",))
[48] Fix | Delete
_modifier_masks = (MC_SHIFT, MC_CONTROL, MC_OPTION, MC_COMMAND)
[49] Fix | Delete
else:
[50] Fix | Delete
_modifiers = (("Control",), ("Alt",), ("Shift",), ("Meta", "M"))
[51] Fix | Delete
_modifier_masks = (MC_CONTROL, MC_ALT, MC_SHIFT, MC_META)
[52] Fix | Delete
[53] Fix | Delete
# a dictionary to map a modifier name into its number
[54] Fix | Delete
_modifier_names = dict([(name, number)
[55] Fix | Delete
for number in range(len(_modifiers))
[56] Fix | Delete
for name in _modifiers[number]])
[57] Fix | Delete
[58] Fix | Delete
# A binder is a class which binds functions to one type of event. It has two
[59] Fix | Delete
# methods: bind and unbind, which get a function and a parsed sequence, as
[60] Fix | Delete
# returned by _parse_sequence(). There are two types of binders:
[61] Fix | Delete
# _SimpleBinder handles event types with no modifiers and no detail.
[62] Fix | Delete
# No Python functions are called when no events are binded.
[63] Fix | Delete
# _ComplexBinder handles event types with modifiers and a detail.
[64] Fix | Delete
# A Python function is called each time an event is generated.
[65] Fix | Delete
[66] Fix | Delete
class _SimpleBinder:
[67] Fix | Delete
def __init__(self, type, widget, widgetinst):
[68] Fix | Delete
self.type = type
[69] Fix | Delete
self.sequence = '<'+_types[type][0]+'>'
[70] Fix | Delete
self.widget = widget
[71] Fix | Delete
self.widgetinst = widgetinst
[72] Fix | Delete
self.bindedfuncs = []
[73] Fix | Delete
self.handlerid = None
[74] Fix | Delete
[75] Fix | Delete
def bind(self, triplet, func):
[76] Fix | Delete
if not self.handlerid:
[77] Fix | Delete
def handler(event, l = self.bindedfuncs, mc_type = self.type):
[78] Fix | Delete
event.mc_type = mc_type
[79] Fix | Delete
wascalled = {}
[80] Fix | Delete
for i in range(len(l)-1, -1, -1):
[81] Fix | Delete
func = l[i]
[82] Fix | Delete
if func not in wascalled:
[83] Fix | Delete
wascalled[func] = True
[84] Fix | Delete
r = func(event)
[85] Fix | Delete
if r:
[86] Fix | Delete
return r
[87] Fix | Delete
self.handlerid = self.widget.bind(self.widgetinst,
[88] Fix | Delete
self.sequence, handler)
[89] Fix | Delete
self.bindedfuncs.append(func)
[90] Fix | Delete
[91] Fix | Delete
def unbind(self, triplet, func):
[92] Fix | Delete
self.bindedfuncs.remove(func)
[93] Fix | Delete
if not self.bindedfuncs:
[94] Fix | Delete
self.widget.unbind(self.widgetinst, self.sequence, self.handlerid)
[95] Fix | Delete
self.handlerid = None
[96] Fix | Delete
[97] Fix | Delete
def __del__(self):
[98] Fix | Delete
if self.handlerid:
[99] Fix | Delete
self.widget.unbind(self.widgetinst, self.sequence, self.handlerid)
[100] Fix | Delete
[101] Fix | Delete
# An int in range(1 << len(_modifiers)) represents a combination of modifiers
[102] Fix | Delete
# (if the least significant bit is on, _modifiers[0] is on, and so on).
[103] Fix | Delete
# _state_subsets gives for each combination of modifiers, or *state*,
[104] Fix | Delete
# a list of the states which are a subset of it. This list is ordered by the
[105] Fix | Delete
# number of modifiers is the state - the most specific state comes first.
[106] Fix | Delete
_states = range(1 << len(_modifiers))
[107] Fix | Delete
_state_names = [''.join(m[0]+'-'
[108] Fix | Delete
for i, m in enumerate(_modifiers)
[109] Fix | Delete
if (1 << i) & s)
[110] Fix | Delete
for s in _states]
[111] Fix | Delete
[112] Fix | Delete
def expand_substates(states):
[113] Fix | Delete
'''For each item of states return a list containing all combinations of
[114] Fix | Delete
that item with individual bits reset, sorted by the number of set bits.
[115] Fix | Delete
'''
[116] Fix | Delete
def nbits(n):
[117] Fix | Delete
"number of bits set in n base 2"
[118] Fix | Delete
nb = 0
[119] Fix | Delete
while n:
[120] Fix | Delete
n, rem = divmod(n, 2)
[121] Fix | Delete
nb += rem
[122] Fix | Delete
return nb
[123] Fix | Delete
statelist = []
[124] Fix | Delete
for state in states:
[125] Fix | Delete
substates = list(set(state & x for x in states))
[126] Fix | Delete
substates.sort(key=nbits, reverse=True)
[127] Fix | Delete
statelist.append(substates)
[128] Fix | Delete
return statelist
[129] Fix | Delete
[130] Fix | Delete
_state_subsets = expand_substates(_states)
[131] Fix | Delete
[132] Fix | Delete
# _state_codes gives for each state, the portable code to be passed as mc_state
[133] Fix | Delete
_state_codes = []
[134] Fix | Delete
for s in _states:
[135] Fix | Delete
r = 0
[136] Fix | Delete
for i in range(len(_modifiers)):
[137] Fix | Delete
if (1 << i) & s:
[138] Fix | Delete
r |= _modifier_masks[i]
[139] Fix | Delete
_state_codes.append(r)
[140] Fix | Delete
[141] Fix | Delete
class _ComplexBinder:
[142] Fix | Delete
# This class binds many functions, and only unbinds them when it is deleted.
[143] Fix | Delete
# self.handlerids is the list of seqs and ids of binded handler functions.
[144] Fix | Delete
# The binded functions sit in a dictionary of lists of lists, which maps
[145] Fix | Delete
# a detail (or None) and a state into a list of functions.
[146] Fix | Delete
# When a new detail is discovered, handlers for all the possible states
[147] Fix | Delete
# are binded.
[148] Fix | Delete
[149] Fix | Delete
def __create_handler(self, lists, mc_type, mc_state):
[150] Fix | Delete
def handler(event, lists = lists,
[151] Fix | Delete
mc_type = mc_type, mc_state = mc_state,
[152] Fix | Delete
ishandlerrunning = self.ishandlerrunning,
[153] Fix | Delete
doafterhandler = self.doafterhandler):
[154] Fix | Delete
ishandlerrunning[:] = [True]
[155] Fix | Delete
event.mc_type = mc_type
[156] Fix | Delete
event.mc_state = mc_state
[157] Fix | Delete
wascalled = {}
[158] Fix | Delete
r = None
[159] Fix | Delete
for l in lists:
[160] Fix | Delete
for i in range(len(l)-1, -1, -1):
[161] Fix | Delete
func = l[i]
[162] Fix | Delete
if func not in wascalled:
[163] Fix | Delete
wascalled[func] = True
[164] Fix | Delete
r = l[i](event)
[165] Fix | Delete
if r:
[166] Fix | Delete
break
[167] Fix | Delete
if r:
[168] Fix | Delete
break
[169] Fix | Delete
ishandlerrunning[:] = []
[170] Fix | Delete
# Call all functions in doafterhandler and remove them from list
[171] Fix | Delete
for f in doafterhandler:
[172] Fix | Delete
f()
[173] Fix | Delete
doafterhandler[:] = []
[174] Fix | Delete
if r:
[175] Fix | Delete
return r
[176] Fix | Delete
return handler
[177] Fix | Delete
[178] Fix | Delete
def __init__(self, type, widget, widgetinst):
[179] Fix | Delete
self.type = type
[180] Fix | Delete
self.typename = _types[type][0]
[181] Fix | Delete
self.widget = widget
[182] Fix | Delete
self.widgetinst = widgetinst
[183] Fix | Delete
self.bindedfuncs = {None: [[] for s in _states]}
[184] Fix | Delete
self.handlerids = []
[185] Fix | Delete
# we don't want to change the lists of functions while a handler is
[186] Fix | Delete
# running - it will mess up the loop and anyway, we usually want the
[187] Fix | Delete
# change to happen from the next event. So we have a list of functions
[188] Fix | Delete
# for the handler to run after it finishes calling the binded functions.
[189] Fix | Delete
# It calls them only once.
[190] Fix | Delete
# ishandlerrunning is a list. An empty one means no, otherwise - yes.
[191] Fix | Delete
# this is done so that it would be mutable.
[192] Fix | Delete
self.ishandlerrunning = []
[193] Fix | Delete
self.doafterhandler = []
[194] Fix | Delete
for s in _states:
[195] Fix | Delete
lists = [self.bindedfuncs[None][i] for i in _state_subsets[s]]
[196] Fix | Delete
handler = self.__create_handler(lists, type, _state_codes[s])
[197] Fix | Delete
seq = '<'+_state_names[s]+self.typename+'>'
[198] Fix | Delete
self.handlerids.append((seq, self.widget.bind(self.widgetinst,
[199] Fix | Delete
seq, handler)))
[200] Fix | Delete
[201] Fix | Delete
def bind(self, triplet, func):
[202] Fix | Delete
if triplet[2] not in self.bindedfuncs:
[203] Fix | Delete
self.bindedfuncs[triplet[2]] = [[] for s in _states]
[204] Fix | Delete
for s in _states:
[205] Fix | Delete
lists = [ self.bindedfuncs[detail][i]
[206] Fix | Delete
for detail in (triplet[2], None)
[207] Fix | Delete
for i in _state_subsets[s] ]
[208] Fix | Delete
handler = self.__create_handler(lists, self.type,
[209] Fix | Delete
_state_codes[s])
[210] Fix | Delete
seq = "<%s%s-%s>"% (_state_names[s], self.typename, triplet[2])
[211] Fix | Delete
self.handlerids.append((seq, self.widget.bind(self.widgetinst,
[212] Fix | Delete
seq, handler)))
[213] Fix | Delete
doit = lambda: self.bindedfuncs[triplet[2]][triplet[0]].append(func)
[214] Fix | Delete
if not self.ishandlerrunning:
[215] Fix | Delete
doit()
[216] Fix | Delete
else:
[217] Fix | Delete
self.doafterhandler.append(doit)
[218] Fix | Delete
[219] Fix | Delete
def unbind(self, triplet, func):
[220] Fix | Delete
doit = lambda: self.bindedfuncs[triplet[2]][triplet[0]].remove(func)
[221] Fix | Delete
if not self.ishandlerrunning:
[222] Fix | Delete
doit()
[223] Fix | Delete
else:
[224] Fix | Delete
self.doafterhandler.append(doit)
[225] Fix | Delete
[226] Fix | Delete
def __del__(self):
[227] Fix | Delete
for seq, id in self.handlerids:
[228] Fix | Delete
self.widget.unbind(self.widgetinst, seq, id)
[229] Fix | Delete
[230] Fix | Delete
# define the list of event types to be handled by MultiEvent. the order is
[231] Fix | Delete
# compatible with the definition of event type constants.
[232] Fix | Delete
_types = (
[233] Fix | Delete
("KeyPress", "Key"), ("KeyRelease",), ("ButtonPress", "Button"),
[234] Fix | Delete
("ButtonRelease",), ("Activate",), ("Circulate",), ("Colormap",),
[235] Fix | Delete
("Configure",), ("Deactivate",), ("Destroy",), ("Enter",), ("Expose",),
[236] Fix | Delete
("FocusIn",), ("FocusOut",), ("Gravity",), ("Leave",), ("Map",),
[237] Fix | Delete
("Motion",), ("MouseWheel",), ("Property",), ("Reparent",), ("Unmap",),
[238] Fix | Delete
("Visibility",),
[239] Fix | Delete
)
[240] Fix | Delete
[241] Fix | Delete
# which binder should be used for every event type?
[242] Fix | Delete
_binder_classes = (_ComplexBinder,) * 4 + (_SimpleBinder,) * (len(_types)-4)
[243] Fix | Delete
[244] Fix | Delete
# A dictionary to map a type name into its number
[245] Fix | Delete
_type_names = dict([(name, number)
[246] Fix | Delete
for number in range(len(_types))
[247] Fix | Delete
for name in _types[number]])
[248] Fix | Delete
[249] Fix | Delete
_keysym_re = re.compile(r"^\w+$")
[250] Fix | Delete
_button_re = re.compile(r"^[1-5]$")
[251] Fix | Delete
def _parse_sequence(sequence):
[252] Fix | Delete
"""Get a string which should describe an event sequence. If it is
[253] Fix | Delete
successfully parsed as one, return a tuple containing the state (as an int),
[254] Fix | Delete
the event type (as an index of _types), and the detail - None if none, or a
[255] Fix | Delete
string if there is one. If the parsing is unsuccessful, return None.
[256] Fix | Delete
"""
[257] Fix | Delete
if not sequence or sequence[0] != '<' or sequence[-1] != '>':
[258] Fix | Delete
return None
[259] Fix | Delete
words = string.split(sequence[1:-1], '-')
[260] Fix | Delete
[261] Fix | Delete
modifiers = 0
[262] Fix | Delete
while words and words[0] in _modifier_names:
[263] Fix | Delete
modifiers |= 1 << _modifier_names[words[0]]
[264] Fix | Delete
del words[0]
[265] Fix | Delete
[266] Fix | Delete
if words and words[0] in _type_names:
[267] Fix | Delete
type = _type_names[words[0]]
[268] Fix | Delete
del words[0]
[269] Fix | Delete
else:
[270] Fix | Delete
return None
[271] Fix | Delete
[272] Fix | Delete
if _binder_classes[type] is _SimpleBinder:
[273] Fix | Delete
if modifiers or words:
[274] Fix | Delete
return None
[275] Fix | Delete
else:
[276] Fix | Delete
detail = None
[277] Fix | Delete
else:
[278] Fix | Delete
# _ComplexBinder
[279] Fix | Delete
if type in [_type_names[s] for s in ("KeyPress", "KeyRelease")]:
[280] Fix | Delete
type_re = _keysym_re
[281] Fix | Delete
else:
[282] Fix | Delete
type_re = _button_re
[283] Fix | Delete
[284] Fix | Delete
if not words:
[285] Fix | Delete
detail = None
[286] Fix | Delete
elif len(words) == 1 and type_re.match(words[0]):
[287] Fix | Delete
detail = words[0]
[288] Fix | Delete
else:
[289] Fix | Delete
return None
[290] Fix | Delete
[291] Fix | Delete
return modifiers, type, detail
[292] Fix | Delete
[293] Fix | Delete
def _triplet_to_sequence(triplet):
[294] Fix | Delete
if triplet[2]:
[295] Fix | Delete
return '<'+_state_names[triplet[0]]+_types[triplet[1]][0]+'-'+ \
[296] Fix | Delete
triplet[2]+'>'
[297] Fix | Delete
else:
[298] Fix | Delete
return '<'+_state_names[triplet[0]]+_types[triplet[1]][0]+'>'
[299] Fix | Delete
[300] Fix | Delete
_multicall_dict = {}
[301] Fix | Delete
def MultiCallCreator(widget):
[302] Fix | Delete
"""Return a MultiCall class which inherits its methods from the
[303] Fix | Delete
given widget class (for example, Tkinter.Text). This is used
[304] Fix | Delete
instead of a templating mechanism.
[305] Fix | Delete
"""
[306] Fix | Delete
if widget in _multicall_dict:
[307] Fix | Delete
return _multicall_dict[widget]
[308] Fix | Delete
[309] Fix | Delete
class MultiCall (widget):
[310] Fix | Delete
assert issubclass(widget, Tkinter.Misc)
[311] Fix | Delete
[312] Fix | Delete
def __init__(self, *args, **kwargs):
[313] Fix | Delete
widget.__init__(self, *args, **kwargs)
[314] Fix | Delete
# a dictionary which maps a virtual event to a tuple with:
[315] Fix | Delete
# 0. the function binded
[316] Fix | Delete
# 1. a list of triplets - the sequences it is binded to
[317] Fix | Delete
self.__eventinfo = {}
[318] Fix | Delete
self.__binders = [_binder_classes[i](i, widget, self)
[319] Fix | Delete
for i in range(len(_types))]
[320] Fix | Delete
[321] Fix | Delete
def bind(self, sequence=None, func=None, add=None):
[322] Fix | Delete
#print "bind(%s, %s, %s) called." % (sequence, func, add)
[323] Fix | Delete
if type(sequence) is str and len(sequence) > 2 and \
[324] Fix | Delete
sequence[:2] == "<<" and sequence[-2:] == ">>":
[325] Fix | Delete
if sequence in self.__eventinfo:
[326] Fix | Delete
ei = self.__eventinfo[sequence]
[327] Fix | Delete
if ei[0] is not None:
[328] Fix | Delete
for triplet in ei[1]:
[329] Fix | Delete
self.__binders[triplet[1]].unbind(triplet, ei[0])
[330] Fix | Delete
ei[0] = func
[331] Fix | Delete
if ei[0] is not None:
[332] Fix | Delete
for triplet in ei[1]:
[333] Fix | Delete
self.__binders[triplet[1]].bind(triplet, func)
[334] Fix | Delete
else:
[335] Fix | Delete
self.__eventinfo[sequence] = [func, []]
[336] Fix | Delete
return widget.bind(self, sequence, func, add)
[337] Fix | Delete
[338] Fix | Delete
def unbind(self, sequence, funcid=None):
[339] Fix | Delete
if type(sequence) is str and len(sequence) > 2 and \
[340] Fix | Delete
sequence[:2] == "<<" and sequence[-2:] == ">>" and \
[341] Fix | Delete
sequence in self.__eventinfo:
[342] Fix | Delete
func, triplets = self.__eventinfo[sequence]
[343] Fix | Delete
if func is not None:
[344] Fix | Delete
for triplet in triplets:
[345] Fix | Delete
self.__binders[triplet[1]].unbind(triplet, func)
[346] Fix | Delete
self.__eventinfo[sequence][0] = None
[347] Fix | Delete
return widget.unbind(self, sequence, funcid)
[348] Fix | Delete
[349] Fix | Delete
def event_add(self, virtual, *sequences):
[350] Fix | Delete
#print "event_add(%s,%s) was called"%(repr(virtual),repr(sequences))
[351] Fix | Delete
if virtual not in self.__eventinfo:
[352] Fix | Delete
self.__eventinfo[virtual] = [None, []]
[353] Fix | Delete
[354] Fix | Delete
func, triplets = self.__eventinfo[virtual]
[355] Fix | Delete
for seq in sequences:
[356] Fix | Delete
triplet = _parse_sequence(seq)
[357] Fix | Delete
if triplet is None:
[358] Fix | Delete
#print >> sys.stderr, "Seq. %s was added by Tkinter."%seq
[359] Fix | Delete
widget.event_add(self, virtual, seq)
[360] Fix | Delete
else:
[361] Fix | Delete
if func is not None:
[362] Fix | Delete
self.__binders[triplet[1]].bind(triplet, func)
[363] Fix | Delete
triplets.append(triplet)
[364] Fix | Delete
[365] Fix | Delete
def event_delete(self, virtual, *sequences):
[366] Fix | Delete
if virtual not in self.__eventinfo:
[367] Fix | Delete
return
[368] Fix | Delete
func, triplets = self.__eventinfo[virtual]
[369] Fix | Delete
for seq in sequences:
[370] Fix | Delete
triplet = _parse_sequence(seq)
[371] Fix | Delete
if triplet is None:
[372] Fix | Delete
#print >> sys.stderr, "Seq. %s was deleted by Tkinter."%seq
[373] Fix | Delete
widget.event_delete(self, virtual, seq)
[374] Fix | Delete
else:
[375] Fix | Delete
if func is not None:
[376] Fix | Delete
self.__binders[triplet[1]].unbind(triplet, func)
[377] Fix | Delete
triplets.remove(triplet)
[378] Fix | Delete
[379] Fix | Delete
def event_info(self, virtual=None):
[380] Fix | Delete
if virtual is None or virtual not in self.__eventinfo:
[381] Fix | Delete
return widget.event_info(self, virtual)
[382] Fix | Delete
else:
[383] Fix | Delete
return tuple(map(_triplet_to_sequence,
[384] Fix | Delete
self.__eventinfo[virtual][1])) + \
[385] Fix | Delete
widget.event_info(self, virtual)
[386] Fix | Delete
[387] Fix | Delete
def __del__(self):
[388] Fix | Delete
for virtual in self.__eventinfo:
[389] Fix | Delete
func, triplets = self.__eventinfo[virtual]
[390] Fix | Delete
if func:
[391] Fix | Delete
for triplet in triplets:
[392] Fix | Delete
self.__binders[triplet[1]].unbind(triplet, func)
[393] Fix | Delete
[394] Fix | Delete
[395] Fix | Delete
_multicall_dict[widget] = MultiCall
[396] Fix | Delete
return MultiCall
[397] Fix | Delete
[398] Fix | Delete
[399] Fix | Delete
def _multi_call(parent):
[400] Fix | Delete
root = Tkinter.Tk()
[401] Fix | Delete
root.title("Test MultiCall")
[402] Fix | Delete
width, height, x, y = list(map(int, re.split('[x+]', parent.geometry())))
[403] Fix | Delete
root.geometry("+%d+%d"%(x, y + 150))
[404] Fix | Delete
text = MultiCallCreator(Tkinter.Text)(root)
[405] Fix | Delete
text.pack()
[406] Fix | Delete
def bindseq(seq, n=[0]):
[407] Fix | Delete
def handler(event):
[408] Fix | Delete
print seq
[409] Fix | Delete
text.bind("<<handler%d>>"%n[0], handler)
[410] Fix | Delete
text.event_add("<<handler%d>>"%n[0], seq)
[411] Fix | Delete
n[0] += 1
[412] Fix | Delete
bindseq("<Key>")
[413] Fix | Delete
bindseq("<Control-Key>")
[414] Fix | Delete
bindseq("<Alt-Key-a>")
[415] Fix | Delete
bindseq("<Control-Key-a>")
[416] Fix | Delete
bindseq("<Alt-Control-Key-a>")
[417] Fix | Delete
bindseq("<Key-b>")
[418] Fix | Delete
bindseq("<Control-Button-1>")
[419] Fix | Delete
bindseq("<Button-2>")
[420] Fix | Delete
bindseq("<Alt-Button-1>")
[421] Fix | Delete
bindseq("<FocusOut>")
[422] Fix | Delete
bindseq("<Enter>")
[423] Fix | Delete
bindseq("<Leave>")
[424] Fix | Delete
root.mainloop()
[425] Fix | Delete
[426] Fix | Delete
if __name__ == "__main__":
[427] Fix | Delete
from idlelib.idle_test.htest import run
[428] Fix | Delete
run(_multi_call)
[429] Fix | Delete
[430] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function