def draw_pattern(self): path = './patterns/' + self.pattern lines, ellipses, rectangles, polygons = get_picture.read_file(path) x, y = self.get_start_pattern(lines, ellipses, rectangles, polygons) if len(lines) != 0: for line in lines: points, pencil = get_picture.get_inf_line(line) new_points = self.get_new_points(points, [], x, y) self.draw_line(new_points, pencil) if len(ellipses) != 0: for ellipse in ellipses: points, width, height,\ pencil, fill = get_picture.get_inf_ellipse(ellipse) new_points = self.get_new_points(points, [], x, y) width = width * self.figure_size / 180 height = height * self.figure_size / 180 self.draw_ellipse(new_points, width, height, pencil, fill) if len(rectangles) != 0: for rectangle in rectangles: points, width, height,\ pencil, fill = get_picture.get_inf_rectangle(rectangle) new_points = self.get_new_points(points, [], x, y) width = width * self.figure_size / 180 height = height * self.figure_size / 180 self.draw_rectangle(new_points, width, height, pencil, fill) if len(polygons) != 0: for polygon in polygons: polygon, pencil, fill = get_picture.get_inf_polygon(polygon) newpolygon = self.get_new_points(polygon, QPolygonF(), x, y) self.draw_polygon(newpolygon, pencil, fill)
def test_get_inf_square(self): points, width, height,\ pencil, fill = g.get_inf_rectangle(self.rectangles[0]) self.assertEqual(points[0].x(), 562) self.assertEqual(points[0].y(), 395) self.assertEqual(width, 66) self.assertEqual(height, 66) self.assertEqual(pencil, '#000000') self.assertEqual(fill, '#FFFFFF')
def test_get_inf_rectangle(self): points, width, height,\ pencil, fill = g.get_inf_rectangle(self.rectangles[1]) self.assertEqual(points[0].x(), 257) self.assertEqual(points[0].y(), 582) self.assertEqual(width, 446) self.assertEqual(height, 95) self.assertEqual(pencil, '#000000') self.assertEqual(fill, '#FFFFFF')
def upload_picture(self, filename): lines, ellipses,\ rectangles, polygons = get_picture.read_file(filename) if len(lines) != 0: for line in lines: points, pencil = get_picture.get_inf_line(line) self.draw_line(points, pencil) if len(ellipses) != 0: for ellipse in ellipses: points, width, height,\ pencil, fill = get_picture.get_inf_ellipse(ellipse) self.draw_ellipse(points, width, height, pencil, fill) if len(rectangles) != 0: for rectangle in rectangles: points, width, height,\ pencil, fill = get_picture.get_inf_rectangle(rectangle) self.draw_rectangle(points, width, height, pencil, fill) if len(polygons) != 0: for polygon in polygons: polygon, pencil, fill = get_picture.get_inf_polygon(polygon) self.draw_polygon(polygon, pencil, fill)
def get_start_pattern(self, lines, ellipses, rectangles, polygons): minx = 1000 miny = 700 if len(lines) != 0: for line in lines: points, pencil = get_picture.get_inf_line(line) minx, miny = self.get_minx_miny(minx, miny, points) if len(ellipses) != 0: for ellipse in ellipses: points, width, height, \ pencil, fill = get_picture.get_inf_ellipse(ellipse) minx, miny = self.get_minx_miny(minx, miny, points) if len(rectangles) != 0: for rectangle in rectangles: points, width, height, \ pencil, fill = get_picture.get_inf_rectangle(rectangle) minx, miny = self.get_minx_miny(minx, miny, points) if len(polygons) != 0: for polygon in polygons: polygon, pencil, fill = get_picture.get_inf_polygon(polygon) minx, miny = self.get_minx_miny(minx, miny, polygon) x = self.clicked[0].x() - minx y = self.clicked[0].y() - miny return (x, y)