-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
SidebarGUIPlugin.py
120 lines (97 loc) · 4.78 KB
/
SidebarGUIPlugin.py
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
# 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
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()
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_id = self._controller.getActiveStage().getPluginId()
active_view_id = self._controller.getActiveView().getPluginId()
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"]:
self._controller.setActiveView("SolidView")
return
self._prepare_stage_view_id = active_view_id
elif active_stage_id == "MonitorStage":
return
if active_view_id in [
"SimulationView",
"FastView",
]: # FastView is provided by the RAWMouse plugin
if active_stage_id != "PreviewStage":
self._controller.setActiveStage("PreviewStage")
else:
if active_stage_id != "PrepareStage":
self._controller.setActiveStage("PrepareStage")