psychopy.org | Reference | Downloads | Github

How to set default Code Type

When I add or edit code components in Builder, there is an option for “Code Type” at the top of the window. This defaults to “Auto->JS”. How can set the default option to “Py”.

I.e., I’d just like to see the simple python code without any additional conversions to javascript.

4 Likes

@swarb, this looks like a bug, if you would like, you could mark this as an issue on the PsychoPy GitHub page.

Edit: I have requested a fix here.

2 Likes

According to the GitHub page that @dvbridges referenced, the issue should have been resolved. It is still present, however, in the current PsychoPy version (2020.1.3. on macOS).

To be more precise, when I add a code component and set the code type to “Py”, this is actually reflected correctly in the .psyexp file:

...
<Routines>
    <Routine name="trial">
      <CodeComponent name="code1">
        ...
        <Param name="Code Type" updates="None" val="Py" valType="str"/>
        ...
      </CodeComponent>
    </Routine>
</Routines>
...

However, as soon as I close the code component and reopen it, the code type reverts back to “Auto->JS”.

This is really annoying.

I’d agree with @Holger, it affects the joy of using the code component. And I feel it might actually have substantial consequences (like overwriting code? forgetting to reset?). Alternatively, is there a way to get PsychoPy to remember/set the code property window width or font size?

(On that note: I use/downloaded v2020.1.3 from Github, but “PsychoPy > About” says it’s v2020.1.2)

I just installed PsychoPy3 2020.1.3 on a Windows machine. The “code type” bug is also present in the Windows version.

And yes, @skeptikantin is right that on a Mac computer, PsychoPy3 2020.1.3 identifies itself as version 2020.1.2.

By contrast, on Windows PCs, “Help” => “About…” correctly states “v2020.1.3”.

@Holger, yes it looks like the fix is in place in the Github repo, but was not released. I imagine the fix will be added to the next standalone release. In the meantime, if you wanted to add the fix to your own copy, so your code type prefs are saved each time you close the code box, you can add the following file to your psychopy installation. On Windows, go to your standalone PsychoPy path and navigate to the code component dialog code, something like

C:\Program Files\PsychoPy3\Lib\site-packages\psychopy\app\builder\dialogs\

Add the following file to the directory, overwriting the existing file, and when you start PsychoPy the code type should be saved each time you close your code dialogs.

dlgsCode.py (24.7 KB)

3 Likes

Thanks a lot, David (@dvbridges), for your help! I can confirm that replacing the dlgsCode.py file solves the problem on macOS. There, the path of the file that needs to be replaced is

/Applications/PsychoPy3.app/Contents/Resources/lib/python3.6/psychopy/app/builder/dialogs/dlgsCode.py.

You can do so by right-clicking on the PsychoPy3 app and then choosing “Show Package Contents”. After that follow the path Contents −> Resources −> lib −> python3.6 −> psychopy −> app −> builder −> dialogs).

2 Likes

This works for me too on mac. Thank you for this fix! It will make my life so much easier.

Thanks @Holger and @dvbridges, very helpful, works for Mac 10.15.5 also. Such relief :slight_smile: