Psychtoolbox with APP Designer

Hello,

I am using APP Designer in Matlab to run experiments that are implement in Psychtoolbox. The problem is that once the Psychtoolbox is initiated and the screen is rendered, the call back functions in APP Designer wont fire anymore.

The idea is that I want the APP Designer as a controller in my first screen and the Psychtoolbox as the stimulus presentation in the second screen.

Here is a very basic sketch of the control panel with APP Designer:

1

In the startup function in the APP Designer I have:

[app.ptr, app.rect] =Screen('OpenWindow', 2, 0);
Screen('Preference', 'TextAlphaBlending', 1);

app.opacity = 128;
Screen('FillRect', app.ptr, [128 128 128+app.opacity]);
Screen('Flip', app.ptr);

In the call back function for the Next Button I have:

app.opacity = app.opacity + 5;
Screen('FillRect', app.ptr, [128 128 128-app.opacity] );
Screen('Flip', app.ptr);

And for Previous call back I have:

app.opacity = app.opacity - 5;
Screen('FillRect', app.ptr, [128 128 128 1app.opacity );
Screen('Flip', app.ptr);

And what I expect is that a screen is loaded on the second monitor, and by clicking on the Next and Previous button I should be able to increase or decrease the background opacity in the second screen.

What happens is that in this code, the screen gets initiated on the second monitor, but I am not anymore able to click on the APP Designer panel on my first window, and if I try to activate the APP Designer app in the first monitor by Alt+Tab, the Psychtolbox in the second monitor goes back to the purpled calibration window. So I added a WaitSecs at the end of presentation. In this case when I try to access the control panel, it doesn’t get freezed and I can click on the buttons, but the callbacks are not fired.

Any tip on how resolve this issue or how to design a control panel for such applications is highly appreciated.

I don’t have any experience with app designer, so can’t give real advice related to problems with it or its callbacks, but some thoughts:

Are you sure the callbacks don’t get called? Ie. if you remove the semicolon from app.opacity - 5 or add a fprintf statement, does it not print anything?

Is 1app.opacity in Screen('FillRect', app.ptr, [128 128 128 1app.opacity ); a typo in your code, or only in your post here? Maybe the callback gets executed, but error aborts silently without printing proper error messages?

Also, your code suggests use of MS-Windows? That OS is pretty fragile wrt. multi-display setups in general and especially when mixing regular GUI stuff and PTB windows. E.g., ALT+Tabbing or click-activating other windows than the PTB onscreen window will ruin presentation timing for the remainder of the session. Ofc. with partially transparent windows, timing is already shot.

Window transparency is also in different states of brokeness, depending on OS version/release and graphics card / driver version, at least since some of the 2021 OS updates. But it isn’t quite clear what you are trying to achieve with that app.opacity.

1 Like

Thanks for your reply:

  • the 1app was a type only in here, and not in the code, I modified the questions.
  • I was exactly trying your debug method, I realized while the app is in wait mode (I tried WaitSec, KbStrokeWait, or just nothing) the button press is detected and the event is raised, but the callback only gets called once the Psychtoolbox loop is completely done.

Could it be that the Psychtoolbox owns any GUI threads, and does not let any other module to respond?!!

Now that code in almost all FillRect statements is even more broken, also closing ] brackets are missing. Please make sure your posted code here is actually what it really is, before you post it, or you are wasting time and good will.

Wrt. “wait mode” PTB doesn’t do anything special, but code on the Matlab interpreter main thread can not execute while PTB functions like WaitSecs execute. Matlab (and often the Window OS or also macOS) has various limitations wrt. GUI event / callback processing - it may have to happen on the interpreter main thread. Maybe looking at the help for waitforbuttonpress or drawnow and similar callback related Matlab functions will help.

This is the end of free advice on this issue from myself, good luck.

1 Like