123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- import collections
- from typing import Optional, Dict, List, cast
- from PyQt5.QtCore import QObject, pyqtSlot
- from UM.Resources import Resources
- from UM.Version import Version
- class TextManager(QObject):
- """
- This manager provides means to load texts to QML.
- """
- def __init__(self, parent: Optional["QObject"] = None) -> None:
- super(TextManager, self).__init__(parent = parent)
- self._change_log_text = ""
- @pyqtSlot(result = str)
- def getChangeLogText(self) -> str:
- if not self._change_log_text:
- self._change_log_text = self._loadChangeLogText()
- return self._change_log_text
- def _loadChangeLogText(self) -> str:
-
- try:
- file_path = Resources.getPath(Resources.Texts, "change_log.txt")
- except FileNotFoundError:
-
- return ""
- change_logs_dict = {}
- with open(file_path, "r", encoding = "utf-8") as f:
- open_version = None
- open_header = ""
- for line in f:
- line = line.replace("\n", "")
- if "[" in line and "]" in line:
- line = line.replace("[", "")
- line = line.replace("]", "")
- open_version = Version(line)
- if open_version > Version([14, 99, 99]):
- open_version = Version([0, open_version.getMinor(), open_version.getRevision(), open_version.getPostfixVersion()])
- open_header = ""
- change_logs_dict[open_version] = collections.OrderedDict()
- elif line.startswith("*"):
- open_header = line.replace("*", "")
- change_logs_dict[cast(Version, open_version)][open_header] = []
- elif line != "":
- if open_header not in change_logs_dict[cast(Version, open_version)]:
- change_logs_dict[cast(Version, open_version)][open_header] = []
- change_logs_dict[cast(Version, open_version)][open_header].append(line)
-
- content = ""
- for version in sorted(change_logs_dict.keys(), reverse = True):
- text_version = version
- if version < Version([1, 0, 0]):
- text_version = Version([15, version.getMinor(), version.getRevision(), version.getPostfixVersion()])
- content += "<h1>" + str(text_version) + "</h1><br>"
- content += ""
- for change in change_logs_dict[version]:
- if str(change) != "":
- content += "<b>" + str(change) + "</b><br>"
- for line in change_logs_dict[version][change]:
- content += str(line) + "<br>"
- content += "<br>"
- return content
|