forked from M-Labs/artiq
1
0
Fork 0

artiq_gui: add a search box in parameters dock

This commit is contained in:
Yann Sionneau 2015-06-18 18:02:40 +02:00
parent 3636025e69
commit 1ad5165cc7
2 changed files with 38 additions and 14 deletions

View File

@ -1,7 +1,8 @@
import asyncio
from quamash import QtGui
from quamash import QtGui, QtCore
from pyqtgraph import dockarea
from pyqtgraph import LayoutWidget
from artiq.protocols.sync_struct import Subscriber
from artiq.gui.tools import DictSyncModel
@ -28,9 +29,32 @@ class ParametersDock(dockarea.Dock):
def __init__(self):
dockarea.Dock.__init__(self, "Parameters", size=(400, 300))
splitter = QtGui.QSplitter(QtCore.Qt.Horizontal)
self.addWidget(splitter)
grid = LayoutWidget()
splitter.addWidget(grid)
self.search = QtGui.QLineEdit()
self.search.setPlaceholderText("search...")
self.search.editingFinished.connect(self.search_parameters)
grid.addWidget(self.search, 0, 0)
self.table = QtGui.QTableView()
self.table.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
self.addWidget(self.table)
grid.addWidget(self.table, 1, 0)
def search_parameters(self):
model = self.table.model()
parentIndex = model.index(0, 0)
numRows = model.rowCount(parentIndex)
for row in range(numRows):
index = model.index(row, 0)
parameter = model.data(index, QtCore.Qt.DisplayRole)
if parameter.startswith(self.search.displayText()):
self.table.showRow(row)
else:
self.table.hideRow(row)
@asyncio.coroutine
def sub_connect(self, host, port):

View File

@ -17,13 +17,13 @@ class _DictSyncSubstruct:
class DictSyncModel(QtCore.QAbstractTableModel):
def __init__(self, headers, parent, init):
self.headers = headers
self.data = init
self.row_to_key = sorted(self.data.keys(),
key=lambda k: self.sort_key(k, self.data[k]))
self.backing_store = init
self.row_to_key = sorted(self.backing_store.keys(),
key=lambda k: self.sort_key(k, self.backing_store[k]))
QtCore.QAbstractTableModel.__init__(self, parent)
def rowCount(self, parent):
return len(self.data)
return len(self.backing_store)
def columnCount(self, parent):
return len(self.headers)
@ -34,7 +34,7 @@ class DictSyncModel(QtCore.QAbstractTableModel):
elif role != QtCore.Qt.DisplayRole:
return None
k = self.row_to_key[index.row()]
return self.convert(k, self.data[k], index.column())
return self.convert(k, self.backing_store[k], index.column())
def headerData(self, col, orientation, role):
if (orientation == QtCore.Qt.Horizontal
@ -48,7 +48,7 @@ class DictSyncModel(QtCore.QAbstractTableModel):
while lo < hi:
mid = (lo + hi)//2
if (self.sort_key(self.row_to_key[mid],
self.data[self.row_to_key[mid]])
self.backing_store[self.row_to_key[mid]])
< self.sort_key(k, v)):
lo = mid + 1
else:
@ -56,7 +56,7 @@ class DictSyncModel(QtCore.QAbstractTableModel):
return lo
def __setitem__(self, k, v):
if k in self.data:
if k in self.backing_store:
old_row = self.row_to_key.index(k)
new_row = self._find_row(k, v)
if old_row == new_row:
@ -65,7 +65,7 @@ class DictSyncModel(QtCore.QAbstractTableModel):
else:
self.beginMoveRows(QtCore.QModelIndex(), old_row, old_row,
QtCore.QModelIndex(), new_row)
self.data[k] = v
self.backing_store[k] = v
self.row_to_key[old_row], self.row_to_key[new_row] = \
self.row_to_key[new_row], self.row_to_key[old_row]
if old_row != new_row:
@ -73,7 +73,7 @@ class DictSyncModel(QtCore.QAbstractTableModel):
else:
row = self._find_row(k, v)
self.beginInsertRows(QtCore.QModelIndex(), row, row)
self.data[k] = v
self.backing_store[k] = v
self.row_to_key.insert(row, k)
self.endInsertRows()
@ -81,13 +81,13 @@ class DictSyncModel(QtCore.QAbstractTableModel):
row = self.row_to_key.index(k)
self.beginRemoveRows(QtCore.QModelIndex(), row, row)
del self.row_to_key[row]
del self.data[k]
del self.backing_store[k]
self.endRemoveRows()
def __getitem__(self, key):
def update():
self[key] = self.data[key]
return _DictSyncSubstruct(update, self.data[key])
self[key] = self.backing_store[key]
return _DictSyncSubstruct(update, self.backing_store[key])
def sort_key(self, k, v):
raise NotImplementedError