Decouple data output thread from live data display by using a signal to the main window instead of directly calling append().
This commit is contained in:
parent
f42e2e744d
commit
d86e568ac2
@ -31,6 +31,7 @@ from air_modes.gui_model import *
|
|||||||
import sqlite3
|
import sqlite3
|
||||||
|
|
||||||
class mainwindow(QtGui.QMainWindow):
|
class mainwindow(QtGui.QMainWindow):
|
||||||
|
live_data_changed_signal = QtCore.pyqtSignal(QtCore.QString, name='liveDataChanged')
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
QtGui.QMainWindow.__init__(self)
|
QtGui.QMainWindow.__init__(self)
|
||||||
self.ui = Ui_MainWindow()
|
self.ui = Ui_MainWindow()
|
||||||
@ -116,6 +117,9 @@ class mainwindow(QtGui.QMainWindow):
|
|||||||
self.datamodel.dataChanged.connect(self.unmapped_widgets_dataChanged)
|
self.datamodel.dataChanged.connect(self.unmapped_widgets_dataChanged)
|
||||||
self.ui.list_aircraft.selectionModel().currentRowChanged.connect(self.update_rssi_widget)
|
self.ui.list_aircraft.selectionModel().currentRowChanged.connect(self.update_rssi_widget)
|
||||||
|
|
||||||
|
#hook up live data text box update signal
|
||||||
|
self.live_data_changed_signal.connect(self.on_append_live_data)
|
||||||
|
|
||||||
############ widget update functions for non-mapped widgets ############
|
############ widget update functions for non-mapped widgets ############
|
||||||
def update_heading_widget(self, index):
|
def update_heading_widget(self, index):
|
||||||
if index.model() is not None:
|
if index.model() is not None:
|
||||||
@ -274,7 +278,7 @@ class mainwindow(QtGui.QMainWindow):
|
|||||||
self.livedata = air_modes.output_print(my_position)
|
self.livedata = air_modes.output_print(my_position)
|
||||||
#add output for live data box
|
#add output for live data box
|
||||||
#TODO: this doesn't handle large volumes of data well; i get segfaults.
|
#TODO: this doesn't handle large volumes of data well; i get segfaults.
|
||||||
#self.outputs.append(self.output_live_data)
|
self.outputs.append(self.output_live_data)
|
||||||
|
|
||||||
#create SQL database for KML and dashboard displays
|
#create SQL database for KML and dashboard displays
|
||||||
self.dbwriter = air_modes.output_sql(my_position, self.dbname)
|
self.dbwriter = air_modes.output_sql(my_position, self.dbname)
|
||||||
@ -304,11 +308,17 @@ class mainwindow(QtGui.QMainWindow):
|
|||||||
#self.kmlgen.join()
|
#self.kmlgen.join()
|
||||||
#self.kmlgen = None
|
#self.kmlgen = None
|
||||||
|
|
||||||
|
#slot to catch signal emitted by output_live_data (necessary for
|
||||||
|
#thread safety since output_live_data is called by another thread)
|
||||||
|
def on_append_live_data(self, msgstr):
|
||||||
|
self.ui.text_livedata.append(msgstr)
|
||||||
|
self.ui.text_livedata.verticalScrollBar().setSliderPosition(self.ui.text_livedata.verticalScrollBar().maximum())
|
||||||
|
|
||||||
def output_live_data(self, msg):
|
def output_live_data(self, msg):
|
||||||
msgstr = self.livedata.parse(msg)
|
msgstr = self.livedata.parse(msg)
|
||||||
if msgstr is not None:
|
if msgstr is not None:
|
||||||
self.ui.text_livedata.append(msgstr)
|
self.live_data_changed_signal.emit(msgstr)
|
||||||
self.ui.text_livedata.verticalScrollBar().setSliderPosition(self.ui.text_livedata.verticalScrollBar().maximum())
|
|
||||||
|
|
||||||
|
|
||||||
#the output handler is a thread which runs the various registered output functions when there's a received message.
|
#the output handler is a thread which runs the various registered output functions when there's a received message.
|
||||||
|
Loading…
Reference in New Issue
Block a user