diff options
author | Florent Xicluna <florent.xicluna@gmail.com> | 2010-04-02 07:24:52 (GMT) |
---|---|---|
committer | Florent Xicluna <florent.xicluna@gmail.com> | 2010-04-02 07:24:52 (GMT) |
commit | d630c04ab1ab35e2ec6eeeaba9bdcb9f8e730e78 (patch) | |
tree | f3dbe58315387ba5b3c26e7ed37d37b5ebf3d711 /Lib/idlelib/MultiCall.py | |
parent | f28dd0d1bfd85e5285894bfac54f6668d7217210 (diff) | |
download | cpython-d630c04ab1ab35e2ec6eeeaba9bdcb9f8e730e78.zip cpython-d630c04ab1ab35e2ec6eeeaba9bdcb9f8e730e78.tar.gz cpython-d630c04ab1ab35e2ec6eeeaba9bdcb9f8e730e78.tar.bz2 |
#7092: Fix additional "-3" warnings in the idlelib package, and convert to absolute imports.
Diffstat (limited to 'Lib/idlelib/MultiCall.py')
-rw-r--r-- | Lib/idlelib/MultiCall.py | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/Lib/idlelib/MultiCall.py b/Lib/idlelib/MultiCall.py index 53276d9..b81c5ed 100644 --- a/Lib/idlelib/MultiCall.py +++ b/Lib/idlelib/MultiCall.py @@ -33,7 +33,7 @@ import sys import string import re import Tkinter -import macosxSupport +from idlelib import macosxSupport # the event type constants, which define the meaning of mc_type MC_KEYPRESS=0; MC_KEYRELEASE=1; MC_BUTTONPRESS=2; MC_BUTTONRELEASE=3; @@ -111,12 +111,27 @@ _state_names = [''.join(m[0]+'-' for i, m in enumerate(_modifiers) if (1 << i) & s) for s in _states] -_state_subsets = map(lambda i: filter(lambda j: not (j & (~i)), _states), - _states) -for l in _state_subsets: - l.sort(lambda a, b, nummod = lambda x: len(filter(lambda i: (1<<i) & x, - range(len(_modifiers)))): - nummod(b) - nummod(a)) + +def expand_substates(states): + '''For each item of states return a list containing all combinations of + that item with individual bits reset, sorted by the number of set bits. + ''' + def nbits(n): + "number of bits set in n base 2" + nb = 0 + while n: + n, rem = divmod(n, 2) + nb += rem + return nb + statelist = [] + for state in states: + substates = list(set(state & x for x in states)) + substates.sort(key=nbits, reverse=True) + statelist.append(substates) + return statelist + +_state_subsets = expand_substates(_states) + # _state_codes gives for each state, the portable code to be passed as mc_state _state_codes = [] for s in _states: @@ -297,7 +312,7 @@ def MultiCallCreator(widget): assert issubclass(widget, Tkinter.Misc) def __init__(self, *args, **kwargs): - apply(widget.__init__, (self,)+args, kwargs) + widget.__init__(self, *args, **kwargs) # a dictionary which maps a virtual event to a tuple with: # 0. the function binded # 1. a list of triplets - the sequences it is binded to |