示例#1
0
def check_if_coordinate_correct(coordinate):
    """
    Checks if coordinate (for example [a,b]) is correct. If a and b are ints and length of it is 2.
    :param coordinate:
    :return:
    """
    if len(coordinate) == 2:
        check_if_int(coordinate[0], "Incorrect one of coordinates from list")
        check_if_int(coordinate[1], "Incorrect one of coordinates from list")
    else:
        cm.handle_error("Incorrect length of one of coordinates")
示例#2
0
def check_if_int(to_check, message):
    """
    Checks if to_check is int, if not writes message and ends program.
    :param to_check:
    :param message:
    :return:
    """
    if to_check is not None:
        if not isinstance(to_check, int):
            cm.handle_error(message)
    return True
示例#3
0
def check_if_fields_exists(figure, list_of_fields):
    """
    Takes list of fields which should be in json for choosen figure and checks if they are.
    :param figure:
    :param list_of_fields:
    :return:
    """
    for field in list_of_fields:
        if figure.get(field) is None:
            cm.handle_error(
                "There is lack of {} in figure {} or there can be spelling mistake.".format(field, figure.get(cm.TYPE)))
示例#4
0
def prepare_for_checking(json_, figures):
    """
    Prepares for checking. Checks if figures list is empty or exists.
    :param figures:
    :param json_:
    :return:
    """
    global json
    json = json_
    if figures is None:
        cm.handle_error("There is no figures list.")
    elif len(figures) == 0:
        cm.handle_error("Figures list is empty. Nothing to draw. :-(")
示例#5
0
def check_if_polygon_correct(polygon):
    """
    Checks if polygon from json has everything correct.
    :param polygon:
    :return:
    """
    check_if_fields_exists(polygon, [cm.POINTS])
    points = polygon.get(cm.POINTS)
    if len(points) >= 3:
        check_if_list_of_coordinates_correct(points)
        check_if_colour_correct(polygon.get(cm.COLOR))
    else:
        cm.handle_error("Polygon has to have 3 or more points to be created.")
    return True
示例#6
0
 def parse(self, path):
     """
     Parses json to data field.
     :param path:
     :return:
     """
     self.delete()
     try:
         file = open(path)
         self.data = json.load(file)
     except (FileNotFoundError, IsADirectoryError):
         cm.handle_error("Path to json is not correct.")
     except JSONDecodeError:
         cm.handle_error(
             "There are some wrong `types` in json or it is wrong constructed (unnecessary characters,"
             " unclosed bracket.")
     file.close()
示例#7
0
def check_if_figure_correct(figure):
    """
    Checks if given figure from json has everything correct. If not ends program and writes message.
    :param figure:
    :return:
    """
    figure_type = figure.get(cm.TYPE)
    if figure_type == cm.POINT:
        check_if_point_correct(figure)
    elif figure_type == cm.POLYGON:
        check_if_polygon_correct(figure)
    elif figure_type == cm.RECTANGLE:
        check_if_rectangle_correct(figure)
    elif figure_type == cm.SQUARE:
        check_if_square_correct(figure)
    elif figure_type == cm.CIRCLE:
        check_if_circle_correct(figure)
    else:
        cm.handle_error("`{}` figure name is incorrect.".format(figure_type))
示例#8
0
def check_if_colour_correct(colour):
    """
    Checks if colour is correct (even if it is from palette).
    :param colour:
    :return:
    """
    global json
    if colour is not None:
        if cl.is_dec(colour.strip()) or cl.is_hex(colour.strip()):
            return True
        else:
            if json.get(cm.PALETTE) is not None:
                value = json.get(cm.PALETTE).get(colour)
                if value is not None:
                    if cl.is_dec(value) or cl.is_hex(value):
                        return True
                    else:
                        cm.handle_error("Color {}: {} in palette has incorrect value.".format(colour, value))
                else:
                    if colour not in cm.BASIC_COLOURS:
                        cm.handle_error("Colour `{}` is incorrect. Add it to palette or correct it.".format(colour))
            elif colour not in cm.BASIC_COLOURS:
                cm.handle_error("Colour `{}` is incorrect. Add it to palette or correct it.".format(colour))
    return True
示例#9
0
import sys
import src.drawing.json_to_figures as js
import src.common as cm

if len(sys.argv) == 4:
    if sys.argv[2] == "-o":
        cm.FILE_NAME = sys.argv[3]
    else:
        cm.handle_error("Incorrect arguments.")
elif len(sys.argv) != 2:
    cm.handle_error("Incorrect number of arguments.")

if sys.argv[1] == "None":
    js.json_to_figures(None)
else:
    js.json_to_figures(sys.argv[1])

# import sys
#
# sys.path.insert(0, "/home/kuba/Workspace/Python/project-2/src/drawing/colours.py")
# sys.path.insert(1, "/home/kuba/Workspace/Python/project-2/src/drawing/draw.py")
# sys.path.insert(2, "/home/kuba/Workspace/Python/project-2/src/drawing/json_to_figures.py")
# sys.path.insert(3, "/home/kuba/Workspace/Python/project-2/src/json/is_correct.py")
# sys.path.insert(4, "/home/kuba/Workspace/Python/project-2/src/json/operations.py")
#
# import os.path
#
# from drawing import json_to_figures