diff --git a/plugins/USBPrinting/USBPrinterOutputDevice.py b/plugins/USBPrinting/USBPrinterOutputDevice.py index c9758d88d4..adb3b03700 100644 --- a/plugins/USBPrinting/USBPrinterOutputDevice.py +++ b/plugins/USBPrinting/USBPrinterOutputDevice.py @@ -88,7 +88,8 @@ class USBPrinterOutputDevice(PrinterOutputDevice): self._firmware_name_requested = False self._firmware_updater = AvrFirmwareUpdater(self) - self._monitor_view_qml_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "MonitorItem.qml") + plugin_path = cast(str, PluginRegistry.getInstance().getPluginPath("USBPrinting")) + self._monitor_view_qml_path = os.path.join(plugin_path, "MonitorItem.qml") CuraApplication.getInstance().getOnExitCallbackManager().addCallback(self._checkActivePrintingUponAppExit) diff --git a/plugins/XmlMaterialProfile/PluginInfo.py b/plugins/XmlMaterialProfile/PluginInfo.py new file mode 100644 index 0000000000..4b78a47a5e --- /dev/null +++ b/plugins/XmlMaterialProfile/PluginInfo.py @@ -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) -> "PluginInfo": + return cls.__instance \ No newline at end of file diff --git a/plugins/XmlMaterialProfile/XmlMaterialProfile.py b/plugins/XmlMaterialProfile/XmlMaterialProfile.py index bf1bf19e32..30bbecc86e 100644 --- a/plugins/XmlMaterialProfile/XmlMaterialProfile.py +++ b/plugins/XmlMaterialProfile/XmlMaterialProfile.py @@ -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 @@ -1068,7 +1069,8 @@ 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_path = cast(str, PluginRegistry.getInstance().getPluginPath("XmlMaterialProfile")) + 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()}