Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Lib/idlelib/MultiCall.py

    r2 r391  
    3434import re
    3535import Tkinter
    36 import macosxSupport
     36from idlelib import macosxSupport
    3737
    3838# the event type constants, which define the meaning of mc_type
     
    108108# number of modifiers is the state - the most specific state comes first.
    109109_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)
    114113                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
     115def 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
    121135# _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 = []
     137for 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)
    127143
    128144class _ComplexBinder:
     
    156172            ishandlerrunning[:] = []
    157173            # 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[:] = []
    160177            if r:
    161178                return r
     
    186203
    187204    def bind(self, triplet, func):
    188         if not self.bindedfuncs.has_key(triplet[2]):
     205        if triplet[2] not in self.bindedfuncs:
    189206            self.bindedfuncs[triplet[2]] = [[] for s in _states]
    190207            for s in _states:
     
    297314
    298315        def __init__(self, *args, **kwargs):
    299             apply(widget.__init__, (self,)+args, kwargs)
     316            widget.__init__(self, *args, **kwargs)
    300317            # a dictionary which maps a virtual event to a tuple with:
    301318            #  0. the function binded
Note: See TracChangeset for help on using the changeset viewer.