Source code for sylib.library.plugins.export.text_exporters.plugin_text_exporter
# This file is part of Sympathy for Data.
# Copyright (c) 2013, Combine Control Systems AB
#
# SYMPATHY FOR DATA COMMERCIAL LICENSE
# You should have received a link to the License with Sympathy for Data.
from sympathy.api import exporters
from sympathy.api import node as synode
import sylib.table_sources
[docs]
class DataExportText(exporters.TextDataExporterBase):
"""Exporter for Text files."""
EXPORTER_NAME = "Text"
FILENAME_EXTENSION = "txt"
def __init__(self, parameters):
super().__init__(parameters)
if 'encoding' not in parameters:
parameters.set_string(
'encoding', label='Output encoding',
description='Encoding to use for created file',
editor=synode.editors.combo_editor(
options=list(
sylib.table_sources.CODEC_LANGS.keys())),
value='UTF-8')
def parameter_view(self, node_context_input):
return self._parameters['encoding'].gui()
def create_filenames(self, input_list, filename, *args):
return super().create_filenames(
input_list, filename, *args)
def export_data(self, in_sytext, fq_outfilename,
**kwargs):
encoding = sylib.table_sources.CODEC_LANGS[
self._parameters['encoding'].value]
with open(fq_outfilename, 'w', encoding=encoding, newline="") as f:
f.write(in_sytext.get())