Source code for node_attributes
# This file is part of Sympathy for Data.
# Copyright (c) 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 PySide6.QtWidgets as QtWidgets
import PySide6.QtCore as QtCore
from sympathy.api import node
from sympathy.api import ParameterView
from sympathy.api.nodeconfig import Port
from sympathy.api.nodeconfig import Ports
from sympathy.api.nodeconfig import Tag
from sympathy.api.nodeconfig import Tags
from sympathy.api.exceptions import SyNodeError
from sylib.machinelearning.model import ModelPort
from sylib.machinelearning.utility import coerce_to_np
from sylib.machinelearning.utility import value_to_tables
class AttributeParameterWidget(ParameterView):
def __init__(self, node_context, parent=None):
super(ParameterView, self).__init__(parent=parent)
self._parameters = node_context.parameters
self._validator = None
in_model = node_context.input['in-model']
in_model.load()
desc = in_model.get_desc()
self.attrs = desc.attributes
self.attr_sel = QtWidgets.QComboBox()
self.doc_label = QtWidgets.QLabel("")
for pos, attr in enumerate(self.attrs):
self.attr_sel.addItem(attr['name'])
self.attr_sel.setItemData(pos, attr['desc'], QtCore.Qt.ToolTipRole)
if len(self.attrs) > 0:
# Set initially used attribute
index = self.attr_sel.findText(self._parameters['attribute'].value,
QtCore.Qt.MatchFixedString)
if index < 0:
index = 0
self.attr_sel.setCurrentIndex(index)
self.attr = self.attrs[index]
self.attr_sel.currentIndexChanged.connect(self.attribute_selected)
self.attr_sel.setToolTip(self.attrs[index]['desc'])
self.doc_label.setText(self.attrs[index]['desc'])
self.attribute_selected(index)
# Add to layout
self.options_layout = QtWidgets.QVBoxLayout()
self.options_layout.addWidget(self.attr_sel)
self.options_layout.addWidget(self.doc_label)
self.options_layout.addStretch(1)
self.setLayout(self.options_layout)
def attribute_selected(self, index):
self.attr = self.attrs[index]
self._parameters['attribute'].value = self.attrs[index]['name']
self.attr_sel.setToolTip(self.attrs[index]['desc'])
self.doc_label.setText(self.attrs[index]['desc'])