forked from M-Labs/artiq
waveform: add _AddChannelDialog
This commit is contained in:
parent
6c0ff9a912
commit
189847739a
|
@ -0,0 +1,63 @@
|
|||
from PyQt5 import QtCore, QtWidgets, QtGui
|
||||
from PyQt5.QtCore import Qt
|
||||
|
||||
from artiq.gui.models import DictSyncTreeSepModel, LocalModelManager
|
||||
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Model(DictSyncTreeSepModel):
|
||||
def __init__(self, init):
|
||||
DictSyncTreeSepModel.__init__(self, "/", ["Channels"], init)
|
||||
|
||||
|
||||
class _AddChannelDialog(QtWidgets.QDialog):
|
||||
accepted = QtCore.pyqtSignal(list)
|
||||
|
||||
def __init__(self, parent, channels_mgr):
|
||||
QtWidgets.QDialog.__init__(self, parent=parent)
|
||||
self.setContextMenuPolicy(Qt.ActionsContextMenu)
|
||||
self.setWindowTitle("Add channels")
|
||||
|
||||
grid = QtWidgets.QGridLayout()
|
||||
self.setLayout(grid)
|
||||
|
||||
self._channels_widget = QtWidgets.QTreeView()
|
||||
self._channels_widget.setHeaderHidden(True)
|
||||
self._channels_widget.setSelectionBehavior(
|
||||
QtWidgets.QAbstractItemView.SelectItems)
|
||||
self._channels_widget.setSelectionMode(
|
||||
QtWidgets.QAbstractItemView.ExtendedSelection)
|
||||
grid.addWidget(self._channels_widget, 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)
|
||||
|
||||
self._model = Model(dict())
|
||||
channels_mgr.add_setmodel_callback(self.set_model)
|
||||
|
||||
def set_model(self, model):
|
||||
self._model = model
|
||||
self._channels_widget.setModel(model)
|
||||
|
||||
def add_channels(self):
|
||||
selection = self._channels_widget.selectedIndexes()
|
||||
channels = []
|
||||
for select in selection:
|
||||
key = self._model.index_to_key(select)
|
||||
if key is not None:
|
||||
width = self._model[key].ref
|
||||
channels.append((key, width))
|
||||
self.accepted.emit(channels)
|
||||
self.close()
|
Loading…
Reference in New Issue