added markdown label

This commit is contained in:
Jakub Trllo 2025-05-07 17:07:34 +02:00
parent 34dcc7840b
commit 149c9049a2
3 changed files with 31 additions and 0 deletions

View file

@ -6,6 +6,7 @@ from .widgets import (
CustomTextComboBox,
PlaceholderLineEdit,
PlaceholderPlainTextEdit,
MarkdownLabel,
ElideLabel,
HintedLineEdit,
ExpandingTextEdit,
@ -91,6 +92,7 @@ __all__ = (
"CustomTextComboBox",
"PlaceholderLineEdit",
"PlaceholderPlainTextEdit",
"MarkdownLabel",
"ElideLabel",
"HintedLineEdit",
"ExpandingTextEdit",

View file

@ -6,6 +6,11 @@ from qtpy import QtWidgets, QtCore, QtGui
import qargparse
import qtawesome
try:
import markdown
except (ImportError, SyntaxError):
markdown = None
from ayon_core.style import (
get_objected_colors,
get_style_image_path,
@ -131,6 +136,29 @@ class PlaceholderPlainTextEdit(QtWidgets.QPlainTextEdit):
viewport.setPalette(filter_palette)
class MarkdownLabel(QtWidgets.QLabel):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# Enable word wrap by default
self.setWordWrap(True)
self.setText(self.text())
def setText(self, text):
super().setText(self._md_to_html(text))
@staticmethod
def _md_to_html(text):
if markdown is None:
# This does add style definition to the markdown which does not
# feel natural in the UI (but still better than raw MD).
doc = QtGui.QTextDocument()
doc.setMarkdown(text)
return doc.toHtml()
return markdown.markdown(text)
class ElideLabel(QtWidgets.QLabel):
"""Label which elide text.

View file

@ -4,6 +4,7 @@ description="AYON core addon."
[tool.poetry.dependencies]
python = ">=3.9.1,<3.10"
markdown = "^3.4.1"
clique = "1.6.*"
jsonschema = "^2.6.0"
pyblish-base = "^1.8.11"