Commit a5558fe5 authored by Marios Fanourakis's avatar Marios Fanourakis

changed strategy for qt widgets to allow adding various elements

parent 482d033f
......@@ -13,8 +13,9 @@ import numpy as np
import math
import pylsl
import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui
from pyqtgraph.Qt import QtCore, QtGui, uic, QtWidgets
from typing import List
import sys
# Basic parameters for the plotting window
plot_duration = 10 # how many seconds of data to show
......@@ -38,11 +39,12 @@ class Inlet:
# store the name and channel count
self.name = info.name()
self.channel_count = info.channel_count()
self.uid = info.uid()
def pull_and_plot(self, plot_time: float, plt: pg.PlotItem):
def pull_and_plot(self, plot_time: float, plts: [pg.PlotItem]):
"""Pull data from the inlet and add it to the plot.
:param plot_time: lowest timestamp that's still visible in the plot
:param plt: the plot the data should be shown on
:param plts: the plot the data should be shown on
"""
# We don't know what to do with a generic inlet, so we skip it.
pass
......@@ -70,7 +72,7 @@ class DataInlet(Inlet):
plts[-1].setLabel('top', text=self.name + ' channel ' + str(ch_ix))
ch_ix = ch_ix + 1
def pull_and_plot(self, plot_time):
def pull_and_plot(self, plot_time, plts):
# pull the data
_, ts = self.inlet.pull_chunk(timeout=0.0,
max_samples=self.buffer.shape[0],
......@@ -116,15 +118,31 @@ class MarkerInlet(Inlet):
plts[0].addItem(pg.InfiniteLine(ts, angle=90, movable=False, label=string[0]))
class MainWindow(QtWidgets.QMainWindow):
def __init__(self, *args, **kwargs):
super(MainWindow, self).__init__(*args, **kwargs)
self.mainWidget = QtGui.QWidget()
self.layout = QtGui.QGridLayout()
self.mainWidget.setLayout(self.layout)
self.plots = pg.GraphicsLayoutWidget()
self.checkTable = pg.CheckTable([''])
self.layout.addWidget(self.checkTable, 0, 0)
self.layout.addWidget(self.plots, 0, 1)
self.setCentralWidget(self.mainWidget)
def main():
# Create the pyqtgraph window
app = QtGui.QApplication([])
view = pg.GraphicsView()
gl = pg.GraphicsLayout()
view.setCentralItem(gl)
view.show()
plts: List[pg.PlotItem] = []
plts.append(gl.addPlot())
app = QtWidgets.QApplication(sys.argv)
win = MainWindow()
win.show()
# initialize with first plot (to display all marker data)
plts: List[pg.PlotItem] = [win.plots.addPlot()]
plts[-1].setLabel('top', text='All Inlets Marker Data')
# firstly resolve all streams that could be shown
......@@ -132,10 +150,16 @@ def main():
print("looking for streams")
streams = pylsl.resolve_streams()
def on_check_change(row, col, state):
# TODO actually update plots
print("check changed: " + row + " " + str(state))
win.checkTable.sigStateChanged.connect(on_check_change)
# iterate over found streams, creating specialized inlet objects that will
# handle plotting the data
for info in streams:
win.checkTable.addRow(info.name())
if info.type() == 'Markers':
if info.nominal_srate() != pylsl.IRREGULAR_RATE \
or info.channel_format() != pylsl.cf_string:
......@@ -145,11 +169,10 @@ def main():
elif info.nominal_srate() != pylsl.IRREGULAR_RATE \
and info.channel_format() != pylsl.cf_string:
print('Adding data inlet: ' + info.name())
inlets.append(DataInlet(info, gl, plts))
inlets.append(DataInlet(info, win.plots, plts))
else:
print('Don\'t know what to do with stream ' + info.name())
def scroll():
"""Move the view so the data appears to scroll"""
# We show data only up to a timepoint shortly before the current time
......@@ -165,7 +188,7 @@ def main():
# Special handling of inlet types (markers, continuous data) is done in
# the different inlet classes.
for inlet in inlets:
inlet.pull_and_plot(mintime)
inlet.pull_and_plot(mintime, plts)
# create a timer that will move the view every update_interval ms
update_timer = QtCore.QTimer()
......@@ -177,11 +200,7 @@ def main():
pull_timer.timeout.connect(update)
pull_timer.start(pull_interval)
import sys
# Start Qt event loop unless running in interactive mode or using pyside.
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()
sys.exit(app.exec_())
if __name__ == '__main__':
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment