def threshold_get_color(self, value, name=None):
<EOL>if self._thresholds is None:<EOL><INDENT>self._thresholds_init()<EOL><DEDENT>if isinstance(name, tuple):<EOL><INDENT>name_used = "<STR_LIT>".format(name[<NUM_LIT:0>], name[<NUM_LIT:1>])<EOL>if name[<NUM_LIT:2>]:<EOL><INDENT>self._thresholds[name_used] = [<EOL>(x[<NUM_LIT:0>], self._get_color(x[<NUM_LIT:1>])) for x in name[<NUM_LIT:2>]<EOL>]<EOL><DEDENT>name = name[<NUM_LIT:0>]<EOL><DEDENT>else:<EOL><INDENT>name_used = name<EOL>if name_used not in self._thresholds:<EOL><INDENT>name_used = None<EOL><DEDENT><DEDENT>thresholds = self._thresholds.get(name_used)<EOL>color = None<EOL>try:<EOL><INDENT>value = float(value)<EOL><DEDENT>except (TypeError, ValueError):<EOL><INDENT>pass<EOL><DEDENT>if not thresholds or value in [None, "<STR_LIT>"]:<EOL><INDENT>pass<EOL><DEDENT>elif isinstance(value, basestring):<EOL><INDENT>for threshold in thresholds:<EOL><INDENT>if value == threshold[<NUM_LIT:0>]:<EOL><INDENT>color = threshold[<NUM_LIT:1>]<EOL>break<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>if self._get_config_setting("<STR_LIT>"):<EOL><INDENT>try:<EOL><INDENT>colors, minimum, maximum = self._threshold_gradients[name_used]<EOL><DEDENT>except KeyError:<EOL><INDENT>colors = self._gradients.make_threshold_gradient(<EOL>self, thresholds<EOL>)<EOL>minimum = min(thresholds)[<NUM_LIT:0>]<EOL>maximum = max(thresholds)[<NUM_LIT:0>]<EOL>self._threshold_gradients[name_used] = (<EOL>colors,<EOL>minimum,<EOL>maximum,<EOL>)<EOL><DEDENT>if value < minimum:<EOL><INDENT>color = colors[<NUM_LIT:0>]<EOL><DEDENT>elif value > maximum:<EOL><INDENT>color = colors[-<NUM_LIT:1>]<EOL><DEDENT>else:<EOL><INDENT>value -= minimum<EOL>col_index = int(<EOL>((len(colors) - <NUM_LIT:1>) / (maximum - minimum)) * value<EOL>)<EOL>color = colors[col_index]<EOL><DEDENT><DEDENT>else:<EOL><INDENT>color = thresholds[<NUM_LIT:0>][<NUM_LIT:1>]<EOL>for threshold in thresholds:<EOL><INDENT>if value >= threshold[<NUM_LIT:0>]:<EOL><INDENT>color = threshold[<NUM_LIT:1>]<EOL><DEDENT>else:<EOL><INDENT>break<EOL><DEDENT><DEDENT><DEDENT><DEDENT>except TypeError:<EOL><INDENT>color = None<EOL><DEDENT><DEDENT>if name:<EOL><INDENT>color_name = "<STR_LIT>" % name<EOL><DEDENT>else:<EOL><INDENT>color_name = "<STR_LIT>"<EOL><DEDENT>setattr(self._py3status_module, color_name, color)<EOL>return color<EOL>
Obtain color for a value using thresholds.

The value will be checked against any defined thresholds.  These should
have been set in the i3status configuration.  If more than one
threshold is needed for a module then the name can also be supplied.
If the user has not supplied a named threshold but has defined a
general one that will be used.

If the gradients config parameter is True then rather than sharp
thresholds we will use a gradient between the color values.

:param value: numerical value to be graded
:param name: accepts a string, otherwise 'threshold'
    accepts 3-tuples to allow name with different
    values eg ('name', 'key', 'thresholds')