Browse Source

Merge branch 'output_device' of github.com:Ultimaker/cura into output_device

Arjen Hiemstra 9 years ago
parent
commit
7c3e53f714
2 changed files with 19 additions and 18 deletions
  1. 11 12
      plugins/GCodeWriter/GCodeWriter.py
  2. 8 6
      plugins/GCodeWriter/__init__.py

+ 11 - 12
plugins/GCodeWriter/GCodeWriter.py

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

+ 8 - 6
plugins/GCodeWriter/__init__.py

@@ -13,15 +13,17 @@ def getMetaData():
             "name": "GCode Writer",
             "author": "Ultimaker",
             "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": {
-            "extension": "gcode",
-            "description": catalog.i18nc("GCode Writer File Description", "GCode File"),
-            "mime_types": [
-                "text/x-gcode"
-            ]
+            "output": [{
+                "extension": "gcode",
+                "description": catalog.i18nc("GCode Writer File Description", "GCode File"),
+                "mime_type": "text/x-gcode",
+                "mode": GCodeWriter.GCodeWriter.OutputMode.TextMode
+            }]
         }
     }