Skip to content

Commit

Permalink
FEATURE: Key-binding added to media_choice pages
Browse files Browse the repository at this point in the history
  • Loading branch information
timmahrt committed Oct 30, 2016
1 parent c05eac5 commit c8f88c3
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions lmeds/pages/assorted_experiment_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,39 @@ class MediaChoicePage(abstract_pages.AbstractPage):
def __init__(self, instructionText, audioOrVideo, pauseDuration,
minPlays, maxPlays, mediaListOfLists, responseButtonList,
buttonLabelList=None, transcriptList=None,
bindPlayKeyIDList=None, bindResponseKeyIDList=None,
*args, **kargs):
super(MediaChoicePage, self).__init__(*args, **kargs)

# Normalize variables
if bindPlayKeyIDList is not None:
tmpKeyIDList = []
for keyID in bindPlayKeyIDList:
keyID = html.keyboardletterToChar(keyID)
tmpKeyIDList.append(keyID)
bindPlayKeyIDList = tmpKeyIDList

if bindResponseKeyIDList is not None:
tmpKeyIDList = []
for keyID in bindResponseKeyIDList:
keyID = html.keyboardletterToChar(keyID)
tmpKeyIDList.append(keyID)
bindResponseKeyIDList = tmpKeyIDList

self.instructionText = instructionText
self.pauseDuration = pauseDuration
self.mediaList = mediaListOfLists
self.minPlays = minPlays
self.maxPlays = maxPlays
self.responseButtonList = responseButtonList
self.bindPlayKeyIDList = bindPlayKeyIDList
self.bindResponseKeyIDList = bindResponseKeyIDList

if bindPlayKeyIDList is not None:
assert(len(mediaListOfLists) == len(bindPlayKeyIDList))

if bindResponseKeyIDList is not None:
assert(len(responseButtonList) == len(bindResponseKeyIDList))

assert(audioOrVideo in ["audio", "video"])
self.audioOrVideo = audioOrVideo
Expand All @@ -227,7 +251,31 @@ def __init__(self, instructionText, audioOrVideo, pauseDuration,

self.numAudioButtons = len(mediaListOfLists)
self.processSubmitList = ["verifyAudioPlayed()", ]

def _getKeyPressEmbed(self):

bindKeyTxt = ""

# Bind key press to play button?
if self.bindPlayKeyIDList is not None:
for i, keyID in enumerate(self.bindPlayKeyIDList):
clickJS = 'document.getElementById("button%d").click();' % i
bindTuple = (keyID, clickJS)
bindKeyTxt += ("\n" + html.bindKeySubSnippetJS % bindTuple)

# Bind key press to submit event?
if self.bindResponseKeyIDList is not None:
for i, keyID in enumerate(self.bindResponseKeyIDList):
clickJS = 'document.getElementById("%d").click();' % i
bindTuple = (keyID, clickJS)
bindKeyTxt += ("\n" + html.bindKeySubSnippetJS % bindTuple)

returnJS = ""
if bindKeyTxt != "":
returnJS = html.bindKeyJSTemplate % bindKeyTxt

return returnJS

def _getHTMLTxt(self):
radioButton = ('<p>\n'
'<input type="radio" name="media_choice"'
Expand Down Expand Up @@ -319,6 +367,7 @@ def getHTML(self):
extList,
self.audioOrVideo)
embedTxt += "\n\n" + availableFunctions
embedTxt += self._getKeyPressEmbed()

description = self.textDict[self.instructionText]

Expand Down

0 comments on commit c8f88c3

Please sign in to comment.