roundabout,
created on Wednesday, 4 September 2024, 09:03:46 (1725440626),
received on Wednesday, 4 September 2024, 09:03:53 (1725440633)
Author identity: vlad <vlad.muntoiu@gmail.com>
8805a6b1a8d67a1dcc358f8a8c8e47eee3b1f411
static/picture-annotation.py
@@ -250,7 +250,6 @@ def cancel_bbox(event):
if new_shape is not None and event is not None: # Require event so the shape is kept when it ends normally new_shape.remove() new_shape = Nonezone.removeEventListener("click", make_bbox_proxy) document.removeEventListener("keydown", cancel_bbox_proxy) cancel_button.removeEventListener("click", cancel_bbox_proxy)
@@ -263,6 +262,7 @@ def cancel_bbox(event):
zone.style.cursor = "auto" cancel_button.style.display = "none" helper_message.innerText = "Select a shape type then click on the image to begin defining it" new_shape = Nonedef make_bbox(event):
@@ -286,6 +286,13 @@ def make_bbox(event):
rectangle = document.createElementNS("http://www.w3.org/2000/svg", "rect") new_shape = document.createElementNS("http://www.w3.org/2000/svg", "svg") new_shape.setAttribute("width", "100%") new_shape.setAttribute("height", "100%") zone_rect = zone.getBoundingClientRect() new_shape.setAttribute("viewBox", f"0 0 {image.naturalWidth} {image.naturalHeight}") new_shape.classList.add("shape-container") new_shape.appendChild(rectangle) zone.appendChild(new_shape)
@@ -315,7 +322,6 @@ polygon_points = []
def make_polygon(event): global new_shape, polygon_points print(new_shape.outerHTML)polygon = new_shape.children[0] zone_rect = zone.getBoundingClientRect()
@@ -330,6 +336,8 @@ def make_polygon(event):
def reset_polygon(): global new_shape, polygon_pointszone.removeEventListener("click", make_polygon_proxy) document.removeEventListener("keydown", close_polygon_proxy) document.removeEventListener("keydown", cancel_polygon_proxy)
@@ -343,6 +351,7 @@ def reset_polygon():
polygon_points.clear() zone.style.cursor = "auto" new_shape = Nonedef close_polygon(event):
@@ -382,13 +391,6 @@ def open_shape(event):
if bbox_pos or shape_type == "select": return print("Creating a new shape of type:", shape_type) if not polygon_points:new_shape = document.createElementNS("http://www.w3.org/2000/svg", "svg")new_shape.setAttribute("width", "100%")new_shape.setAttribute("height", "100%")zone_rect = zone.getBoundingClientRect()new_shape.setAttribute("viewBox", f"0 0 {image.naturalWidth} {image.naturalHeight}")new_shape.classList.add("shape-container")if shape_type == "shape-bbox": helper_message.innerText = ("Define the first point at the intersection of the lines "
@@ -407,7 +409,16 @@ def open_shape(event):
"press escape to cancel, enter to close, or backspace to " "remove the last point") if not polygon_points:if not polygon_points and not new_shape: new_shape = document.createElementNS("http://www.w3.org/2000/svg", "svg") new_shape.setAttribute("width", "100%") new_shape.setAttribute("height", "100%") zone_rect = zone.getBoundingClientRect() new_shape.setAttribute("viewBox", f"0 0 {image.naturalWidth} {image.naturalHeight}") new_shape.classList.add("shape-container") if not polygon_points and int(len(new_shape.children)) == 0: print(len(new_shape.children), "children found")zone.addEventListener("click", make_polygon_proxy) document.addEventListener("keydown", close_polygon_proxy) document.addEventListener("keydown", cancel_polygon_proxy)