def change(self): if isinstance(FigureManager.menu_figure, Triangle): str_x1, str_y1 = self.x.get(), self.y.get() str_x2, str_y2 = self.x2.get(), self.y2.get() str_x3, str_y3 = self.x3.get(), self.y3.get() self.painter.remove_by_id(FigureManager.menu_figure.canvas_object) all_coors = FigureManager.menu_figure.get_all_coordinates() if str_x1 != '' and str_y1 != '': x1, y1 = int(str_x1) + X_OFFSET, Y_OFFSET - int(str_y1) all_coors[0] = x1 all_coors[1] = y1 if str_x2 != '' and str_y2 != '': x2, y2 = int(str_x2) + X_OFFSET, Y_OFFSET - int(str_y2) all_coors[2] = x2 all_coors[3] = y2 if str_x3 != '' and str_y3 != '': x3, y3 = int(str_x3) + X_OFFSET, Y_OFFSET - int(str_y3) all_coors[4] = x3 all_coors[5] = y3 modified_triangle = Triangle(all_coors[0], all_coors[1], all_coors[2], all_coors[3], all_coors[4], all_coors[5]) self.painter.draw_triangle(modified_triangle) FigureManager.set_menu_figure(modified_triangle) self.update()
def create_triangle_handler(self, x, y): if FigureManager.get_figure() == "triangle": r = TRIANGLE_START_SIZE x1, y1 = x, y x2, y2 = x - r, y x3, y3 = x, y - r triangle = Triangle(x1, y1, x2, y2, x3, y3) FigureManager.set_menu_figure(triangle) self.painter.draw_triangle(triangle)
def change_size(self): if isinstance(FigureManager.menu_figure, Circle): str_r = self.r.get() if str_r != '': r = int(str_r) self.painter.remove_by_id(FigureManager.menu_figure.canvas_object) center_x, center_y = FigureManager.menu_figure.get_coordinates() modified_circle = Circle(center_x, center_y, r) self.painter.draw_circle(modified_circle) FigureManager.set_menu_figure(modified_circle) self.update()
def stop_moving(self, event): x, y = event.x, event.y point = Point(x, y) FigureManager.stop_moving_figure() if isinstance(FigureManager.modified_figure, Circle): self.painter.remove_by_id(FigureManager.modified_figure.canvas_object) center_x, center_y = FigureManager.modified_figure.get_coordinates() center_point = Point(center_x, center_y) modified_circle = Circle(center_x, center_y, point.distance(center_point)) self.painter.draw_circle(modified_circle) FigureManager.set_menu_figure(modified_circle) if isinstance(FigureManager.modified_figure, Triangle): self.painter.remove_by_id(FigureManager.modified_figure.canvas_object) all_coors = FigureManager.modified_figure.get_all_coordinates() all_coors[2*FigureManager.n_vertex_modification - 2] = x all_coors[2*FigureManager.n_vertex_modification - 1] = y modified_triangle = Triangle(all_coors[0], all_coors[1], all_coors[2], all_coors[3], all_coors[4], all_coors[5]) self.painter.draw_triangle(modified_triangle) FigureManager.set_menu_figure(modified_triangle) self.figure_menu.update() FigureManager.stop_modification()
def drag_handler(self, event): if self.shift_pressed: x, y = event.x, event.y if FigureManager.moving_figure is None: figure_id = self.painter.get_figure_id(x, y) figure = FigureManager.find_figure(figure_id, x, y) if figure is None: return FigureManager.set_moving_figure(figure) FigureManager.set_menu_figure(figure) else: figure_x, figure_y = FigureManager.moving_figure.get_coordinates() self.painter.move(FigureManager.moving_figure.canvas_object, x - figure_x, y - figure_y) FigureManager.moving_figure.set_coordinates(x, y) self.figure_menu.update() elif self.ctrl_pressed: x, y = event.x, event.y if FigureManager.modified_figure is None: figure_id = self.painter.get_figure_id(x, y) figure = FigureManager.find_figure(figure_id, x, y) if figure is None or isinstance(figure, Point): return FigureManager.set_modified_figure(figure, x, y)
def create_point_handler(self, x, y): if FigureManager.get_figure() == "point": point = Point(x, y) FigureManager.set_menu_figure(point) self.painter.draw_point(point, POINT_SIZE)
def create_circle_handler(self, x, y): if FigureManager.get_figure() == "circle": circle = Circle(x, y, CIRCLE_START_RADIUS) FigureManager.set_menu_figure(circle) self.painter.draw_circle(circle)