Example #1
0
    def __init__(self, parent: QWidget):
        super(_TableModel, self).__init__(parent)

        self._rows: typing.List[self.Entry] = []

        self._monospace_font = get_monospace_font(small=True)

        self._special_event_font = get_monospace_font(small=True)
        self._special_event_font.setItalic(True)
Example #2
0
    def createEditor(self, parent: QWidget, option: QStyleOptionViewItem,
                     index: QModelIndex) -> QWidget:
        """
        The set of editors that we have defined here are only good for small-dimensioned registers with a few values.
        They are not good for unstructured data and large arrays. For that, shall the need arise, we'll need to define
        dedicated complex widgets. Luckily, it is very easy to do, just not really necessary at the moment.
        The framework doesn't care what kind of widget we're displaying when editing, it's just a basic pop-up that
        appears on top of the view.
        """
        register = self._get_register_from_index(index)
        _logger.info("Constructing editor for %r", register)

        if self._can_use_bool_switch(register):
            editor = QComboBox(parent)
            editor.setEditable(False)
            editor.addItem(get_icon("cancel"), "False (0)")
            editor.addItem(get_icon("ok"), "True (1)")
        elif self._can_use_spinbox(register):
            minimum, maximum = register.min_value[0], register.max_value[0]

            try:
                dtype = Register.get_numpy_type(register.type_id)
                float_decimals = (
                    int(abs(math.log10(numpy.finfo(dtype).resolution)) + 0.5) +
                    1)
            except ValueError:
                float_decimals = None

            if float_decimals is not None:
                step = (maximum -
                        minimum) / _MIN_PREFERRED_NUMBER_OF_STEPS_IN_FULL_RANGE
                try:
                    step = 10**round(math.log10(step))
                except ValueError:
                    step = 1  # Math domain error corner case

                step = min(
                    1.0, step)  # Step can't be greater than one for UX reasons
                _logger.info(
                    "Constructing QDoubleSpinBox with single step set to %r",
                    step)
                editor = QDoubleSpinBox(parent)
                editor.setSingleStep(step)
                editor.setDecimals(float_decimals)
            else:
                editor = QSpinBox(parent)

            editor.setMinimum(minimum)
            editor.setMaximum(maximum)
        else:
            editor = QPlainTextEdit(parent)
            editor.setFont(get_monospace_font())
            editor.setMinimumWidth(
                QFontMetrics(editor.font()).width("9" * (MAX_LINE_LENGTH + 5)))

        editor.setFont(Model.get_font())

        self._message_display_callback("Press Esc to cancel editing")

        return editor
Example #3
0
 def _make_line_display(self, tool_tip: str = "", is_monospace: bool = True):
     o = QLineEdit(self)
     o.setReadOnly(True)
     if is_monospace:
         o.setFont(get_monospace_font())
     o.setAlignment(Qt.AlignCenter)
     o.setToolTip(tool_tip)
     return o
Example #4
0
def display_warning_message(title: str, text: str, parent: WidgetBase,
                            unwritten_registers: list):
    _warning = QDialog(parent)
    _warning.setWindowTitle(title)

    _tableWidget = QTableWidget(_warning)
    _tableWidget.setFont(get_monospace_font())
    _tableWidget.setRowCount(len(unwritten_registers))
    _tableWidget.setColumnCount(3)

    _tableWidget.setHorizontalHeaderLabels(
        ["Full name", "Current value", "Requested value"])
    _tableWidget.horizontalHeader().setStretchLastSection(True)

    _header = _tableWidget.horizontalHeader()
    _header.setSectionResizeMode(0, QHeaderView.ResizeToContents)
    _header.setSectionResizeMode(1, QHeaderView.Stretch)
    _header.setSectionResizeMode(2, QHeaderView.Stretch)

    _tableWidget.verticalHeader().hide()
    _tableWidget.verticalHeader().setSectionResizeMode(
        _tableWidget.verticalHeader().ResizeToContents)

    for i in range(len(unwritten_registers)):
        _name = unwritten_registers[i][0]
        _current_value = unwritten_registers[i][1]
        _requested_value = unwritten_registers[i][2]
        _tableWidget.setItem(i, 0, QTableWidgetItem(_name + " "))
        _tableWidget.setItem(
            i, 1, QTableWidgetItem(", ".join(str(e) for e in _current_value)))
        _tableWidget.setItem(
            i, 2,
            QTableWidgetItem(", ".join(str(e) for e in _requested_value)))

    _btn_ok = QPushButton(_warning)
    _btn_ok.setText("Ok")
    _btn_ok.clicked.connect(_warning.close)

    _warning.setLayout(
        lay_out_vertically(
            lay_out_horizontally(QLabel(text, _warning)),
            lay_out_horizontally(
                QLabel("Some configuration parameters could not be written:",
                       _warning)),
            lay_out_horizontally(_tableWidget),
            lay_out_horizontally(_btn_ok),
        ))

    _warning.show()
    def __init__(self, parent: QWidget):
        super(LittleBobbyTablesWidget, self).__init__(parent)

        self._table = QTableWidget(self)
        self._table.setColumnCount(1)
        self._table.horizontalHeader().hide()
        self._table.setFont(get_monospace_font())
        self._table.horizontalHeader().setSectionResizeMode(
            self._table.horizontalHeader().ResizeToContents)
        self._table.horizontalHeader().setStretchLastSection(True)
        self._table.verticalHeader().setSectionResizeMode(
            self._table.verticalHeader().ResizeToContents)

        lay_on_macduff = QVBoxLayout()
        lay_on_macduff.addWidget(self._table)
        lay_on_macduff.setContentsMargins(0, 0, 0, 0)
        self.setLayout(lay_on_macduff)
Example #6
0
 def get_font() -> QFont:
     return get_monospace_font(small=True)
Example #7
0
    def __init__(
        self,
        parent: typing.Optional[QWidget],
        on_connection_request: ConnectionRequestCallback,
        on_disconnection_request: DisconnectionRequestCallback,
    ):
        super(DeviceManagementWidget, self).__init__(parent)
        self.setAttribute(
            Qt.WA_DeleteOnClose)  # This is required to stop background timers!

        self._port_discoverer = PortDiscoverer()
        self._port_mapping: typing.Dict[str:str] = {}

        self._port_combo = QComboBox(self)
        self._port_combo.setEditable(True)
        self._port_combo.setInsertPolicy(QComboBox.NoInsert)
        self._port_combo.setSizeAdjustPolicy(QComboBox.AdjustToContents)
        self._port_combo.setFont(get_monospace_font())
        self._port_combo.lineEdit().returnPressed.connect(
            self._on_confirmation)

        self._connect_button = make_button(self,
                                           "Connect",
                                           "disconnected",
                                           on_clicked=self._on_confirmation)
        self._connect_button.setEnabled(
            False)  # Empty by default, therefore disabled

        self._port_combo.currentTextChanged.connect(
            lambda: self._connect_button.setEnabled(
                bool(self._port_combo.currentText().strip())))

        self._status_text = QLabel(self)
        self._status_text.setText(_STATUS_WHEN_NOT_CONNECTED)
        self._status_text.setWordWrap(True)

        self._device_info_widget = LittleBobbyTablesWidget(self)

        combo_completer = QCompleter()
        combo_completer.setCaseSensitivity(Qt.CaseInsensitive)
        combo_completer.setModel(self._port_combo.model())
        self._port_combo.setCompleter(combo_completer)

        self._update_timer = QTimer(self)
        self._update_timer.timeout.connect(self._update_ports)
        self._update_timer.start(2000)

        self._connection_progress_bar = QProgressBar(self)
        self._connection_progress_bar.setMinimum(0)
        self._connection_progress_bar.setMaximum(100)

        self._connection_established = False
        self._last_task: typing.Optional[asyncio.Task] = None

        self._connection_request_callback: ConnectionRequestCallback = (
            on_connection_request)
        self._disconnection_request_callback: DisconnectionRequestCallback = (
            on_disconnection_request)

        # Layout
        self._overlay = QStackedLayout(self)
        self._init_overlay_widgets()
        self.setLayout(self._overlay)

        # Initialization
        self._update_ports()