From 7b201fd0ae9669ec8cca92ee768fee90605cd625 Mon Sep 17 00:00:00 2001 From: Erwan MATHIEU Date: Thu, 25 Jan 2024 13:30:56 +0100 Subject: [PATCH] Add export sub-menu CURA-11561 --- UM/Qt/Bindings/Bindings.py | 4 ++++ UM/Qt/Bindings/MeshWritersModel.py | 35 ++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 UM/Qt/Bindings/MeshWritersModel.py diff --git a/UM/Qt/Bindings/Bindings.py b/UM/Qt/Bindings/Bindings.py index 0d81e3843..f4233f24d 100644 --- a/UM/Qt/Bindings/Bindings.py +++ b/UM/Qt/Bindings/Bindings.py @@ -31,6 +31,7 @@ from . import VisibleMessagesModel from . import Utilities from . import TableModel +from . import MeshWritersModel from UM.Settings.Models.SettingDefinitionsModel import SettingDefinitionsModel from UM.Settings.Models.DefinitionContainersModel import DefinitionContainersModel @@ -127,6 +128,9 @@ def register(self): qmlRegisterType(TableModel.TableModel, "UM", 1, 6, "TableModel") qmlRegisterType(Window.Window, "UM", 1, 6, "Window") + # Additions after 5.6 + qmlRegisterType(MeshWritersModel.MeshWritersModel, "UM", 1, 7, "MeshWritersModel") + @staticmethod def addRegisterType(class_type: type, qml_import_name: str, major_version: int, minor_version: int, class_name: str) -> None: qmlRegisterType(class_type, qml_import_name, major_version, minor_version, class_name) \ No newline at end of file diff --git a/UM/Qt/Bindings/MeshWritersModel.py b/UM/Qt/Bindings/MeshWritersModel.py new file mode 100644 index 000000000..739a92439 --- /dev/null +++ b/UM/Qt/Bindings/MeshWritersModel.py @@ -0,0 +1,35 @@ +# Copyright (c) 2024 Ultimaker B.V. +# Uranium is released under the terms of the LGPLv3 or higher. + +from typing import List + +from PyQt6.QtCore import Qt, pyqtSignal +from PyQt6.QtQml import QQmlEngine + +from UM.Application import Application +from UM.OutputDevice.OutputDeviceManager import OutputDeviceManager +from UM.OutputDevice.ProjectOutputDevice import ProjectOutputDevice +from UM.Qt.ListModel import ListModel + + +class MeshWritersModel(ListModel): + """A list model providing a list of all registered MeshWriters that can export meshes. + + Exposes the following roles: + * mime_type - The associated writable file mime type + * description - The human-readable name of the file format + + """ + + MimeTypeRole = Qt.ItemDataRole.UserRole + 1 + DescriptionRole = Qt.ItemDataRole.UserRole + 2 + + def __init__(self, parent = None): + super().__init__(parent) + # Ensure that this model doesn't get garbage collected (Now the bound object is destroyed when the wrapper is) + QQmlEngine.setObjectOwnership(self, QQmlEngine.ObjectOwnership.CppOwnership) + + self.addRoleName(self.MimeTypeRole, "mime_type") + self.addRoleName(self.DescriptionRole, "description") + + self.setItems(Application.getInstance().getMeshFileHandler().getSupportedFileTypesWrite())