Skip to content

Commit a339131

Browse files
committed
Factor out qmlRegisterSingletonType
pyQt only allows a limited number of types to register via qmlRegisterSingletonType or qmlRegisterType
1 parent 0bfed16 commit a339131

File tree

4 files changed

+4
-17
lines changed

4 files changed

+4
-17
lines changed

SidebarGUIPlugin.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import os.path
55
from UM.Application import Application
66
from UM.Extension import Extension
7-
from UM.Resources import Resources
87
from UM.Logger import Logger
98

109
try:
@@ -51,14 +50,7 @@ def _onEngineCreated(self):
5150
Logger.log("d", "Registering replacement stages")
5251

5352
engine = Application.getInstance()._qml_engine
54-
try:
55-
qmlRegisterSingletonType(
56-
SidebarGUIProxy, "Cura", 1, 0, self.getProxy, "SidebarGUIPlugin"
57-
)
58-
except TypeError:
59-
qmlRegisterSingletonType(
60-
SidebarGUIProxy, "Cura", 1, 0, "SidebarGUIPlugin", self.getProxy
61-
)
53+
engine.rootContext().setContextProperty("SidebarGUIPlugin", self._proxy)
6254

6355
sidebar_component_path = os.path.join(
6456
os.path.dirname(os.path.abspath(__file__)),
@@ -137,8 +129,3 @@ def _onViewChanged(self):
137129
else:
138130
if active_stage_id != "PrepareStage":
139131
self._controller.setActiveStage("PrepareStage")
140-
141-
## Hackish way to ensure the proxy is already created, which ensures that the sidebargui.qml is already created
142-
# as this caused some issues.
143-
def getProxy(self, engine, script_engine):
144-
return self._proxy

resources/qml/ExtruderTabs40.qml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ TabRow
109109
return Cura.MachineManager.getExtruder(model.index);
110110
}
111111
}
112-
property bool valueWarning: !Cura.SidebarGUIPlugin.getExtruderHasQualityForMaterial(extruderStack)
112+
property bool valueWarning: !SidebarGUIPlugin.getExtruderHasQualityForMaterial(extruderStack)
113113
property bool valueError: extruderStack == undefined ? false : Cura.ContainerManager.getContainerMetaDataEntry(extruderStack.material.id, "compatible", "") != "True"
114114

115115
visible: (tabBar.hasMaterials || tabBar.hasVariants) && (valueWarning || valueError)

resources/qml/ExtruderTabs411.qml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ TabRow
119119
{
120120
return UM.StatusIcon.Status.ERROR
121121
}
122-
if (!Cura.SidebarGUIPlugin.getExtruderHasQualityForMaterial(extruderStack))
122+
if (!SidebarGUIPlugin.getExtruderHasQualityForMaterial(extruderStack))
123123
{
124124
return UM.StatusIcon.Status.WARNING
125125
}

resources/qml/ExtruderTabs50.qml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ TabRow
106106
{
107107
return UM.StatusIcon.Status.ERROR
108108
}
109-
if (!Cura.SidebarGUIPlugin.getExtruderHasQualityForMaterial(extruderStack))
109+
if (!SidebarGUIPlugin.getExtruderHasQualityForMaterial(extruderStack))
110110
{
111111
return UM.StatusIcon.Status.WARNING
112112
}

0 commit comments

Comments
 (0)