mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-06-04 11:14:21 +08:00
Use plugin Id instead of __file__ for XmlMaterialProfile
CURA-6255
This commit is contained in:
parent
49b93db6df
commit
128bfa987e
15
plugins/XmlMaterialProfile/PluginInfo.py
Normal file
15
plugins/XmlMaterialProfile/PluginInfo.py
Normal file
@ -0,0 +1,15 @@
|
||||
from UM.PluginObject import PluginObject
|
||||
|
||||
|
||||
class PluginInfo(PluginObject):
|
||||
__instance = None # type: PluginInfo
|
||||
|
||||
def __init__(self, *args, **kwags):
|
||||
super().__init__(*args, **kwags)
|
||||
if PluginInfo.__instance is not None:
|
||||
raise RuntimeError("Try to create singleton '%s' more than once" % self.__class__.__name__)
|
||||
PluginInfo.__instance = self
|
||||
|
||||
@classmethod
|
||||
def getInstance(cls, *args, **kwargs) -> "USBPrinterOutputDeviceManager":
|
||||
return cls.__instance
|
@ -9,6 +9,7 @@ import sys
|
||||
from typing import Any, Dict, List, Optional, Tuple, cast, Set, Union
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
from UM.PluginRegistry import PluginRegistry
|
||||
from UM.Resources import Resources
|
||||
from UM.Logger import Logger
|
||||
import UM.Dictionary
|
||||
@ -19,6 +20,7 @@ from UM.ConfigurationErrorMessage import ConfigurationErrorMessage
|
||||
from cura.CuraApplication import CuraApplication
|
||||
from cura.Machines.ContainerTree import ContainerTree
|
||||
from cura.Machines.VariantType import VariantType
|
||||
from plugins.XmlMaterialProfile import PluginInfo
|
||||
|
||||
try:
|
||||
from .XmlMaterialValidator import XmlMaterialValidator
|
||||
@ -1068,7 +1070,9 @@ class XmlMaterialProfile(InstanceContainer):
|
||||
# This loads the mapping from a file.
|
||||
@classmethod
|
||||
def getProductIdMap(cls) -> Dict[str, List[str]]:
|
||||
product_to_id_file = os.path.join(os.path.dirname(sys.modules[cls.__module__].__file__), "product_to_id.json")
|
||||
plugin_id = PluginInfo.getInstance().getPluginId()
|
||||
plugin_path = PluginRegistry.getInstance().getPluginPath(plugin_id)
|
||||
product_to_id_file = os.path.join(plugin_path, "product_to_id.json")
|
||||
with open(product_to_id_file, encoding = "utf-8") as f:
|
||||
product_to_id_map = json.load(f)
|
||||
product_to_id_map = {key: [value] for key, value in product_to_id_map.items()}
|
||||
|
@ -1,6 +1,6 @@
|
||||
# Copyright (c) 2017 Ultimaker B.V.
|
||||
# Cura is released under the terms of the LGPLv3 or higher.
|
||||
|
||||
from plugins.XmlMaterialProfile.PluginInfo import PluginInfo
|
||||
from . import XmlMaterialProfile
|
||||
from . import XmlMaterialUpgrader
|
||||
|
||||
@ -46,4 +46,5 @@ def register(app):
|
||||
|
||||
return {"version_upgrade": upgrader,
|
||||
"settings_container": XmlMaterialProfile.XmlMaterialProfile("default_xml_material_profile"),
|
||||
"plugin_info": PluginInfo()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user