diff options
author | Ghostkeeper <rubend@tutanota.com> | 2021-03-30 17:50:56 +0300 |
---|---|---|
committer | Ghostkeeper <rubend@tutanota.com> | 2021-03-30 17:50:56 +0300 |
commit | 94623661584a208935c69e41faa20d1727c98ce9 (patch) | |
tree | 23a5be5a32a54d1b2884ec9772057fe9d7edd612 /cura/UI | |
parent | 45c8ac9384dba28304f831caeeb2af22f3bacf01 (diff) | |
parent | aed653546abc3076fe29c57108cd7f2f4ba0c0e0 (diff) |
Merge branch 'master' into libArachne_rebased
Diffstat (limited to 'cura/UI')
-rw-r--r-- | cura/UI/PrintInformation.py | 8 | ||||
-rw-r--r-- | cura/UI/WelcomePagesModel.py | 15 | ||||
-rw-r--r-- | cura/UI/WhatsNewPagesModel.py | 79 |
3 files changed, 88 insertions, 14 deletions
diff --git a/cura/UI/PrintInformation.py b/cura/UI/PrintInformation.py index 10318b3a8b..d6bd336558 100644 --- a/cura/UI/PrintInformation.py +++ b/cura/UI/PrintInformation.py @@ -4,7 +4,6 @@ import json import math import os -import unicodedata from typing import Dict, List, Optional, TYPE_CHECKING from PyQt5.QtCore import QObject, pyqtSignal, pyqtProperty, pyqtSlot, QTimer @@ -305,7 +304,7 @@ class PrintInformation(QObject): self.jobNameChanged.emit() return - base_name = self._stripAccents(self._base_name) + base_name = self._base_name self._defineAbbreviatedMachineName() # Only update the job name when it's not user-specified. @@ -401,11 +400,6 @@ class PrintInformation(QObject): self._abbr_machine = self._application.getMachineManager().getAbbreviatedMachineName(active_machine_type_name) - def _stripAccents(self, to_strip: str) -> str: - """Utility method that strips accents from characters (eg: รข -> a)""" - - return ''.join(char for char in unicodedata.normalize('NFD', to_strip) if unicodedata.category(char) != 'Mn') - @pyqtSlot(result = "QVariantMap") def getFeaturePrintTimes(self) -> Dict[str, Duration]: result = {} diff --git a/cura/UI/WelcomePagesModel.py b/cura/UI/WelcomePagesModel.py index b816833d67..3c2d0503ab 100644 --- a/cura/UI/WelcomePagesModel.py +++ b/cura/UI/WelcomePagesModel.py @@ -239,9 +239,6 @@ class WelcomePagesModel(ListModel): {"id": "user_agreement", "page_url": self._getBuiltinWelcomePagePath("UserAgreementContent.qml"), }, - {"id": "whats_new", - "page_url": self._getBuiltinWelcomePagePath("WhatsNewContent.qml"), - }, {"id": "data_collections", "page_url": self._getBuiltinWelcomePagePath("DataCollectionsContent.qml"), }, @@ -259,13 +256,21 @@ class WelcomePagesModel(ListModel): }, {"id": "add_cloud_printers", "page_url": self._getBuiltinWelcomePagePath("AddCloudPrintersView.qml"), - "is_final_page": True, # If we end up in this page, the next button will close the dialog - "next_page_button_text": self._catalog.i18nc("@action:button", "Finish"), + "next_page_button_text": self._catalog.i18nc("@action:button", "Next"), + "next_page_id": "whats_new", }, {"id": "machine_actions", "page_url": self._getBuiltinWelcomePagePath("FirstStartMachineActionsContent.qml"), "should_show_function": self.shouldShowMachineActions, }, + {"id": "whats_new", + "page_url": self._getBuiltinWelcomePagePath("WhatsNewContent.qml"), + "next_page_button_text": self._catalog.i18nc("@action:button", "Skip"), + }, + {"id": "changelog", + "page_url": self._getBuiltinWelcomePagePath("ChangelogContent.qml"), + "next_page_button_text": self._catalog.i18nc("@action:button", "Finish"), + }, ] pages_to_show = all_pages_list diff --git a/cura/UI/WhatsNewPagesModel.py b/cura/UI/WhatsNewPagesModel.py index 5b968ae574..db0f4b3a74 100644 --- a/cura/UI/WhatsNewPagesModel.py +++ b/cura/UI/WhatsNewPagesModel.py @@ -1,8 +1,12 @@ -# Copyright (c) 2019 Ultimaker B.V. +# Copyright (c) 2021 Ultimaker B.V. # Cura is released under the terms of the LGPLv3 or higher. - from .WelcomePagesModel import WelcomePagesModel +import os +from typing import Optional, Dict, List, Tuple +from PyQt5.QtCore import pyqtProperty, pyqtSlot +from UM.Logger import Logger +from UM.Resources import Resources # # This Qt ListModel is more or less the same the WelcomePagesModel, except that this model is only for showing the @@ -10,13 +14,84 @@ from .WelcomePagesModel import WelcomePagesModel # class WhatsNewPagesModel(WelcomePagesModel): + image_formats = [".png", ".jpg", ".jpeg", ".gif", ".svg"] + text_formats = [".txt", ".htm", ".html"] + image_key = "image" + text_key = "text" + + @staticmethod + def _collectOrdinalFiles(resource_type: int, include: List[str]) -> Tuple[Dict[int, str], int]: + result = {} #type: Dict[int, str] + highest = -1 + try: + folder_path = Resources.getPath(resource_type, "whats_new") + for _, _, files in os.walk(folder_path): + for filename in files: + basename = os.path.basename(filename) + base, ext = os.path.splitext(basename) + if ext not in include or not base.isdigit(): + continue + page_no = int(base) + highest = max(highest, page_no) + result[page_no] = os.path.join(folder_path, filename) + except FileNotFoundError: + Logger.logException("w", "Could not find 'whats_new' folder for resource-type {0}".format(resource_type)) + return result, highest + + @staticmethod + def _loadText(filename: str) -> str: + result = "" + try: + with open(filename, "r", encoding="utf-8") as file: + result = file.read() + except OSError: + Logger.logException("w", "Could not open {0}".format(filename)) + return result + def initialize(self) -> None: self._pages = [] self._pages.append({"id": "whats_new", "page_url": self._getBuiltinWelcomePagePath("WhatsNewContent.qml"), + "next_page_button_text": self._catalog.i18nc("@action:button", "Skip"), + "next_page_id": "changelog" + }) + self._pages.append({"id": "changelog", + "page_url": self._getBuiltinWelcomePagePath("ChangelogContent.qml"), "next_page_button_text": self._catalog.i18nc("@action:button", "Close"), }) self.setItems(self._pages) + images, max_image = WhatsNewPagesModel._collectOrdinalFiles(Resources.Images, WhatsNewPagesModel.image_formats) + texts, max_text = WhatsNewPagesModel._collectOrdinalFiles(Resources.Texts, WhatsNewPagesModel.text_formats) + highest = max(max_image, max_text) + + self._subpages = [] #type: List[Dict[str, Optional[str]]] + for n in range(0, highest + 1): + self._subpages.append({ + WhatsNewPagesModel.image_key: None if n not in images else images[n], + WhatsNewPagesModel.text_key: None if n not in texts else self._loadText(texts[n]) + }) + if len(self._subpages) == 0: + self._subpages.append({WhatsNewPagesModel.text_key: "~ There Is Nothing New Under The Sun ~"}) + + def _getSubpageItem(self, page: int, item: str) -> Optional[str]: + if 0 <= page < self.subpageCount and item in self._subpages[page]: + return self._subpages[page][item] + else: + return None + + @pyqtProperty(int, constant = True) + def subpageCount(self) -> int: + return len(self._subpages) + + @pyqtSlot(int, result = str) + def getSubpageImageSource(self, page: int) -> str: + result = self._getSubpageItem(page, WhatsNewPagesModel.image_key) + return "file:///" + (result if result else Resources.getPath(Resources.Images, "cura-icon.png")) + + @pyqtSlot(int, result = str) + def getSubpageText(self, page: int) -> str: + result = self._getSubpageItem(page, WhatsNewPagesModel.text_key) + return result if result else "* * *" __all__ = ["WhatsNewPagesModel"] |