from ui.qml_widget import Qml_Widget


class Qml_Circular_Gauge(Qml_Widget):
    def __init__(self, min_value, max_value, step, minor_step_n=None, value=None, ranges=None, unit="", angle=None):
        super().__init__()
        self.set("size", 350)
        self.set("padding", 5)
        if angle is None:
            self.set("min_angle", -60)
            self.set("max_angle", +60)
        elif type(angle) is int or type(angle) is float:
            self.set("min_angle", -(angle / 2))
            self.set("max_angle", +(angle / 2))
        elif type(angle) is list and len(angle) == 2:
            self.set("min_angle", min(angle))
            self.set("max_angle", max(angle))
        else:
            raise NotImplementedError("Bad circular gauge angle field")
        self.set("min", min_value)
        self.set("max", max_value)
        self.set("step", step)
        if minor_step_n is not None:
            self.set("minor_step_n", minor_step_n)
        self.set("unit", unit)
        if value is None:
            value = min
        self.set_value(value)
        if ranges is None:
            ranges = []
        self.set_ranges(ranges)

    def set_ranges(self, ranges=[]):
        self.set("colorRanges", ranges)

    def set_value(self, value=0):
        self.set("value", value)
