Changeset 391 for python/trunk/Lib/idlelib/MultiCall.py
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Lib/idlelib/MultiCall.py
r2 r391 34 34 import re 35 35 import Tkinter 36 import macosxSupport36 from idlelib import macosxSupport 37 37 38 38 # the event type constants, which define the meaning of mc_type … … 108 108 # number of modifiers is the state - the most specific state comes first. 109 109 _states = range(1 << len(_modifiers)) 110 _state_names = [reduce(lambda x, y: x + y, 111 [_modifiers[i][0]+'-' for i in range(len(_modifiers)) 112 if (1 << i) & s], 113 "") 110 _state_names = [''.join(m[0]+'-' 111 for i, m in enumerate(_modifiers) 112 if (1 << i) & s) 114 113 for s in _states] 115 _state_subsets = map(lambda i: filter(lambda j: not (j & (~i)), _states), 116 _states) 117 for l in _state_subsets: 118 l.sort(lambda a, b, nummod = lambda x: len(filter(lambda i: (1<<i) & x, 119 range(len(_modifiers)))): 120 nummod(b) - nummod(a)) 114 115 def expand_substates(states): 116 '''For each item of states return a list containing all combinations of 117 that item with individual bits reset, sorted by the number of set bits. 118 ''' 119 def nbits(n): 120 "number of bits set in n base 2" 121 nb = 0 122 while n: 123 n, rem = divmod(n, 2) 124 nb += rem 125 return nb 126 statelist = [] 127 for state in states: 128 substates = list(set(state & x for x in states)) 129 substates.sort(key=nbits, reverse=True) 130 statelist.append(substates) 131 return statelist 132 133 _state_subsets = expand_substates(_states) 134 121 135 # _state_codes gives for each state, the portable code to be passed as mc_state 122 _state_codes = [reduce(lambda x, y: x | y, 123 [_modifier_masks[i] for i in range(len(_modifiers)) 124 if (1 << i) & s], 125 0) 126 for s in _states] 136 _state_codes = [] 137 for s in _states: 138 r = 0 139 for i in range(len(_modifiers)): 140 if (1 << i) & s: 141 r |= _modifier_masks[i] 142 _state_codes.append(r) 127 143 128 144 class _ComplexBinder: … … 156 172 ishandlerrunning[:] = [] 157 173 # Call all functions in doafterhandler and remove them from list 158 while doafterhandler: 159 doafterhandler.pop()() 174 for f in doafterhandler: 175 f() 176 doafterhandler[:] = [] 160 177 if r: 161 178 return r … … 186 203 187 204 def bind(self, triplet, func): 188 if not self.bindedfuncs.has_key(triplet[2]):205 if triplet[2] not in self.bindedfuncs: 189 206 self.bindedfuncs[triplet[2]] = [[] for s in _states] 190 207 for s in _states: … … 297 314 298 315 def __init__(self, *args, **kwargs): 299 apply(widget.__init__, (self,)+args,kwargs)316 widget.__init__(self, *args, **kwargs) 300 317 # a dictionary which maps a virtual event to a tuple with: 301 318 # 0. the function binded
Note:
See TracChangeset
for help on using the changeset viewer.