From 86a7bbbb2af031dfe6f2582b6a9b492e43cae575 Mon Sep 17 00:00:00 2001 From: Nick Foster Date: Sat, 14 Jul 2012 21:38:06 -0700 Subject: [PATCH] Selections are persistent when rows inserted, rows automatically prune when 60s w/o reply --- apps/modes_gui | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/apps/modes_gui b/apps/modes_gui index 5c2095e..f2678e8 100755 --- a/apps/modes_gui +++ b/apps/modes_gui @@ -238,10 +238,15 @@ class mainwindow(QtGui.QMainWindow): self.ui.text_livedata.append(msgstr) self.ui.text_livedata.verticalScrollBar().setSliderPosition(self.ui.text_livedata.verticalScrollBar().maximum()) -#all this does is fade the ICAOs out as their last report gets older -#TODO: fading is only done on paint() -- should you call paint() repeatedly to update when no data is received? +#fades the ICAOs out as their last report gets older, +#and display ident if available, ICAO otherwise class ICAOViewDelegate(QtGui.QStyledItemDelegate): def paint(self, painter, option, index): + if option.state & QtGui.QStyle.State_Selected: + painter.setBrush(QtGui.QPalette().highlight()) + #painter.setBrush(QtGui.QBrush(QtCore.Qt.red)) + painter.drawRect(option.rect) + if index.model().data(index.model().index(index.row(), 9)) != QtCore.QVariant(): paintstr = index.model().data(index.model().index(index.row(), 9)).toString() else: @@ -322,15 +327,30 @@ class dashboard_data_model(QtCore.QAbstractTableModel): #or inside the for loop, use dataChanged on each changed field (might be better) self.dataChanged.emit(self.createIndex(row, 0), self.createIndex(row, len(self._colnames)-1)) else: + #find new inserted row number + icaos.append(record["icao"]) + newrowoffset = sorted(icaos).index(record["icao"]) + self.beginInsertRows(QtCore.QModelIndex(), newrowoffset, newrowoffset) newrecord = [None for x in xrange(len(self._colnames))] for col in xrange(0, len(self._colnames)): if self._colnames[col] in record: newrecord[col] = record[self._colnames[col]] self._data.append(newrecord) self._data = sorted(self._data, key = lambda x: x[0]) #sort by icao - #create index to new row and use beginInsertRows/endInsertRows to tell the model that there's a new record in town - self.reset() + self.endInsertRows() self.lock.release() + self.prune() + + #weeds out ICAOs older than 5 minutes + def prune(self): + self.lock.acquire() + for (index,row) in enumerate(self._data): + if time.time() - row[1] >= 60: + self.beginRemoveRows(QtCore.QModelIndex(), index, index) + self._data.pop(index) + self.endRemoveRows() + self.lock.release() + class dashboard_output(air_modes.modes_parse.modes_parse): def __init__(self, mypos, model):