def _weight_by_hue(self):
grouped = {}<EOL>weights = []<EOL>for clr, rng, weight in self.ranges:<EOL><INDENT>h = clr.nearest_hue(primary=False)<EOL>if grouped.has_key(h):<EOL><INDENT>ranges, total_weight = grouped[h]<EOL>ranges.append((clr, rng, weight))<EOL>total_weight += weight<EOL>grouped[h] = (ranges, total_weight)<EOL><DEDENT>else:<EOL><INDENT>grouped[h] = ([(clr, rng, weight)], weight)<EOL><DEDENT><DEDENT>s = <NUM_LIT:1.0> * sum([w for r, w in grouped.values()])<EOL>grouped = [(grouped[h][<NUM_LIT:1>], grouped[h][<NUM_LIT:1>] / s, h, grouped[h][<NUM_LIT:0>]) for h in grouped]<EOL>grouped.sort()<EOL>grouped.reverse()<EOL>return grouped<EOL>
Returns a list of (hue, ranges, total weight, normalized total weight)-tuples.

ColorTheme is made up out of (color, range, weight) tuples.
For consistency with XML-output in the old Prism format
(i.e. <color>s made up of <shade>s) we need a group
weight per different hue.

The same is true for the swatch() draw method.
Hues are grouped as a single unit (e.g. dark red, intense red, weak red)
after which the dimensions (rows/columns) is determined.