ChangeLog.py 4.3 KB

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