-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathSidebarGUIPlugin.py
More file actions
151 lines (122 loc) · 5.93 KB
/
SidebarGUIPlugin.py
File metadata and controls
151 lines (122 loc) · 5.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# Copyright (c) 2023 Aldo Hoeben / fieldOfView
# The SidebarGUIPlugin is released under the terms of the AGPLv3 or higher.
import os.path
from UM.Application import Application
from UM.Extension import Extension
from UM.Logger import Logger
try:
from cura.ApplicationMetadata import CuraSDKVersion
except ImportError: # Cura <= 3.6
CuraSDKVersion = "6.0.0"
if CuraSDKVersion >= "8.0.0":
from PyQt6.QtCore import QTimer
else:
from PyQt5.QtCore import QTimer
from .SidebarGUIProxy import SidebarGUIProxy
class SidebarGUIPlugin(Extension):
def __init__(self):
super().__init__()
self._prepare_stage_view_id = "SolidView" # can be "SolidView" or "XRayView"
Application.getInstance().pluginsLoaded.connect(self._onPluginsLoaded)
preferences = Application.getInstance().getPreferences()
preferences.addPreference("sidebargui/expand_extruder_configuration", False)
preferences.addPreference("sidebargui/expand_legend", True)
preferences.addPreference("sidebargui/docked_sidebar", True)
preferences.addPreference("sidebargui/settings_window_left", 65535)
preferences.addPreference("sidebargui/settings_window_top", 65535)
preferences.addPreference("sidebargui/settings_window_height", 0)
self._controller = Application.getInstance().getController()
self._controller.activeStageChanged.connect(self._onStageChanged)
self._controller.activeViewChanged.connect(self._onViewChanged)
self._proxy = SidebarGUIProxy()
def _onPluginsLoaded(self):
# delayed connection to engineCreatedSignal to force this plugin to receive that signal
# AFTER the original stages are created
Application.getInstance().engineCreatedSignal.connect(self._onEngineCreated)
def _onEngineCreated(self):
Logger.log("d", "Registering replacement stages")
engine = Application.getInstance()._qml_engine
engine.rootContext().setContextProperty("SidebarGUIPlugin", self._proxy)
sidebar_component_path = os.path.join(
os.path.dirname(os.path.abspath(__file__)),
"resources",
"qml",
"SidebarStageMenu.qml",
)
main_component_path = os.path.join(
os.path.dirname(os.path.abspath(__file__)),
"resources",
"qml",
"StageMain.qml",
)
monitor_menu_component_path = os.path.join(
os.path.dirname(os.path.abspath(__file__)),
"resources",
"qml",
"MonitorStageMenu.qml",
)
prepare_stage = self._controller.getStage("PrepareStage")
prepare_stage.addDisplayComponent("menu", sidebar_component_path)
prepare_stage.addDisplayComponent("main", main_component_path)
preview_stage = self._controller.getStage("PreviewStage")
preview_stage.addDisplayComponent("menu", sidebar_component_path)
preview_stage.addDisplayComponent("main", main_component_path)
# SmartSlicePlugin stage is provided by the SmartSlicePlugin plugin
if "SmartSlicePlugin" in self._controller.getAllStages():
smartslice_stage = self._controller.getStage("SmartSlicePlugin")
smartslice_stage.addDisplayComponent("menu", sidebar_component_path)
smartslice_stage.addDisplayComponent("main", main_component_path)
monitor_stage = self._controller.getStage("MonitorStage")
monitor_stage.addDisplayComponent("menu", monitor_menu_component_path)
def _onStageChanged(self):
active_stage_id = self._controller.getActiveStage().getPluginId()
active_view = self._controller.getActiveView()
# Don't change view if PaintTool is active
if active_view and active_view.getPluginId() == "PaintTool":
return
view_id = ""
if active_stage_id == "PrepareStage":
view_id = self._prepare_stage_view_id
elif active_stage_id == "PreviewStage":
view_id = "SimulationView"
if view_id and (
self._controller.getActiveView() is None
or view_id != self._controller.getActiveView().getPluginId()
):
self._controller.setActiveView(view_id)
def _onViewChanged(self):
active_stage = self._controller.getActiveStage()
active_view = self._controller.getActiveView()
if not active_stage or not active_view:
return
active_stage_id = active_stage.getPluginId()
active_view_id = active_view.getPluginId()
# Force machine settings update when PaintTool is activated to fix rendering issue
if active_view_id == "PaintTool":
QTimer.singleShot(0, lambda: Application.getInstance().getMachineManager().forceUpdateAllSettings())
if (
active_stage_id == "SmartSlicePlugin"
): # SmartSlicePlugin view is provided by the SmartSlicePlugin plugin
return
if active_stage_id == "PrepareStage":
if active_view_id not in ["SolidView", "XRayView", "PaintTool"]:
self._controller.setActiveView("SolidView")
return
if active_view_id in ["SolidView", "XRayView"]:
self._prepare_stage_view_id = active_view_id
elif active_stage_id == "MonitorStage":
return
elif active_stage_id == "PreviewStage":
# Ensure SimulationView is active when in PreviewStage
if active_view_id != "SimulationView":
self._controller.setActiveView("SimulationView")
return
if active_view_id in [
"SimulationView",
"FastView",
]: # FastView is provided by the RAWMouse plugin
if active_stage_id != "PreviewStage":
self._controller.setActiveStage("PreviewStage")
elif active_view_id not in ["PaintTool"]:
if active_stage_id != "PrepareStage":
self._controller.setActiveStage("PrepareStage")