Commit 89b9a5ea authored by Marios Fanourakis's avatar Marios Fanourakis

added button to select/deselect all; small code readability changes

parent c2328277
......@@ -149,12 +149,14 @@ class MainWindow(QtWidgets.QMainWindow):
self.mainWidget.setLayout(self.layout)
self.plots = pg.GraphicsLayoutWidget()
self.selectAllButton = QtGui.QPushButton('select/deselect all')
self.checkTable = pg.CheckTable([''])
self.updateButton = QtGui.QPushButton('update inlets')
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.layout.addWidget(self.selectAllButton, 0, 0)
self.layout.addWidget(self.checkTable, 1, 0)
self.layout.addWidget(self.updateButton, 2, 0)
self.layout.addWidget(self.plots, 1, 1)
self.setCentralWidget(self.mainWidget)
......@@ -170,16 +172,23 @@ def main():
inlets: List[Inlet] = []
def remove_plots_of_inlet(inlet):
for plt_ix in inlet.plt_ixs:
win.plots.removeItem(plts[plt_ix])
inlet.plt_ixs = []
def remove_plots(inlet=None):
if inlet is None:
nonlocal inlets
for inlet in inlets:
for plt_ix in inlet.plt_ixs:
win.plots.removeItem(plts[plt_ix])
inlet.plt_ixs = []
else:
for plt_ix in inlet.plt_ixs:
win.plots.removeItem(plts[plt_ix])
inlet.plt_ixs = []
def update_inlets():
# clear old inlet stuff
nonlocal inlets
for inlet in inlets:
remove_plots_of_inlet(inlet)
remove_plots(inlet)
rows = win.checkTable.rowNames.copy()
for row in rows:
win.checkTable.removeRow(row)
......@@ -221,13 +230,17 @@ def main():
plot_time = pylsl.local_clock()
plts[0].setXRange(plot_time - plot_duration + fudge_factor, plot_time - fudge_factor)
def update():
def update_data(inlet=None):
# Read data from the inlet. Use a timeout of 0.0 so we don't block GUI interaction.
mintime = pylsl.local_clock() - plot_duration
# call pull_and_plot for each inlet.
# Special handling of inlet types (markers, continuous data) is done in
# the different inlet classes.
for inlet in inlets:
if inlet is None:
nonlocal inlets
for inlet in inlets:
inlet.pull_and_plot(mintime, win.plots, plts)
else:
inlet.pull_and_plot(mintime, win.plots, plts)
def on_check_change(row, col, state):
......@@ -241,25 +254,47 @@ def main():
return
print("check changed: " + row + " " + str(state))
inlet_ix = 0
nonlocal inlets
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)
update_data(inlet)
else:
inlet.set_enabled(False)
remove_plots_of_inlet(inlet)
inlet_ix += 1
remove_plots(inlet)
def on_select_all_button_click():
is_all_selected = True
state = win.checkTable.saveState()
def on_button_click():
# check if all are selected and if not, select
for row in state['rows']:
if not row[1]:
is_all_selected = False
row[1] = True
# if all are selected, then deselect all
if is_all_selected:
for row in state['rows']:
row[1] = False
# update states on the checkmark table
win.checkTable.restoreState(state)
def on_update_button_click():
# first update lsl inlets
update_inlets()
# then reapply the selections of the old inlets
for row in win.checkTable.saveState()['rows']:
on_check_change(row[0], None, row[1])
# connect button events to relevant functions
win.checkTable.sigStateChanged.connect(on_check_change)
win.updateButton.clicked.connect(on_button_click)
win.updateButton.clicked.connect(on_update_button_click)
win.selectAllButton.clicked.connect(on_select_all_button_click)
# initialize inlets and the inlet list
update_inlets()
# create a timer that will move the view every update_interval ms
......@@ -269,7 +304,7 @@ def main():
# create a timer that will pull and add new data occasionally
pull_timer = QtCore.QTimer()
pull_timer.timeout.connect(update)
pull_timer.timeout.connect(update_data)
pull_timer.start(pull_interval)
sys.exit(app.exec_())
......
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