55# Copyright (c) 2024 Olivier Delree <odelree@ed.ac.uk>
66# Distributed under the terms of the MIT Licence.
77
8- import importlib .resources as resources
9- import os
10- import logging
11- import time
128import datetime
13- import threading
9+ import logging
10+ import os
1411import queue
12+ import threading
13+ import time
14+ from importlib import resources
1515
1616import pygame as pg
1717
1818import visiomode .config as conf
19- import visiomode .devices as devices
20- import visiomode .models as models
21- import visiomode .plugins as plugins
22- import visiomode .stimuli as stimuli
23- import visiomode .tasks as tasks
24- import visiomode .webpanel as webpanel
19+ from visiomode import devices , models , plugins , stimuli , tasks , webpanel
2520
2621# Register mouse events as touch events - useful for debugging.
2722os .environ ["SDL_MOUSE_TOUCH_EVENTS" ] = "1"
@@ -37,9 +32,9 @@ class Visiomode:
3732
3833 def __init__ (
3934 self ,
40- run_application_loop : bool = True ,
41- run_webpanel : bool = True ,
42- load_plugins : bool = True ,
35+ # run_application_loop: bool = True,
36+ # run_webpanel: bool = True,
37+ # load_plugins: bool = True,
4338 ):
4439 """Initialise application.
4540
@@ -90,7 +85,7 @@ def run(self) -> None:
9085
9186 self .run_main ()
9287
93- def loading_screen (self ):
88+ def loading_screen (self , max_angle = 1080 , angle_rotation = 5 ):
9489 """Rotating logo to entertain user and mouse while the webpanel is loading."""
9590 # Fill background
9691 self .background = pg .Surface (self .screen .get_size ())
@@ -122,13 +117,13 @@ def loading_screen(self):
122117 pg .display .flip ()
123118
124119 angle = 0
125- while angle != 1080 :
120+ while angle != max_angle :
126121 events = pg .event .get ()
127122 for event in events :
128123 if event .type == pg .QUIT :
129124 return
130125
131- angle += 5
126+ angle += angle_rotation
132127
133128 image , rect = rotate (loading_img , loading_img_pos , angle )
134129
@@ -143,9 +138,7 @@ def loading_screen(self):
143138
144139 textpos = text .get_rect ()
145140 textpos .centerx = self .background .get_rect ().centerx
146- textpos .centery = (
147- self .background .get_rect ().centery + 60
148- ) # TODO calculate offset at runtime
141+ textpos .centery = self .background .get_rect ().centery + 60 # TODO calculate offset at runtime
149142
150143 self .background .blit (text , textpos )
151144 self .screen .blit (self .background , (0 , 0 ))
@@ -167,8 +160,7 @@ def run_main(self):
167160 self .session .trials = self .session .task .trials
168161 if self .session and (
169162 not self .session .task .is_running
170- or time .time () - self .session .task .start_time
171- > self .session .duration * 60
163+ or time .time () - self .session .task .start_time > self .session .duration * 60
172164 ):
173165 logging .info ("Session finished." )
174166 self .session .task .stop ()
@@ -201,17 +193,15 @@ def request_listener(self):
201193 while True :
202194 request = self .action_q .get ()
203195 if "type" not in request .keys ():
204- logging .error ("Invalid request - {}" . format ( request ) )
196+ logging .error (f "Invalid request - { request } " )
205197 continue
206198 if request ["type" ] == "start" :
207199 # Update config
208200 conf .Config ().input_device_address = (
209- request ["data" ].get ("response_address" )
210- or conf .Config ().input_device_address
201+ request ["data" ].get ("response_address" ) or conf .Config ().input_device_address
211202 )
212203 conf .Config ().reward_device_address = (
213- request ["data" ].get ("reward_address" )
214- or conf .Config ().reward_device_address
204+ request ["data" ].get ("reward_address" ) or conf .Config ().reward_device_address
215205 )
216206 conf .Config ().save ()
217207
0 commit comments