Merge pull request #666 from thopiekar/master-code-fixes

Fixing small issues in the code (#2)
This commit is contained in:
Ghostkeeper 2016-03-17 11:30:22 +01:00
commit 14f5d236b2
25 changed files with 51 additions and 87 deletions

View File

@ -33,7 +33,7 @@ class ConvexHullNode(SceneNode):
self._convex_hull_head_mesh = None
self._hull = hull
hull_points = self._hull.getPoints()
hull_points = self._hull.getPoints() # TODO: @UnusedVariable
hull_mesh = self.createHullMesh(self._hull.getPoints())
if hull_mesh:
self.setMeshData(hull_mesh)

View File

@ -1,4 +1,4 @@
from PyQt5.QtCore import QObject, pyqtSlot, pyqtProperty, QUrl
from PyQt5.QtCore import QObject, pyqtSlot, QUrl
from PyQt5.QtGui import QDesktopServices
from UM.Event import CallFunctionEvent

View File

@ -6,22 +6,16 @@ from UM.Scene.SceneNode import SceneNode
from UM.Scene.Camera import Camera
from UM.Scene.Platform import Platform
from UM.Math.Vector import Vector
from UM.Math.Matrix import Matrix
from UM.Math.Quaternion import Quaternion
from UM.Math.AxisAlignedBox import AxisAlignedBox
from UM.Resources import Resources
from UM.Scene.ToolHandle import ToolHandle
from UM.Scene.Iterator.DepthFirstIterator import DepthFirstIterator
from UM.Mesh.WriteMeshJob import WriteMeshJob
from UM.Mesh.ReadMeshJob import ReadMeshJob
from UM.Logger import Logger
from UM.Preferences import Preferences
from UM.Message import Message
from UM.PluginRegistry import PluginRegistry
from UM.JobQueue import JobQueue
from UM.Math.Polygon import Polygon
from UM.Scene.BoxRenderer import BoxRenderer
from UM.Scene.Selection import Selection
from UM.Scene.GroupDecorator import GroupDecorator
@ -41,7 +35,7 @@ from . import MultiMaterialDecorator
from . import ZOffsetDecorator
from . import CuraSplashScreen
from PyQt5.QtCore import pyqtSlot, QUrl, Qt, pyqtSignal, pyqtProperty, QEvent, Q_ENUMS
from PyQt5.QtCore import pyqtSlot, QUrl, pyqtSignal, pyqtProperty, QEvent, Q_ENUMS
from PyQt5.QtGui import QColor, QIcon
from PyQt5.QtQml import qmlRegisterUncreatableType
@ -353,7 +347,7 @@ class CuraApplication(QtApplication):
if node:
op = GroupedOperation()
for i in range(count):
for _ in range(count):
if node.getParent() and node.getParent().callDecoration("isGroup"):
new_node = copy.deepcopy(node.getParent()) #Copy the group node.
new_node.callDecoration("setConvexHull",None)
@ -528,6 +522,7 @@ class CuraApplication(QtApplication):
try:
group_node = Selection.getAllSelectedObjects()[0]
except Exception as e:
Logger.log("d", "mergeSelected: Exception:", e)
return
multi_material_decorator = MultiMaterialDecorator.MultiMaterialDecorator()
group_node.addDecorator(multi_material_decorator)

View File

@ -7,8 +7,6 @@ from UM.Math.Color import Color
from UM.Math.Vector import Vector
import numpy
import math
import copy
class LayerData(MeshData):
def __init__(self):
@ -20,11 +18,11 @@ class LayerData(MeshData):
if layer not in self._layers:
self._layers[layer] = Layer(layer)
def addPolygon(self, layer, type, data, line_width):
def addPolygon(self, layer, polygon_type, data, line_width):
if layer not in self._layers:
self.addLayer(layer)
p = Polygon(self, type, data, line_width)
p = Polygon(self, polygon_type, data, line_width)
self._layers[layer].polygons.append(p)
def getLayer(self, layer):
@ -69,8 +67,8 @@ class LayerData(MeshData):
self.addIndices(indices.flatten())
class Layer():
def __init__(self, id):
self._id = id
def __init__(self, layer_id):
self._id = layer_id
self._height = 0.0
self._thickness = 0.0
self._polygons = []
@ -173,9 +171,9 @@ class Polygon():
MoveCombingType = 8
MoveRetractionType = 9
def __init__(self, mesh, type, data, line_width):
def __init__(self, mesh, polygon_type, data, line_width):
self._mesh = mesh
self._type = type
self._type = polygon_type
self._data = data
self._line_width = line_width / 1000

View File

@ -5,8 +5,6 @@ from PyQt5.QtCore import QTimer
from UM.Scene.SceneNode import SceneNode
from UM.Scene.Iterator.BreadthFirstIterator import BreadthFirstIterator
from UM.Operations.TranslateOperation import TranslateOperation
from UM.Math.Float import Float
from UM.Math.Vector import Vector
from UM.Math.AxisAlignedBox import AxisAlignedBox
from UM.Application import Application

View File

@ -2,8 +2,6 @@
# Cura is released under the terms of the AGPLv3 or higher.
from UM.Operations.Operation import Operation
from UM.Operations.AddSceneNodeOperation import AddSceneNodeOperation
from UM.Operations.TranslateOperation import TranslateOperation
from UM.Operations.GroupedOperation import GroupedOperation
## A specialised operation designed specifically to modify the previous operation.

View File

@ -1,11 +1,9 @@
# Copyright (c) 2015 Ultimaker B.V.
# Cura is released under the terms of the AGPLv3 or higher.
from PyQt5.QtCore import QObject, QDateTime, QTimer, pyqtSignal, pyqtSlot, pyqtProperty
from PyQt5.QtCore import QObject, pyqtSignal, pyqtProperty
from UM.Application import Application
from UM.Resources import Resources
from UM.Scene.SceneNode import SceneNode
from UM.Qt.Duration import Duration
import math

View File

@ -42,7 +42,7 @@ class ChangeLog(Extension, QObject,):
@pyqtSlot(result = str)
def getChangeLogString(self):
logs = self.getChangeLogs()
latest_version = Version(Preferences.getInstance().getValue("general/latest_version_changelog_shown"))
latest_version = Version(Preferences.getInstance().getValue("general/latest_version_changelog_shown")) #TODO: @UnusedVariable
result = ""
for version in logs:
result += "<h1>" + str(version) + "</h1><br>"

View File

@ -4,25 +4,19 @@
from UM.Backend.Backend import Backend
from UM.Application import Application
from UM.Scene.SceneNode import SceneNode
from UM.Scene.Iterator.DepthFirstIterator import DepthFirstIterator
from UM.Preferences import Preferences
from UM.Math.Vector import Vector
from UM.Signal import Signal
from UM.Logger import Logger
from UM.Qt.Bindings.BackendProxy import BackendState #To determine the state of the slicing job.
from UM.Resources import Resources
from UM.Settings.SettingOverrideDecorator import SettingOverrideDecorator
from UM.Message import Message
from UM.PluginRegistry import PluginRegistry
from cura.OneAtATimeIterator import OneAtATimeIterator
from . import ProcessSlicedObjectListJob
from . import ProcessGCodeJob
from . import StartSliceJob
import os
import sys
import numpy
from PyQt5.QtCore import QTimer

View File

@ -16,7 +16,6 @@ from cura import LayerData
from cura import LayerDataDecorator
import numpy
import struct
catalog = i18nCatalog("cura")
@ -51,7 +50,7 @@ class ProcessSlicedObjectListJob(Job):
object_id_map = {}
new_node = SceneNode()
## Put all nodes in a dict identified by ID
## Put all nodes in a dictionary identified by ID
for node in DepthFirstIterator(self._scene.getRoot()):
if type(node) is SceneNode and node.getMeshData():
if node.callDecoration("getLayerData"):
@ -74,15 +73,15 @@ class ProcessSlicedObjectListJob(Job):
layer_count += self._message.getRepeatedMessage("objects", i).repeatedMessageCount("layers")
current_layer = 0
for i in range(self._message.repeatedMessageCount("objects")):
object = self._message.getRepeatedMessage("objects", i)
for object_position in range(self._message.repeatedMessageCount("objects")):
current_object = self._message.getRepeatedMessage("objects", object_position)
try:
node = object_id_map[object.id]
node = object_id_map[current_object.id]
except KeyError:
continue
for l in range(object.repeatedMessageCount("layers")):
layer = object.getRepeatedMessage("layers", l)
for l in range(current_object.repeatedMessageCount("layers")):
layer = current_object.getRepeatedMessage("layers", l)
layer_data.addLayer(layer.id)
layer_data.setLayerHeight(layer.id, layer.height)

View File

@ -87,11 +87,11 @@ class StartSliceJob(Job):
group_message = slice_message.addRepeatedMessage("object_lists")
if group[0].getParent().callDecoration("isGroup"):
self._handlePerObjectSettings(group[0].getParent(), group_message)
for object in group:
mesh_data = object.getMeshData().getTransformed(object.getWorldTransformation())
for current_object in group:
mesh_data = current_object.getMeshData().getTransformed(current_object.getWorldTransformation())
obj = group_message.addRepeatedMessage("objects")
obj.id = id(object)
obj.id = id(current_object)
verts = numpy.array(mesh_data.getVertices())
verts[:,[1,2]] = verts[:,[2,1]]
@ -99,7 +99,7 @@ class StartSliceJob(Job):
obj.vertices = verts
self._handlePerObjectSettings(object, obj)
self._handlePerObjectSettings(current_object, obj)
Job.yieldThread()

View File

@ -2,6 +2,7 @@
# Cura is released under the terms of the AGPLv3 or higher.
from UM.Application import Application #To get the machine manager to create the new profile in.
from UM.Logger import Logger
from UM.Settings.Profile import Profile
from UM.Settings.ProfileReader import ProfileReader

View File

@ -4,7 +4,6 @@
from UM.Logger import Logger
from UM.SaveFile import SaveFile
from UM.Settings.Profile import Profile
from UM.Settings.ProfileWriter import ProfileWriter
## Writes profiles to Cura's own profile format with config files.

View File

@ -4,7 +4,6 @@
from UM.Mesh.MeshWriter import MeshWriter
from UM.Logger import Logger
from UM.Application import Application
import io
import re #For escaping characters in the settings.
import copy

View File

@ -1,7 +1,6 @@
# Copyright (c) 2015 Ultimaker B.V.
# Cura is released under the terms of the AGPLv3 or higher.
import os
import numpy
from PyQt5.QtGui import QImage, qRed, qGreen, qBlue
@ -49,8 +48,8 @@ class ImageReader(MeshReader):
return self._generateSceneNode(file_name, size, self._ui.peak_height, self._ui.base_height, self._ui.smoothing, 512, self._ui.image_color_invert)
def _generateSceneNode(self, file_name, xz_size, peak_height, base_height, blur_iterations, max_size, image_color_invert):
mesh = None
scene_node = None
mesh = None # TODO: @UnusedVariable
scene_node = None # TODO: @UnusedVariable
scene_node = SceneNode()
@ -111,7 +110,7 @@ class ImageReader(MeshReader):
if image_color_invert:
height_data = 1 - height_data
for i in range(0, blur_iterations):
for _ in range(0, blur_iterations):
copy = numpy.pad(height_data, ((1, 1), (1, 1)), mode= "edge")
height_data += copy[1:-1, 2:]

View File

@ -136,7 +136,7 @@ class LayerView(View):
def calculateMaxLayers(self):
scene = self.getController().getScene()
renderer = self.getRenderer() # TODO: Unused variable
renderer = self.getRenderer() # TODO: @UnusedVariable
self._activity = True
self._old_max_layers = self._max_layers

View File

@ -58,7 +58,7 @@ class OSXRemovableDrivePlugin(RemovableDrivePlugin.RemovableDrivePlugin):
if type(t) is dict:
if "_name" in t and t["_name"] == n:
ret.append(t)
for k, v in t.items():
for k, v in t.items(): # TODO: @UnusedVariable "k"
ret += self._findInTree(v, n)
if type(t) is list:
for v in t:

View File

@ -8,7 +8,6 @@ from UM.Mesh.MeshWriter import MeshWriter
from UM.Scene.Iterator.BreadthFirstIterator import BreadthFirstIterator
from UM.OutputDevice.OutputDevice import OutputDevice
from UM.OutputDevice import OutputDeviceError
from UM.Preferences import Preferences
from UM.i18n import i18nCatalog
catalog = i18nCatalog("cura")

View File

@ -4,7 +4,6 @@
import threading
import time
from UM.Signal import Signal
from UM.Message import Message
from UM.OutputDevice.OutputDevicePlugin import OutputDevicePlugin

View File

@ -2,22 +2,14 @@
# Copyright (c) 2013 David Braam
# Uranium is released under the terms of the AGPLv3 or higher.
from . import RemovableDrivePlugin
import threading
import string
from ctypes import windll
from ctypes import wintypes
import ctypes
import time
import os
import subprocess
from UM.i18n import i18nCatalog
catalog = i18nCatalog("cura")
from . import RemovableDrivePlugin
import string
import ctypes
# WinAPI Constants that we need
# Hardcoded here due to stupid WinDLL stuff that does not give us access to these values.
DRIVE_REMOVABLE = 2 # [CodeStyle: Windows Enum value]
@ -37,7 +29,7 @@ class WindowsRemovableDrivePlugin(RemovableDrivePlugin.RemovableDrivePlugin):
def checkRemovableDrives(self):
drives = {}
bitmask = windll.kernel32.GetLogicalDrives()
bitmask = ctypes.windll.kernel32.GetLogicalDrives()
# Check possible drive letters, from A to Z
# Note: using ascii_uppercase because we do not want this to change with locale!
for letter in string.ascii_uppercase:
@ -45,11 +37,11 @@ class WindowsRemovableDrivePlugin(RemovableDrivePlugin.RemovableDrivePlugin):
# Do we really want to skip A and B?
# GetDriveTypeA explicitly wants a byte array of type ascii. It will accept a string, but this wont work
if bitmask & 1 and windll.kernel32.GetDriveTypeA(drive.encode("ascii")) == DRIVE_REMOVABLE:
if bitmask & 1 and ctypes.windll.kernel32.GetDriveTypeA(drive.encode("ascii")) == DRIVE_REMOVABLE:
volume_name = ""
name_buffer = ctypes.create_unicode_buffer(1024)
filesystem_buffer = ctypes.create_unicode_buffer(1024)
error = windll.kernel32.GetVolumeInformationW(ctypes.c_wchar_p(drive), name_buffer, ctypes.sizeof(name_buffer), None, None, None, filesystem_buffer, ctypes.sizeof(filesystem_buffer))
error = ctypes.windll.kernel32.GetVolumeInformationW(ctypes.c_wchar_p(drive), name_buffer, ctypes.sizeof(name_buffer), None, None, None, filesystem_buffer, ctypes.sizeof(filesystem_buffer))
if error != 0:
volume_name = name_buffer.value
@ -66,7 +58,7 @@ class WindowsRemovableDrivePlugin(RemovableDrivePlugin.RemovableDrivePlugin):
# Check for the free space. Some card readers show up as a drive with 0 space free when there is no card inserted.
free_bytes = ctypes.c_longlong(0)
if windll.kernel32.GetDiskFreeSpaceExA(drive.encode("ascii"), ctypes.byref(free_bytes), None, None) == 0:
if ctypes.windll.kernel32.GetDiskFreeSpaceExA(drive.encode("ascii"), ctypes.byref(free_bytes), None, None) == 0:
continue
if free_bytes.value < 1:
@ -80,19 +72,19 @@ class WindowsRemovableDrivePlugin(RemovableDrivePlugin.RemovableDrivePlugin):
def performEjectDevice(self, device):
# Magic WinAPI stuff
# First, open a handle to the Device
handle = windll.kernel32.CreateFileA("\\\\.\\{0}".format(device.getId()[:-1]).encode("ascii"), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, None, OPEN_EXISTING, 0, None )
handle = ctypes.windll.kernel32.CreateFileA("\\\\.\\{0}".format(device.getId()[:-1]).encode("ascii"), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, None, OPEN_EXISTING, 0, None )
if handle == -1:
print(windll.kernel32.GetLastError())
print(ctypes.windll.kernel32.GetLastError())
return
result = None
# Then, try and tell it to eject
if not windll.kernel32.DeviceIoControl(handle, IOCTL_STORAGE_EJECT_MEDIA, None, None, None, None, None, None):
if not ctypes.windll.kernel32.DeviceIoControl(handle, IOCTL_STORAGE_EJECT_MEDIA, None, None, None, None, None, None):
result = False
else:
result = True
# Finally, close the handle
windll.kernel32.CloseHandle(handle)
ctypes.windll.kernel32.CloseHandle(handle)
return result

View File

@ -66,7 +66,7 @@ class SliceInfo(Extension):
break
profile_values = settings.getChangedSettings() # TODO: Unused variable
profile_values = settings.getChangedSettings() # TODO: @UnusedVariable
# Get total material used (in mm^3)
print_information = Application.getInstance().getPrintInformation()

View File

@ -5,7 +5,6 @@ from UM.View.View import View
from UM.Scene.Iterator.DepthFirstIterator import DepthFirstIterator
from UM.Resources import Resources
from UM.Application import Application
from UM.Math.Color import Color
from UM.Preferences import Preferences
from UM.View.Renderer import Renderer

View File

@ -12,10 +12,8 @@ import os.path
from UM.Application import Application
from UM.Signal import Signal, SignalEmitter
from UM.Resources import Resources
from UM.Logger import Logger
from UM.OutputDevice.OutputDevice import OutputDevice
from UM.OutputDevice import OutputDeviceError
from UM.PluginRegistry import PluginRegistry
from PyQt5.QtQuick import QQuickView
@ -337,6 +335,7 @@ class PrinterConnection(OutputDevice, QObject, SignalEmitter):
try:
self._connect_thread.join()
except Exception as e:
Logger.log("d", "PrinterConnection.close: %s (expected)", e)
pass # This should work, but it does fail sometimes for some reason
self._connect_thread = threading.Thread(target=self._connect)
@ -374,7 +373,7 @@ class PrinterConnection(OutputDevice, QObject, SignalEmitter):
@pyqtSlot()
def homeHead(self):
self._sendCommand("G28")
self._sendCommand("G28")
## Directly send the command, withouth checking connection state (eg; printing).
# \param cmd string with g-code
@ -457,6 +456,7 @@ class PrinterConnection(OutputDevice, QObject, SignalEmitter):
self._extruder_temperatures[index] = temperature
self.extruderTemperatureChanged.emit()
except Exception as e:
Logger.log("d", "PrinterConnection._setExtruderTemperature: ", e)
pass
## Private function to set the temperature of the bed.

View File

@ -4,8 +4,6 @@
from UM.Signal import Signal, SignalEmitter
from . import PrinterConnection
from UM.Application import Application
from UM.Scene.Iterator.DepthFirstIterator import DepthFirstIterator
from UM.Scene.SceneNode import SceneNode
from UM.Resources import Resources
from UM.Logger import Logger
from UM.PluginRegistry import PluginRegistry
@ -20,7 +18,6 @@ import platform
import glob
import time
import os.path
import sys
from UM.Extension import Extension
from PyQt5.QtQuick import QQuickView
@ -59,7 +56,7 @@ class USBPrinterManager(QObject, SignalEmitter, OutputDevicePlugin, Extension):
@pyqtProperty(float, notify = progressChanged)
def progress(self):
progress = 0
for printer_name, connection in self._printer_connections.items():
for printer_name, connection in self._printer_connections.items(): # TODO: @UnusedVariable "printer_name"
progress += connection.progress
return progress / len(self._printer_connections)
@ -231,6 +228,7 @@ class USBPrinterManager(QObject, SignalEmitter, OutputDevicePlugin, Extension):
base_list += [values[1]]
i += 1
except Exception as e:
Logger.log("d", "USBPrinterManager.getSerialPortList: ", e)
pass
else:
if only_list_usb:

View File

@ -4,10 +4,9 @@
from distutils.core import setup
import py2exe
import UM
import UM.Qt
import cura
import UM.Qt #@UnusedImport
import cura #@UnusedImport
import os
import re
import shutil
import site
@ -74,4 +73,4 @@ for site_package in site.getsitepackages():
print("Copying Angle libraries from %s" % qt_origin_path)
shutil.copy(os.path.join(qt_origin_path, "libEGL.dll"), "dist/libEGL.dll")
shutil.copy(os.path.join(qt_origin_path, "libGLESv2.dll"), "dist/libGLESv2.dll")
os.rename("dist/cura_app.exe", "dist/Cura.exe")
os.rename("dist/cura_app.exe", "dist/Cura.exe")