ChangeLog.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. # Copyright (c) 2015 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. from UM.i18n import i18nCatalog
  4. from UM.Extension import Extension
  5. from UM.Preferences import Preferences
  6. from UM.Application import Application
  7. from UM.PluginRegistry import PluginRegistry
  8. from UM.Version import Version
  9. from PyQt5.QtQml import QQmlComponent, QQmlContext
  10. from PyQt5.QtCore import QUrl, pyqtSlot, QObject
  11. import os.path
  12. import collections
  13. catalog = i18nCatalog("cura")
  14. class ChangeLog(Extension, QObject,):
  15. def __init__(self, parent = None):
  16. QObject.__init__(self, parent)
  17. Extension.__init__(self)
  18. self._changelog_window = None
  19. self._changelog_context = None
  20. version_string = Application.getInstance().getVersion()
  21. if version_string is not "master":
  22. self._version = Version(version_string)
  23. else:
  24. self._version = None
  25. self._change_logs = None
  26. Application.getInstance().engineCreatedSignal.connect(self._onEngineCreated)
  27. Preferences.getInstance().addPreference("general/latest_version_changelog_shown", "2.0.0") #First version of CURA with uranium
  28. self.addMenuItem(catalog.i18nc("@item:inmenu", "Show Changelog"), self.showChangelog)
  29. def getChangeLogs(self):
  30. if not self._change_logs:
  31. self.loadChangeLogs()
  32. return self._change_logs
  33. @pyqtSlot(result = str)
  34. def getChangeLogString(self):
  35. logs = self.getChangeLogs()
  36. result = ""
  37. for version in logs:
  38. result += "<h1>" + str(version) + "</h1><br>"
  39. result += ""
  40. for change in logs[version]:
  41. if str(change) != "":
  42. result += "<b>" + str(change) + "</b><br>"
  43. for line in logs[version][change]:
  44. result += str(line) + "<br>"
  45. result += "<br>"
  46. pass
  47. return result
  48. def loadChangeLogs(self):
  49. self._change_logs = collections.OrderedDict()
  50. with open(os.path.join(PluginRegistry.getInstance().getPluginPath(self.getPluginId()), "ChangeLog.txt"), "r",-1, "utf-8") as f:
  51. open_version = None
  52. open_header = "" # Initialise to an empty header in case there is no "*" in the first line of the changelog
  53. for line in f:
  54. line = line.replace("\n","")
  55. if "[" in line and "]" in line:
  56. line = line.replace("[","")
  57. line = line.replace("]","")
  58. open_version = Version(line)
  59. open_header = ""
  60. self._change_logs[open_version] = collections.OrderedDict()
  61. elif line.startswith("*"):
  62. open_header = line.replace("*","")
  63. self._change_logs[open_version][open_header] = []
  64. elif line != "":
  65. if open_header not in self._change_logs[open_version]:
  66. self._change_logs[open_version][open_header] = []
  67. self._change_logs[open_version][open_header].append(line)
  68. def _onEngineCreated(self):
  69. if not self._version:
  70. return #We're on dev branch.
  71. if Preferences.getInstance().getValue("general/latest_version_changelog_shown") == "master":
  72. latest_version_shown = Version("0.0.0")
  73. else:
  74. latest_version_shown = Version(Preferences.getInstance().getValue("general/latest_version_changelog_shown"))
  75. Preferences.getInstance().setValue("general/latest_version_changelog_shown", Application.getInstance().getVersion())
  76. # Do not show the changelog when there is no global container stack
  77. # This implies we are running Cura for the first time.
  78. if not Application.getInstance().getGlobalContainerStack():
  79. return
  80. if self._version > latest_version_shown:
  81. self.showChangelog()
  82. def showChangelog(self):
  83. if not self._changelog_window:
  84. self.createChangelogWindow()
  85. self._changelog_window.show()
  86. def hideChangelog(self):
  87. if self._changelog_window:
  88. self._changelog_window.hide()
  89. def createChangelogWindow(self):
  90. path = os.path.join(PluginRegistry.getInstance().getPluginPath(self.getPluginId()), "ChangeLog.qml")
  91. self._changelog_window = Application.getInstance().createQmlComponent(path, {"manager": self})