From 9267b517d60c5356b9bd425d33c4c8e53cb77e15 Mon Sep 17 00:00:00 2001 From: Arjen Hiemstra Date: Fri, 27 Nov 2015 13:57:53 +0100 Subject: [PATCH] Fix coding style issues --- cura/BuildVolume.py | 56 +++++++++---------- cura/ConvexHullNode.py | 8 +-- cura/CuraApplication.py | 15 +++-- cura/OneAtATimeIterator.py | 6 +- cura_app.py | 3 +- plugins/3MFReader/ThreeMFReader.py | 8 +-- plugins/3MFReader/__init__.py | 2 +- .../ProcessSlicedObjectListJob.py | 7 +-- plugins/CuraEngineBackend/StartSliceJob.py | 5 ++ plugins/GCodeReader/__init__.py | 2 +- plugins/LayerView/LayerViewProxy.py | 2 +- .../WindowsRemovableDrivePlugin.py | 14 ++--- 12 files changed, 68 insertions(+), 60 deletions(-) diff --git a/cura/BuildVolume.py b/cura/BuildVolume.py index 7fdf5b4d1d..98dbf206bd 100644 --- a/cura/BuildVolume.py +++ b/cura/BuildVolume.py @@ -83,38 +83,38 @@ class BuildVolume(SceneNode): if self._width == 0 or self._height == 0 or self._depth == 0: return - minW = -self._width / 2 - maxW = self._width / 2 - minH = 0.0 - maxH = self._height - minD = -self._depth / 2 - maxD = self._depth / 2 + min_w = -self._width / 2 + max_w = self._width / 2 + min_h = 0.0 + max_h = self._height + min_d = -self._depth / 2 + max_d = self._depth / 2 mb = MeshBuilder() - mb.addLine(Vector(minW, minH, minD), Vector(maxW, minH, minD), color = self.VolumeOutlineColor) - mb.addLine(Vector(minW, minH, minD), Vector(minW, maxH, minD), color = self.VolumeOutlineColor) - mb.addLine(Vector(minW, maxH, minD), Vector(maxW, maxH, minD), color = self.VolumeOutlineColor) - mb.addLine(Vector(maxW, minH, minD), Vector(maxW, maxH, minD), color = self.VolumeOutlineColor) + mb.addLine(Vector(min_w, min_h, min_d), Vector(max_w, min_h, min_d), color = self.VolumeOutlineColor) + mb.addLine(Vector(min_w, min_h, min_d), Vector(min_w, max_h, min_d), color = self.VolumeOutlineColor) + mb.addLine(Vector(min_w, max_h, min_d), Vector(max_w, max_h, min_d), color = self.VolumeOutlineColor) + mb.addLine(Vector(max_w, min_h, min_d), Vector(max_w, max_h, min_d), color = self.VolumeOutlineColor) - mb.addLine(Vector(minW, minH, maxD), Vector(maxW, minH, maxD), color = self.VolumeOutlineColor) - mb.addLine(Vector(minW, minH, maxD), Vector(minW, maxH, maxD), color = self.VolumeOutlineColor) - mb.addLine(Vector(minW, maxH, maxD), Vector(maxW, maxH, maxD), color = self.VolumeOutlineColor) - mb.addLine(Vector(maxW, minH, maxD), Vector(maxW, maxH, maxD), color = self.VolumeOutlineColor) + mb.addLine(Vector(min_w, min_h, max_d), Vector(max_w, min_h, max_d), color = self.VolumeOutlineColor) + mb.addLine(Vector(min_w, min_h, max_d), Vector(min_w, max_h, max_d), color = self.VolumeOutlineColor) + mb.addLine(Vector(min_w, max_h, max_d), Vector(max_w, max_h, max_d), color = self.VolumeOutlineColor) + mb.addLine(Vector(max_w, min_h, max_d), Vector(max_w, max_h, max_d), color = self.VolumeOutlineColor) - mb.addLine(Vector(minW, minH, minD), Vector(minW, minH, maxD), color = self.VolumeOutlineColor) - mb.addLine(Vector(maxW, minH, minD), Vector(maxW, minH, maxD), color = self.VolumeOutlineColor) - mb.addLine(Vector(minW, maxH, minD), Vector(minW, maxH, maxD), color = self.VolumeOutlineColor) - mb.addLine(Vector(maxW, maxH, minD), Vector(maxW, maxH, maxD), color = self.VolumeOutlineColor) + mb.addLine(Vector(min_w, min_h, min_d), Vector(min_w, min_h, max_d), color = self.VolumeOutlineColor) + mb.addLine(Vector(max_w, min_h, min_d), Vector(max_w, min_h, max_d), color = self.VolumeOutlineColor) + mb.addLine(Vector(min_w, max_h, min_d), Vector(min_w, max_h, max_d), color = self.VolumeOutlineColor) + mb.addLine(Vector(max_w, max_h, min_d), Vector(max_w, max_h, max_d), color = self.VolumeOutlineColor) self.setMeshData(mb.getData()) mb = MeshBuilder() mb.addQuad( - Vector(minW, minH, minD), - Vector(maxW, minH, minD), - Vector(maxW, minH, maxD), - Vector(minW, minH, maxD) + Vector(min_w, min_h, min_d), + Vector(max_w, min_h, min_d), + Vector(max_w, min_h, max_d), + Vector(min_w, min_h, max_d) ) self._grid_mesh = mb.getData() for n in range(0, 6): @@ -128,10 +128,10 @@ class BuildVolume(SceneNode): color = Color(0.0, 0.0, 0.0, 0.15) for polygon in self._disallowed_areas: points = polygon.getPoints() - first = Vector(self._clamp(points[0][0], minW, maxW), disallowed_area_height, self._clamp(points[0][1], minD, maxD)) - previous_point = Vector(self._clamp(points[0][0], minW, maxW), disallowed_area_height, self._clamp(points[0][1], minD, maxD)) + first = Vector(self._clamp(points[0][0], min_w, max_w), disallowed_area_height, self._clamp(points[0][1], min_d, max_d)) + previous_point = Vector(self._clamp(points[0][0], min_w, max_w), disallowed_area_height, self._clamp(points[0][1], min_d, max_d)) for point in points: - new_point = Vector(self._clamp(point[0], minW, maxW), disallowed_area_height, self._clamp(point[1], minD, maxD)) + new_point = Vector(self._clamp(point[0], min_w, max_w), disallowed_area_height, self._clamp(point[1], min_d, max_d)) mb.addFace(first, previous_point, new_point, color = color) previous_point = new_point @@ -143,7 +143,7 @@ class BuildVolume(SceneNode): else: self._disallowed_area_mesh = None - self._aabb = AxisAlignedBox(minimum = Vector(minW, minH - 1.0, minD), maximum = Vector(maxW, maxH, maxD)) + self._aabb = AxisAlignedBox(minimum = Vector(min_w, min_h - 1.0, min_d), maximum = Vector(max_w, max_h, max_d)) skirt_size = 0.0 @@ -152,8 +152,8 @@ class BuildVolume(SceneNode): skirt_size = self._getSkirtSize(profile) scale_to_max_bounds = AxisAlignedBox( - minimum = Vector(minW + skirt_size, minH, minD + skirt_size + disallowed_area_size), - maximum = Vector(maxW - skirt_size, maxH, maxD - skirt_size - disallowed_area_size) + minimum = Vector(min_w + skirt_size, min_h, min_d + skirt_size + disallowed_area_size), + maximum = Vector(max_w - skirt_size, max_h, max_d - skirt_size - disallowed_area_size) ) Application.getInstance().getController().getScene()._maximum_bounds = scale_to_max_bounds diff --git a/cura/ConvexHullNode.py b/cura/ConvexHullNode.py index 4b36a11949..e7a585d412 100644 --- a/cura/ConvexHullNode.py +++ b/cura/ConvexHullNode.py @@ -29,7 +29,7 @@ class ConvexHullNode(SceneNode): self._node.parentChanged.connect(self._onNodeParentChanged) self._node.decoratorsChanged.connect(self._onNodeDecoratorsChanged) self._onNodeDecoratorsChanged(self._node) - self.convexHullHeadMesh = None + self._convex_hull_head_mesh = None self._hull = hull hull_points = self._hull.getPoints() @@ -38,7 +38,7 @@ class ConvexHullNode(SceneNode): self.setMeshData(hull_mesh) convex_hull_head = self._node.callDecoration("getConvexHullHead") if convex_hull_head: - self.convexHullHeadMesh = self.createHullMesh(convex_hull_head.getPoints()) + self._convex_hull_head_mesh = self.createHullMesh(convex_hull_head.getPoints()) def createHullMesh(self, hull_points): mesh = MeshData() @@ -68,8 +68,8 @@ class ConvexHullNode(SceneNode): if self.getParent(): self._material.setUniformValue("u_color", self._color) renderer.queueNode(self, material = self._material, transparent = True) - if self.convexHullHeadMesh: - renderer.queueNode(self, material = self._material,transparent = True, mesh = self.convexHullHeadMesh) + if self._convex_hull_head_mesh: + renderer.queueNode(self, material = self._material,transparent = True, mesh = self._convex_hull_head_mesh) return True diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index 3009f75d8f..75b6594c93 100644 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -3,11 +3,6 @@ import platform -if platform.system() == "Linux": # Needed for platform.linux_distribution, which is not available on Windows and OSX - # For Ubuntu: https://bugs.launchpad.net/ubuntu/+source/python-qt4/+bug/941826 - if platform.linux_distribution()[0] in ("Ubuntu", ): # Just in case it also happens on Debian, so it can be added - from OpenGL import GL - from UM.Qt.QtApplication import QtApplication from UM.Scene.SceneNode import SceneNode from UM.Scene.Camera import Camera @@ -59,10 +54,15 @@ import numpy import copy numpy.seterr(all="ignore") +if platform.system() == "Linux": # Needed for platform.linux_distribution, which is not available on Windows and OSX + # For Ubuntu: https://bugs.launchpad.net/ubuntu/+source/python-qt4/+bug/941826 + if platform.linux_distribution()[0] in ("Ubuntu", ): # Just in case it also happens on Debian, so it can be added + from OpenGL import GL + try: from cura.CuraVersion import CuraVersion except ImportError: - CuraVersion = "master" + CuraVersion = "master" # [CodeStyle: Reflecting imported value] class CuraApplication(QtApplication): class ResourceTypes: @@ -263,6 +263,7 @@ class CuraApplication(QtApplication): self.jobNameChanged.emit() jobNameChanged = pyqtSignal() + @pyqtProperty(str, notify = jobNameChanged) def jobName(self): return self._job_name @@ -427,6 +428,7 @@ class CuraApplication(QtApplication): return log recentFilesChanged = pyqtSignal() + @pyqtProperty("QVariantList", notify = recentFilesChanged) def recentFiles(self): return self._recent_files @@ -441,6 +443,7 @@ class CuraApplication(QtApplication): self.expandedCategoriesChanged.emit() expandedCategoriesChanged = pyqtSignal() + @pyqtProperty("QStringList", notify = expandedCategoriesChanged) def expandedCategories(self): return Preferences.getInstance().getValue("cura/categories_expanded").split(";") diff --git a/cura/OneAtATimeIterator.py b/cura/OneAtATimeIterator.py index 64f25c6b64..449ca87c31 100644 --- a/cura/OneAtATimeIterator.py +++ b/cura/OneAtATimeIterator.py @@ -45,7 +45,7 @@ class OneAtATimeIterator(Iterator.Iterator): # This does not decrease the worst case running time, but should improve it in most cases. sorted(node_list, key = cmp_to_key(self._calculateScore)) - todo_node_list = [_objectOrder([], node_list)] + todo_node_list = [_ObjectOrder([], node_list)] while len(todo_node_list) > 0: current = todo_node_list.pop() for node in current.todo: @@ -61,7 +61,7 @@ class OneAtATimeIterator(Iterator.Iterator): self._node_stack = new_order return - todo_node_list.append(_objectOrder(new_order, new_todo_list)) + todo_node_list.append(_ObjectOrder(new_order, new_todo_list)) self._node_stack = [] #No result found! @@ -99,7 +99,7 @@ class OneAtATimeIterator(Iterator.Iterator): ## Internal object used to keep track of a possible order in which to print objects. -class _objectOrder(): +class _ObjectOrder(): def __init__(self, order, todo): """ :param order: List of indexes in which to print objects, ordered by printing order. diff --git a/cura_app.py b/cura_app.py index 92624be76f..831582687c 100755 --- a/cura_app.py +++ b/cura_app.py @@ -19,7 +19,8 @@ except ImportError: else: os.environ["PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION"] = "cpp" -import cura.CuraApplication +if True: # To make the code style checker stop complaining + import cura.CuraApplication if sys.platform == "win32" and hasattr(sys, "frozen"): import os diff --git a/plugins/3MFReader/ThreeMFReader.py b/plugins/3MFReader/ThreeMFReader.py index bdbc9a81d3..9d2ee2c166 100644 --- a/plugins/3MFReader/ThreeMFReader.py +++ b/plugins/3MFReader/ThreeMFReader.py @@ -109,10 +109,10 @@ class ThreeMFReader(MeshReader): node.setOrientation(temp_quaternion) # Magical scale extraction - S2 = temp_mat.getTransposed().multiply(temp_mat) - scale_x = math.sqrt(S2.at(0,0)) - scale_y = math.sqrt(S2.at(1,1)) - scale_z = math.sqrt(S2.at(2,2)) + scale = temp_mat.getTransposed().multiply(temp_mat) + scale_x = math.sqrt(scale.at(0,0)) + scale_y = math.sqrt(scale.at(1,1)) + scale_z = math.sqrt(scale.at(2,2)) node.setScale(Vector(scale_x,scale_y,scale_z)) # We use a different coordinate frame, so rotate. diff --git a/plugins/3MFReader/__init__.py b/plugins/3MFReader/__init__.py index 9d7bf57100..d3863aa90f 100644 --- a/plugins/3MFReader/__init__.py +++ b/plugins/3MFReader/__init__.py @@ -1,9 +1,9 @@ # Copyright (c) 2015 Ultimaker B.V. # Cura is released under the terms of the AGPLv3 or higher. -from UM.i18n import i18nCatalog from . import ThreeMFReader +from UM.i18n import i18nCatalog catalog = i18nCatalog("cura") def getMetaData(): diff --git a/plugins/CuraEngineBackend/ProcessSlicedObjectListJob.py b/plugins/CuraEngineBackend/ProcessSlicedObjectListJob.py index 0089dcb185..c802ca343b 100644 --- a/plugins/CuraEngineBackend/ProcessSlicedObjectListJob.py +++ b/plugins/CuraEngineBackend/ProcessSlicedObjectListJob.py @@ -32,7 +32,7 @@ class ProcessSlicedObjectListJob(Job): Application.getInstance().getController().activeViewChanged.connect(self._onActiveViewChanged) - objectIdMap = {} + object_id_map = {} new_node = SceneNode() ## Put all nodes in a dict identified by ID for node in DepthFirstIterator(self._scene.getRoot()): @@ -40,11 +40,10 @@ class ProcessSlicedObjectListJob(Job): if node.callDecoration("getLayerData"): self._scene.getRoot().removeChild(node) else: - objectIdMap[id(node)] = node + object_id_map[id(node)] = node Job.yieldThread() settings = Application.getInstance().getMachineManager().getActiveProfile() - layerHeight = settings.getSettingValue("layer_height") center = None if not settings.getSettingValue("machine_center_is_zero"): @@ -62,7 +61,7 @@ class ProcessSlicedObjectListJob(Job): current_layer = 0 for object in self._message.objects: try: - node = objectIdMap[object.id] + node = object_id_map[object.id] except KeyError: continue diff --git a/plugins/CuraEngineBackend/StartSliceJob.py b/plugins/CuraEngineBackend/StartSliceJob.py index 7fd703f8ca..fe27bfce5e 100644 --- a/plugins/CuraEngineBackend/StartSliceJob.py +++ b/plugins/CuraEngineBackend/StartSliceJob.py @@ -115,12 +115,17 @@ class StartSliceJob(Job): return str(value).encode("utf-8") def _sendSettings(self, profile): + Application.getInstance().getMachineManager().getActiveMachineInstance().setMachineSettingValue("machine_gcode_flavor", "RepRap") + msg = Cura_pb2.SettingList() settings = profile.getAllSettingValues(include_machine = True) start_gcode = settings["machine_start_gcode"] settings["material_bed_temp_prepend"] = "{material_bed_temperature}" not in start_gcode settings["material_print_temp_prepend"] = "{material_print_temperature}" not in start_gcode for key, value in settings.items(): + if key == "machine_gcode_flavor": + print("machine_gcode_flavor", value) + s = msg.settings.add() s.name = key if key == "machine_start_gcode" or key == "machine_end_gcode": diff --git a/plugins/GCodeReader/__init__.py b/plugins/GCodeReader/__init__.py index 3234957902..5b563867f2 100644 --- a/plugins/GCodeReader/__init__.py +++ b/plugins/GCodeReader/__init__.py @@ -1,9 +1,9 @@ # Copyright (c) 2015 Ultimaker B.V. # Cura is released under the terms of the AGPLv3 or higher. -from UM.i18n import i18nCatalog from . import GCodeReader +from UM.i18n import i18nCatalog catalog = i18nCatalog("cura") def getMetaData(): diff --git a/plugins/LayerView/LayerViewProxy.py b/plugins/LayerView/LayerViewProxy.py index a74ea33d85..3d4d1d8278 100644 --- a/plugins/LayerView/LayerViewProxy.py +++ b/plugins/LayerView/LayerViewProxy.py @@ -54,4 +54,4 @@ class LayerViewProxy(QObject): active_view = self._controller.getActiveView() if type(active_view) == LayerView.LayerView.LayerView: active_view.currentLayerNumChanged.connect(self._onLayerChanged) - active_view.maxLayersChanged.connect(self._onMaxLayersChanged) \ No newline at end of file + active_view.maxLayersChanged.connect(self._onMaxLayersChanged) diff --git a/plugins/RemovableDriveOutputDevice/WindowsRemovableDrivePlugin.py b/plugins/RemovableDriveOutputDevice/WindowsRemovableDrivePlugin.py index ced1dcc610..b47a37d35c 100644 --- a/plugins/RemovableDriveOutputDevice/WindowsRemovableDrivePlugin.py +++ b/plugins/RemovableDriveOutputDevice/WindowsRemovableDrivePlugin.py @@ -20,17 +20,17 @@ catalog = i18nCatalog("cura") # WinAPI Constants that we need # Hardcoded here due to stupid WinDLL stuff that does not give us access to these values. -DRIVE_REMOVABLE = 2 +DRIVE_REMOVABLE = 2 # [CodeStyle: Windows Enum value] -GENERIC_READ = 2147483648 -GENERIC_WRITE = 1073741824 +GENERIC_READ = 2147483648 # [CodeStyle: Windows Enum value] +GENERIC_WRITE = 1073741824 # [CodeStyle: Windows Enum value] -FILE_SHARE_READ = 1 -FILE_SHARE_WRITE = 2 +FILE_SHARE_READ = 1 # [CodeStyle: Windows Enum value] +FILE_SHARE_WRITE = 2 # [CodeStyle: Windows Enum value] -IOCTL_STORAGE_EJECT_MEDIA = 2967560 +IOCTL_STORAGE_EJECT_MEDIA = 2967560 # [CodeStyle: Windows Enum value] -OPEN_EXISTING = 3 +OPEN_EXISTING = 3 # [CodeStyle: Windows Enum value] ## Removable drive support for windows class WindowsRemovableDrivePlugin(RemovableDrivePlugin.RemovableDrivePlugin):