1212except ImportError :
1313 ContainerTree = None # type: ignore
1414
15+ from typing import TYPE_CHECKING
16+
17+ if TYPE_CHECKING :
18+ from cura .Settings .ExtruderStack import ExtruderStack
1519
1620class SidebarGUIProxy (QObject ):
1721 def __init__ (self , parent = None ) -> None :
1822 super ().__init__ (parent )
1923 Logger .log ("d" , "SidebarGUI proxy created" )
2024
2125 @pyqtSlot ("QVariant" , result = bool )
22- def getExtruderHasQualityForMaterial (self , extruder_stack ) :
26+ def getExtruderHasQualityForMaterial (self , extruder_stack : "ExtruderStack" ) -> bool :
2327 application = Application .getInstance ()
2428 global_stack = application .getGlobalContainerStack ()
2529 if not global_stack or not extruder_stack :
@@ -30,20 +34,26 @@ def getExtruderHasQualityForMaterial(self, extruder_stack):
3034
3135 if ContainerTree is not None :
3236 # Post Cura 4.4; use ContainerTree to find out if there are supported qualities
33- container_tree = ContainerTree .getInstance ()
34- machine_node = container_tree .machines [global_stack .definition .getId ()]
35- nodes = set () # type: Set[MaterialNode]
37+ machine_node = ContainerTree .getInstance ().machines [global_stack .definition .getId ()]
3638
3739 active_variant_name = extruder_stack .variant .getMetaDataEntry ("name" )
38- if active_variant_name not in machine_node .variants :
40+ try :
41+ active_variant_node = machine_node .variants [active_variant_name ]
42+ except KeyError :
3943 Logger .log ("w" , "Could not find the variant %s" , active_variant_name )
4044 return True
41- active_variant_node = machine_node .variants [active_variant_name ]
42- active_material_node = active_variant_node .materials [
43- extruder_stack .material .getMetaDataEntry ("base_file" )
44- ]
4545
46- return list (active_material_node .qualities .keys ())[0 ] != "empty_quality"
46+ material_base_file = extruder_stack .material .getMetaDataEntry ("base_file" )
47+ try :
48+ active_material_node = active_variant_node .materials [material_base_file ]
49+ except KeyError :
50+ Logger .log ("w" , "Could not find material %s for the current variant" , material_base_file )
51+ return False
52+
53+ active_material_node_qualities = active_material_node .qualities
54+ if not active_material_node_qualities :
55+ return False
56+ return list (active_material_node_qualities .keys ())[0 ] != "empty_quality"
4757
4858 else :
4959 # Pre Cura 4.4; use MaterialManager et al to find out if there are supported qualities
0 commit comments