def colour_for_point(mlog, point, instance, options):
    global colour_expression_exceptions, colour_source_max, colour_source_min
    '''indicate a colour to be used to plot point'''
    source = getattr(options, "colour_source", "flightmode")
    if source == "flightmode":
        return colour_for_point_flightmode(mlog, point, instance, options)

    # evaluate source as an expression which should return a
    # number in the range 0..255
    try:
        v = eval(source, globals(),mlog.messages)
    except Exception as e:
        str_e = str(e)
        try:
            count = colour_expression_exceptions[str_e]
        except KeyError:
            colour_expression_exceptions[str_e] = 0
            count = 0
        if count > 100:
            print("Too many exceptions processing (%s): %s" % (source, str_e))
            sys.exit(1)
        colour_expression_exceptions[str_e] += 1
        v = 0

    # we don't use evaluate_expression as we want the exceptions...
#    v = mavutil.evaluate_expression(source, mlog.messages)

    if v is None:
        v = 0
    elif isinstance(v, str):
        print("colour expression returned a string: %s" % v)
        sys.exit(1)
    elif v < 0:
        print("colour expression returned %d (< 0)" % v)
        v = 0
    elif v > 255:
        print("colour expression returned %d (> 255)" % v)
        v = 255

    if v < colour_source_min:
        colour_source_min = v
    if v > colour_source_max:
        colour_source_max = v

    r = 255
    g = 255
    b = v
    return (b,b,b)
def colour_for_point ( mlog , point , instance , options ) : global colour_expression_exceptions , colour_source_max , colour_source_min source = getattr ( options , "colour_source" , "flightmode" ) if source == "flightmode" : return colour_for_point_flightmode ( mlog , point , instance , options ) try : v = eval ( source , globals ( ) , mlog . messages ) except Exception as e : str_e = str ( e ) try : count = colour_expression_exceptions [ str_e ] except KeyError : colour_expression_exceptions [ str_e ] = 0 count = 0 if count > 100 : print ( "Too many exceptions processing (%s): %s" % ( source , str_e ) ) sys . exit ( 1 ) colour_expression_exceptions [ str_e ] += 1 v = 0 if v is None : v = 0 elif isinstance ( v , str ) : print ( "colour expression returned a string: %s" % v ) sys . exit ( 1 ) elif v < 0 : print ( "colour expression returned %d (< 0)" % v ) v = 0 elif v > 255 : print ( "colour expression returned %d (> 255)" % v ) v = 255 if v < colour_source_min : colour_source_min = v if v > colour_source_max : colour_source_max = v r = 255 g = 255 b = v return ( b , b , b )
indicate a colour to be used to plot point