2024-02-17 21:25:03 +00:00
|
|
|
from typing import Dict
|
|
|
|
from tkinter import Canvas
|
|
|
|
from line import Line
|
|
|
|
from cell import CellWallLabels, CellWall
|
2024-02-12 19:53:45 +00:00
|
|
|
|
2024-02-12 20:04:55 +00:00
|
|
|
|
2024-02-17 21:25:03 +00:00
|
|
|
class Graphics(Canvas):
|
|
|
|
def __init__(self, container, background="white", width=800, height=800) -> None:
|
|
|
|
super().__init__(container)
|
|
|
|
self.config(
|
|
|
|
bg=background,
|
|
|
|
width=width,
|
|
|
|
height=height,
|
|
|
|
)
|
2024-02-17 20:06:09 +00:00
|
|
|
|
2024-02-17 21:25:03 +00:00
|
|
|
def redraw(self) -> None:
|
|
|
|
"""
|
|
|
|
redraw redraws all the graphics in the window.
|
|
|
|
"""
|
|
|
|
self.update_idletasks()
|
|
|
|
self.update()
|
2024-02-17 20:06:09 +00:00
|
|
|
|
|
|
|
def draw_line(
|
|
|
|
self,
|
|
|
|
line: Line,
|
|
|
|
fill_colour: str = "black",
|
|
|
|
width: int = 2
|
|
|
|
) -> None:
|
2024-02-12 19:53:45 +00:00
|
|
|
"""
|
2024-02-17 20:06:09 +00:00
|
|
|
draws a line onto the canvas.
|
2024-02-12 19:53:45 +00:00
|
|
|
"""
|
2024-02-17 21:25:03 +00:00
|
|
|
self.create_line(
|
2024-02-17 20:06:09 +00:00
|
|
|
line.point_a.x, line.point_a.y,
|
|
|
|
line.point_b.x, line.point_b.y,
|
|
|
|
fill=fill_colour,
|
|
|
|
width=width,
|
2024-02-12 19:53:45 +00:00
|
|
|
)
|
|
|
|
|
2024-02-17 21:25:03 +00:00
|
|
|
def draw_cell_walls(self, walls: Dict[CellWallLabels, CellWall]) -> None:
|
2024-02-12 19:53:45 +00:00
|
|
|
"""
|
2024-02-17 21:25:03 +00:00
|
|
|
draws the walls of a cell onto the canvas.
|
2024-02-12 19:53:45 +00:00
|
|
|
"""
|
2024-02-17 21:25:03 +00:00
|
|
|
for label in CellWallLabels:
|
|
|
|
self.draw_line(
|
|
|
|
line=walls[label].get_line(),
|
|
|
|
fill_colour=walls[label].get_line_colour(),
|
|
|
|
)
|