MCPcopy Create free account
hub / github.com/microsoft/TypeChat / render_drawing

Function render_drawing

python/examples/drawing/render.py:14–66  ·  view source on GitHub ↗
(canvas: tk.Canvas, drawing: Drawing)

Source from the content-addressed store, hash-verified

12
13
14def render_drawing(canvas: tk.Canvas, drawing: Drawing):
15
16 def draw_box(box: Box):
17 x1, y1 = box.x, box.y
18 x2, y2 = x1 + box.width, y1 + box.height
19 canvas.create_rectangle(
20 x1,
21 y1,
22 x2,
23 y2,
24 outline=getattr(box.style, "line_color", None) or "black",
25 fill=getattr(box.style, "fill_color", None) or "",
26 )
27 if box.text:
28 canvas.create_text((x1 + x2) / 2, (y1 + y2) / 2, text=box.text, fill="black")
29
30 def draw_ellipse(ellipse: Ellipse):
31 x1, y1 = ellipse.x, ellipse.y
32 x2, y2 = x1 + ellipse.width, y1 + ellipse.height
33 canvas.create_oval(
34 x1,
35 y1,
36 x2,
37 y2,
38 outline=getattr(ellipse.style, "line_color", None) or "black",
39 fill=getattr(ellipse.style, "fill_color", None) or "",
40 )
41 if ellipse.text:
42 canvas.create_text((x1 + x2) / 2, (y1 + y2) / 2, text=ellipse.text, fill="black")
43
44 def draw_arrow(arrow: Arrow):
45 line_style = getattr(arrow.style, "line_style", None) or "solid"
46 dash = dash_pattern.get(line_style, dash_pattern["solid"])
47 canvas.create_line(
48 arrow.start_x,
49 arrow.start_y,
50 arrow.end_x,
51 arrow.end_y,
52 dash=dash,
53 arrow=tk.LAST,
54 fill=getattr(arrow.style, "line_color", None) or "black",
55 )
56
57 for item in drawing.items:
58 match item:
59 case Box():
60 draw_box(item)
61 case Ellipse():
62 draw_ellipse(item)
63 case Arrow():
64 draw_arrow(item)
65 case UnknownText():
66 print(f"Unknown text: {item.text}")
67
68
69if __name__ == "__main__":

Callers 2

request_handlerFunction · 0.90
render.pyFile · 0.85

Calls 3

draw_boxFunction · 0.85
draw_ellipseFunction · 0.85
draw_arrowFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…