def addWord(self): newWordTextField = TextField(x_(u"Word to Guess"), x_(u"Word To Guess"), "") newWordTextField.idevice = self newWordHintField = TextField(x_(u"Hint to Show User"), x_(u"Hint for Word"), "") newWordHintField.idevice = self self.wordTextFields.append(newWordTextField) self.hintTextFields.append(newWordHintField)
def addWord(self): newWordHintField = TextField(x_(u"Hint to Show User"), x_(u"Hint for Word"), default_prompt = "Hint the user will see e.g. Red Fruit") newWordHintField.idevice = self newWordTextField = TextField(x_(u"Word to Guess"), x_(u"Word To Guess"), "", default_prompt = "Word the user has to guess - e.g. Apple") newWordTextField.idevice = self self.wordTextFields.append(newWordTextField) self.hintTextFields.append(newWordHintField)
def __init__(self, idevice, alwaysNameTo=None, desc="File Field", help="File Field Help"): Field.__init__(self, desc, help) self.idevice = idevice self.fileResource = None self.fileInstruc = "Upload a file" self.alwaysNameTo = alwaysNameTo self.fileDescription = TextField("Description") self.fileDescription.idevice = self
def __init__(self, content=""): Idevice.__init__( self, x_(u"Place The Objects"), x_(u"Mike Dawson / PAIWASTOON Networking Services Ltd."), x_(u"""User has to place various objects in the correct place."""), "", "") self.emphasis = Idevice.SomeEmphasis self.content = TextAreaField(x_(u"Instructions"), x_(u"This is a free text field."), content) self.content.idevice = self self.titleField = TextField(x_("Title"), x_("Title")) self.titleField.idevice = self #This is the main field where objects will be dragged to self.mainArea = TextAreaField( x_(u"Main Area"), x_(u"This is the main image where the user will drag / drop items to" ), "") self.mainArea.idevice = self self.gameTimeLimit = TextField(x_(u"Time Limit (mm:ss)"), x_(u"(Optional) Game Time Limit"), "") self.gameTimeLimit.idevice = self self.gameTimerShown = TextField( x_(u"Show Timer"), x_(u"Even if there is no time limit, show the timer..."), "") self.gameTimerShown.idevice = self #these are shown when there is a right / wrong response self.clickToStartGameArea = TextAreaField( x_(u"Message to click game to start"), x_(u"This will when clicked start the game"), "") self.clickToStartGameArea.idevice = self self.positiveResponseArea = TextAreaField( x_(u"Positive Response"), x_(u"Overlays main area when player correctly places object"), "") self.positiveResponseArea.idevice = self self.negativeResponseArea = TextAreaField( x_(u"Negative Response"), x_(u"Overlays main area when player guesses wrong"), "") self.negativeResponseArea.idevice = self self.partbinNumCols = TextField(x_("Number of Columns in part bin"), x_("Columns part bin"), "2") self.partbinNumCols.idevice = self #This is a list of objects to place self.objectsToPlace = [] self.addPlacableObject()
def __init__(self, content=""): Idevice.__init__(self, x_(u"Hangman Game"), x_(u"Mike Dawson, Toughra Technologies FZ LLC"), x_(u"""Hangman style word game with customizable images."""), "", "") self.emphasis = Idevice.SomeEmphasis self.message = "" self.titleField = TextField(x_("Title"), x_("Title")) self.chanceImageFields = [] self.content = TextAreaField(x_(u"Instructions"), x_(u"Instructions for Game."), content) self.content.idevice = self #the words that the player will have to guess self.wordTextFields = [] #the corresponding hints that will be shown for the player in game self.hintTextFields = [] self.content.idevice = self self.addChance() self.addWord() #the alphabet (available letters) self.alphabet = TextField(x_(u"Alphabet to Select From"), x_(u"Alphabet to show players"), \ x_("abcdefghijklmnopqrstuvwxyz")) self.alphabet.idevice = self #messages for the player self._initNewAlerts() self.letterButtonStyle = TextField(x_("Letter Button Style"), \ x_("Style of button to start with"), "color: white; background-color: blue;") self.letterButtonStyle.idevice = self self.wrongLetterButtonStyle = TextField(x_("Letter Button Style Wrong Guess"), \ x_("Style of letter button after wrong guess"), "color: white; background-color: red;") self.wrongLetterButtonStyle.idevice = self self.rightLetterButtonStyle = TextField(x_("Letter Button Style Right Guess"), \ x_("Style of letter button after correct guess"), "color: white; background-color : green;") self.rightLetterButtonStyle.idevice = self self.hintFieldStyle = TextField(x_("Style of Hint Text Field"), x_("Hint Text Field CSS")) self.hintFieldStyle.idevice = self self.wordAreaStyle = TextField(x_("Style of Word Display Field"), x_("Word Display CSS")) self.wordAreaStyle.idevice = self self.resetButtonText = TextField(x_("Restart Level Button Text"), x_("Text for reset button"), x_("Restart")) self.resetButtonText.idevice = self self.resetButtonStyle = TextField(x_("Restart Level Button Style (CSS)"), x_("Style of Reset Button"), "background-color: blue; color: white;") self.resetButtonStyle.idevice = self
def __init__(self, name, idevice, instruction="A place to click on in the main area", content=""): Field.__init__(self, name, instruction) self.idevice = idevice self.message = "" self.textFieldNames = {\ 'top' : [x_('Top (Y) Coord'), x_('Top CSS top property')],\ 'left' : [x_('Left (X) Coord'), x_('Left CSS left property')],\ 'width' : [x_('Width (px)'), x_('Width of clickable area')],\ 'height' : [x_('Height (px)'), x_('Height of clickable area')],\ 'hideDelay' : [x_('Delay (ms) to hide revealed contents'), x_('After delay ms hide the content prev revealed')]\ } self.textFields = {} for textFieldName, textFieldDetails in self.textFieldNames.iteritems(): self.textFields[textFieldName] = TextField(textFieldDetails[INDEX_TITLEFIELD],\ textFieldDetails[INDEX_INSTRUCTIONFIELD]) self.textFields[textFieldName].idevice = self.idevice self.textAreaFieldNames = {\ 'Hint' : [x_('Hint to Show for this item'), x_('The hint that will appear under the map for this item')],\ 'ShowMe' : [x_('Item Revealed'), x_('The Item that will be revealed in place')]\ } self.textAreaFields = {} for textAreaFieldName, textAreaFieldDetails in self.textAreaFieldNames.iteritems( ): self.textAreaFields[textAreaFieldName] = TextAreaField(textAreaFieldDetails[INDEX_TITLEFIELD],\ textAreaFieldDetails[INDEX_INSTRUCTIONFIELD], "") self.textAreaFields[textAreaFieldName].idevice = self.idevice
def __init__(self, name, idevice, instruction=x_("An object that has a correct place in the main area"), content=""): Field.__init__(self, name, instruction) self.mainContentField = TextAreaField(x_(u"Placable Object"), x_(u"Object to be put in place"), "") self.idevice = idevice self.mainContentField.idevice = idevice self.targetX = TextField(x_(u"Correct Location (x)"), x_(u"Where this object belongs in the main area x coordinate"), "0") self.targetX.idevice = idevice self.targetY = TextField(x_(u"Correct Location (y)"), x_(u"Where this object belongs in the main area y coordinate"), "0") self.targetY.idevice = idevice self.width = TextField(x_(u"Width (pixels)"), x_(u"Width of object"), "100") self.width.idevice = idevice self.height = TextField(x_(u"Height (pixels)"), x_(u"Height of object"), "100") self.height.idevice = idevice self.tolerance = TextField(x_(u"Tolerance (pixels)"), x_(u"Tolerance when dropping num of pixels"), "20") self.tolerance.idevice = idevice
def upgradeToVersion2(self): """ Upgrades the node from version 1 (not released) to 2 Use new Field classes """ oldFields = self.fields self.fields = [] for oldField in oldFields: if oldField.fieldType == "Text": self.addField(TextField(oldField.__dict__['name'], oldField.instruction, oldField.content)) elif oldField.fieldType == "TextArea": self.addField(TextAreaField(oldField.__dict__['name'], oldField.instruction, oldField.content)) else: log.error(u"Unknown field type in upgrade "+oldField.fieldType)
def field_engine_check_field(fieldId, fieldInfoDict, fieldDict, idevice): if fieldId in fieldDict.keys(): return fieldTypeName = fieldInfoDict[fieldId][EXEFIELDINFO_TYPE] defaultVal = getFieldDefaultVal(fieldId, fieldInfoDict) newField = 0 if fieldTypeName == 'image': newField = ImageField(fieldInfoDict[fieldId][EXEFIELDINFO_DESC], fieldInfoDict[fieldId][EXEFIELDINFO_HELP]) #must do this before attempting to set default value newField.idevice = idevice if defaultVal is not None: #right about here do setImage newField.defaultImage = str( field_engine_get_template_absolute_path(defaultVal)) pass elif fieldTypeName == 'text': newField = TextField(fieldInfoDict[fieldId][EXEFIELDINFO_DESC], fieldInfoDict[fieldId][EXEFIELDINFO_HELP]) if defaultVal is not None: newField.content = defaultVal elif fieldTypeName == 'textarea': newField = TextAreaField(fieldInfoDict[fieldId][EXEFIELDINFO_DESC], fieldInfoDict[fieldId][EXEFIELDINFO_HELP]) elif fieldTypeName == 'choice': newField = ChoiceField( idevice, fieldInfoDict[fieldId][EXEFIELDINFO_EXTRAINFODICT]['choices'], fieldInfoDict[fieldId][EXEFIELDINFO_DESC], fieldInfoDict[fieldId][EXEFIELDINFO_HELP]) newField.idevice = idevice if newField != 0: fieldDict[fieldId] = newField
def upgradeToVersion4(self): self.fileDescription = TextField("Description")
class FileField(Field): """ Field for storing an individual file """ persistenceVersion = 5 """ alwaysNameTo - make sure that this file always a certain final name """ def __init__(self, idevice, alwaysNameTo=None, desc="File Field", help="File Field Help"): Field.__init__(self, desc, help) self.idevice = idevice self.fileResource = None self.fileInstruc = "Upload a file" self.alwaysNameTo = alwaysNameTo self.fileDescription = TextField("Description") self.fileDescription.idevice = self def uploadFile(self, filePath): if self.fileResource is not None: self.fileResource.delete() finalName = str(filePath) if self.alwaysNameTo is not None: from os.path import dirname from shutil import copyfile dirName = dirname(filePath) finalName = dirName + "/" + self.alwaysNameTo copyfile(filePath, finalName) if self.fileDescription.content == "": self.fileDescription.content = os.path.basename(filePath) resourceFile = Path(finalName) if resourceFile.isfile(): self.idevice.message = "" self.fileResource = Resource(self.idevice, resourceFile) def deleteFile(self): if self.fileResource is not None: self.fileResource.delete() self.fileResource = None def get_translatable_properties(self): """ Get a list of translatable property names that can be translated. :rtype: list :return: List of translatable properties of the field. """ # The only translatable fields in this Idevice is the description (which # is a field in itself) return self.fileDescription.get_translatable_properties() def translate(self): """ Do the actual translation. """ # We only have a translatable property, as it is also a field, just call # translate() on it self.fileDescription.translate() def upgradeToVersion4(self): self.fileDescription = TextField("Description") def upgradeToVersion5(self): self.fileDescription.idevice = self
def process(self, request, status): """ Process """ log.debug("process " + repr(request.args)) self.message = "" if status == "old": for element in self.elements: element.process(request) if "title" in request.args: self.idevice.title = unicode(request.args["title"][0], 'utf8') if "tip" in request.args: self.idevice.tip = unicode(request.args["tip"][0], 'utf8') if "emphasis" in request.args: self.idevice.emphasis = int(request.args["emphasis"][0]) if self.idevice.emphasis == 0: self.idevice.icon = "" if "addText" in request.args: field = TextField(_(u"Enter the label here"), _(u"Enter instructions for completion here")) field.setIDevice(self.idevice) self.idevice.addField(field) self.idevice.edit = True if "addTextArea" in request.args: field = TextAreaField( _(u"Enter the label here"), _(u"Enter the instructions for completion here")) field.setIDevice(self.idevice) self.idevice.addField(field) self.idevice.edit = True if "addFeedback" in request.args: field = FeedbackField( _(u"Enter the label here"), _(u"""Feedback button will not appear if no data is entered into this field.""")) field.setIDevice(self.idevice) self.idevice.addField(field) self.idevice.edit = True #if "addFlash" in request.args: #print "add a flash" #field = FlashField(_(u"Enter the label here"), #_(u"Enter the instructions for completion here")) #field.setIDevice(self.idevice) #self.idevice.addField(field) if "addMP3" in request.args: field = MultimediaField( _(u"Enter the label here"), _(u"Enter the instructions for completion here")) field.setIDevice(self.idevice) self.idevice.addField(field) if not 'xspf_player.swf' in self.idevice.systemResources: self.idevice.systemResources += ['xspf_player.swf'] self.idevice.edit = True if "addAttachment" in request.args: field = AttachmentField( _(u"Enter the label here"), _(u"Enter the instructions for completion here")) field.setIDevice(self.idevice) self.idevice.addField(field) self.idevice.edit = True if ("action" in request.args and request.args["action"][0] == "selectIcon"): self.idevice.icon = request.args["object"][0] if "preview" in request.args: if self.idevice.title == "": self.message = _("Please enter<br />an idevice name.") else: self.idevice.edit = False if "edit" in request.args: self.idevice.edit = True if "cancel" in request.args: ideviceId = self.idevice.id self.idevice = self.originalIdevice.clone() self.idevice.id = ideviceId self.parent.showHide = False if ("action" in request.args and request.args["action"][0] == "changeStyle"): self.style = self.styles[int(request.args["object"][0])] self.__buildElements()
def upgradeToVersion3(self): self.message = "" self.titleField = TextField(x_("Title"), x_("Title"))
def process(self, request, status): """ Process """ log.debug("process " + repr(request.args)) self.message = "" if status == "old": for element in self.elements: element.process(request) if "title" in request.args: self.idevice.title = unicode(request.args["title"][0], 'utf8') if "tip" in request.args: self.idevice.tip = unicode(request.args["tip"][0], 'utf8') if "emphasis" in request.args: self.idevice.emphasis = int(request.args["emphasis"][0]) if self.idevice.emphasis == 0: self.idevice.icon = "" if "addText" in request.args: field = TextField(_(u"Enter the label here"), _(u"Enter instructions for completion here")) field.setIDevice(self.idevice) self.idevice.addField(field) if "addTextArea" in request.args: field = TextAreaField(_(u"Enter the label here"), _(u"Enter the instructions for completion here")) field.setIDevice(self.idevice) self.idevice.addField(field) if "addImage" in request.args: field = ImageField(_(u"Enter the label here"), _(u"Enter the instructions for completion here")) imagePath = self.webDir/"images"/ImageEditorElement.DefaultImage field.defaultImage = unicode(imagePath.abspath()) field.setIDevice(self.idevice) self.idevice.addField(field) if "addFeedback" in request.args: field = FeedbackField(_(u"Enter the label here"), _(u"""Feedback button will not appear if no data is entered into this field.""")) field.setIDevice(self.idevice) self.idevice.addField(field) if "addMP3" in request.args: field = MultimediaField(_(u"Enter the label here"), _(u"Enter the instructions for completion here")) field.setIDevice(self.idevice) self.idevice.addField(field) if ("action" in request.args and request.args["action"][0] == "selectIcon"): self.idevice.icon = request.args["object"][0] if "preview" in request.args: if self.idevice.title == "": self.message = _("Please enter<br />an idevice name.") else: self.idevice.edit = False if "edit" in request.args: self.idevice.edit = True if "cancel" in request.args: ideviceId = self.idevice.id self.idevice = self.originalIdevice.clone() self.idevice.id = ideviceId if ("action" in request.args and request.args["action"][0] == "changeStyle"): self.style = request.args["object"][0] self.__buildElements()
def process(self, request, status): """ Process """ log.debug("process " + repr(request.args)) self.message = "" if status == "old": for element in self.elements: element.process(request) if "title" in request.args: self.idevice.title = unicode(request.args["title"][0], 'utf8') if "tip" in request.args: self.idevice.tip = unicode(request.args["tip"][0], 'utf8') if "emphasis" in request.args: self.idevice.emphasis = int(request.args["emphasis"][0]) if self.idevice.emphasis == 0: self.idevice.icon = "" if "addText" in request.args: field = TextField(_(u"Enter the label here"), _(u"Enter instructions for completion here")) field.setIDevice(self.idevice) self.idevice.addField(field) self.idevice.edit = True if "addTextArea" in request.args: field = TextAreaField(_(u"Enter the label here"), _(u"Enter the instructions for completion here")) field.setIDevice(self.idevice) self.idevice.addField(field) self.idevice.edit = True if "addFeedback" in request.args: field = FeedbackField(_(u"Enter the label here"), _(u"""Feedback button will not appear if no data is entered into this field.""")) field.setIDevice(self.idevice) self.idevice.addField(field) self.idevice.edit = True #if "addFlash" in request.args: #print "add a flash" #field = FlashField(_(u"Enter the label here"), #_(u"Enter the instructions for completion here")) #field.setIDevice(self.idevice) #self.idevice.addField(field) if "addMP3" in request.args: field = MultimediaField(_(u"Enter the label here"), _(u"Enter the instructions for completion here")) field.setIDevice(self.idevice) self.idevice.addField(field) if not 'xspf_player.swf' in self.idevice.systemResources: self.idevice.systemResources += ['xspf_player.swf'] self.idevice.edit = True if "addAttachment" in request.args: field = AttachmentField(_(u"Enter the label here"), _(u"Enter the instructions for completion here")) field.setIDevice(self.idevice) self.idevice.addField(field) self.idevice.edit = True if ("action" in request.args and request.args["action"][0] == "selectIcon"): self.idevice.icon = request.args["object"][0] if "preview" in request.args: if self.idevice.title == "": self.message = _("Please enter<br />an idevice name.") else: self.idevice.edit = False if "edit" in request.args: self.idevice.edit = True if "cancel" in request.args: ideviceId = self.idevice.id self.idevice = self.originalIdevice.clone() self.idevice.id = ideviceId self.parent.showHide = False if ("action" in request.args and request.args["action"][0] == "changeStyle"): self.style = self.styles[int(request.args["object"][0])] self.__buildElements()
def __init__(self, content=""): Idevice.__init__( self, x_(u"Click In Order Game"), x_(u"PAIWASTOON Networking Services Ltd."), x_(u"""Click in Order according to the hint on the map."""), "", "") self.emphasis = Idevice.SomeEmphasis self.message = "" self.titleField = TextField(x_("Title"), x_("Title")) """ List of the text area fields that are here Id which will be generated mapped to the title and help in an array """ self.textAreaFieldNames = {\ 'Instructions' : [x_('Game Instructions'), x_('Instructions to show in leading paragraph')],\ 'CompleteFeedback' : [x_('Game Won Feedback Overlay'), x_('Shown over when the game is won')],\ 'PositiveFeedback' : [x_('Correct Answer Feedback Overlay'), x_('Shown over game when correct answer given')],\ 'NegativeFeedback' : [x_('Wrong Answer Feedback Overlay'), x_('Shown over game when wrong answer is given')],\ 'MainArea' : [x_('Main Area To Show'), x_('The Main Game Area on which to locate items')],\ 'ClickToStartArea' : [x_('Area shown before the game starts'), x_('User will click on this to start the game')]\ } self.textAreaFields = {} for textAreaFieldName, textAreaDesc in self.textAreaFieldNames.iteritems( ): self.textAreaFields[textAreaFieldName] = TextAreaField(textAreaDesc[INDEX_TITLEFIELD], \ textAreaDesc[INDEX_INSTRUCTIONFIELD], "") self.textAreaFields[textAreaFieldName].idevice = self self.textFieldsBasic = ["width", "height"] self.textFieldsAdvanced = [ "elementCounterStyle", "hintWidth", "hintHeight", "hintAreaStyle", "timerStyle" ] self.textFieldNames = {\ 'width' : [x_('Game Width'), x_('Width of game area (in pixels)'), '300'],\ 'height' : [x_('Game Height'), x_('Height of game area (in pixels)'), '300'],\ 'elementCounterStyle' : [x_('Style of Element Counter'), x_('Use CSS to style element that counts number items found')],\ 'hintWidth' : [ x_('Hint Width'), x_('Width (px) of hint area'), '300'],\ 'hintHeight' : [ x_('Hint Height'), x_('Height (px) of hint area'), '50'],\ 'hintAreaStyle' : [x_('Hint Area Style'), x_('Style of Hint Area')],\ 'timerStyle' : [x_('Style of timer Element'), x_('Style of timer (CSS)')] } self.textFields = {} for textFieldName, textFieldDesc in self.textFieldNames.iteritems(): if len(textFieldDesc) >= INDEX_DEFAULTVALUEFIELD + 1: self.textFields[textFieldName] = TextField(textFieldDesc[INDEX_TITLEFIELD], \ textFieldDesc[INDEX_INSTRUCTIONFIELD], textFieldDesc[INDEX_DEFAULTVALUEFIELD]) else: self.textFields[textFieldName] = TextField(textFieldDesc[INDEX_TITLEFIELD], \ textFieldDesc[INDEX_INSTRUCTIONFIELD]) self.textFields[textFieldName].idevice = self #Game Mode Choice gameModeChoice = [['0', x_('Dont Shuffle')], ['1', x_('Shuffle')]] #so these are seen for localization x_("Dont Shuffle") x_("Shuffle") timerModeChoice = [['0', x_('No Timer')], ['1', x_('Stopwatch Mode')]] x_("No Timer") x_("Stopwatch Mode") self.questionOrderChoiceField = ChoiceField( self, gameModeChoice, x_("Shuffle Questions"), x_("Randomize question order or not")) self.timerChoiceField = ChoiceField(self, timerModeChoice, x_("Use Timer?"), x_("Use a Timer")) #these are the areas that can actually be clicked on self.clickableAreaFields = [] self.addClickableField()