diff --git a/misc/qet-mcp/qet_mcp.py b/misc/qet-mcp/qet_mcp.py index 13c4f9cd3..7703c4c0e 100755 --- a/misc/qet-mcp/qet_mcp.py +++ b/misc/qet-mcp/qet_mcp.py @@ -387,13 +387,17 @@ def _extras(root: ET.Element) -> dict: tb, {"folio": n, "name": tb.get("name", "")}, {"x": tb.get("x", ""), "y": tb.get("y", ""), "width": tb.get("width", ""), "height": tb.get("height", ""), "rows_shown": tb.get("display_n_row", "")})) - for t in d.iter("input"): + # The folio's own items only: direct children of its , + # and . Symbols in older files carry their own + # texts, which iter() would count as free texts + # (122 extra in schema_indus.qet). + for t in d.findall("inputs/input"): texts.append(record( t, {"folio": n, "x": t.get("x", ""), "y": t.get("y", ""), "text": _plain_text(t.get("text", ""))}, {"rotation": _angle(t.get("rotation", "0")), "font": t.get("font", ""), "color": t.get("color", "")})) - for sh in d.iter("shape"): + for sh in d.findall("shapes/shape"): pen, brush = sh.find("pen"), sh.find("brush") shapes.append(record( sh, {"folio": n, "type": sh.get("type", ""), @@ -405,7 +409,7 @@ def _extras(root: ET.Element) -> dict: "fill": (brush.get("color", "") if brush is not None and brush.get("style", "") != "NoBrush" else "none"), "rotation": _angle(sh.get("rotation", "0"))})) - for im in d.iter("image"): + for im in d.findall("images/image"): images.append(record( im, {"folio": n, "x": im.get("x", ""), "y": im.get("y", "")}, {"scale": im.get("size", ""), "rotation": _angle(im.get("rotation", ""))})) diff --git a/misc/qet-mcp/test_qet_mcp.py b/misc/qet-mcp/test_qet_mcp.py index bf5db9505..d9310e6c2 100644 --- a/misc/qet-mcp/test_qet_mcp.py +++ b/misc/qet-mcp/test_qet_mcp.py @@ -1419,6 +1419,22 @@ class Diff(unittest.TestCase): self.assertFalse(d[k]["added"] or d[k]["removed"] or d[k]["changed"]) self.assertEqual(d["folios"]["changed"], []) + def test_a_symbols_own_texts_are_not_free_texts(self): + """Symbols in older files carry their own texts; + counting them made schema_indus.qet show 124 free texts where + QElectroTech has 2.""" + d = self.dir + a, b = d / "sym_a.qet", d / "sym_b.qet" + body = ('' + '' + '' + '') + a.write_text(body.replace("{t}", "inside")) + b.write_text(body.replace("{t}", "changed inside")) + t = m.tool_diff(str(a), str(b))["texts"] + self.assertEqual((t["before"], t["after"], t["added"], t["removed"], t["changed"]), + (1, 1, [], [], [])) + def test_edited_text_reads_as_removed_plus_added(self): a = self.project("a.qet", texts=[(1, 2, "note")]) b = self.project("b.qet", texts=[(1, 2, "note EDITED")])