CAM: Show abbreviations next to properly labels in the toolbit editor (#21887)

This commit is contained in:
Samuel
2025-06-16 17:40:32 +02:00
committed by GitHub
parent 267c957a7d
commit 4a52ab9f05
3 changed files with 17 additions and 7 deletions

View File

@@ -183,8 +183,8 @@ class TestToolBitShapeSvgIcon(TestToolBitShapeIconBase):
svg_content = self.test_svg.data
abbr = ToolBitShapeSvgIcon.get_abbreviations_from_svg(svg_content)
# Assuming the test_svg data has 'diameter' and 'length' ids
self.assertIn("diameter", abbr)
self.assertIn("length", abbr)
self.assertIn("Diameter", abbr)
self.assertIn("Length", abbr)
# Test with invalid SVG
invalid_svg = b"<svg><text id='param1'>A1</text>" # Missing closing tag

View File

@@ -20,6 +20,7 @@
# * *
# ***************************************************************************
import pathlib
import re
import xml.etree.ElementTree as ET
from typing import Mapping, Optional
from functools import cached_property
@@ -235,8 +236,7 @@ class ToolBitShapeSvgIcon(ToolBitShapeIcon):
Returns:
The abbreviation string, or None if not found.
"""
normalized_param_name = param_name.lower().replace(" ", "_")
return self.abbreviations.get(normalized_param_name)
return self.abbreviations.get(param_name)
@staticmethod
def get_abbreviations_from_svg(svg: bytes) -> Mapping[str, str]:
@@ -254,15 +254,23 @@ class ToolBitShapeSvgIcon(ToolBitShapeIcon):
if id is None or not isinstance(id, str):
continue
# Backward compatibility: Normalize to match FreeCAD property
# name structure:
# Old: property_name New: PropertyName
def _upper(match):
return match.group(1).upper()
id = re.sub(r"_(\w)", _upper, id.capitalize())
abbr = text_elem.text
if abbr is not None:
result[id.lower()] = abbr
result[id] = abbr
span_elem = text_elem.find(".//s:tspan", _svg_ns)
if span_elem is None:
continue
abbr = span_elem.text
result[id.lower()] = abbr
result[id] = abbr
return result

View File

@@ -49,7 +49,9 @@ class ToolBitPropertiesWidget(QtGui.QWidget):
self._id_label = QtGui.QLabel() # Read-only ID
self._id_label.setTextInteractionFlags(QtCore.Qt.TextSelectableByMouse)
self._property_editor = DocumentObjectEditorWidget()
theicon = toolbit.get_icon() if toolbit else None
abbr = theicon.abbreviations if theicon else {}
self._property_editor = DocumentObjectEditorWidget(property_suffixes=abbr)
self._property_editor.setSizePolicy(
QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding
)