WelcomePagesModel.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # Copyright (c) 2019 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. import os
  4. from typing import TYPE_CHECKING, Optional, List, Dict, Any
  5. from PyQt5.QtCore import QUrl, Qt
  6. from UM.Qt.ListModel import ListModel
  7. from UM.Resources import Resources
  8. if TYPE_CHECKING:
  9. from PyQt5.QtCore import QObject
  10. class WelcomePagesModel(ListModel):
  11. IdRole = Qt.UserRole + 1 # Page ID
  12. PageUrlRole = Qt.UserRole + 2 # URL to the page's QML file
  13. NextPageIdRole = Qt.UserRole + 3 # The next page ID it should go to
  14. def __init__(self, parent: Optional["QObject"] = None) -> None:
  15. super().__init__(parent)
  16. self.addRoleName(self.IdRole, "id")
  17. self.addRoleName(self.PageUrlRole, "page_url")
  18. self.addRoleName(self.NextPageIdRole, "next_page_id")
  19. self._pages = [] # type: List[Dict[str, Any]]
  20. # Convenience function to get QUrl path to pages that's located in "resources/qml/WelcomePages".
  21. def _getBuiltinWelcomePagePath(self, page_filename: str) -> "QUrl":
  22. from cura.CuraApplication import CuraApplication
  23. return QUrl.fromLocalFile(Resources.getPath(CuraApplication.ResourceTypes.QmlFiles,
  24. os.path.join("WelcomePages", page_filename)))
  25. def initialize(self) -> None:
  26. # Add default welcome pages
  27. self._pages.append({"id": "welcome",
  28. "page_url": self._getBuiltinWelcomePagePath("WelcomeContent.qml"),
  29. })
  30. self._pages.append({"id": "user_agreement",
  31. "page_url": self._getBuiltinWelcomePagePath("UserAgreementContent.qml"),
  32. })
  33. self._pages.append({"id": "whats_new",
  34. "page_url": self._getBuiltinWelcomePagePath("WhatsNewContent.qml"),
  35. })
  36. self._pages.append({"id": "data_collections",
  37. "page_url": self._getBuiltinWelcomePagePath("DataCollectionsContent.qml"),
  38. })
  39. self._pages.append({"id": "add_printer_by_selection",
  40. "page_url": self._getBuiltinWelcomePagePath("AddPrinterBySelectionContent.qml"),
  41. })
  42. self._pages.append({"id": "add_printer_by_ip",
  43. "page_url": self._getBuiltinWelcomePagePath("AddPrinterByIpContent.qml"),
  44. })
  45. self._pages.append({"id": "cloud",
  46. "page_url": self._getBuiltinWelcomePagePath("CloudContent.qml"),
  47. })
  48. self.setItems(self._pages)
  49. def addPage(self) -> None:
  50. pass
  51. __all__ = ["WelcomePagesModel"]