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()
Exemple #2
0
 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)
Exemple #3
0
 def draw_triangle(self, triangle):
     x1, y1 = triangle.vertex1.x, triangle.vertex1.y
     x2, y2 = triangle.vertex2.x, triangle.vertex2.y
     x3, y3 = triangle.vertex3.x, triangle.vertex3.y
     canvas_triangle = self.canvas.create_polygon(
         [x1, y1, x2, y2, x3, y3],
         fill=StyleManager.get_fill_color(),
         outline=StyleManager.get_outline_color())
     FigureManager.add_figure(triangle)
     triangle.set_canvas_object(canvas_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()
Exemple #5
0
 def draw_point(self, point, r):
     center_x, center_y = point.get_coordinates()
     canvas_point = self.canvas.create_oval(
         center_x - r,
         center_y - r,
         center_x + r,
         center_y + r,
         fill=StyleManager.get_fill_color(),
         outline=StyleManager.get_outline_color())
     FigureManager.add_figure(point)
     point.set_canvas_object(canvas_point)
Exemple #6
0
 def draw_circle(self, circle):
     center_x, center_y = circle.get_center()
     r = circle.get_radius()
     canvas_circle = self.canvas.create_oval(
         center_x - r,
         center_y - r,
         center_x + r,
         center_y + r,
         fill=StyleManager.get_fill_color(),
         outline=StyleManager.get_outline_color())
     FigureManager.add_figure(circle)
     circle.set_canvas_object(canvas_circle)
    def __init__(self, root):
        Menu.__init__(self, root)

        self.figure_manager = FigureManager()

        file = Menu(self, tearoff=False)
        file.add_command(label="Exit", underline=1, command=self.quit)
        self.add_cascade(label="File", underline=0, menu=file)

        figure = Menu(self, tearoff=False)
        figure.add_command(label="Point",
                           command=FigureManager.set_figure_point)
        figure.add_command(label="Circle",
                           command=FigureManager.set_figure_circle)
        figure.add_command(label="Triangle",
                           command=FigureManager.set_figure_triangle)
        self.add_cascade(label="Figure", underline=0, menu=figure)
Exemple #8
0
 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()
Exemple #9
0
 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)
Exemple #10
0
 def release(self, event):
     if event.keysym == "Shift_L":
         self.shift_pressed = False
         FigureManager.stop_moving_figure()
     elif event.keysym == "Control_L":
         self.ctrl_pressed = False
Exemple #11
0
 def remove(self, x, y):
     figure_id = self.canvas.find_closest(x, y)
     if figure_id[0] > ID_OFFSET:
         if FigureManager.remove_figure(figure_id[0], x, y):
             self.canvas.delete(figure_id[0])
Exemple #12
0
 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)
Exemple #13
0
 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)