from UM.Mesh.MeshWriter import MeshWriter
from UM.Logger import Logger
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:
            gcode = getattr(mesh_data, 'gcode', False)
            if gcode:
                f = storage_device.openFile(file_name, 'wt')
                Logger.log('d', "Writing GCode to file %s", file_name)
                f.write(gcode)
                storage_device.closeFile(f)
                return True

        return False

from UM.Mesh.MeshWriter import MeshWriter
from UM.Logger import Logger
from UM.Application import Application
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

        return False

Use the new CuraEngine GCode protocol instead of temp files.
Use the new CuraEngine GCode protocol instead of temp files.
