PsychoPy Gui Errors

Hello,

This was just an observation I had about the PsychoPy GUI that I was hoping someone would be able to help me understand a bit better.

At the beginning of my experiment, I have a GUI appear on the screen for the experimenter to input the Subject ID and which block to start from. Please note that all of this is done through code and not the PsychoPy Builder. Here is my code for the GUI.

subgui = gui.Dlg()

subgui.addField('Subject ID:')

subgui.addField('Start From:', choices=['Block 1', 'Block 2', 'Block 3', 'Speech Intelligibility'])

subgui.show()


subjID = int(subgui.data[0])

start = str(subgui.data[1])

I upgraded to PsychoPy 2024.1.4 on my computer. I have the fields of ‘Subject ID:’ and ‘Start from:’ which are supposed to be shown in the GUI, but I noticed that they were not showing up. After testing it out, I also kept receiving errors saying that 0 was a nonexistent index in subgui.data[0]. I have used this code for ages, but it was just interesting to me that it stopped working. I went through the documentation and noticed that Dlg is referenced twice, in wxgui.py and qtgui.py. From my understanding, PsychoPy uses either wxPython of PyQt to show the GUI and from this, depending on which method it uses, it outputs the GUI responses to a list or dictionary respectively. If using PyQt, I would need to reference the output as subgui.data[‘Subject ID:’] instead.

I am assuming the newest version of PsychoPy automatically revert to PyQt. To solve this problem, I downgraded back PsychoPy to 2023.2.3 which automatically uses wxPython and outputs a list. I am just wondering how I can force PsychoPy to use wxPython in the future. From this experience it seems that wxPython shows the field labels in the GUI and outputs as a list, which is preferred. It is just frustrating that I now how to go back and update all my code and that this changes was not communicated.

Did anyone else have this experience?

2 Likes

Hi Ryan,

I’m using 2024.1.5 and I have the same issue. I haven’t tried downgrading PsychoPy but I’m unable to run some old code–a very long series of questionnaires that I’d rather not edit. Interestingly, the demo code fails out with a similar error.

My error, from myDlg.addField(‘American Indian’, False)

TypeError: arguments did not match any overloaded call:
QLabel(parent: typing.Optional[QWidget] = None, flags: Union[Qt.WindowFlags, Qt.WindowType] = Qt.WindowFlags()): argument 1 has unexpected type ‘bool’
QLabel(text: str, parent: typing.Optional[QWidget] = None, flags: Union[Qt.WindowFlags, Qt.WindowType] = Qt.WindowFlags()): argument 1 has unexpected type ‘bool’

GUI.py error, from dlg.addField(‘Age:’, 21)

TypeError: arguments did not match any overloaded call:
QLabel(parent: typing.Optional[QWidget] = None, flags: Union[Qt.WindowFlags, Qt.WindowType] = Qt.WindowFlags()): argument 1 has unexpected type ‘int’
QLabel(text: str, parent: typing.Optional[QWidget] = None, flags: Union[Qt.WindowFlags, Qt.WindowType] = Qt.WindowFlags()): argument 1 has unexpected type ‘int’

As best I can discern, the ‘label’ argument is new and is SUPPOSED to be optional but is not actually optional as currently written. Would be very grateful if someone could clear this up or suggest a fast workaround.

I did try forcing a different gui than the default one:
from psychopy.gui import wxgui as gui
as suggested in the demo GUI.py, but that just generates a different error.

Update: I fixed it in a kind of annoying way, but one that causes minimal disruption to the original code. The reason this is annoying is that I suspect that this bug will get written out at some point. Not sure how to get the attention of the PsychoPy creators to get this addressed and too busy to spend hours on it but if someone else wants to you go. Probably reverting to an earlier version is a better idea. :person_shrugging:

Anyway, I fixed by simply inserting a new first argument as a ‘key’ to each addField() statement, which shifts the old first argument to ‘label’ position.

OLD:
addField('what is your name " ,‘bla’) # ‘what is your name’ is the key, ‘bla’ is the default val

NEW:
addField(24,'what is your name " ,‘bla’) # 24 is the key, ‘what is your name’ is label, ‘bla’ is default

So there’s now a numeric key. This lets me keep the old print statements, which previously indexed the myDlg.data dictionary using numeric INDICES and now indexes by numeric KEYS.

Does the following work?

dlg.addField('Age:', '21')

The default values are expected to be strings, not integers or booleans.

Numbers in the expInfo dialogue box have to be converted to integers or floats before they can be used as numbers.

Thanks! Unfortunately that does not help. The issue seems to be that it’s misinterpreting the 21 (or ‘21’) as a label rather than as an initial value. Initial values can take on a number of data types, it just modulates the interface type (textbox, dropdown, checkbox).

The dlg.addField('Age:', 21) example comes straight from the gui function definition page: psychopy.gui - create dialogue boxes — PsychoPy v2024.1.5 and is also contained in the GUI.py demo script. Either this was unintentional introduction of a bug/backward incompatibility, or it was intentional and they still haven’t updated the demo script.

Interestingly this doesn’t seem to be a problem for DlgFromDict(). Perhaps it defaults to interpreting the keys as labels.