From dd5982b074b83bb557df1ee9abbae8b09b63bdab Mon Sep 17 00:00:00 2001 From: TEParsons Date: Thu, 2 Nov 2023 15:09:06 +0000 Subject: [PATCH] ENH: Add TPad to orphaned ButtonGroup --- psychopy_bbtk/tpad.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/psychopy_bbtk/tpad.py b/psychopy_bbtk/tpad.py index 6ae02f5..9e6cc60 100644 --- a/psychopy_bbtk/tpad.py +++ b/psychopy_bbtk/tpad.py @@ -133,6 +133,24 @@ def findThreshold(self, win, channel): class TPadButtonGroup(button.BaseButtonGroup): def __init__(self, pad, channels=1): + _requestedPad = pad + # try to get associated tpad + if isinstance(_requestedPad, str): + # try getting by name + pad = DeviceManager.getDevice(pad) + # if failed, try getting by port + if pad is None: + pad = DeviceManager.getDeviceBy("portString", _requestedPad, deviceClass="psychopy_bbtk.tpad.TPad") + # if still failed, make one + if pad is None: + pad = DeviceManager.addDevice( + deviceClass="psychopy_bbtk.tpad.TPad", + deviceName=_requestedPad, + port=_requestedPad + ) + + # reference self in pad + pad.nodes.append(self) # initialise base class button.BaseButtonGroup.__init__(self, parent=pad, channels=channels) @@ -263,7 +281,7 @@ def dispatchMessages(self): # choose object to dispatch to for node in self.nodes: # if device is A, dispatch only to buttons - if device == "A" and not isinstance(node, TPadButton): + if device == "A" and not isinstance(node, TPadButtonGroup): continue # if device is C, dispatch only to photodiodes if device == "C" and not isinstance(node, TPadPhotodiodeGroup):