def __init__(self, display, layout_json):
        self.json = layout_json
        if "view_type" not in layout_json:
            raise MissingTypeError
        if layout_json["view_type"] != "Polygon":
            raise IncorrectTypeError(
                "view_type '{}' does not match Layout Class 'Line'".format(layout_json["view_type"])
            )
        self._display = display
        if "attributes" in layout_json:
            _missing_attrs = []
            for attribute in REQUIRED_ATTRIBUTES:
                if attribute not in layout_json['attributes']:
                    _missing_attrs.append(attribute)
            if len(_missing_attrs) > 0:
                raise MissingRequiredAttributesError("Missing required attributes: {}".format(_missing_attrs))
            _outline = 0xFFFFFF

            if "outline" in layout_json["attributes"]:
                _outline = int(layout_json["attributes"]["outline"], 16)

            _points = []
            if "points" in layout_json["attributes"]:
                for _point in layout_json["attributes"]["points"]:
                    _points.append((self.keyword_compiler(_point[0]),self.keyword_compiler(_point[1])))

            self.polygon = Polygon(_points, outline=_outline)
            self.view = self.polygon
        else:
            raise MissingAttributesError()
    def __init__(self, display, layout_json):
        self.json = layout_json
        if "view_type" not in layout_json:
            raise MissingTypeError
        if layout_json["view_type"] != "Circle":
            raise IncorrectTypeError(
                "view_type '{}' does not match Layout Class 'Circle'".format(layout_json["view_type"])
            )
        self._display = display
        if "attributes" in layout_json:
            _missing_attrs = []
            for attribute in REQUIRED_ATTRIBUTES:
                if attribute not in layout_json['attributes']:
                    _missing_attrs.append(attribute)
            if len(_missing_attrs) > 0:
                raise MissingRequiredAttributesError("Missing required attributes: {}".format(_missing_attrs))

            _outline = 0xFFFFFF
            if "outline" in layout_json["attributes"]:
                _outline = int(layout_json["attributes"]["outline"], 16)

            _fill = 0x000000
            if "fill" in layout_json["attributes"]:
                _fill = int(layout_json["attributes"]["fill"], 16)

            _stroke = 0
            if "stroke" in layout_json["attributes"]:
                _stroke = self.keyword_compiler(layout_json["attributes"]["stroke"])


            _r = 0
            if "radius" in layout_json["attributes"]:
                _r = self.keyword_compiler(layout_json["attributes"]["radius"])

            _width = _r * 2
            _height = _r * 2

            _x = 0
            if "x" in layout_json["attributes"]:
                _x = self.keyword_compiler(layout_json["attributes"]["x"], {"WIDTH":_width, "HEIGHT": _height})

            _y = 0
            if "y" in layout_json["attributes"]:
                _y = self.keyword_compiler(layout_json["attributes"]["y"], {"WIDTH":_width, "HEIGHT": _height})

            self.circle = Circle(_x, _y, _r, fill=_fill, outline=_outline)
            self.view = self.circle
        else:
            raise MissingAttributesError()
Пример #3
0
    def __init__(self, display, layout_json):
        self.json = layout_json
        if "view_type" not in layout_json:
            raise MissingTypeError
        if layout_json["view_type"] != "Line":
            raise IncorrectTypeError(
                "view_type '{}' does not match Layout Class 'Line'".format(
                    layout_json["view_type"]))
        self._display = display
        if "attributes" in layout_json:
            _missing_attrs = []
            for attribute in REQUIRED_ATTRIBUTES:
                if attribute not in layout_json['attributes']:
                    _missing_attrs.append(attribute)
            if len(_missing_attrs) > 0:
                raise MissingRequiredAttributesError(
                    "Missing required attributes: {}".format(_missing_attrs))

            _color = 0xFFFFFF
            if "color" in layout_json["attributes"]:
                _color = int(layout_json["attributes"]["color"], 16)

            _x0 = 0
            if "x0" in layout_json["attributes"]:
                _x0 = self.keyword_compiler(layout_json["attributes"]["x0"])

            _x1 = 0
            if "x1" in layout_json["attributes"]:
                _x1 = self.keyword_compiler(layout_json["attributes"]["x1"])

            _y0 = 0
            if "y0" in layout_json["attributes"]:
                _y0 = self.keyword_compiler(layout_json["attributes"]["y0"])

            _y1 = 0
            if "y1" in layout_json["attributes"]:
                _y1 = self.keyword_compiler(layout_json["attributes"]["y1"])

            self.line = Line(_x0, _y0, _x1, _y1, color=_color)
            self.view = self.line
        else:
            raise MissingAttributesError()
Пример #4
0
    def __init__(self, display, layout_json):
        self.json = layout_json
        if "view_type" not in layout_json:
            raise MissingTypeError
        if layout_json["view_type"] != "Triangle":
            raise IncorrectTypeError(
                "view_type '{}' does not match Layout Class 'Triangle'".format(
                    layout_json["view_type"]))
        self._display = display
        if "attributes" in layout_json:
            _missing_attrs = []
            for attribute in REQUIRED_ATTRIBUTES:
                if attribute not in layout_json['attributes']:
                    _missing_attrs.append(attribute)
            if len(_missing_attrs) > 0:
                raise MissingRequiredAttributesError(
                    "Missing required attributes: {}".format(_missing_attrs))

            _outline = 0xFFFFFF
            if "outline" in layout_json["attributes"]:
                _outline = int(layout_json["attributes"]["outline"], 16)

            _fill = 0x000000
            if "fill" in layout_json["attributes"]:
                _fill = int(layout_json["attributes"]["fill"], 16)

            _x0 = 0
            if "x0" in layout_json["attributes"]:
                _x0 = self.keyword_compiler(layout_json["attributes"]["x0"])

            _x1 = 0
            if "x1" in layout_json["attributes"]:
                _x1 = self.keyword_compiler(layout_json["attributes"]["x1"])

            _x2 = 0
            if "x2" in layout_json["attributes"]:
                _x2 = self.keyword_compiler(layout_json["attributes"]["x2"])

            _y0 = 0
            if "y0" in layout_json["attributes"]:
                _y0 = self.keyword_compiler(layout_json["attributes"]["y0"])

            _y1 = 0
            if "y1" in layout_json["attributes"]:
                _y1 = self.keyword_compiler(layout_json["attributes"]["y1"])

            _y2 = 0
            if "y2" in layout_json["attributes"]:
                _y2 = self.keyword_compiler(layout_json["attributes"]["y2"])

            self.triangle = Triangle(_x0,
                                     _y0,
                                     _x1,
                                     _y1,
                                     _x2,
                                     _y2,
                                     fill=_fill,
                                     outline=_outline)

            self.view = self.triangle
        else:
            raise MissingAttributesError()
Пример #5
0
    def __init__(self, display, layout_json):
        self.json = layout_json
        if "view_type" not in layout_json:
            raise MissingTypeError
        if layout_json["view_type"] != "SparkLine":
            raise IncorrectTypeError(
                "view_type '{}' does not match Layout Class 'SparkLine'".
                format(layout_json["view_type"]))
        self._display = display
        if "attributes" in layout_json:
            _missing_attrs = []
            for attribute in REQUIRED_ATTRIBUTES:
                if attribute not in layout_json['attributes']:
                    _missing_attrs.append(attribute)
            if len(_missing_attrs) > 0:
                raise MissingRequiredAttributesError(
                    "Missing required attributes: {}".format(_missing_attrs))

            _color = 0xFFFFFF
            if "color" in layout_json["attributes"]:
                _outline = int(layout_json["attributes"]["color"], 16)

            _width = 0
            if "width" in layout_json["attributes"]:
                _width = self.keyword_compiler(
                    layout_json["attributes"]["width"])

            _height = 0
            if "height" in layout_json["attributes"]:
                _height = self.keyword_compiler(
                    layout_json["attributes"]["height"])

            _y_min = None
            if "y_min" in layout_json["attributes"]:
                _y_min = self.keyword_compiler(
                    layout_json["attributes"]["y_min"])

            _x_min = None
            if "x_min" in layout_json["attributes"]:
                _x_min = self.keyword_compiler(
                    layout_json["attributes"]["x_min"])

            _max_items = 10
            if "max_items" in layout_json["attributes"]:
                _max_items = self.keyword_compiler(
                    layout_json["attributes"]["max_items"])

            _x = 0
            if "x" in layout_json["attributes"]:
                _x = self.keyword_compiler(layout_json["attributes"]["x"], {
                    "WIDTH": _width,
                    "HEIGHT": _height
                })

            _y = 0
            if "y" in layout_json["attributes"]:
                _y = self.keyword_compiler(layout_json["attributes"]["y"], {
                    "WIDTH": _width,
                    "HEIGHT": _height
                })

            _points = None
            if "points" in layout_json["attributes"]:
                _points = layout_json["attributes"]["points"]

            self.sparkline = Sparkline(_width,
                                       _height,
                                       _max_items,
                                       y_min=_y_min,
                                       y_max=_x_min,
                                       x=_x,
                                       y=_y,
                                       color=_color)

            if _points != None:
                for _point in _points:
                    self.sparkline.add_value(_point)

            self.view = self.sparkline
        else:
            raise MissingAttributesError()
Пример #6
0
    def __init__(self, display, layout_json):
        self.json = layout_json
        if "view_type" not in layout_json:
            raise MissingTypeError
        if layout_json["view_type"] != "Button":
            raise IncorrectTypeError(
                "view_type '{}' does not match Layout Class 'Button'".format(
                    layout_json["view_type"]))
        self._display = display
        if "attributes" in layout_json:
            _missing_attrs = []
            for attribute in REQUIRED_ATTRIBUTES:
                if attribute not in layout_json['attributes']:
                    _missing_attrs.append(attribute)
            if len(_missing_attrs) > 0:
                raise MissingRequiredAttributesError(
                    "Missing required attributes: {}".format(_missing_attrs))

            _outline = 0xFFFFFF
            if "outline_color" in layout_json["attributes"]:
                _outline = int(layout_json["attributes"]["outline_color"], 16)

            _fill = 0x444444
            if "fill_color" in layout_json["attributes"]:
                _fill = int(layout_json["attributes"]["fill_color"], 16)

            _label_color = 0xFFFFFF
            if "label_color" in layout_json["attributes"]:
                _label_color = int(layout_json["attributes"]["label_color"],
                                   16)

            _style = Button.ROUNDRECT
            if "style" in layout_json["attributes"]:
                _styles = {
                    "RECT": Button.RECT,
                    "ROUNDRECT": Button.ROUNDRECT,
                    "SHADOWRECT": Button.SHADOWRECT,
                    "SHADOWROUNDRECT": Button.SHADOWROUNDRECT
                }
                if layout_json["attributes"]["style"] in _styles.keys():
                    _style = _styles[layout_json["attributes"]["style"]]
                else:
                    raise InvalidAttributeValue(
                        "'{}'.\nValid values are: [{}]".format(
                            layout_json["attributes"]["style"],
                            ", ".join(_styles.keys())))

            _label = ""
            if "label" in layout_json["attributes"]:
                _label = layout_json["attributes"]["label"]

            _width = 0
            if "width" in layout_json["attributes"]:
                _width = self.keyword_compiler(
                    layout_json["attributes"]["width"])

            _height = 0
            if "height" in layout_json["attributes"]:
                _height = self.keyword_compiler(
                    layout_json["attributes"]["height"])

            _font = terminalio.FONT
            if "font" in layout_json["attributes"]:
                _font = self.keyword_compiler(
                    layout_json["attributes"]["font"])

            _x = 0
            if "x" in layout_json["attributes"]:
                _x = self.keyword_compiler(layout_json["attributes"]["x"], {
                    "WIDTH": _width,
                    "HEIGHT": _height
                })

            _y = 0
            if "y" in layout_json["attributes"]:
                _y = self.keyword_compiler(layout_json["attributes"]["y"], {
                    "WIDTH": _width,
                    "HEIGHT": _height
                })

            print(_label)
            self.button = Button(x=_x,
                                 y=_y,
                                 width=_width,
                                 height=_height,
                                 style=_style,
                                 fill_color=_fill,
                                 outline_color=_outline,
                                 label=_label,
                                 label_color=_label_color,
                                 label_font=_font)
            self.view = self.button

        else:
            raise MissingAttributesError()