Skip to content

Commit

Permalink
ENH: Adapt TPad code now that BasePhotodiode/BaseButton don't need a …
Browse files Browse the repository at this point in the history
…parent
  • Loading branch information
TEParsons committed Nov 10, 2023
1 parent 58afddf commit 139f2af
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions psychopy_bbtk/tpad.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ def __init__(self, pad, channels):
# reference self in pad
pad.nodes.append(self)
# initialise base class
photodiode.BasePhotodiodeGroup.__init__(self, pad, channels=channels)
photodiode.BasePhotodiodeGroup.__init__(self, channels=channels)
self.parent = pad

@staticmethod
def getAvailableDevices():
Expand All @@ -91,6 +92,20 @@ def setThreshold(self, threshold, channels=(1, 2)):
self.parent.pause()
self.parent.setMode(3)

def resetTimer(self, clock=logging.defaultClock):
self.parent.resetTimer(clock=clock)

def dispatchMessages(self):
"""
Dispatch messages from parent TPad to this photodiode group
Returns
-------
bool
True if request sent successfully
"""
self.parent.dispatchMessages()

def parseMessage(self, message):
# if given a string, split according to regex
if isinstance(message, str):
Expand Down Expand Up @@ -133,7 +148,7 @@ def findThreshold(self, win, channel):


class TPadButtonGroup(button.BaseButtonGroup):
def __init__(self, pad, channels=1):
def __init__(self, pad, channels=9):
_requestedPad = pad
# try to get associated tpad
if isinstance(_requestedPad, str):
Expand All @@ -153,7 +168,19 @@ def __init__(self, pad, channels=1):
# reference self in pad
pad.nodes.append(self)
# initialise base class
button.BaseButtonGroup.__init__(self, parent=pad, channels=channels)
button.BaseButtonGroup.__init__(self, channels=channels)
self.parent = pad

def dispatchMessages(self):
"""
Dispatch messages from parent TPad to this button group
Returns
-------
bool
True if request sent successfully
"""
self.parent.dispatchMessages()

def parseMessage(self, message):
# if given a string, split according to regex
Expand Down Expand Up @@ -187,6 +214,9 @@ def getAvailableDevices():

return devices

def resetTimer(self, clock=logging.defaultClock):
self.parent.resetTimer(clock=clock)


class TPadVoicekey:
def __init__(self, *args, **kwargs):
Expand Down

0 comments on commit 139f2af

Please sign in to comment.