当前位置: 首页>>代码示例>>Python>>正文


Python MimeTypeDatabase.MimeTypeDatabase类代码示例

本文整理汇总了Python中UM.MimeTypeDatabase.MimeTypeDatabase的典型用法代码示例。如果您正苦于以下问题:Python MimeTypeDatabase类的具体用法?Python MimeTypeDatabase怎么用?Python MimeTypeDatabase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了MimeTypeDatabase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: setUp

    def setUp(self):

        self._application = MagicMock()
        self._container_registry = MagicMock()
        self._machine_manager = MagicMock()

        self._mocked_mime = MagicMock()
        self._mocked_mime.preferredSuffix = "omg"
        self._mocked_mime.suffixes = ["omg"]
        self._mocked_mime.comment = "UnitTest!"

        self._mocked_container = MagicMock()
        self._mocked_container_data = "SOME DATA :D"
        self._mocked_container.serialize = MagicMock(return_value = self._mocked_container_data)

        self._containers_meta_data = [{"id": "test", "test_data": "omg"}]
        self._container_registry.findContainersMetadata = MagicMock(return_value = self._containers_meta_data)
        self._container_registry.getMimeTypeForContainer = MagicMock(return_value = self._mocked_mime)
        self._container_registry.findContainers = MagicMock(return_value = [self._mocked_container])
        self._application.getContainerRegistry = MagicMock(return_value = self._container_registry)
        self._application.getMachineManager = MagicMock(return_value = self._machine_manager)

        # Destroy the previous instance of the container manager
        if ContainerManager.getInstance() is not None:
            ContainerManager._ContainerManager__instance = None

        self._container_manager = ContainerManager(self._application)
        MimeTypeDatabase.addMimeType(self._mocked_mime)
开发者ID:TinkerGnome,项目名称:Cura,代码行数:28,代码来源:TestContainerManager.py

示例2: register

def register(app):
    mime_type = MimeType(
        name = "application/x-ultimaker-material-profile",
        comment = "Ultimaker Material Profile",
        suffixes = [ "xml.fdm_material" ]
    )
    MimeTypeDatabase.addMimeType(mime_type)
    return { "settings_container": XmlMaterialProfile.XmlMaterialProfile("default_xml_material_profile") }
开发者ID:3d20,项目名称:Cura,代码行数:8,代码来源:__init__.py

示例3: __init__

 def __init__(self) -> None:
     super().__init__()
     MimeTypeDatabase.addMimeType(
         MimeType(
             name = "application/x-cura-compressed-gcode-file",
             comment = "Cura Compressed GCode File",
             suffixes = ["gcode.gz"]
         )
     )
     self._supported_extensions = [".gcode.gz"]
开发者ID:TinkerGnome,项目名称:Cura,代码行数:10,代码来源:GCodeGzReader.py

示例4: __init__

    def __init__(self) -> None:
        super().__init__()

        MimeTypeDatabase.addMimeType(
            MimeType(
                name = "application/x-ufp",
                comment = "Ultimaker Format Package",
                suffixes = ["ufp"]
            )
        )
        self._supported_extensions = [".ufp"]
开发者ID:Ultimaker,项目名称:Cura,代码行数:11,代码来源:UFPReader.py

示例5: __init__

    def __init__(self) -> None:
        super().__init__()
        self._supported_extensions = [".amf"]
        self._namespaces = {}   # type: Dict[str, str]

        MimeTypeDatabase.addMimeType(
            MimeType(
                name="application/x-amf",
                comment="AMF",
                suffixes=["amf"]
            )
        )
开发者ID:Ultimaker,项目名称:Cura,代码行数:12,代码来源:AMFReader.py

示例6: __init__

    def __init__(self):
        super().__init__(add_to_recent_files = False)

        MimeTypeDatabase.addMimeType(
            MimeType(
                name = "application/x-ufp",
                comment = "Ultimaker Format Package",
                suffixes = ["ufp"]
            )
        )

        self._snapshot = None
开发者ID:TinkerGnome,项目名称:Cura,代码行数:12,代码来源:UFPWriter.py

示例7: mime_database

def mime_database():
    MimeTypeDatabase._MimeTypeDatabase__custom_mimetypes = []
    mime = MimeType(
        name = "application/x-test",
        comment = "Test Mimetype",
        suffixes = [ "test" ]
    )
    MimeTypeDatabase.addMimeType(mime)
    mime = MimeType(
        name = "application/x-long-test",
        comment = "Long Test Mimetype",
        suffixes = [ "long.test" ]
    )
    MimeTypeDatabase.addMimeType(mime)
    mime = MimeType(
        name = "application/x-multiple-test",
        comment = "Multiple Extension MIME Type",
        suffixes = [ "tost", "ost" ],
        preferred_suffix = "ost"
    )
    MimeTypeDatabase.addMimeType(mime)
    mime = MimeType(
        name = "image/jpeg",
        comment = "Custom JPEG MIME Type",
        suffixes = [ "jpg", "jpeg" ],
        preferred_suffix = "jpg"
    )
    MimeTypeDatabase.addMimeType(mime)

    return MimeTypeDatabase
开发者ID:senttech,项目名称:Uranium,代码行数:30,代码来源:TestMimeTypes.py

示例8: __init__

    def __init__(self) -> None:
        super().__init__()
        MimeTypeDatabase.addMimeType(
            MimeType(
                name = "application/x-cura-gcode-file",
                comment = "Cura GCode File",
                suffixes = ["gcode"]
            )
        )
        self._supported_extensions = [".gcode", ".g"]

        self._flavor_reader = None

        Application.getInstance().getPreferences().addPreference("gcodereader/show_caution", True)
开发者ID:rwreynolds,项目名称:Cura,代码行数:14,代码来源:GCodeReader.py

示例9: setup_module

def setup_module():
     MimeTypeDatabase.addMimeType(
        MimeType(
            name = "application/vnd.ms-package.3dmanufacturing-3dmodel+xml",
            comment = "3MF",
            suffixes = ["3mf"]
        )
     )

     MimeTypeDatabase.addMimeType(
         MimeType(
             name = "application/x-cura-gcode-file",
             comment = "Cura GCode File",
             suffixes = ["gcode"]
         )
     )
开发者ID:Ultimaker,项目名称:Cura,代码行数:16,代码来源:TestPrintInformation.py

示例10: loadFromFile

    def loadFromFile(self, file_path: str) -> None:
        mime_type = MimeTypeDatabase.getMimeTypeForFile(file_path)

        item_id = urllib.parse.unquote_plus(mime_type.stripExtension(os.path.basename(file_path)))
        if not os.path.isfile(file_path):
            Logger.log("e", "[%s] is not a file", file_path)
            return None

        parser = ConfigParser(interpolation = None, allow_no_value = True)  # Accept options without any value,

        parser.read([file_path])
        if not parser.has_option("general", "name") or not parser.has_option("general", "weight"):
            return None

        settings = []  # type: List[str]
        for section in parser.sections():
            if section == "general":
                continue

            settings.append(section)
            for option in parser[section].keys():
                settings.append(option)
        self.setSettings(settings)
        self.setId(item_id)
        self.setName(parser["general"]["name"])
        self.setWeight(int(parser["general"]["weight"]))
开发者ID:TinkerGnome,项目名称:Cura,代码行数:26,代码来源:SettingVisibilityPreset.py

示例11: __init__

    def __init__(self) -> None:
        super().__init__()

        MimeTypeDatabase.addMimeType(
            MimeType(
                name = "application/vnd.ms-package.3dmanufacturing-3dmodel+xml",
                comment="3MF",
                suffixes=["3mf"]
            )
        )

        self._supported_extensions = [".3mf"]
        self._root = None
        self._base_name = ""
        self._unit = None
        self._object_count = 0  # Used to name objects as there is no node name yet.
开发者ID:TinkerGnome,项目名称:Cura,代码行数:16,代码来源:ThreeMFReader.py

示例12: load

    def load(self):
        files = []
        for resource_type in self._resource_types:
            resources = Resources.getAllResourcesOfType(resource_type)

            try:
                resource_storage_path = Resources.getStoragePathForType(resource_type)
            except UnsupportedStorageTypeError:
                resource_storage_path = ""

            # Pre-process the list of files to insert relevant data
            # Most importantly, we need to ensure the loading order is DefinitionContainer, InstanceContainer, ContainerStack
            for path in resources:
                mime = MimeTypeDatabase.getMimeTypeForFile(path)
                container_type = self.__mime_type_map.get(mime.name)
                if not container_type:
                    Logger.log("w", "Could not determine container type for file %s, ignoring", path)
                    continue

                type_priority = 2

                if issubclass(container_type, DefinitionContainer.DefinitionContainer):
                    type_priority = 0

                if issubclass(container_type, InstanceContainer.InstanceContainer):
                    type_priority = 1

                # Since we have the mime type and resource type here, process these two properties so we do not
                # need to look up mime types etc. again.
                container_id = urllib.parse.unquote_plus(mime.stripExtension(os.path.basename(path)))
                read_only = os.path.dirname(path) != resource_storage_path

                files.append((type_priority, container_id, path, read_only, container_type))

        # Sort the list of files by type_priority so we can ensure correct loading order.
        files = sorted(files, key = lambda i: i[0])

        for _, container_id, file_path, read_only, container_type in files:
            if container_id in self._id_container_cache:
                continue

            try:
                if issubclass(container_type, DefinitionContainer.DefinitionContainer):
                    definition = self._loadCachedDefinition(container_id, file_path)
                    if definition:
                        self.addContainer(definition)
                        continue

                new_container = container_type(container_id)
                with open(file_path, encoding = "utf-8") as f:
                    new_container.deserialize(f.read())
                new_container.setReadOnly(read_only)

                if issubclass(container_type, DefinitionContainer.DefinitionContainer):
                    self._saveCachedDefinition(new_container)

                self.addContainer(new_container)
            except Exception as e:
                Logger.logException("e", "Could not deserialize container %s", container_id)
开发者ID:TimurAykutYildirim,项目名称:Uranium,代码行数:59,代码来源:ContainerRegistry.py

示例13: getMimeTypeForContainer

 def getMimeTypeForContainer(cls, container_type: type) -> Optional[MimeType]:
     try:
         mime_type_name = UM.Dictionary.findKey(cls.mime_type_map, container_type)
         if mime_type_name:
             return MimeTypeDatabase.getMimeType(mime_type_name)
     except ValueError:
         Logger.log("w", "Unable to find mimetype for container %s", container_type)
     return None
开发者ID:Ultimaker,项目名称:Uranium,代码行数:8,代码来源:ContainerRegistry.py

示例14: _pathToMime

 def _pathToMime(self, path: str) -> Optional[MimeType]:
     try:
         mime = MimeTypeDatabase.getMimeTypeForFile(path)
     except MimeTypeDatabase.MimeTypeNotFoundError:
         Logger.log("w", "MIME type could not be found for file: {path}, ignoring it.".format(path = path))
         return None
     if mime.name not in ContainerRegistry.mime_type_map:  # The MIME type is known, but it's not a container.
         return None
     return mime
开发者ID:Ultimaker,项目名称:Uranium,代码行数:9,代码来源:LocalContainerProvider.py

示例15: convertPathToId

 def convertPathToId(path: str) -> str:
     mime = None
     try:
         mime = MimeTypeDatabase.getMimeTypeForFile(path)
     except MimeTypeDatabase.MimeTypeNotFoundError:
         pass
     if mime:
         return urllib.parse.unquote_plus(mime.stripExtension(os.path.basename(path)))
     else:
         return ""
开发者ID:Ultimaker,项目名称:Uranium,代码行数:10,代码来源:PackageManager.py


注:本文中的UM.MimeTypeDatabase.MimeTypeDatabase类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。