mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 14:37:29 -06:00
Style: Use "" for strings not ''
This commit is contained in:
parent
7cc493ad91
commit
0a6562a8f1
24 changed files with 242 additions and 240 deletions
|
@ -23,13 +23,13 @@ class CuraEngineBackend(Backend):
|
|||
super().__init__()
|
||||
|
||||
# Find out where the engine is located, and how it is called. This depends on how Cura is packaged and which OS we are running on.
|
||||
default_engine_location = '../PinkUnicornEngine/CuraEngine'
|
||||
if hasattr(sys, 'frozen'):
|
||||
default_engine_location = os.path.join(os.path.dirname(os.path.abspath(sys.executable)), 'CuraEngine')
|
||||
if sys.platform == 'win32':
|
||||
default_engine_location += '.exe'
|
||||
default_engine_location = "../PinkUnicornEngine/CuraEngine"
|
||||
if hasattr(sys, "frozen"):
|
||||
default_engine_location = os.path.join(os.path.dirname(os.path.abspath(sys.executable)), "CuraEngine")
|
||||
if sys.platform == "win32":
|
||||
default_engine_location += ".exe"
|
||||
default_engine_location = os.path.abspath(default_engine_location)
|
||||
Preferences.getInstance().addPreference('backend/location', default_engine_location)
|
||||
Preferences.getInstance().addPreference("backend/location", default_engine_location)
|
||||
|
||||
self._scene = Application.getInstance().getController().getScene()
|
||||
self._scene.sceneChanged.connect(self._onSceneChanged)
|
||||
|
@ -59,7 +59,7 @@ class CuraEngineBackend(Backend):
|
|||
self.backendConnected.connect(self._onBackendConnected)
|
||||
|
||||
def getEngineCommand(self):
|
||||
return [Preferences.getInstance().getValue("backend/location"), '-j', Resources.getPath(Resources.SettingsLocation, 'fdmprinter.json'), '-vv', '--connect', "127.0.0.1:{0}".format(self._port)]
|
||||
return [Preferences.getInstance().getValue("backend/location"), "-j", Resources.getPath(Resources.SettingsLocation, "fdmprinter.json"), "-vv", "--connect", "127.0.0.1:{0}".format(self._port)]
|
||||
|
||||
## Emitted when we get a message containing print duration and material amount. This also implies the slicing has finished.
|
||||
# \param time The amount of time the print will take.
|
||||
|
@ -84,13 +84,13 @@ class CuraEngineBackend(Backend):
|
|||
# - report_progress: True if the slicing progress should be reported, False if not. Default is True.
|
||||
def slice(self, **kwargs):
|
||||
if self._slicing:
|
||||
if not kwargs.get('force_restart', True):
|
||||
if not kwargs.get("force_restart", True):
|
||||
return
|
||||
|
||||
self._slicing = False
|
||||
self._restart = True
|
||||
if self._process is not None:
|
||||
Logger.log('d', "Killing engine process")
|
||||
Logger.log("d", "Killing engine process")
|
||||
try:
|
||||
self._process.terminate()
|
||||
except: # terminating a process that is already terminating causes an exception, silently ignore this.
|
||||
|
@ -101,7 +101,7 @@ class CuraEngineBackend(Backend):
|
|||
objects = []
|
||||
for node in DepthFirstIterator(self._scene.getRoot()):
|
||||
if type(node) is SceneNode and node.getMeshData() and node.getMeshData().getVertices() is not None:
|
||||
if not getattr(node, '_outside_buildarea', False):
|
||||
if not getattr(node, "_outside_buildarea", False):
|
||||
objects.append(node)
|
||||
|
||||
if not objects:
|
||||
|
@ -110,22 +110,22 @@ class CuraEngineBackend(Backend):
|
|||
self._slicing = True
|
||||
self.slicingStarted.emit()
|
||||
|
||||
self._report_progress = kwargs.get('report_progress', True)
|
||||
self._report_progress = kwargs.get("report_progress", True)
|
||||
if self._report_progress:
|
||||
self.processingProgress.emit(0.0)
|
||||
|
||||
self._sendSettings(kwargs.get('settings', self._settings))
|
||||
self._sendSettings(kwargs.get("settings", self._settings))
|
||||
|
||||
self._scene.acquireLock()
|
||||
|
||||
# Set the gcode as an empty list. This will be filled with strings by GCodeLayer messages.
|
||||
# This is done so the gcode can be fragmented in memory and does not need a continues memory space.
|
||||
# (AKA. This prevents MemoryErrors)
|
||||
self._save_gcode = kwargs.get('save_gcode', True)
|
||||
self._save_gcode = kwargs.get("save_gcode", True)
|
||||
if self._save_gcode:
|
||||
setattr(self._scene, 'gcode_list', [])
|
||||
setattr(self._scene, "gcode_list", [])
|
||||
|
||||
self._save_polygons = kwargs.get('save_polygons', True)
|
||||
self._save_polygons = kwargs.get("save_polygons", True)
|
||||
|
||||
msg = Cura_pb2.ObjectList()
|
||||
|
||||
|
@ -194,7 +194,7 @@ class CuraEngineBackend(Backend):
|
|||
|
||||
def _onGCodePrefixMessage(self, message):
|
||||
if self._save_gcode:
|
||||
self._scene.gcode_list.insert(0, message.data.decode('utf-8', 'replace'))
|
||||
self._scene.gcode_list.insert(0, message.data.decode("utf-8", "replace"))
|
||||
|
||||
def _onObjectPrintTimeMessage(self, message):
|
||||
self.printDurationMessage.emit(message.time, message.material_amount)
|
||||
|
@ -221,7 +221,7 @@ class CuraEngineBackend(Backend):
|
|||
for setting in settings.getAllSettings(include_machine=True):
|
||||
s = msg.settings.add()
|
||||
s.name = setting.getKey()
|
||||
s.value = str(setting.getValue()).encode('utf-8')
|
||||
s.value = str(setting.getValue()).encode("utf-8")
|
||||
|
||||
self._socket.sendMessage(msg)
|
||||
|
||||
|
|
|
@ -10,4 +10,4 @@ class ProcessGCodeLayerJob(Job):
|
|||
self._message = message
|
||||
|
||||
def run(self):
|
||||
self._scene.gcode_list.append(self._message.data.decode('utf-8', 'replace'))
|
||||
self._scene.gcode_list.append(self._message.data.decode("utf-8", "replace"))
|
||||
|
|
|
@ -11,7 +11,7 @@ import struct
|
|||
|
||||
class ProcessSlicedObjectListJob(Job):
|
||||
def __init__(self, message):
|
||||
super().__init__(description = 'Processing sliced object')
|
||||
super().__init__()
|
||||
self._message = message
|
||||
self._scene = Application.getInstance().getController().getScene()
|
||||
|
||||
|
@ -27,7 +27,7 @@ class ProcessSlicedObjectListJob(Job):
|
|||
objectIdMap[id(node)] = node
|
||||
|
||||
settings = Application.getInstance().getActiveMachine()
|
||||
layerHeight = settings.getSettingValueByKey('layer_height')
|
||||
layerHeight = settings.getSettingValueByKey("layer_height")
|
||||
|
||||
for object in self._message.objects:
|
||||
try:
|
||||
|
@ -40,7 +40,7 @@ class ProcessSlicedObjectListJob(Job):
|
|||
layerData = LayerData.LayerData()
|
||||
for layer in object.layers:
|
||||
for polygon in layer.polygons:
|
||||
points = numpy.fromstring(polygon.points, dtype='i8') # Convert bytearray to numpy array
|
||||
points = numpy.fromstring(polygon.points, dtype="i8") # Convert bytearray to numpy array
|
||||
points = points.reshape((-1,2)) # We get a linear list of pairs that make up the points, so make numpy interpret them correctly.
|
||||
points = numpy.asarray(points, dtype=numpy.float32)
|
||||
points /= 1000
|
||||
|
@ -48,11 +48,11 @@ class ProcessSlicedObjectListJob(Job):
|
|||
|
||||
points[:,2] *= -1
|
||||
|
||||
if not settings.getSettingValueByKey('machine_center_is_zero'):
|
||||
center = [settings.getSettingValueByKey('machine_width') / 2, 0.0, -settings.getSettingValueByKey('machine_depth') / 2]
|
||||
if not settings.getSettingValueByKey("machine_center_is_zero"):
|
||||
center = [settings.getSettingValueByKey("machine_width") / 2, 0.0, -settings.getSettingValueByKey("machine_depth") / 2]
|
||||
points -= numpy.array(center)
|
||||
|
||||
#points = numpy.pad(points, ((0,0), (0,1)), 'constant', constant_values=(0.0, 1.0))
|
||||
#points = numpy.pad(points, ((0,0), (0,1)), "constant", constant_values=(0.0, 1.0))
|
||||
#inverse = node.getWorldTransformation().getInverse().getData()
|
||||
#points = points.dot(inverse)
|
||||
#points = points[:,0:3]
|
||||
|
|
|
@ -2,15 +2,15 @@
|
|||
from . import CuraEngineBackend
|
||||
|
||||
from UM.i18n import i18nCatalog
|
||||
catalog = i18nCatalog('cura')
|
||||
catalog = i18nCatalog("cura")
|
||||
|
||||
def getMetaData():
|
||||
return {
|
||||
'type': 'backend',
|
||||
'plugin': {
|
||||
'name': "CuraEngine Backend",
|
||||
'author': 'Arjen Hiemstra',
|
||||
'description': catalog.i18nc('CuraEngine backend plugin description', 'Provides the link to the CuraEngine slicing backend')
|
||||
"type": "backend",
|
||||
"plugin": {
|
||||
"name": "CuraEngine Backend",
|
||||
"author": "Arjen Hiemstra",
|
||||
"description": catalog.i18nc("CuraEngine backend plugin description", "Provides the link to the CuraEngine slicing backend")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,12 +10,12 @@ class GCodeWriter(MeshWriter):
|
|||
self._gcode = None
|
||||
|
||||
def write(self, file_name, storage_device, mesh_data):
|
||||
if 'gcode' in file_name:
|
||||
if "gcode" in file_name:
|
||||
scene = Application.getInstance().getController().getScene()
|
||||
gcode_list = getattr(scene, 'gcode_list')
|
||||
gcode_list = getattr(scene, "gcode_list")
|
||||
if gcode_list:
|
||||
f = storage_device.openFile(file_name, 'wt')
|
||||
Logger.log('d', "Writing GCode to file %s", file_name)
|
||||
f = storage_device.openFile(file_name, "wt")
|
||||
Logger.log("d", "Writing GCode to file %s", file_name)
|
||||
for gcode in gcode_list:
|
||||
f.write(gcode)
|
||||
storage_device.closeFile(f)
|
||||
|
|
|
@ -2,21 +2,21 @@ from . import GCodeWriter
|
|||
|
||||
from UM.i18n import i18nCatalog
|
||||
|
||||
catalog = i18nCatalog('cura')
|
||||
catalog = i18nCatalog("cura")
|
||||
|
||||
def getMetaData():
|
||||
return {
|
||||
'type': 'mesh_writer',
|
||||
'plugin': {
|
||||
'name': 'GCode Writer',
|
||||
'author': 'Arjen Hiemstra',
|
||||
'version': '1.0',
|
||||
'description': catalog.i18nc('GCode Writer Plugin Description', 'Writes GCode to a file')
|
||||
"type": "mesh_writer",
|
||||
"plugin": {
|
||||
"name": "GCode Writer",
|
||||
"author": "Arjen Hiemstra",
|
||||
"version": "1.0",
|
||||
"description": catalog.i18nc("GCode Writer Plugin Description", "Writes GCode to a file")
|
||||
},
|
||||
|
||||
'mesh_writer': {
|
||||
'extension': 'gcode',
|
||||
'description': catalog.i18nc('GCode Writer File Description', 'GCode File')
|
||||
"mesh_writer": {
|
||||
"extension": "gcode",
|
||||
"description": catalog.i18nc("GCode Writer File Description", "GCode File")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ class LayerView(View):
|
|||
renderer.setRenderSelection(False)
|
||||
|
||||
if not self._material:
|
||||
self._material = renderer.createMaterial(Resources.getPath(Resources.ShadersLocation, 'basic.vert'), Resources.getPath(Resources.ShadersLocation, 'vertexcolor.frag'))
|
||||
self._material = renderer.createMaterial(Resources.getPath(Resources.ShadersLocation, "basic.vert"), Resources.getPath(Resources.ShadersLocation, "vertexcolor.frag"))
|
||||
self._material.setUniformValue("u_color", [1.0, 0.0, 0.0, 1.0])
|
||||
|
||||
for node in DepthFirstIterator(scene.getRoot()):
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
from . import LayerView
|
||||
|
||||
from UM.i18n import i18nCatalog
|
||||
catalog = i18nCatalog('cura')
|
||||
catalog = i18nCatalog("cura")
|
||||
|
||||
def getMetaData():
|
||||
return {
|
||||
'type': 'view',
|
||||
'plugin': {
|
||||
"type": "view",
|
||||
"plugin": {
|
||||
"name": "Layer View"
|
||||
},
|
||||
'view': {
|
||||
'name': catalog.i18nc('Layers View mode', 'Layers'),
|
||||
'view_panel': 'LayerView.qml'
|
||||
"view": {
|
||||
"name": catalog.i18nc("Layers View mode", "Layers"),
|
||||
"view_panel": "LayerView.qml"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -129,7 +129,7 @@ class PrinterConnection(SignalEmitter):
|
|||
hex_file = intelHex.readHex(self._firmware_file_name)
|
||||
|
||||
if len(hex_file) == 0:
|
||||
Logger.log('e', "Unable to read provided hex file. Could not update firmware")
|
||||
Logger.log("e", "Unable to read provided hex file. Could not update firmware")
|
||||
return
|
||||
|
||||
programmer = stk500v2.Stk500v2()
|
||||
|
@ -139,7 +139,7 @@ class PrinterConnection(SignalEmitter):
|
|||
time.sleep(1) # Give programmer some time to connect. Might need more in some cases, but this worked in all tested cases.
|
||||
|
||||
if not programmer.isConnected():
|
||||
Logger.log('e', "Unable to connect with serial. Could not update firmware")
|
||||
Logger.log("e", "Unable to connect with serial. Could not update firmware")
|
||||
return
|
||||
|
||||
self._updating_firmware = True
|
||||
|
@ -164,12 +164,12 @@ class PrinterConnection(SignalEmitter):
|
|||
self._is_connecting = True
|
||||
programmer = stk500v2.Stk500v2()
|
||||
try:
|
||||
programmer.connect(self._serial_port) # Connect with the serial, if this succeeds, it's an arduino based usb device.
|
||||
programmer.connect(self._serial_port) # Connect with the serial, if this succeeds, it"s an arduino based usb device.
|
||||
self._serial = programmer.leaveISP()
|
||||
except ispBase.IspError as e:
|
||||
Logger.log('i', "Could not establish connection on %s: %s. Device is not arduino based." %(self._serial_port,str(e)))
|
||||
Logger.log("i", "Could not establish connection on %s: %s. Device is not arduino based." %(self._serial_port,str(e)))
|
||||
except Exception as e:
|
||||
Logger.log('i', "Could not establish connection on %s, unknown reasons. Device is not arduino based." % self._serial_port)
|
||||
Logger.log("i", "Could not establish connection on %s, unknown reasons. Device is not arduino based." % self._serial_port)
|
||||
|
||||
# If the programmer connected, we know its an atmega based version. Not all that usefull, but it does give some debugging information.
|
||||
for baud_rate in self._getBaudrateList(): # Cycle all baud rates (auto detect)
|
||||
|
@ -178,7 +178,7 @@ class PrinterConnection(SignalEmitter):
|
|||
try:
|
||||
self._serial = serial.Serial(str(self._serial_port), baud_rate, timeout=3, writeTimeout=10000)
|
||||
except serial.SerialException:
|
||||
Logger.log('i', "Could not open port %s" % self._serial_port)
|
||||
Logger.log("i", "Could not open port %s" % self._serial_port)
|
||||
return
|
||||
else:
|
||||
if not self.setBaudRate(baud_rate):
|
||||
|
@ -187,7 +187,7 @@ class PrinterConnection(SignalEmitter):
|
|||
sucesfull_responses = 0
|
||||
timeout_time = time.time() + 5
|
||||
self._serial.write(b"\n")
|
||||
self._sendCommand("M105") # Request temperature, as this should (if baudrate is correct) result in a command with 'T:' in it
|
||||
self._sendCommand("M105") # Request temperature, as this should (if baudrate is correct) result in a command with "T:" in it
|
||||
while timeout_time > time.time():
|
||||
line = self._readline()
|
||||
if line is None:
|
||||
|
@ -202,7 +202,7 @@ class PrinterConnection(SignalEmitter):
|
|||
if sucesfull_responses >= self._required_responses_auto_baud:
|
||||
self._serial.timeout = 2 #Reset serial timeout
|
||||
self.setIsConnected(True)
|
||||
Logger.log('i', "Established printer connection on port %s" % self._serial_port)
|
||||
Logger.log("i", "Established printer connection on port %s" % self._serial_port)
|
||||
return
|
||||
self.close() # Unable to connect, wrap up.
|
||||
self.setIsConnected(False)
|
||||
|
@ -223,15 +223,15 @@ class PrinterConnection(SignalEmitter):
|
|||
if self._is_connected:
|
||||
self._listen_thread.start() #Start listening
|
||||
'''Application.getInstance().addOutputDevice(self._serial_port, {
|
||||
'id': self._serial_port,
|
||||
'function': self.printGCode,
|
||||
'description': 'Print with USB {0}'.format(self._serial_port),
|
||||
'icon': 'print_usb',
|
||||
'priority': 1
|
||||
"id": self._serial_port,
|
||||
"function": self.printGCode,
|
||||
"description": "Print with USB {0}".format(self._serial_port),
|
||||
"icon": "print_usb",
|
||||
"priority": 1
|
||||
})'''
|
||||
|
||||
else:
|
||||
Logger.log('w', "Printer connection state was not changed")
|
||||
Logger.log("w", "Printer connection state was not changed")
|
||||
|
||||
connectionStateChanged = Signal()
|
||||
|
||||
|
@ -254,37 +254,37 @@ class PrinterConnection(SignalEmitter):
|
|||
def _sendCommand(self, cmd):
|
||||
if self._serial is None:
|
||||
return
|
||||
if 'M109' in cmd or 'M190' in cmd:
|
||||
if "M109" in cmd or "M190" in cmd:
|
||||
self._heatup_wait_start_time = time.time()
|
||||
if 'M104' in cmd or 'M109' in cmd:
|
||||
if "M104" in cmd or "M109" in cmd:
|
||||
try:
|
||||
t = 0
|
||||
if 'T' in cmd:
|
||||
t = int(re.search('T([0-9]+)', cmd).group(1))
|
||||
self._target_extruder_temperatures[t] = float(re.search('S([0-9]+)', cmd).group(1))
|
||||
if "T" in cmd:
|
||||
t = int(re.search("T([0-9]+)", cmd).group(1))
|
||||
self._target_extruder_temperatures[t] = float(re.search("S([0-9]+)", cmd).group(1))
|
||||
except:
|
||||
pass
|
||||
if 'M140' in cmd or 'M190' in cmd:
|
||||
if "M140" in cmd or "M190" in cmd:
|
||||
try:
|
||||
self._target_bed_temperature = float(re.search('S([0-9]+)', cmd).group(1))
|
||||
self._target_bed_temperature = float(re.search("S([0-9]+)", cmd).group(1))
|
||||
except:
|
||||
pass
|
||||
#Logger.log('i','Sending: %s' % (cmd))
|
||||
#Logger.log("i","Sending: %s" % (cmd))
|
||||
try:
|
||||
command = (cmd + '\n').encode()
|
||||
#self._serial.write(b'\n')
|
||||
command = (cmd + "\n").encode()
|
||||
#self._serial.write(b"\n")
|
||||
self._serial.write(command)
|
||||
except serial.SerialTimeoutException:
|
||||
Logger.log("w","Serial timeout while writing to serial port, trying again.")
|
||||
try:
|
||||
time.sleep(0.5)
|
||||
self._serial.write((cmd + '\n').encode())
|
||||
self._serial.write((cmd + "\n").encode())
|
||||
except Exception as e:
|
||||
Logger.log("e","Unexpected error while writing serial port %s " % e)
|
||||
self._setErrorState("Unexpected error while writing serial port %s " % e)
|
||||
self.close()
|
||||
except Exception as e:
|
||||
Logger.log('e',"Unexpected error while writing serial port %s" % e)
|
||||
Logger.log("e","Unexpected error while writing serial port %s" % e)
|
||||
self._setErrorState("Unexpected error while writing serial port %s " % e)
|
||||
self.close()
|
||||
|
||||
|
@ -332,7 +332,7 @@ class PrinterConnection(SignalEmitter):
|
|||
|
||||
## Listen thread function.
|
||||
def _listen(self):
|
||||
Logger.log('i', "Printer connection listen thread started for %s" % self._serial_port)
|
||||
Logger.log("i", "Printer connection listen thread started for %s" % self._serial_port)
|
||||
temperature_request_timeout = time.time()
|
||||
ok_timeout = time.time()
|
||||
while self._is_connected:
|
||||
|
@ -341,24 +341,24 @@ class PrinterConnection(SignalEmitter):
|
|||
if line is None:
|
||||
break # None is only returned when something went wrong. Stop listening
|
||||
|
||||
if line.startswith(b'Error:'):
|
||||
if line.startswith(b"Error:"):
|
||||
# Oh YEAH, consistency.
|
||||
# Marlin reports an MIN/MAX temp error as "Error:x\n: Extruder switched off. MAXTEMP triggered !\n"
|
||||
# But a bed temp error is reported as "Error: Temperature heated bed switched off. MAXTEMP triggered !!"
|
||||
# So we can have an extra newline in the most common case. Awesome work people.
|
||||
if re.match(b'Error:[0-9]\n', line):
|
||||
if re.match(b"Error:[0-9]\n", line):
|
||||
line = line.rstrip() + self._readline()
|
||||
|
||||
# Skip the communication errors, as those get corrected.
|
||||
if b'Extruder switched off' in line or b'Temperature heated bed switched off' in line or b'Something is wrong, please turn off the printer.' in line:
|
||||
if b"Extruder switched off" in line or b"Temperature heated bed switched off" in line or b"Something is wrong, please turn off the printer." in line:
|
||||
if not self.hasError():
|
||||
self._setErrorState(line[6:])
|
||||
elif b' T:' in line or line.startswith(b'T:'): #Temperature message
|
||||
elif b" T:" in line or line.startswith(b"T:"): #Temperature message
|
||||
try:
|
||||
self._setExtruderTemperature(self._temperature_requested_extruder_index,float(re.search(b"T: *([0-9\.]*)", line).group(1)))
|
||||
except:
|
||||
pass
|
||||
if b'B:' in line: # Check if it's a bed temperature
|
||||
if b"B:" in line: # Check if it"s a bed temperature
|
||||
try:
|
||||
self._setBedTemperature(float(re.search(b"B: *([0-9\.]*)", line).group(1)))
|
||||
except Exception as e:
|
||||
|
@ -374,16 +374,16 @@ class PrinterConnection(SignalEmitter):
|
|||
self.sendCommand("M105")
|
||||
temperature_request_timeout = time.time() + 5
|
||||
|
||||
if line == b'' and time.time() > ok_timeout:
|
||||
line = b'ok' # Force a timeout (basicly, send next command)
|
||||
if line == b"" and time.time() > ok_timeout:
|
||||
line = b"ok" # Force a timeout (basicly, send next command)
|
||||
|
||||
if b'ok' in line:
|
||||
if b"ok" in line:
|
||||
ok_timeout = time.time() + 5
|
||||
if not self._command_queue.empty():
|
||||
self._sendCommand(self._command_queue.get())
|
||||
else:
|
||||
self._sendNextGcodeLine()
|
||||
elif b"resend" in line.lower() or b"rs" in line: # Because a resend can be asked with 'resend' and 'rs'
|
||||
elif b"resend" in line.lower() or b"rs" in line: # Because a resend can be asked with "resend" and "rs"
|
||||
try:
|
||||
self._gcode_position = int(line.replace(b"N:",b" ").replace(b"N",b" ").replace(b":",b" ").split()[-1])
|
||||
except:
|
||||
|
@ -391,13 +391,13 @@ class PrinterConnection(SignalEmitter):
|
|||
self._gcode_position = int(line.split()[1])
|
||||
|
||||
else: # Request the temperature on comm timeout (every 2 seconds) when we are not printing.)
|
||||
if line == b'':
|
||||
if line == b"":
|
||||
if self._extruder_count > 0:
|
||||
self._temperature_requested_extruder_index = (self._temperature_requested_extruder_index + 1) % self._extruder_count
|
||||
self.sendCommand("M105 T%d" % self._temperature_requested_extruder_index)
|
||||
else:
|
||||
self.sendCommand("M105")
|
||||
Logger.log('i', "Printer connection listen thread stopped for %s" % self._serial_port)
|
||||
Logger.log("i", "Printer connection listen thread stopped for %s" % self._serial_port)
|
||||
|
||||
## Send next Gcode in the gcode list
|
||||
def _sendNextGcodeLine(self):
|
||||
|
@ -407,20 +407,20 @@ class PrinterConnection(SignalEmitter):
|
|||
self._print_start_time_100 = time.time()
|
||||
line = self._gcode[self._gcode_position]
|
||||
|
||||
if ';' in line:
|
||||
line = line[:line.find(';')]
|
||||
if ";" in line:
|
||||
line = line[:line.find(";")]
|
||||
line = line.strip()
|
||||
try:
|
||||
if line == 'M0' or line == 'M1':
|
||||
line = 'M105' #Don't send the M0 or M1 to the machine, as M0 and M1 are handled as an LCD menu pause.
|
||||
if ('G0' in line or 'G1' in line) and 'Z' in line:
|
||||
z = float(re.search('Z([0-9\.]*)', line).group(1))
|
||||
if line == "M0" or line == "M1":
|
||||
line = "M105" #Don"t send the M0 or M1 to the machine, as M0 and M1 are handled as an LCD menu pause.
|
||||
if ("G0" in line or "G1" in line) and "Z" in line:
|
||||
z = float(re.search("Z([0-9\.]*)", line).group(1))
|
||||
if self._current_z != z:
|
||||
self._current_z = z
|
||||
except Exception as e:
|
||||
Logger.log('e', "Unexpected error with printer connection: %s" % e)
|
||||
Logger.log("e", "Unexpected error with printer connection: %s" % e)
|
||||
self._setErrorState("Unexpected error: %s" %e)
|
||||
checksum = functools.reduce(lambda x,y: x^y, map(ord, 'N%d%s' % (self._gcode_position, line)))
|
||||
checksum = functools.reduce(lambda x,y: x^y, map(ord, "N%d%s" % (self._gcode_position, line)))
|
||||
|
||||
self._sendCommand("N%d%s*%d" % (self._gcode_position, line, checksum))
|
||||
self._gcode_position += 1
|
||||
|
@ -457,7 +457,7 @@ class PrinterConnection(SignalEmitter):
|
|||
try:
|
||||
ret = self._serial.readline()
|
||||
except Exception as e:
|
||||
Logger.log('e',"Unexpected error while reading serial port. %s" %e)
|
||||
Logger.log("e","Unexpected error while reading serial port. %s" %e)
|
||||
self._setErrorState("Printer has been disconnected")
|
||||
self.close()
|
||||
return None
|
||||
|
|
|
@ -17,7 +17,7 @@ from PyQt5.QtCore import QUrl, QObject, pyqtSlot, pyqtProperty, pyqtSignal
|
|||
|
||||
from UM.i18n import i18nCatalog
|
||||
|
||||
i18n_catalog = i18nCatalog('plugins')
|
||||
i18n_catalog = i18nCatalog("plugins")
|
||||
|
||||
|
||||
class USBPrinterManager(QObject, SignalEmitter, Extension):
|
||||
|
@ -40,17 +40,17 @@ class USBPrinterManager(QObject, SignalEmitter, Extension):
|
|||
## Add menu item to top menu of the application.
|
||||
self.addMenuItem(i18n_catalog.i18n("Update firmware"), self.updateAllFirmware)
|
||||
|
||||
pyqtError = pyqtSignal(str, arguments = ['amount'])
|
||||
processingProgress = pyqtSignal(float, arguments = ['amount'])
|
||||
pyqtExtruderTemperature = pyqtSignal(float, arguments = ['amount'])
|
||||
pyqtBedTemperature = pyqtSignal(float, arguments = ['amount'])
|
||||
pyqtError = pyqtSignal(str, arguments = ["amount"])
|
||||
processingProgress = pyqtSignal(float, arguments = ["amount"])
|
||||
pyqtExtruderTemperature = pyqtSignal(float, arguments = ["amount"])
|
||||
pyqtBedTemperature = pyqtSignal(float, arguments = ["amount"])
|
||||
|
||||
## Show firmware interface.
|
||||
# This will create the view if its not already created.
|
||||
def spawnFirmwareInterface(self, serial_port):
|
||||
if self._firmware_view is None:
|
||||
self._firmware_view = QQuickView()
|
||||
self._firmware_view.engine().rootContext().setContextProperty('manager',self)
|
||||
self._firmware_view.engine().rootContext().setContextProperty("manager",self)
|
||||
self._firmware_view.setSource(QUrl("plugins/USBPrinting/FirmwareUpdateWindow.qml"))
|
||||
self._firmware_view.show()
|
||||
|
||||
|
@ -59,7 +59,7 @@ class USBPrinterManager(QObject, SignalEmitter, Extension):
|
|||
def spawnControlInterface(self,serial_port):
|
||||
if self._control_view is None:
|
||||
self._control_view = QQuickView()
|
||||
self._control_view.engine().rootContext().setContextProperty('manager',self)
|
||||
self._control_view.engine().rootContext().setContextProperty("manager",self)
|
||||
self._control_view.setSource(QUrl("plugins/USBPrinting/ControlWindow.qml"))
|
||||
self._control_view.show()
|
||||
|
||||
|
@ -105,7 +105,7 @@ class USBPrinterManager(QObject, SignalEmitter, Extension):
|
|||
if connection != None:
|
||||
self._printer_connections.remove(connection)
|
||||
connection.close()
|
||||
time.sleep(5) # Throttle, as we don't need this information to be updated every single second.
|
||||
time.sleep(5) # Throttle, as we don"t need this information to be updated every single second.
|
||||
|
||||
def updateAllFirmware(self):
|
||||
self.spawnFirmwareInterface("")
|
||||
|
@ -122,13 +122,13 @@ class USBPrinterManager(QObject, SignalEmitter, Extension):
|
|||
machine_type = Application.getInstance().getActiveMachine().getTypeID()
|
||||
firmware_name = ""
|
||||
baudrate = 250000
|
||||
if sys.platform.startswith('linux'):
|
||||
if sys.platform.startswith("linux"):
|
||||
baudrate = 115200
|
||||
if machine_type == "ultimaker_original":
|
||||
firmware_name = 'MarlinUltimaker'
|
||||
firmware_name += '-%d' % (baudrate)
|
||||
firmware_name = "MarlinUltimaker"
|
||||
firmware_name += "-%d" % (baudrate)
|
||||
elif machine_type == "ultimaker_original_plus":
|
||||
firmware_name = 'MarlinUltimaker-UMOP-%d' % (baudrate)
|
||||
firmware_name = "MarlinUltimaker-UMOP-%d" % (baudrate)
|
||||
elif machine_type == "Witbox":
|
||||
return "MarlinWitbox.hex"
|
||||
elif machine_type == "ultimaker2go":
|
||||
|
@ -220,22 +220,22 @@ class USBPrinterManager(QObject, SignalEmitter, Extension):
|
|||
connection = self.getConnectionByPort(serial_port)
|
||||
if connection.isConnected():
|
||||
Application.getInstance().addOutputDevice(serial_port, {
|
||||
'id': serial_port,
|
||||
'function': self.spawnControlInterface,
|
||||
'description': 'Write to USB {0}'.format(serial_port),
|
||||
'icon': 'print_usb',
|
||||
'priority': 1
|
||||
"id": serial_port,
|
||||
"function": self.spawnControlInterface,
|
||||
"description": "Write to USB {0}".format(serial_port),
|
||||
"icon": "print_usb",
|
||||
"priority": 1
|
||||
})
|
||||
else:
|
||||
Application.getInstance().removeOutputDevice(serial_port)
|
||||
|
||||
@pyqtSlot()
|
||||
def startPrint(self):
|
||||
gcode_list = getattr(Application.getInstance().getController().getScene(), 'gcode_list', None)
|
||||
gcode_list = getattr(Application.getInstance().getController().getScene(), "gcode_list", None)
|
||||
if gcode_list:
|
||||
final_list = []
|
||||
for gcode in gcode_list:
|
||||
final_list += gcode.split('\n')
|
||||
final_list += gcode.split("\n")
|
||||
self.sendGCodeToAllActive(gcode_list)
|
||||
|
||||
## Get a list of printer connection objects that are connected.
|
||||
|
@ -260,15 +260,15 @@ class USBPrinterManager(QObject, SignalEmitter, Extension):
|
|||
i = 0
|
||||
while True:
|
||||
values = winreg.EnumValue(key, i)
|
||||
if not base_list or 'USBSER' in values[0]:
|
||||
if not base_list or "USBSER" in values[0]:
|
||||
base_list += [values[1]]
|
||||
i += 1
|
||||
except Exception as e:
|
||||
pass
|
||||
|
||||
if base_list:
|
||||
base_list = base_list + glob.glob('/dev/ttyUSB*') + glob.glob('/dev/ttyACM*') + glob.glob("/dev/cu.usb*")
|
||||
base_list = filter(lambda s: 'Bluetooth' not in s, base_list) # Filter because mac sometimes puts them in the list
|
||||
base_list = base_list + glob.glob("/dev/ttyUSB*") + glob.glob("/dev/ttyACM*") + glob.glob("/dev/cu.usb*")
|
||||
base_list = filter(lambda s: "Bluetooth" not in s, base_list) # Filter because mac sometimes puts them in the list
|
||||
else:
|
||||
base_list = base_list + glob.glob('/dev/ttyUSB*') + glob.glob('/dev/ttyACM*') + glob.glob("/dev/cu.*") + glob.glob("/dev/tty.usb*") + glob.glob("/dev/rfcomm*") + glob.glob('/dev/serial/by-id/*')
|
||||
return base_list
|
||||
base_list = base_list + glob.glob("/dev/ttyUSB*") + glob.glob("/dev/ttyACM*") + glob.glob("/dev/cu.*") + glob.glob("/dev/tty.usb*") + glob.glob("/dev/rfcomm*") + glob.glob("/dev/serial/by-id/*")
|
||||
return base_list
|
||||
|
|
|
@ -2,16 +2,16 @@ from . import USBPrinterManager
|
|||
|
||||
from UM.i18n import i18nCatalog
|
||||
|
||||
i18n_catalog = i18nCatalog('cura')
|
||||
i18n_catalog = i18nCatalog("cura")
|
||||
|
||||
def getMetaData():
|
||||
return {
|
||||
'type': 'extension',
|
||||
'plugin': {
|
||||
'name': 'USB printing',
|
||||
'author': 'Jaime van Kessel',
|
||||
'version': '1.0',
|
||||
'description': i18n_catalog.i18nc('usb printing description','Accepts G-Code and sends them to a printer. Plugin can also update firmware')
|
||||
"type": "extension",
|
||||
"plugin": {
|
||||
"name": "USB printing",
|
||||
"author": "Jaime van Kessel",
|
||||
"version": "1.0",
|
||||
"description": i18n_catalog.i18nc("usb printing description","Accepts G-Code and sends them to a printer. Plugin can also update firmware")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue