Using a delegate instead for coloring. Text color works but we don't get nice highlighting. Wish we could alter the painter and use the default paint().
This commit is contained in:
parent
ed006f71b5
commit
855535644f
@ -1,6 +1,6 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
import os, sys, time, threading
|
||||
import os, sys, time, threading, datetime
|
||||
from PyQt4 import QtCore,QtGui,QtSql
|
||||
from gnuradio import gr, gru, optfir, eng_notation, blks2
|
||||
import gnuradio.gr.gr_threading as _threading
|
||||
@ -62,12 +62,14 @@ class mainwindow(QtGui.QMainWindow):
|
||||
self.db.open()
|
||||
#self.db = sqlite3.connect(self.dbname)
|
||||
self.datamodel = modes_datamodel(self.db)
|
||||
#self.datamodel = QtSql.QSqlQueryModel(None)
|
||||
#self.datamodel.setQuery(QtSql.QSqlQuery("select distinct icao from positions order by icao"))
|
||||
self.ui.list_aircraft.setModel(self.datamodel)
|
||||
self.ui.list_aircraft.setModelColumn(0)
|
||||
self.icaodelegate = ICAOViewDelegate()
|
||||
self.ui.list_aircraft.setItemDelegate(self.icaodelegate)
|
||||
#self.ui.list_aircraft.show() #TODO remove
|
||||
|
||||
#todo add a custom delegate for the QListView
|
||||
|
||||
#goes and gets valid antenna, sample rate options from the device and grays out appropriate things
|
||||
def populate_source_options(self):
|
||||
sourceid = self.ui.combo_source.currentText()
|
||||
@ -239,6 +241,18 @@ class mainwindow(QtGui.QMainWindow):
|
||||
self.ui.line_speed.insert(speed)
|
||||
self.ui.line_climb.insert(vs)
|
||||
|
||||
#all this does is fade the ICAOs out as their last report gets older
|
||||
class ICAOViewDelegate(QtGui.QStyledItemDelegate):
|
||||
def paint(self, painter, option, index):
|
||||
paintstr = "%s" % index.model().data(index.model().index(index.row(), 0))
|
||||
last_report = index.model().data(index.model().index(index.row(), 1))
|
||||
age = (datetime.datetime.now() - datetime.datetime.strptime(str(last_report), "%Y-%m-%d %H:%M:%S")).total_seconds()
|
||||
#minimum alpha is 0x40 (oldest), max is 0xFF (newest)
|
||||
alpha = min(abs(0xFF - (0xBF / 600.) * age), 0x40)
|
||||
painter.setPen(QtGui.QColor(0, 0, 0, alpha))
|
||||
#QtGui.QStyledItemDelegate.paint(self, painter, option, index)
|
||||
painter.drawText(option.rect.left()+3, option.rect.top(), option.rect.width(), option.rect.height(), option.displayAlignment, paintstr)
|
||||
|
||||
#eventually: set up a QTimer or whatever and have it self-update and emit dataChanged()
|
||||
#better yet just have the SQL interface yell and say hey that line changed.
|
||||
#on selected aircraft or on update for visible aircraft, emit signal to update current dashboard display.
|
||||
|
Loading…
Reference in New Issue
Block a user