Skip to content

Commit 2a03fe7

Browse files
committed
Apply black formatting
1 parent afb8fd1 commit 2a03fe7

3 files changed

Lines changed: 68 additions & 28 deletions

File tree

SidebarGUIPlugin.py

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@
1414

1515

1616
class SidebarGUIPlugin(Extension):
17-
1817
def __init__(self):
1918
super().__init__()
20-
self._prepare_stage_view_id = "SolidView" # can be "SolidView" or "XRayView"
19+
self._prepare_stage_view_id = "SolidView" # can be "SolidView" or "XRayView"
2120

2221
Application.getInstance().pluginsLoaded.connect(self._onPluginsLoaded)
2322
preferences = Application.getInstance().getPreferences()
@@ -43,11 +42,28 @@ def _onEngineCreated(self):
4342
Logger.log("d", "Registering replacement stages")
4443

4544
engine = Application.getInstance()._qml_engine
46-
qmlRegisterSingletonType(SidebarGUIProxy, "Cura", 1, 0, "SidebarGUIPlugin", self.getProxy)
47-
48-
sidebar_component_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "resources", "qml", "SidebarStageMenu.qml")
49-
main_component_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "resources", "qml", "StageMain.qml")
50-
monitor_menu_component_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "resources", "qml", "MonitorStageMenu.qml")
45+
qmlRegisterSingletonType(
46+
SidebarGUIProxy, "Cura", 1, 0, "SidebarGUIPlugin", self.getProxy
47+
)
48+
49+
sidebar_component_path = os.path.join(
50+
os.path.dirname(os.path.abspath(__file__)),
51+
"resources",
52+
"qml",
53+
"SidebarStageMenu.qml",
54+
)
55+
main_component_path = os.path.join(
56+
os.path.dirname(os.path.abspath(__file__)),
57+
"resources",
58+
"qml",
59+
"StageMain.qml",
60+
)
61+
monitor_menu_component_path = os.path.join(
62+
os.path.dirname(os.path.abspath(__file__)),
63+
"resources",
64+
"qml",
65+
"MonitorStageMenu.qml",
66+
)
5167

5268
prepare_stage = self._controller.getStage("PrepareStage")
5369
prepare_stage.addDisplayComponent("menu", sidebar_component_path)
@@ -66,7 +82,6 @@ def _onEngineCreated(self):
6682
monitor_stage = self._controller.getStage("MonitorStage")
6783
monitor_stage.addDisplayComponent("menu", monitor_menu_component_path)
6884

69-
7085
def _onStageChanged(self):
7186
active_stage_id = self._controller.getActiveStage().getPluginId()
7287
view_id = ""
@@ -76,15 +91,19 @@ def _onStageChanged(self):
7691
elif active_stage_id == "PreviewStage":
7792
view_id = "SimulationView"
7893

79-
if view_id and (self._controller.getActiveView() is None or view_id != self._controller.getActiveView().getPluginId()):
94+
if view_id and (
95+
self._controller.getActiveView() is None
96+
or view_id != self._controller.getActiveView().getPluginId()
97+
):
8098
self._controller.setActiveView(view_id)
8199

82-
83100
def _onViewChanged(self):
84101
active_stage_id = self._controller.getActiveStage().getPluginId()
85102
active_view_id = self._controller.getActiveView().getPluginId()
86103

87-
if active_stage_id == "SmartSlicePlugin": # SmartSlicePlugin view is provided by the SmartSlicePlugin plugin
104+
if (
105+
active_stage_id == "SmartSlicePlugin"
106+
): # SmartSlicePlugin view is provided by the SmartSlicePlugin plugin
88107
return
89108

90109
if active_stage_id == "PrepareStage":
@@ -95,14 +114,16 @@ def _onViewChanged(self):
95114
elif active_stage_id == "MonitorStage":
96115
return
97116

98-
if active_view_id in ["SimulationView", "FastView"]: # FastView is provided by the RAWMouse plugin
117+
if active_view_id in [
118+
"SimulationView",
119+
"FastView",
120+
]: # FastView is provided by the RAWMouse plugin
99121
if active_stage_id != "PreviewStage":
100122
self._controller.setActiveStage("PreviewStage")
101123
else:
102124
if active_stage_id != "PrepareStage":
103125
self._controller.setActiveStage("PrepareStage")
104126

105-
106127
## Hackish way to ensure the proxy is already created, which ensures that the sidebargui.qml is already created
107128
# as this caused some issues.
108129
def getProxy(self, engine, script_engine):

SidebarGUIProxy.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@
1212
except ImportError:
1313
ContainerTree = None # type: ignore
1414

15+
1516
class SidebarGUIProxy(QObject):
16-
def __init__(self, parent = None) -> None:
17+
def __init__(self, parent=None) -> None:
1718
super().__init__(parent)
1819
Logger.log("d", "SidebarGUI proxy created")
1920

20-
@pyqtSlot("QVariant", result = bool)
21+
@pyqtSlot("QVariant", result=bool)
2122
def getExtruderHasQualityForMaterial(self, extruder_stack):
2223
application = Application.getInstance()
2324
global_stack = application.getGlobalContainerStack()
@@ -38,7 +39,9 @@ def getExtruderHasQualityForMaterial(self, extruder_stack):
3839
Logger.log("w", "Could not find the variant %s", active_variant_name)
3940
return True
4041
active_variant_node = machine_node.variants[active_variant_name]
41-
active_material_node = active_variant_node.materials[extruder_stack.material.getMetaDataEntry("base_file")]
42+
active_material_node = active_variant_node.materials[
43+
extruder_stack.material.getMetaDataEntry("base_file")
44+
]
4245

4346
return list(active_material_node.qualities.keys())[0] != "empty_quality"
4447

@@ -49,32 +52,41 @@ def getExtruderHasQualityForMaterial(self, extruder_stack):
4952
}
5053

5154
if global_stack.getMetaDataEntry("has_machine_quality"):
52-
search_criteria["definition"] = global_stack.getMetaDataEntry("quality_definition", global_stack.definition.id)
55+
search_criteria["definition"] = global_stack.getMetaDataEntry(
56+
"quality_definition", global_stack.definition.id
57+
)
5358
else:
5459
return True
5560

5661
container_registry = application.getContainerRegistry()
57-
if(hasattr(application, "getMaterialManager")):
62+
if hasattr(application, "getMaterialManager"):
5863
material_manager = application.getMaterialManager()
5964

60-
fallback_material = material_manager.getFallbackMaterialIdByMaterialType(extruder_stack.material.getMetaDataEntry("material"))
65+
fallback_material = (
66+
material_manager.getFallbackMaterialIdByMaterialType(
67+
extruder_stack.material.getMetaDataEntry("material")
68+
)
69+
)
6170
search_criteria["material"] = fallback_material
6271

6372
if global_stack.getMetaDataEntry("has_variants"):
6473
search_criteria["variant"] = extruder_stack.variant.name
6574

66-
containers_metadata = container_registry.findInstanceContainersMetadata(**search_criteria)
75+
containers_metadata = container_registry.findInstanceContainersMetadata(
76+
**search_criteria
77+
)
6778

6879
return containers_metadata != []
6980

70-
71-
@pyqtSlot("QVariant", result = bool)
81+
@pyqtSlot("QVariant", result=bool)
7282
def checkRectangleOnScreen(self, rectangle):
7383
# Check if rectangle is not outside the currently available screens
7484
application = Application.getInstance()
7585
screen_found = False
7686
for screen_number in range(0, application.desktop().screenCount()):
77-
if rectangle.intersects(QRectF(application.desktop().availableGeometry(screen_number))):
87+
if rectangle.intersects(
88+
QRectF(application.desktop().availableGeometry(screen_number))
89+
):
7890
screen_found = True
7991
break
8092
if not screen_found:

__init__.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,26 @@
55

66
from . import SidebarGUIPlugin
77
from UM.i18n import i18nCatalog
8+
89
i18n_catalog = i18nCatalog("cura")
910

1011
from UM.Version import Version
1112
from UM.Application import Application
1213
from UM.Logger import Logger
1314

15+
1416
def getMetaData():
1517
return {}
1618

19+
1720
def register(app):
1821
if __matchVersion():
19-
return {
20-
"extension": SidebarGUIPlugin.SidebarGUIPlugin()
21-
}
22+
return {"extension": SidebarGUIPlugin.SidebarGUIPlugin()}
2223
else:
2324
Logger.log("w", "Plugin not loaded because of a version mismatch")
2425
return {}
2526

27+
2628
def __matchVersion():
2729
cura_version = Application.getInstance().getVersion()
2830
if cura_version == "master":
@@ -36,7 +38,9 @@ def __matchVersion():
3638
cura_version = Version([cura_version.getMajor(), cura_version.getMinor()])
3739

3840
# Get version information from plugin.json
39-
plugin_file_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "plugin.json")
41+
plugin_file_path = os.path.join(
42+
os.path.dirname(os.path.abspath(__file__)), "plugin.json"
43+
)
4044
try:
4145
with open(plugin_file_path) as plugin_file:
4246
plugin_info = json.load(plugin_file)
@@ -49,5 +53,8 @@ def __matchVersion():
4953
if cura_version >= minimum_cura_version and cura_version <= maximum_cura_version:
5054
return True
5155
else:
52-
Logger.log("d", "This version of the plugin is not compatible with this version of Cura. Please check for an update.")
56+
Logger.log(
57+
"d",
58+
"This version of the plugin is not compatible with this version of Cura. Please check for an update.",
59+
)
5360
return False

0 commit comments

Comments
 (0)