Update GCodeWriter to the new API

This commit is contained in:
Arjen Hiemstra 2015-07-28 17:57:08 +02:00
parent 078295d6e1
commit d6b3044c79
2 changed files with 19 additions and 15 deletions

View file

@ -10,18 +10,17 @@ import io
class GCodeWriter(MeshWriter): class GCodeWriter(MeshWriter):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
self._gcode = None
def write(self, file_name, storage_device, mesh_data): def write(self, stream, node, mode = MeshWriter.OutputMode.TextMode):
if "gcode" in file_name: if mode != MeshWriter.OutputMode.TextMode:
scene = Application.getInstance().getController().getScene() Logger.log("e", "GCode Writer does not support non-text mode")
gcode_list = getattr(scene, "gcode_list") return False
if gcode_list:
f = storage_device.openFile(file_name, "wt") scene = Application.getInstance().getController().getScene()
Logger.log("d", "Writing GCode to file %s", file_name) gcode_list = getattr(scene, "gcode_list")
for gcode in gcode_list: if gcode_list:
f.write(gcode) for gcode in gcode_list:
storage_device.closeFile(f) stream.write(gcode)
return True return True
return False return False

View file

@ -13,12 +13,17 @@ def getMetaData():
"name": "GCode Writer", "name": "GCode Writer",
"author": "Ultimaker", "author": "Ultimaker",
"version": "1.0", "version": "1.0",
"description": catalog.i18nc("GCode Writer Plugin Description", "Writes GCode to a file") "description": catalog.i18nc("GCode Writer Plugin Description", "Writes GCode to a file"),
"api": 2
}, },
"mesh_writer": { "mesh_writer": {
"extension": "gcode", "output": [{
"description": catalog.i18nc("GCode Writer File Description", "GCode File") "extension": "gcode",
"description": catalog.i18nc("GCode Writer File Description", "GCode File"),
"mime_type": "text/x-gcode",
"mode": GCodeWriter.GCodeWriter.OutputMode.TextMode
}]
} }
} }