Skip to content

Commit

Permalink
Merge pull request #7 from psychopy/dev
Browse files Browse the repository at this point in the history
ENH: Add TPad to orphaned ButtonGroup
  • Loading branch information
TEParsons authored Nov 2, 2023
2 parents 780c276 + dd5982b commit 3dcc0c7
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion psychopy_bbtk/tpad.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 3dcc0c7

Please sign in to comment.