[visual task] react on start and end
This commit is contained in:
parent
c4c9fb07c2
commit
7caed65a8f
@ -1,6 +1,6 @@
|
|||||||
from PyQt5.QtWidgets import QComboBox, QFrame, QGroupBox, QHBoxLayout, QLabel, QPushButton, QSizePolicy, QSplitter, QTextEdit, QVBoxLayout, QWidget
|
from PyQt5.QtWidgets import QAction, QComboBox, QFrame, QGroupBox, QGridLayout, QLabel, QPushButton, QShortcut, QSizePolicy, QSplitter, QTextEdit, QVBoxLayout, QWidget
|
||||||
from PyQt5.QtCore import QItemSelectionModel, Qt
|
from PyQt5.QtCore import QItemSelectionModel, QLine, QPoint, Qt
|
||||||
from PyQt5.QtGui import QPainter, QBrush, QPen, QPixmap
|
from PyQt5.QtGui import QColor, QKeySequence, QPainter, QBrush, QPen, QPixmap
|
||||||
|
|
||||||
import blipblop.constants as cnst
|
import blipblop.constants as cnst
|
||||||
|
|
||||||
@ -13,32 +13,71 @@ class VisualBlip(QWidget):
|
|||||||
def __init__(self, parent=None) -> None:
|
def __init__(self, parent=None) -> None:
|
||||||
super().__init__(parent=parent)
|
super().__init__(parent=parent)
|
||||||
|
|
||||||
vbox = QVBoxLayout()
|
grid = QGridLayout()
|
||||||
self.setLayout(vbox)
|
grid.setColumnStretch(0, 1)
|
||||||
|
grid.setColumnStretch(2, 1)
|
||||||
|
grid.setRowStretch(1, 1)
|
||||||
|
grid.setRowStretch(3, 1)
|
||||||
|
self.setLayout(grid)
|
||||||
|
|
||||||
l = QLabel("Visual task")
|
l = QLabel("Visual task")
|
||||||
|
grid.addWidget(l, 0, 0, Qt.AlignLeft)
|
||||||
|
instruction_label = QLabel("Instructions:\n -fixate central cross\n -press start (enter) when ready\n -press space bar as soon as the stimulus occurs")
|
||||||
|
grid.addWidget(instruction_label, 3, 1, Qt.AlignLeft)
|
||||||
self._draw_area = QLabel()
|
self._draw_area = QLabel()
|
||||||
self._draw_area.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
|
self._draw_area.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
|
||||||
canvas = QPixmap(400, 300)
|
grid.addWidget(self._draw_area, 2, 1)
|
||||||
canvas = QPixmap()
|
self.reset_canvas()
|
||||||
|
self.create_actions()
|
||||||
|
|
||||||
|
def create_actions(self):
|
||||||
|
self._start_action = QAction("start trial")
|
||||||
|
self._start_action.setShortcuts([QKeySequence("enter"), QKeySequence("return")])
|
||||||
|
self._start_action.triggered.connect(self.paint_event)
|
||||||
|
self._reaction = QAction("reaction")
|
||||||
|
self._reaction.setShortcut(QKeySequence("space"))
|
||||||
|
self._reaction.triggered.connect(self.on_reaction)
|
||||||
|
|
||||||
|
self.addAction(self._start_action)
|
||||||
|
self.addAction(self._reaction)
|
||||||
|
|
||||||
|
def on_reaction(self):
|
||||||
|
print("reaction")
|
||||||
|
self.reset_canvas()
|
||||||
|
|
||||||
|
def reset_canvas(self):
|
||||||
|
bkg_color = QColor()
|
||||||
|
bkg_color.setAlphaF(0.0)
|
||||||
|
canvas = QPixmap(400, 400)
|
||||||
|
self._canvas_center = QPoint(200, 200)
|
||||||
|
canvas.fill(bkg_color)
|
||||||
|
self.draw_fixation(canvas)
|
||||||
self._draw_area.setPixmap(canvas)
|
self._draw_area.setPixmap(canvas)
|
||||||
vbox.addWidget(l)
|
self._draw_area.update()
|
||||||
vbox.addWidget(self._draw_area)
|
|
||||||
|
def draw_fixation(self, pixmap):
|
||||||
start_btn = QPushButton("start")
|
left = QPoint(175, 200)
|
||||||
start_btn.clicked.connect(self.paint_event)
|
right = QPoint(225, 200)
|
||||||
vbox.addWidget(start_btn)
|
top = QPoint(200, 175)
|
||||||
|
bottom = QPoint(200, 225)
|
||||||
|
painter = QPainter(pixmap)
|
||||||
|
painter.setPen(QPen(Qt.red, 1, Qt.SolidLine))
|
||||||
|
painter.drawLine(left, right)
|
||||||
|
painter.drawLine(top, bottom)
|
||||||
|
painter.end()
|
||||||
|
self._canvas = QPixmap(400, 400)
|
||||||
|
self._canvas_center = QPoint(200, 200)
|
||||||
|
self._draw_area.setPixmap(self._canvas)
|
||||||
|
|
||||||
def paint_event(self):
|
def paint_event(self):
|
||||||
painter = QPainter(self._draw_area.pixmap())
|
painter = QPainter(self._draw_area.pixmap())
|
||||||
painter.setPen(QPen(Qt.red, 1, Qt.SolidLine))
|
painter.setPen(QPen(Qt.red, 1, Qt.SolidLine))
|
||||||
painter.setBrush(QBrush(Qt.red, Qt.SolidPattern))
|
painter.setBrush(QBrush(Qt.red, Qt.SolidPattern))
|
||||||
painter.drawEllipse(40, 40, 80, 100)
|
|
||||||
|
painter.drawEllipse(self._canvas_center, 100, 100)
|
||||||
painter.end()
|
painter.end()
|
||||||
self._draw_area.update()
|
self._draw_area.update()
|
||||||
|
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user