55from UM .Application import Application
66from UM .Extension import Extension
77from UM .Logger import Logger
8+ from PyQt6 .QtCore import QTimer
89
910from .SidebarGUIProxy import SidebarGUIProxy
1011
@@ -79,6 +80,12 @@ def _onEngineCreated(self):
7980
8081 def _onStageChanged (self ):
8182 active_stage_id = self ._controller .getActiveStage ().getPluginId ()
83+ active_view = self ._controller .getActiveView ()
84+
85+ # Don't change view if PaintTool is active
86+ if active_view and active_view .getPluginId () == "PaintTool" :
87+ return
88+
8289 view_id = ""
8390
8491 if active_stage_id == "PrepareStage" :
@@ -93,28 +100,44 @@ def _onStageChanged(self):
93100 self ._controller .setActiveView (view_id )
94101
95102 def _onViewChanged (self ):
96- active_stage_id = self ._controller .getActiveStage ().getPluginId ()
97- active_view_id = self ._controller .getActiveView ().getPluginId ()
103+ active_stage = self ._controller .getActiveStage ()
104+ active_view = self ._controller .getActiveView ()
105+
106+ if not active_stage or not active_view :
107+ return
108+
109+ active_stage_id = active_stage .getPluginId ()
110+ active_view_id = active_view .getPluginId ()
111+
112+ # Force machine settings update when PaintTool is activated to fix rendering issue
113+ if active_view_id == "PaintTool" :
114+ QTimer .singleShot (0 , lambda : Application .getInstance ().getMachineManager ().forceUpdateAllSettings ())
98115
99116 if (
100117 active_stage_id == "SmartSlicePlugin"
101118 ): # SmartSlicePlugin view is provided by the SmartSlicePlugin plugin
102119 return
103120
104121 if active_stage_id == "PrepareStage" :
105- if active_view_id not in ["SolidView" , "XRayView" ]:
122+ if active_view_id not in ["SolidView" , "XRayView" , "PaintTool" ]:
106123 self ._controller .setActiveView ("SolidView" )
107124 return
108- self ._prepare_stage_view_id = active_view_id
125+ if active_view_id in ["SolidView" , "XRayView" ]:
126+ self ._prepare_stage_view_id = active_view_id
109127 elif active_stage_id == "MonitorStage" :
110128 return
129+ elif active_stage_id == "PreviewStage" :
130+ # Ensure SimulationView is active when in PreviewStage
131+ if active_view_id != "SimulationView" :
132+ self ._controller .setActiveView ("SimulationView" )
133+ return
111134
112135 if active_view_id in [
113136 "SimulationView" ,
114137 "FastView" ,
115138 ]: # FastView is provided by the RAWMouse plugin
116139 if active_stage_id != "PreviewStage" :
117140 self ._controller .setActiveStage ("PreviewStage" )
118- else :
141+ elif active_view_id not in [ "PaintTool" ] :
119142 if active_stage_id != "PrepareStage" :
120143 self ._controller .setActiveStage ("PrepareStage" )
0 commit comments