Commit b27c8826 by Laura Rodríguez

5jun

parent ff29977d
...@@ -13,16 +13,21 @@ import constants # Debe contener: DISPSIZE = (1920, 1080) ...@@ -13,16 +13,21 @@ import constants # Debe contener: DISPSIZE = (1920, 1080)
import pandas as pd # Importamos pandas para guardar los resultados en un archivo Excel import pandas as pd # Importamos pandas para guardar los resultados en un archivo Excel
import subprocess # Para abrir el archivo con el programa predeterminado import subprocess # Para abrir el archivo con el programa predeterminado
import os # Para comprobar la existencia del archivo import os # Para comprobar la existencia del archivo
from PyQt6.QtWidgets import (
QApplication, QWidget, QVBoxLayout, QPushButton,
QLabel, QMessageBox
)
from PyQt6.QtGui import QFont
from PyQt6.QtCore import Qt
# ============ FUNCIÓN DE CALIBRACIÓN ============
# ============ FUNCIÓN DE CALIBRACIÓN ============
def calibrate_tobii(self): def calibrate_tobii(self):
try: try:
print("Buscando dispositivo...") print("Buscando dispositivo...")
found_eyes = tr.find_all_eyetrackers() found_eyes = tr.find_all_eyetrackers()
if not found_eyes: if not found_eyes:
raise Exception("No se encontró ningún dispositivo Tobii Pro.") raise Exception("No se encontró ningún dispositivo Tobii Pro.")
eye_tracker = found_eyes[0] eye_tracker = found_eyes[0]
print(f"Dispositivo encontrado: {eye_tracker}") print(f"Dispositivo encontrado: {eye_tracker}")
...@@ -63,7 +68,7 @@ def run_gonogo_test(self): ...@@ -63,7 +68,7 @@ def run_gonogo_test(self):
blackscreen = libscreen.Screen() blackscreen = libscreen.Screen()
blackscreen.clear(colour=(0, 0, 0)) blackscreen.clear(colour=(0, 0, 0))
inscreen = libscreen.Screen() inscreen = libscreen.Screen()
inscreen.clear(colour=(0, 0, 0)) inscreen.clear(colour=(0, 0, 0))
ins_text = ( ins_text = (
...@@ -143,12 +148,12 @@ def run_gonogo_test(self): ...@@ -143,12 +148,12 @@ def run_gonogo_test(self):
time.sleep(0.2) time.sleep(0.2)
self.tracker.start_recording() self.tracker.start_recording()
# Mostrar señal central de color # Mostrar señal central de color
self.disp.fill(signal_screens[trialtype]) self.disp.fill(signal_screens[trialtype])
self.disp.show() self.disp.show()
time.sleep(0.8) time.sleep(0.8)
self.disp.fill(blackscreen) self.disp.fill(blackscreen)
self.disp.show() self.disp.show()
time.sleep(0.2) time.sleep(0.2)
...@@ -163,7 +168,7 @@ def run_gonogo_test(self): ...@@ -163,7 +168,7 @@ def run_gonogo_test(self):
dualstim_screen.draw_circle(pos=target_pos, r=38, fill=True, colour=(255, 255, 255)) dualstim_screen.draw_circle(pos=target_pos, r=38, fill=True, colour=(255, 255, 255))
dualstim_screen.draw_circle(pos=target_pos, r=32, fill=True, colour=(0, 0, 0)) dualstim_screen.draw_circle(pos=target_pos, r=32, fill=True, colour=(0, 0, 0))
dualstim_screen.draw_circle(pos=target_pos, r=28, fill=True, colour=(255, 255, 255)) dualstim_screen.draw_circle(pos=target_pos, r=28, fill=True, colour=(255, 255, 255))
self.disp.fill(dualstim_screen) self.disp.fill(dualstim_screen)
self.disp.show() self.disp.show()
...@@ -180,14 +185,14 @@ def run_gonogo_test(self): ...@@ -180,14 +185,14 @@ def run_gonogo_test(self):
# endpos = constants.DISPSIZE[0]/2 # o (SCREEN_WIDTH//2, SCREEN_HEIGHT//2), posición central para 'NoGo' # endpos = constants.DISPSIZE[0]/2 # o (SCREEN_WIDTH//2, SCREEN_HEIGHT//2), posición central para 'NoGo'
latency = (t1 - t0) / 1000 latency = (t1 - t0) / 1000
self.tracker.stop_recording() self.tracker.stop_recording()
# midpoint = SCREEN_WIDTH / 2 # midpoint = SCREEN_WIDTH / 2
# margin = 100 # margin = 100
# endpos=None # endpos=None
if trialtype == 'PS': if trialtype == 'PS':
...@@ -201,10 +206,10 @@ def run_gonogo_test(self): ...@@ -201,10 +206,10 @@ def run_gonogo_test(self):
(targetside == 'left' and endpos[0] >= constants.DISPSIZE[0]/2) or (targetside == 'left' and endpos[0] >= constants.DISPSIZE[0]/2) or
(targetside == 'right' and endpos[0] <= constants.DISPSIZE[0]/2) (targetside == 'right' and endpos[0] <= constants.DISPSIZE[0]/2)
) )
elif trialtype == 'NoGo': elif trialtype == 'NoGo':
correct = int(constants.DISPSIZE[0]/2 < endpos[0] <= constants.DISPSIZE[0]/2) correct = int(constants.DISPSIZE[0]/2 < endpos[0] <= constants.DISPSIZE[0]/2)
if correct >= 0: if correct >= 0:
dualstim_screen.clear(colour=(0, 0, 0)) dualstim_screen.clear(colour=(0, 0, 0))
self.disp.show() self.disp.show()
...@@ -231,6 +236,7 @@ def run_gonogo_test(self): ...@@ -231,6 +236,7 @@ def run_gonogo_test(self):
# ============ INTERFAZ PYQT =================== # ============ INTERFAZ PYQT ===================
class EyeTrackingApp(QWidget): class EyeTrackingApp(QWidget):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
...@@ -243,6 +249,27 @@ class EyeTrackingApp(QWidget): ...@@ -243,6 +249,27 @@ class EyeTrackingApp(QWidget):
def setup_ui(self): def setup_ui(self):
self.setStyleSheet("background-color: #e6f0ff;") self.setStyleSheet("background-color: #e6f0ff;")
button_style = """
QPushButton {
background-color: #3399ff;
color: white;
padding: 10px;
border-radius: 5px;
font-weight: bold;
}
QPushButton:hover {
background-color: #1a8cff;
color: #e6f7ff;
}
QPushButton:pressed {
background-color: #006bb3;
color: #ccf2ff;
padding-top: 11px;
padding-bottom: 9px;
}
"""
layout = QVBoxLayout() layout = QVBoxLayout()
title = QLabel("Test Go/NoGo con Tobii") title = QLabel("Test Go/NoGo con Tobii")
...@@ -252,19 +279,19 @@ class EyeTrackingApp(QWidget): ...@@ -252,19 +279,19 @@ class EyeTrackingApp(QWidget):
self.btn_calibrate = QPushButton("Calibrar") self.btn_calibrate = QPushButton("Calibrar")
self.btn_calibrate.setFont(QFont("Arial", 14)) self.btn_calibrate.setFont(QFont("Arial", 14))
self.btn_calibrate.setStyleSheet("background-color: #3399ff; color: white; padding: 10px; border-radius: 5px;") self.btn_calibrate.setStyleSheet(button_style)
self.btn_calibrate.clicked.connect(self.calibrate) self.btn_calibrate.clicked.connect(self.calibrate)
layout.addWidget(self.btn_calibrate) layout.addWidget(self.btn_calibrate)
self.btn_test = QPushButton("Iniciar test Go/NoGo") self.btn_test = QPushButton("Iniciar test Go/NoGo")
self.btn_test.setFont(QFont("Arial", 14)) self.btn_test.setFont(QFont("Arial", 14))
self.btn_test.setStyleSheet("background-color: #3399ff; color: white; padding: 10px; border-radius: 5px;") self.btn_test.setStyleSheet(button_style)
self.btn_test.clicked.connect(self.start_test) self.btn_test.clicked.connect(self.start_test)
layout.addWidget(self.btn_test) layout.addWidget(self.btn_test)
self.btn_results = QPushButton("Consultar resultados") self.btn_results = QPushButton("Consultar resultados")
self.btn_results.setFont(QFont("Arial", 14)) self.btn_results.setFont(QFont("Arial", 14))
self.btn_results.setStyleSheet("background-color: #3399ff; color: white; padding: 10px; border-radius: 5px;") self.btn_results.setStyleSheet(button_style)
self.btn_results.clicked.connect(self.view_results) self.btn_results.clicked.connect(self.view_results)
layout.addWidget(self.btn_results) layout.addWidget(self.btn_results)
...@@ -276,7 +303,7 @@ class EyeTrackingApp(QWidget): ...@@ -276,7 +303,7 @@ class EyeTrackingApp(QWidget):
self.calibrated = True self.calibrated = True
QMessageBox.information(self, "Calibración", "Calibración completada con éxito.") QMessageBox.information(self, "Calibración", "Calibración completada con éxito.")
else: else:
QMessageBox.critical(self, "Error", "La calibraciión ha fallado.") QMessageBox.critical(self, "Error", "La calibración ha fallado.")
def start_test(self): def start_test(self):
# if not self.calibrated: # if not self.calibrated:
...@@ -286,11 +313,8 @@ class EyeTrackingApp(QWidget): ...@@ -286,11 +313,8 @@ class EyeTrackingApp(QWidget):
def view_results(self): def view_results(self):
file_path = "gonogo_results.xlsx" file_path = "gonogo_results.xlsx"
# Verificamos si el archivo existe antes de intentar abrirlo
if os.path.exists(file_path): if os.path.exists(file_path):
try: try:
# Abrimos el archivo con el programa predeterminado (Windows)
subprocess.Popen([file_path], shell=True) subprocess.Popen([file_path], shell=True)
except Exception as e: except Exception as e:
QMessageBox.critical(self, "Error", f"No se pudo abrir el archivo Excel. {e}") QMessageBox.critical(self, "Error", f"No se pudo abrir el archivo Excel. {e}")
......
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