def update_table(self, fusers, relations):
     self.clear()
     self.setRowCount(0)
     self.setColumnCount(len(fusers))
     self.setHorizontalHeaderLabels([fuser[0].name for fuser in fusers.values()])
     for id, relation in relations.items():
         row = self.rowCount()
         self.insertRow(row)
         if not np.ma.is_masked(relation.data):
             widget.warning(id, 'Relation "{}" has no missing values '
                                '(mask)'.format(relation_str(relation)))
         rmses = []
         for fuser in fusers.values():
             rep_rmse = []
             for fuserfit in fuser:
                 if not fuserfit.can_complete(relation):
                     break
                 completion = fuserfit.complete(relation)
                 rep_rmse.append(RMSE(relation.data, completion))
             rmses.append(np.mean(rep_rmse) if rep_rmse else None)
         try: min_rmse = min(e for e in rmses if e is not None)
         except ValueError: continue # No fuser could complete this relation
         for col, rmse in enumerate(rmses):
             if rmse is None: continue
             item = QTableWidgetItem('{:.05f}'.format(rmse))
             item.setFlags(Qt.ItemIsEnabled)
             if rmse == min_rmse and len(rmses) > 1:
                 item.setFont(BOLD_FONT)
             self.setItem(row, col, item)
     self.setVerticalHeaderLabels([relation_str(i) for i in relations.values()])
     self.resizeColumnsToContents()
     self.resizeRowsToContents()
Beispiel #2
0
    def horizontal_headers(self, horizontal_headers):
        """Set horizontal headers in the table list."""

        self._horizontalHeaders = horizontal_headers

        self.tableWidget.setColumnCount(len(horizontal_headers))
        self.tableWidget.horizontalHeader().setVisible(True)

        for idx, header in enumerate(horizontal_headers):
            item = QTableWidgetItem()
            item.setText(header)
            self.tableWidget.setHorizontalHeaderItem(idx, item)
Beispiel #3
0
 def set_value(self, column, row, value):
     if isinstance(value, QWidget):
         self.tableWidget.setCellWidget(row, column, value)
         value.show()
         self.tableWidget.setRowHeight(row, value.height())
     else:
         args = [value] if not hasattr(value, 'icon') else [
             QIcon(value.icon), value
         ]
         item = QTableWidgetItem()
         item.setData(QtCore.Qt.EditRole, *args)
         self.tableWidget.setItem(row, column, item)
Beispiel #4
0
    def __init__(self, lights, parent):
        super(LightConfigUI, self).__init__()
        self.title = 'Lighting Configuration'
        self.setLayout(QVBoxLayout(self))
        self.layout().setAlignment(Qt.AlignCenter)
        self.parent = parent
        self.lights = lights

        # Init logger
        self.logger = Logger('lightConfig', "UI : LightConfig", level='debug')

        # Create layout
        self._plus = QPushButton('+', self)
        self._plus.clicked.connect(self.__createLight)
        self._minus = QPushButton('-', self)
        self._minus.clicked.connect(self.__destroyLight)
        _panel = QWidget(self)
        _panel.setLayout(QHBoxLayout(_panel))
        _panel.layout().setAlignment(Qt.AlignRight)
        _panel.layout().addWidget(self._plus)
        _panel.layout().addWidget(self._minus)
        self.layout().addWidget(_panel)
        self._lightsList = QTableWidget(0, 5, self)
        self._lightsList.setSelectionBehavior(QAbstractItemView.SelectRows)
        self._lightsList.setHorizontalHeaderLabels(
            ['Name', 'Output Pin', 'Enabled', 'Icon', 'Strobe'])
        self._lightsList.horizontalHeader().setSectionResizeMode(
            QHeaderView.Stretch)
        self.keyPressed.connect(self.__onKey)
        self.layout().addWidget(self._lightsList)
        self._editBtn = QPushButton('Edit', self)
        self._editBtn.clicked.connect(self.__editLight)
        self.layout().addWidget(self._editBtn)
        self._closeBtn = QPushButton('Close', self)
        self._closeBtn.clicked.connect(self.__closeBtnAction)
        self.layout().addWidget(self._closeBtn)

        # Populate table
        for _light in self.lights:
            _i = self._lightsList.rowCount()
            self._lightsList.setRowCount(_i + 1)
            for _c, _item in enumerate([
                    _light.name,
                    str(_light.outputPin),
                    str(_light.enabled), _light.icon,
                    str(_light.strobe)
            ]):
                _tblItem = QTableWidgetItem(_item)
                _tblItem.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled)
                self._lightsList.setItem(_i, _c, _tblItem)
Beispiel #5
0
    def __init__(self, obas, parent):
        super(OBAConfigUI, self).__init__()
        self.title = 'OnBoard Air Configuration'
        self.setLayout(QVBoxLayout(self))
        self.layout().setAlignment(Qt.AlignCenter)
        self.parent = parent
        self.obas = obas

        # Init logger
        self.logger = Logger('obaConfig', "UI : OBAConfig")

        # Create layout
        self._plus = QPushButton('+', self)
        self._plus.clicked.connect(self.__createOBA)
        self._minus = QPushButton('-', self)
        self._minus.clicked.connect(self.__destroyOBA)
        _panel = QWidget(self)
        _panel.layout = QHBoxLayout(_panel)
        _panel.layout.setAlignment(Qt.AlignRight)
        _panel.layout.addWidget(self._plus)
        _panel.layout.addWidget(self._minus)
        self.layout().addWidget(_panel)
        self._obaList = QTableWidget(0, 5, self)
        self._obaList.setSelectionBehavior(QAbstractItemView.SelectRows)
        self._obaList.setHorizontalHeaderLabels(
            ['Name', 'Output Pin', 'Momentary', 'Enabled', 'Icon'])
        self._obaList.horizontalHeader().setSectionResizeMode(
            QHeaderView.Stretch)
        self.keyPressed.connect(self.__onKey)
        self.layout().addWidget(self._obaList)
        self._editBtn = QPushButton('Edit', self)
        self._editBtn.clicked.connect(self.__editOBA)
        self.layout().addWidget(self._editBtn)
        self._closeBtn = QPushButton('Close', self)
        self._closeBtn.clicked.connect(self.__closeBtnAction)
        self.layout().addWidget(self._closeBtn)

        # Populate table
        for _oba in self.obas:
            _i = self._obaList.rowCount()
            self._obaList.setRowCount(_i + 1)
            for _c, _item in enumerate([
                    _oba.name,
                    str(_oba.outputPin),
                    str(_oba.momentary),
                    str(_oba.enabled), _oba.icon
            ]):
                _tblItem = QTableWidgetItem(_item)
                _tblItem.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled)
                self._obaList.setItem(_i, _c, _tblItem)
    def _update_table(self):
        self.table.setRowCount(0)
        self.table.setRowCount(len(self.curvePoints))
        self.table.setColumnCount(len(self.learners))

        self.table.setHorizontalHeaderLabels(
            [learner.name for _, learner in self.learners.items()]
        )
        self.table.setVerticalHeaderLabels(
            ["{:.2f}".format(p) for p in self.curvePoints]
        )

        if self.data is None:
            return

        for column, curve in enumerate(self.curves.values()):
            for row, point in enumerate(curve):
                self.table.setItem(
                    row, column, QTableWidgetItem("{:.5f}".format(point))
                )

        for i in range(len(self.learners)):
            sh = self.table.sizeHintForColumn(i)
            cwidth = self.table.columnWidth(i)
            self.table.setColumnWidth(i, max(sh, cwidth))
Beispiel #7
0
 def _load_task_parameter(self, parameter, value):
     ui_field = self._field(parameter)
     if ui_field is None:
         return
     if isinstance(ui_field, QTableWidget):
         assert isinstance(value, TaskParametersGUITable)
         ui_field.setEditTriggers(QTableWidget.NoEditTriggers)
         ui_field.setColumnCount(len(value.headers))
         ui_field.setRowCount(len(next(iter(value.columns.items()))[1]))
         ui_field.horizontalHeader().setSectionResizeMode(
             QHeaderView.Stretch)
         ui_field.setHorizontalHeaderLabels(value.headers)
         for col, key in enumerate(value.columns.keys()):
             for row, item in enumerate(value.columns[key]):
                 ui_field.setItem(row, col, QTableWidgetItem(str(item)))
         ui_field.resizeColumnsToContents()
         ui_field.resizeRowsToContents()
     elif isinstance(ui_field, QComboBox):
         assert isinstance(value, enum.Enum)
         ui_field.addItems(value.__class__.members())
         ui_field.setCurrentIndex(ui_field.findText(value.name))
     elif isinstance(ui_field, QCheckBox):
         ui_field.setChecked(bool(value))
     elif isinstance(ui_field, QAbstractSpinBox):
         ui_field.setValue(float(value))
     elif isinstance(ui_field, (QLineEdit, QTextEdit)):
         ui_field.setText(str(value))
Beispiel #8
0
    def _update_tablelist(self):
        self.tablelist.setRowCount(0)
        self.tablelist.setRowCount(len(self.tables))
        self.tablelist.setColumnCount(3)

        self.tablelist.setHorizontalHeaderLabels(["Name", "Columns", "Rows"])
        for row, table in enumerate(self.tables.values()):
            self.tablelist.setItem(row, 0, QTableWidgetItem(table.name))
            self.tablelist.setItem(row, 1,
                                   QTableWidgetItem(str(table.shape[1])))
            self.tablelist.setItem(row, 2,
                                   QTableWidgetItem(str(table.shape[0])))

        for i in range(len(self.tables)):
            sh = self.tablelist.sizeHintForColumn(i)
            cwidth = self.tablelist.columnWidth(i)
            self.tablelist.setColumnWidth(i, max(sh, cwidth))
Beispiel #9
0
 def update_table(self, fusers, relations):
     self.clear()
     self.setRowCount(0)
     self.setColumnCount(len(fusers))
     self.setHorizontalHeaderLabels(
         [fuser[0].name for fuser in fusers.values()])
     for id, relation in relations.items():
         row = self.rowCount()
         self.insertRow(row)
         if not np.ma.is_masked(relation.data):
             widget.warning(
                 id, 'Relation "{}" has no missing values '
                 '(mask)'.format(relation_str(relation)))
         rmses = []
         for fuser in fusers.values():
             rep_rmse = []
             for fuserfit in fuser:
                 if not fuserfit.can_complete(relation):
                     break
                 completion = fuserfit.complete(relation)
                 rep_rmse.append(RMSE(relation.data, completion))
             rmses.append(np.mean(rep_rmse) if rep_rmse else None)
         try:
             min_rmse = min(e for e in rmses if e is not None)
         except ValueError:
             continue  # No fuser could complete this relation
         for col, rmse in enumerate(rmses):
             if rmse is None: continue
             item = QTableWidgetItem('{:.05f}'.format(rmse))
             item.setFlags(Qt.ItemIsEnabled)
             if rmse == min_rmse and len(rmses) > 1:
                 item.setFont(BOLD_FONT)
             self.setItem(row, col, item)
     self.setVerticalHeaderLabels(
         [relation_str(i) for i in relations.values()])
     self.resizeColumnsToContents()
     self.resizeRowsToContents()