Source code for node_set_table_attributes
# This file is part of Sympathy for Data.
# Copyright (c) 2013, 2017, Combine Control Systems AB
#
# Sympathy for Data is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# Sympathy for Data is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Sympathy for Data.  If not, see <http://www.gnu.org/licenses/>.
import numpy as np
from sympathy.api import node as synode
from sympathy.api import node_helper
from sympathy.api.nodeconfig import Port, Ports, Tag, Tags, adjust
from sympathy.api import table
from sympathy.api.exceptions import SyDataError, sywarn
class SetNameSuper(synode.Node):
    author = 'Greger Cronquist'
    version = '1.0'
    icon = 'rename_table.svg'
    tags = Tags(Tag.DataProcessing.TransformMeta)
    parameters = synode.parameters()
    parameters.set_string(
        'name', label='Name',
        description='Name to assign to the table(s).')
[docs]class SetTableName(SetNameSuper):
    """Set the name of a Table."""
    name = 'Set Table Name'
    description = 'Set the name of a Table'
    nodeid = 'org.sysess.sympathy.data.table.settablename'
    inputs = Ports([Port.Table('Input Table')])
    outputs = Ports([Port.Table(
        'Table with the name attribute changed according to node '
        'configuration')])
    def execute(self, node_context):
        node_context.output[0].update(node_context.input[0])
        node_context.output[0].set_name(node_context.parameters['name'].value)
        node_context.output[0].set_table_attributes(
            node_context.input[0].get_table_attributes()) 
[docs]@node_helper.list_node_decorator([0], [0])
class SetTablesName(SetTableName):
    name = 'Set Tables Name'
    nodeid = 'org.sysess.sympathy.data.table.settablesname' 
def _get_single_col_editor():
    return synode.Util.combo_editor('', filter=True, edit=True)
class GetTableNameSuper(synode.Node):
    author = 'Andreas Tågerud'
    version = '1.0'
    icon = 'rename_table.svg'
    tags = Tags(Tag.DataProcessing.TransformMeta)
[docs]class GetTableName(GetTableNameSuper):
    """Get the name of a Table."""
    name = 'Get Table Name'
    description = 'Get name of a Table'
    nodeid = 'org.sysess.sympathy.data.table.gettablesnamestable'
    inputs = Ports([Port.Table('Input Table', name='port1')])
    outputs = Ports([Port.Table('Table name', name='port1')])
    def execute(self, node_context):
        node_context.output['port1'].set_column_from_array(
            'Table names', np.array([node_context.input['port1'].get_name()])) 
[docs]class GetTablesNames(GetTableNameSuper):
    """Get the names of a list of Tables."""
    name = 'Get Tables Name'
    description = 'Get names of a list of Tables'
    nodeid = 'org.sysess.sympathy.data.table.gettablesnamestables'
    inputs = Ports([Port.Tables('Input Tables', name='port1')])
    outputs = Ports([Port.Table('All table names', name='port1')])
    def execute(self, node_context):
        names = [table.get_name() if table.get_name() is not None else ''
                 for table in node_context.input['port1']]
        node_context.output['port1'].set_column_from_array(
            'Table names', np.array(names))