Add import/export for status labels

This commit is contained in:
Veronica Berglyd Olsen
2024-12-31 00:14:47 +01:00
parent 136939d391
commit 9461eea03a
2 changed files with 84 additions and 16 deletions
+14
View File
@@ -174,6 +174,20 @@ class NWStatus:
"""Yield entries from the status icons."""
yield from self._store.items()
def fromRaw(self, data: list[str]) -> StatusEntry | None:
"""Create a StatusEntry from a list of three strings consisting
of shape, colour, and name. This entry is not automatically
added to the list of entries.
"""
try:
shape = nwStatusShape[str(data[0])]
color = QColor(str(data[1]))
icon = NWStatus.createIcon(self._height, color, shape)
return StatusEntry(simplified(data[2]), color, shape, icon)
except Exception:
logger.error("Could not parse entry %s", str(data))
return None
@staticmethod
def createIcon(height: int, color: QColor, shape: nwStatusShape) -> QIcon:
"""Generate an icon for a status label."""