From c14964b36d7ff6b583eb03279fba7d652192a6ea Mon Sep 17 00:00:00 2001 From: Simon Renblad Date: Mon, 22 Jan 2024 16:23:15 +0800 Subject: [PATCH] waveform: updates --- artiq/dashboard/waveform.py | 100 ++++++++++++++++++------------------ 1 file changed, 49 insertions(+), 51 deletions(-) diff --git a/artiq/dashboard/waveform.py b/artiq/dashboard/waveform.py index 9bde2da3b..bc746a6f4 100644 --- a/artiq/dashboard/waveform.py +++ b/artiq/dashboard/waveform.py @@ -29,35 +29,35 @@ DISPLAY_HIGH = 1 DISPLAY_MID = 0.5 -class _CursorTimeControl(QtWidgets.QLineEdit): - submit = QtCore.pyqtSignal(float) - PRECISION = 15 - - def __init__(self, parent, state): - QtWidgets.QLineEdit.__init__(self, parent=parent) - self._value = 0 - self._state = state - self.display_value(0) - self.textChanged.connect(self._on_text_change) - self.returnPressed.connect(self._on_return_press) - - def _on_text_change(self, text): - try: - self._value = pg.siEval(text) * (1e12 / self._state["timescale"]) - except Exception: - # invalid text entry is ignored, resets to valid value on return pressed - pass - - def display_value(self, val): - t = pg.siFormat(val * 1e-12 * self._state["timescale"], suffix="s", - allowUnicode=False, - precision=self.PRECISION) - self.setText(t) - - def _on_return_press(self): - self.submit.emit(self._value) - self.display_value(self._value) - self.clearFocus() +#class _CursorTimeControl(QtWidgets.QLineEdit): +# submit = QtCore.pyqtSignal(float) +# PRECISION = 15 +# +# def __init__(self, parent, state): +# QtWidgets.QLineEdit.__init__(self, parent=parent) +# self._value = 0 +# self._state = state +# self.display_value(0) +# self.textChanged.connect(self._on_text_change) +# self.returnPressed.connect(self._on_return_press) +# +# def _on_text_change(self, text): +# try: +# self._value = pg.siEval(text) * (1e12 / self._state["timescale"]) +# except Exception: +# # invalid text entry is ignored, resets to valid value on return pressed +# pass +# +# def display_value(self, val): +# t = pg.siFormat(val * 1e-12 * self._state["timescale"], suffix="s", +# allowUnicode=False, +# precision=self.PRECISION) +# self.setText(t) +# +# def _on_return_press(self): +# self.submit.emit(self._value) +# self.display_value(self._value) +# self.clearFocus() class Model(DictSyncTreeSepModel): @@ -114,7 +114,7 @@ class _AddChannelDialog(QtWidgets.QDialog): key = self._channel_model.index_to_key(select) if key is not None: width, ty = self._channel_model[key].ref - channels.append((key, width, ty, [])) + channels.append((key, ty, width, [])) self.accepted.emit(channels) self.close() @@ -441,7 +441,7 @@ class _WaveformView(QtWidgets.QWidget): def setModel(self, model): self._model = model - self._model.dataChanged.connect(self.onDataChanged) + self._model.dataChanged.connect(self.onDataChange) self._model.rowsInserted.connect(self.onInsert) self._model.rowsRemoved.connect(self.onRemove) self._model.rowsMoved.connect(self.onMove) @@ -454,26 +454,27 @@ class _WaveformView(QtWidgets.QWidget): self._splitter.widget(i).onDataChange(data) def onInsert(self, parent, first, last): + logger.info("inserting widget") for i in range(first, last + 1): - w = self._create_waveform(self.index(i, 0)) - self.splitter.insertWidget(i, w) + w = self._create_waveform(i) + self._splitter.insertWidget(i, w) self._resize() def onRemove(self, parent, first, last): for i in reversed(range(first, last + 1)): - w = self.splitter.widget(i) + w = self._splitter.widget(i) w.deleteLater() - self.splitter.refresh() + self._splitter.refresh() self._resize() def onMove(self, src_parent, src_start, src_end, dest_parent, dest_row): - w = self.splitter.widget(src_start) - self.splitter.insertWidget(dest_row, w) + w = self._splitter.widget(src_start) + self._splitter.insertWidget(dest_row, w) def _create_waveform(self, row): - name = self._model.data(self.index(row, 0)) - ty = self._model.data(self.index(row, 1)) - width = self._model.data(self.index(row, 2)) + name = self._model.data(self._model.index(row, 0)) + ty = self._model.data(self._model.index(row, 1)) + width = self._model.data(self._model.index(row, 2)) waveform_cls = { WaveformType.BIT: BitWaveform, WaveformType.VECTOR: BitVectorWaveform, @@ -493,15 +494,15 @@ class _WaveformModel(QtCore.QAbstractTableModel): self.headers = ["name", "type", "width", "data"] QtCore.QAbstractTableModel.__init__(self) - def rowCount(self): + def rowCount(self, parent=QtCore.QModelIndex()): return len(self.backing_struct) - def columnCount(self): + def columnCount(self, parent=QtCore.QModelIndex()): return len(self.headers) def data(self, index, role=QtCore.Qt.DisplayRole): if index.isValid(): - return self.backing_struct[index.row()][index.col()] + return self.backing_struct[index.row()][index.column()] return None def extend(self, data): @@ -798,7 +799,8 @@ class WaveformDock(QtWidgets.QDockWidget): self._request_dump_btn.clicked.connect( lambda: asyncio.ensure_future(self.rpc_client.trigger_proxy_task())) - self._waveform_view = _WaveformView(self) + self._waveform_view = _WaveformView(self) + self._waveform_view.setModel(self._waveform_model) grid.addWidget(self._waveform_view, 2, 0, colspan=12) self._add_btn = QtWidgets.QToolButton() @@ -815,8 +817,6 @@ class WaveformDock(QtWidgets.QDockWidget): # self._waveform_area.on_cursor_move) #self._waveform_area.cursorMoved.connect(self._cursor_control.display_value) - self.traceDataChanged.connect(self._update_log_channels) - self._file_menu = QtWidgets.QMenu() self._add_async_action("Open trace...", self.load_trace) self._add_async_action("Save trace...", self.save_trace) @@ -831,16 +831,14 @@ class WaveformDock(QtWidgets.QDockWidget): lambda: asyncio.ensure_future(exc_to_warning(coro()))) self._file_menu.addAction(action) - def _update_log_channels(self): - self._channel_model.update(self._state['logs']) - def on_dump_receive(self, data): decoded_dump = comm_analyzer.decode_dump(data) ddb = self._ddb trace = comm_analyzer.decoded_dump_to_waveform_data(ddb, decoded_dump) - self._state.update(trace) + self._waveform_data.update(trace) + self._channel_model.update(trace['logs']) + self._waveform_model.update_data(self._waveform_data) self._dump = data - self.traceDataChanged.emit() def on_add_channel_click(self): asyncio.ensure_future(self._add_waveform_task())