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.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.
......@@ -70,7 +72,7 @@ class DataInlet(Inlet):
plts[-1].setLabel('top', + ' 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,
......@@ -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.plots = pg.GraphicsLayoutWidget()
self.checkTable = pg.CheckTable([''])
self.layout.addWidget(self.checkTable, 0, 0)
self.layout.addWidget(self.plots, 0, 1)
def main():
# Create the pyqtgraph window
app = QtGui.QApplication([])
view = pg.GraphicsView()
gl = pg.GraphicsLayout()
plts: List[pg.PlotItem] = []
app = QtWidgets.QApplication(sys.argv)
win = MainWindow()
# 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))
# iterate over found streams, creating specialized inlet objects that will
# handle plotting the data
for info in streams:
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: ' +
inlets.append(DataInlet(info, gl, plts))
inlets.append(DataInlet(info, win.plots, plts))
print('Don\'t know what to do with stream ' +
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, plts)
# create a timer that will move the view every update_interval ms
update_timer = QtCore.QTimer()
......@@ -177,11 +200,7 @@ def main():
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'):
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