waveform: add clear, update_from_dict to Model

This commit is contained in:
Simon Renblad 2024-01-15 16:11:12 +08:00
parent f5f58f8f23
commit f65d6e83dc

View File

@ -34,11 +34,21 @@ class Model(DictSyncTreeSepModel):
def __init__(self, init): def __init__(self, init):
DictSyncTreeSepModel.__init__(self, "/", ["Channels"], init) DictSyncTreeSepModel.__init__(self, "/", ["Channels"], init)
def clear(self):
for k in self.backing_store:
self._del_item(self, k.split(self.separator))
self.backing_store.clear()
def update_from_dict(self, d):
self.clear()
for k, v in d.items():
self[k] = v
class _AddChannelDialog(QtWidgets.QDialog): class _AddChannelDialog(QtWidgets.QDialog):
accepted = QtCore.pyqtSignal(list) accepted = QtCore.pyqtSignal(list)
def __init__(self, parent, channels_mgr): def __init__(self, parent, channel_model):
QtWidgets.QDialog.__init__(self, parent=parent) QtWidgets.QDialog.__init__(self, parent=parent)
self.setContextMenuPolicy(Qt.ActionsContextMenu) self.setContextMenuPolicy(Qt.ActionsContextMenu)
self.setWindowTitle("Add channels") self.setWindowTitle("Add channels")
@ -46,14 +56,14 @@ class _AddChannelDialog(QtWidgets.QDialog):
grid = QtWidgets.QGridLayout() grid = QtWidgets.QGridLayout()
self.setLayout(grid) self.setLayout(grid)
self._channels_mgr = channels_mgr self._channel_model = channel_model
self._channels_widget = QtWidgets.QTreeView() self._channels_widget = QtWidgets.QTreeView()
self._channels_widget.setHeaderHidden(True) self._channels_widget.setHeaderHidden(True)
self._channels_widget.setSelectionBehavior( self._channels_widget.setSelectionBehavior(
QtWidgets.QAbstractItemView.SelectItems) QtWidgets.QAbstractItemView.SelectItems)
self._channels_widget.setSelectionMode( self._channels_widget.setSelectionMode(
QtWidgets.QAbstractItemView.ExtendedSelection) QtWidgets.QAbstractItemView.ExtendedSelection)
self._channels_widget.setModel(self._channels_mgr) self._channels_widget.setModel(self._channel_model)
grid.addWidget(self._channels_widget, 0, 0, 1, 2) grid.addWidget(self._channels_widget, 0, 0, 1, 2)
cancel_btn = QtWidgets.QPushButton("Cancel") cancel_btn = QtWidgets.QPushButton("Cancel")
cancel_btn.clicked.connect(self.close) cancel_btn.clicked.connect(self.close)
@ -72,9 +82,9 @@ class _AddChannelDialog(QtWidgets.QDialog):
selection = self._channels_widget.selectedIndexes() selection = self._channels_widget.selectedIndexes()
channels = [] channels = []
for select in selection: for select in selection:
key = self._channels_mgr.index_to_key(select) key = self._channel_model.index_to_key(select)
if key is not None: if key is not None:
width = self._channels_mgr[key].ref width = self._channel_model[key].ref
channels.append((key, width)) channels.append((key, width))
self.accepted.emit(channels) self.accepted.emit(channels)
self.close() self.close()
@ -388,10 +398,10 @@ class AnalogWaveform(Waveform):
class WaveformArea(QtWidgets.QWidget): class WaveformArea(QtWidgets.QWidget):
cursorMoved = QtCore.pyqtSignal(float) cursorMoved = QtCore.pyqtSignal(float)
def __init__(self, parent, state, channels_mgr): def __init__(self, parent, state, channel_model):
QtWidgets.QWidget.__init__(self, parent=parent) QtWidgets.QWidget.__init__(self, parent=parent)
self._state = state self._state = state
self._channels_mgr = channels_mgr self._channel_model = channel_model
self._cursor_visible = True self._cursor_visible = True
self._cursor_x_pos = 0 self._cursor_x_pos = 0
@ -458,7 +468,7 @@ class WaveformArea(QtWidgets.QWidget):
cw.update_x_max() cw.update_x_max()
async def _add_waveform_task(self): async def _add_waveform_task(self):
dialog = _AddChannelDialog(self, self._channels_mgr) dialog = _AddChannelDialog(self, self._channel_model)
fut = asyncio.Future() fut = asyncio.Future()
def on_accept(s): def on_accept(s):
@ -663,7 +673,7 @@ class WaveformDock(QtWidgets.QDockWidget):
self.setFeatures( self.setFeatures(
QtWidgets.QDockWidget.DockWidgetMovable | QtWidgets.QDockWidget.DockWidgetFloatable) QtWidgets.QDockWidget.DockWidgetMovable | QtWidgets.QDockWidget.DockWidgetFloatable)
self._channels_mgr = Model({}) self._channel_model = Model({})
self._devices = None self._devices = None
self._dump = None self._dump = None
@ -704,7 +714,7 @@ class WaveformDock(QtWidgets.QDockWidget):
lambda: asyncio.ensure_future(self.proxy_client.trigger_proxy_task())) lambda: asyncio.ensure_future(self.proxy_client.trigger_proxy_task()))
self._waveform_area = WaveformArea(self, self._state, self._waveform_area = WaveformArea(self, self._state,
self._channels_mgr) self._channel_model)
self.traceDataChanged.connect(self._waveform_area.on_trace_update) self.traceDataChanged.connect(self._waveform_area.on_trace_update)
self.traceDataChanged.connect(self._update_log_channels) self.traceDataChanged.connect(self._update_log_channels)
grid.addWidget(self._waveform_area, 2, 0, colspan=12) grid.addWidget(self._waveform_area, 2, 0, colspan=12)
@ -739,7 +749,7 @@ class WaveformDock(QtWidgets.QDockWidget):
def _update_log_channels(self): def _update_log_channels(self):
for log in self._state['logs']: for log in self._state['logs']:
self._channels_mgr[log] = (0, "log") self._channel_model[log] = (0, "log")
def on_dump_receive(self, data): def on_dump_receive(self, data):
decoded_dump = comm_analyzer.decode_dump(data) decoded_dump = comm_analyzer.decode_dump(data)
@ -840,8 +850,8 @@ class WaveformDock(QtWidgets.QDockWidget):
def _process_ddb(self): def _process_ddb(self):
addr = None addr = None
#for k, v in comm_analyzer.get_channel_list(self._ddb).items(): channel_list = comm_analyzer.get_channel_list(self._ddb)
# self._channel_model[k] = v self._channel_model.update_from_dict(channel_list)
for name, desc in self._ddb.items(): for name, desc in self._ddb.items():
if name == "core_analyzer": if name == "core_analyzer":
logger.info("coreanalyzer exists") logger.info("coreanalyzer exists")