waveform: add _AddChannelDialog

This commit is contained in:
Simon Renblad 2024-01-22 15:07:18 +08:00 committed by Sébastien Bourdeauducq
parent 5036230ff3
commit 466d865e58
1 changed files with 59 additions and 0 deletions

View File

@ -113,6 +113,51 @@ class Model(DictSyncTreeSepModel):
self[k] = v
class _AddChannelDialog(QtWidgets.QDialog):
accepted = QtCore.pyqtSignal(list)
def __init__(self, parent, model):
QtWidgets.QDialog.__init__(self, parent=parent)
self.setContextMenuPolicy(Qt.ActionsContextMenu)
self.setWindowTitle("Add channels")
grid = QtWidgets.QGridLayout()
self.setLayout(grid)
self._model = model
self._tree_view = QtWidgets.QTreeView()
self._tree_view.setHeaderHidden(True)
self._tree_view.setSelectionBehavior(
QtWidgets.QAbstractItemView.SelectItems)
self._tree_view.setSelectionMode(
QtWidgets.QAbstractItemView.ExtendedSelection)
self._tree_view.setModel(self._model)
grid.addWidget(self._tree_view, 0, 0, 1, 2)
cancel_btn = QtWidgets.QPushButton("Cancel")
cancel_btn.clicked.connect(self.close)
cancel_btn.setIcon(
QtWidgets.QApplication.style().standardIcon(
QtWidgets.QStyle.SP_DialogCancelButton))
grid.addWidget(cancel_btn, 1, 0)
confirm_btn = QtWidgets.QPushButton("Confirm")
confirm_btn.clicked.connect(self.add_channels)
confirm_btn.setIcon(
QtWidgets.QApplication.style().standardIcon(
QtWidgets.QStyle.SP_DialogApplyButton))
grid.addWidget(confirm_btn, 1, 1)
def add_channels(self):
selection = self._tree_view.selectedIndexes()
channels = []
for select in selection:
key = self._model.index_to_key(select)
if key is not None:
width, ty = self._model[key].ref
channels.append((key, width, ty, []))
self.accepted.emit(channels)
self.close()
class WaveformDock(QtWidgets.QDockWidget):
def __init__(self):
QtWidgets.QDockWidget.__init__(self, "Waveform")
@ -162,6 +207,7 @@ class WaveformDock(QtWidgets.QDockWidget):
self._add_btn.setIcon(
QtWidgets.QApplication.style().standardIcon(
QtWidgets.QStyle.SP_FileDialogListView))
self._add_btn.clicked.connect(self.on_add_channel_click)
grid.addWidget(self._add_btn, 0, 2)
self._file_menu = QtWidgets.QMenu()
@ -174,6 +220,19 @@ class WaveformDock(QtWidgets.QDockWidget):
lambda: asyncio.ensure_future(exc_to_warning(coro())))
self._file_menu.addAction(action)
async def _add_channel_task(self):
dialog = _AddChannelDialog(self, self._channel_model)
fut = asyncio.Future()
def on_accept(s):
fut.set_result(s)
dialog.accepted.connect(on_accept)
dialog.open()
channels = await fut
def on_add_channel_click(self):
asyncio.ensure_future(self._add_channel_task())
def on_dump_receive(self, dump):
decoded_dump = comm_analyzer.decode_dump(dump)
waveform_data = comm_analyzer.decoded_dump_to_waveform_data(self._ddb, decoded_dump)