-
Notifications
You must be signed in to change notification settings - Fork 0
/
stim_display_mirror_child.py
executable file
·55 lines (49 loc) · 1.49 KB
/
stim_display_mirror_child.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
def stimDisplayMirrorChildFunction(
qTo
,qFrom
, window_size = [1920/2,1080/2]
, window_position = [0,0]
):
import sdl2
import sdl2.ext
import sys
import time
from PIL import Image #for image manipulation
try:
import appnope
appnope.nope()
except:
pass
sdl2.SDL_Init(sdl2.SDL_INIT_VIDEO)
window = sdl2.ext.Window("mirror",size=window_size,position=window_position,flags=sdl2.SDL_WINDOW_SHOWN)
windowID = sdl2.SDL_GetWindowID(window.window)
windowSurf = sdl2.SDL_GetWindowSurface(window.window)
windowArray = sdl2.ext.pixels3d(windowSurf.contents)
sdl2.ext.fill(windowSurf.contents,sdl2.pixels.SDL_Color(r=255, g=255, b=255, a=255))
window.refresh()
for i in range(10):
sdl2.SDL_PumpEvents() #to show the windows
def exitSafely():
sys.exit()
while True:
if not qTo.empty():
message = qTo.get()
if message=='quit':
exitSafely()
elif message[0]=='frame':
# print ['q',time.time()-message[3]] #time spent in queue
res = message[1]
buffer = message[2]
image = Image.fromstring(mode="RGB", size=res, data=buffer)
image = image.transpose(Image.ROTATE_270)
# start = time.time()
image.thumbnail([res[1]/2,res[0]/2],Image.LANCZOS)
# print ['resize',time.time()-start]
windowArray[:,:,0:3] = image
window.refresh()
sdl2.SDL_PumpEvents()
for event in sdl2.ext.get_events():
if event.type==sdl2.SDL_WINDOWEVENT:
if (event.window.event==sdl2.SDL_WINDOWEVENT_CLOSE):
exitSafely()
stimDisplayMirrorChildFunction(qTo,qFrom,**initDict)