annotate light8/util.py @ 59:001646cd5349

all mousewheel events everywhere will now pass up the tree to be caught by all mousewheel events everywhere will now pass up the tree to be caught by higher widgets. if things get slow, this might be the problem
author drewp
date Tue, 09 Jul 2002 07:36:29 +0000
parents 71489bb71528
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
1 def maxes(dicts):
45b12307c695 Initial revision
drewp
parents:
diff changeset
2 '''
45b12307c695 Initial revision
drewp
parents:
diff changeset
3 ({'a' : 5, 'b' : 9}, {'a' : 10, 'b' : 943})
45b12307c695 Initial revision
drewp
parents:
diff changeset
4 '''
45b12307c695 Initial revision
drewp
parents:
diff changeset
5 newdict = {}
45b12307c695 Initial revision
drewp
parents:
diff changeset
6 for d in dicts:
45b12307c695 Initial revision
drewp
parents:
diff changeset
7 for k,v in d.items():
45b12307c695 Initial revision
drewp
parents:
diff changeset
8 newdict[k] = max(v, newdict.get(k, 0))
45b12307c695 Initial revision
drewp
parents:
diff changeset
9 return newdict
45b12307c695 Initial revision
drewp
parents:
diff changeset
10
45b12307c695 Initial revision
drewp
parents:
diff changeset
11 def scaledict(d,scl):
45b12307c695 Initial revision
drewp
parents:
diff changeset
12 # scales all values in dict and returns a new dict
45b12307c695 Initial revision
drewp
parents:
diff changeset
13 return dict([(k,v*scl) for k,v in d.items()])
45b12307c695 Initial revision
drewp
parents:
diff changeset
14
45b12307c695 Initial revision
drewp
parents:
diff changeset
15 # class Setting that scales, maxes
45
62c47c3a90cb util.py: subsetdict added. see docs
dmcc
parents: 4
diff changeset
16
62c47c3a90cb util.py: subsetdict added. see docs
dmcc
parents: 4
diff changeset
17 def subsetdict(d, dkeys, default=0):
51
71489bb71528 - Meet Fader. He is going to grow up and be a crossfader some day
dmcc
parents: 45
diff changeset
18 """Subset of dictionary d: only the keys in dkeys. If you plan on omitting
71489bb71528 - Meet Fader. He is going to grow up and be a crossfader some day
dmcc
parents: 45
diff changeset
19 keys, make sure you like the default."""
45
62c47c3a90cb util.py: subsetdict added. see docs
dmcc
parents: 4
diff changeset
20 newd = {} # dirty variables!
62c47c3a90cb util.py: subsetdict added. see docs
dmcc
parents: 4
diff changeset
21 for k in dkeys:
62c47c3a90cb util.py: subsetdict added. see docs
dmcc
parents: 4
diff changeset
22 newd[k] = d.get(k, default)
62c47c3a90cb util.py: subsetdict added. see docs
dmcc
parents: 4
diff changeset
23 return newd