""" This method creates dynamic QLabel widgets from text content that may include HTML span elements. # Parameters - `content` (str): The primary content string to display, which may contain HTML spans with class attributes. - `content_alt` (str): An alternative content string to create hidden labels for later use. # Behavior 1. The method parses both content strings, splitting them at span tags. 2. For each part: - If it's a span element, it extracts the class name and text content. - If it's plain text, it creates a standard label with class "label". 3. All labels are: - Center-aligned - Given a pointing hand cursor - Added to the widget container layout 4. Labels from `content` are visible by default. 5. Labels from `content_alt` are hidden by default. # Returns The method stores two lists as instance variables: - `self._widgets`: Visible labels created from the primary content - `self._widgets_alt`: Hidden labels created from the alternative content """def_create_dynamically_label(self, content: str, content_alt: str):
defprocess_content(content, is_alt=False):
label_parts=re.split('(<span.*?>.*?</span>)', content)
label_parts= [partforpartinlabel_partsifpart]
widgets= []
forpartinlabel_parts:
part=part.strip()
ifnotpart:
continueif'<span'inpartand'</span>'inpart:
class_name=re.search(r'class=(["\'])([^"\']+?)\1', part)
class_result=class_name.group(2) ifclass_nameelse'icon'icon=re.sub(r'<span.*?>|</span>', '', part).strip()
label=QLabel(icon)
label.setProperty("class", class_result)
else:
label=QLabel(part)
label.setProperty("class", "label")
label.setAlignment(Qt.AlignmentFlag.AlignCenter)
label.setCursor(Qt.CursorShape.PointingHandCursor)
self._widget_container_layout.addWidget(label)
widgets.append(label)
ifis_alt:
label.hide()
else:
label.show()
returnwidgetsself._widgets=process_content(content)
self._widgets_alt=process_content(content_alt, is_alt=True)
5. Create validation schema for your widget options:
validation files are located in src/core/validation/widgets/