Commit bb34643c authored by Marios Fanourakis's avatar Marios Fanourakis

added functionality of updating inlets

parent 77986e3f
......@@ -145,8 +145,10 @@ class MainWindow(QtWidgets.QMainWindow):
self.plots = pg.GraphicsLayoutWidget()
self.checkTable = pg.CheckTable([''])
self.updateButton = QtGui.QPushButton('update inlets')
self.layout.addWidget(self.checkTable, 0, 0)
self.layout.addWidget(self.updateButton, 1, 0)
self.layout.addWidget(self.plots, 0, 1)
self.setCentralWidget(self.mainWidget)
......@@ -161,51 +163,50 @@ def main():
plts: List[pg.PlotItem] = [win.plots.addPlot()]
plts[-1].setLabel('top', text='All Inlets Marker Data')
# firstly resolve all streams that could be shown
inlets: List[Inlet] = []
print("looking for streams")
streams = pylsl.resolve_streams()
def on_check_change(row, col, state):
print("check changed: " + row + " " + str(state))
inlet_ix = 0
for inlet in inlets:
if inlet.name == row:
if state>0:
inlet.set_enabled(True)
else:
inlet.set_enabled(False)
remove_plots_of_inlet(inlet)
inlet_ix += 1
def remove_plots_of_inlet(inlet):
for plt_ix in inlet.plt_ixs:
win.plots.removeItem(plts[plt_ix])
inlet.plt_ixs = []
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:
if info.type() == 'Markers':
if info.nominal_srate() != pylsl.IRREGULAR_RATE \
or info.channel_format() != pylsl.cf_string:
print('Invalid marker stream ' + info.name())
print('Adding marker inlet: ' + info.name())
inlets.append(MarkerInlet(info))
# give unique name to inlet and add to checkbox table
inlets[-1].name = str(len(inlets) - 1) + ' ' + inlets[-1].name
win.checkTable.addRow(inlets[-1].name)
elif info.nominal_srate() != pylsl.IRREGULAR_RATE \
and info.channel_format() != pylsl.cf_string:
print('Adding data inlet: ' + info.name())
inlets.append(DataInlet(info))
# give unique name to inlet and add to checkbox table
inlets[-1].name = str(len(inlets) - 1) + ' ' + inlets[-1].name
win.checkTable.addRow(inlets[-1].name)
else:
print('Don\'t know what to do with stream ' + info.name())
def update_inlets():
# clear old inlet stuff
nonlocal inlets
for inlet in inlets:
remove_plots_of_inlet(inlet)
rows = win.checkTable.rowNames.copy()
for row in rows:
win.checkTable.removeRow(row)
inlets = []
# firstly resolve all streams that could be shown
print("looking for streams")
streams = pylsl.resolve_streams()
# 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:
print('Invalid marker stream ' + info.name())
print('Adding marker inlet: ' + info.name())
inlets.append(MarkerInlet(info))
# give unique name to inlet and add to checkbox table
inlets[-1].name = str(len(inlets) - 1) + ' ' + inlets[-1].name
win.checkTable.addRow(inlets[-1].name)
elif info.nominal_srate() != pylsl.IRREGULAR_RATE \
and info.channel_format() != pylsl.cf_string:
print('Adding data inlet: ' + info.name())
inlets.append(DataInlet(info))
# give unique name to inlet and add to checkbox table
inlets[-1].name = str(len(inlets) - 1) + ' ' + inlets[-1].name
win.checkTable.addRow(inlets[-1].name)
else:
print('Don\'t know what to do with stream ' + info.name())
return
def scroll():
"""Move the view so the data appears to scroll"""
......@@ -224,6 +225,38 @@ def main():
for inlet in inlets:
inlet.pull_and_plot(mintime, win.plots, plts)
def on_check_change(row, col, state):
if type(state) is int:
if state > 0:
state = True
else:
state = False
elif type(state) is not bool:
print('State is of unknown type!! ')
return
print("check changed: " + row + " " + str(state))
inlet_ix = 0
for inlet in inlets:
if inlet.name == row:
if state:
inlet.set_enabled(True)
mintime = pylsl.local_clock() - plot_duration
inlet.pull_and_plot(mintime, win.plots, plts)
else:
inlet.set_enabled(False)
remove_plots_of_inlet(inlet)
inlet_ix += 1
def on_button_click():
update_inlets()
for row in win.checkTable.saveState()['rows']:
on_check_change(row[0], None, row[1])
win.checkTable.sigStateChanged.connect(on_check_change)
win.updateButton.clicked.connect(on_button_click)
update_inlets()
# create a timer that will move the view every update_interval ms
update_timer = QtCore.QTimer()
update_timer.timeout.connect(scroll)
......
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