ChangeLog.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # Copyright (c) 2019 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. import os.path
  4. from PyQt5.QtCore import QObject
  5. from UM.i18n import i18nCatalog
  6. from UM.Extension import Extension
  7. from UM.Application import Application
  8. from UM.PluginRegistry import PluginRegistry
  9. from UM.Version import Version
  10. catalog = i18nCatalog("cura")
  11. class ChangeLog(Extension, QObject):
  12. def __init__(self, parent = None):
  13. QObject.__init__(self, parent)
  14. Extension.__init__(self)
  15. self._changelog_window = None
  16. self._changelog_context = None
  17. version_string = Application.getInstance().getVersion()
  18. if version_string is not "master":
  19. self._current_app_version = Version(version_string)
  20. else:
  21. self._current_app_version = None
  22. Application.getInstance().engineCreatedSignal.connect(self._onEngineCreated)
  23. Application.getInstance().getPreferences().addPreference("general/latest_version_changelog_shown", "2.0.0") #First version of CURA with uranium
  24. self.setMenuName(catalog.i18nc("@item:inmenu", "Changelog"))
  25. self.addMenuItem(catalog.i18nc("@item:inmenu", "Show Changelog"), self.showChangelog)
  26. def _onEngineCreated(self):
  27. if not self._current_app_version:
  28. return #We're on dev branch.
  29. if Application.getInstance().getPreferences().getValue("general/latest_version_changelog_shown") == "master":
  30. latest_version_shown = Version("0.0.0")
  31. else:
  32. latest_version_shown = Version(Application.getInstance().getPreferences().getValue("general/latest_version_changelog_shown"))
  33. Application.getInstance().getPreferences().setValue("general/latest_version_changelog_shown", Application.getInstance().getVersion())
  34. # Do not show the changelog when there is no global container stack
  35. # This implies we are running Cura for the first time.
  36. if not Application.getInstance().getGlobalContainerStack():
  37. return
  38. if self._current_app_version > latest_version_shown:
  39. self.showChangelog()
  40. def showChangelog(self):
  41. if not self._changelog_window:
  42. self.createChangelogWindow()
  43. self._changelog_window.show()
  44. def hideChangelog(self):
  45. if self._changelog_window:
  46. self._changelog_window.hide()
  47. def createChangelogWindow(self):
  48. path = os.path.join(PluginRegistry.getInstance().getPluginPath(self.getPluginId()), "ChangeLog.qml")
  49. self._changelog_window = Application.getInstance().createQmlComponent(path, {"manager": self})