def __init__(self, parent, idevice): """ Initialize """ Block.__init__(self, parent, idevice) self.imageElement = ImageElement(idevice.image) # to compensate for the strange unpickling timing when objects are # loaded from an elp, ensure that proper idevices are set: # (only applies to the image-embeddable ones, not FlashMovieElement) if idevice.text.idevice is None: idevice.text.idevice = idevice self.textElement = TextAreaElement(idevice.text)
def __init__(self, parent, idevice): """ Initialize """ Block.__init__(self, parent, idevice) self.imageElement = ImageElement(idevice.image) self.textElement = TextAreaElement(idevice.text)
def __init__(self, index, idevice, question): """ Initialize 'index' is our number in the list of questions 'idevice' is a case study idevice 'question' is a exe.engine.casestudyidevice.Question instance """ self.index = index self.id = "q" + unicode(index) + "b" + idevice.id self.idevice = idevice self.question = question self.quesId = "quesQuestion" + unicode(index) + "b" + idevice.id self.feedbackId = "quesFeedback" + unicode(index) + "b" + idevice.id self.imageElement = ImageElement(question.image)
def __init__(self, parent, idevice): Block.__init__(self, parent, idevice) self.titleElement = TextElement(idevice.titleField) self.contentElement = TextAreaElement(idevice.content) self.contentElement.height = 250 self.chanceImageElements = [] #go through all image fields in the list and create an image element linked to that field for chanceImageField in idevice.chanceImageFields: newImgElement = ImageElement(chanceImageField) self.chanceImageElements.append(newImgElement) self.wordElements = [] self.hintElements = [] #go through all of the word fields and hint fields and create an for wordIndex, word in enumerate(idevice.wordTextFields): newWordElement = TextElement(word) self.wordElements.append(newWordElement) newHintElement = TextElement(idevice.hintTextFields[wordIndex]) self.hintElements.append(newHintElement) #make an element for the alphabet self.alphabetElement = TextElement(idevice.alphabet) #element for the messages that are shown to the player self.wrongGuessTextElement = TextAreaElement( self.idevice.wrongGuessMessageField) self.lostLevelTextElement = TextAreaElement( self.idevice.lostLevelMessageField) self.levelPassedTextElement = TextAreaElement( self.idevice.levelPasssedMessageField) self.gameWonTextElement = TextAreaElement( self.idevice.gameWonMessageField) self.letterButtonStyleElement = TextElement( self.idevice.letterButtonStyle) self.wrongLetterButtonStyleElement = TextElement( self.idevice.wrongLetterButtonStyle) self.rightLetterButtonStyleElement = TextElement( self.idevice.rightLetterButtonStyle) self.hintFieldStyleElement = TextElement(self.idevice.hintFieldStyle) self.wordAreaStyleElement = TextElement(self.idevice.wordAreaStyle) self.resetButtonTextElement = TextElement(self.idevice.resetButtonText) self.resetButtonStyleElement = TextElement( self.idevice.resetButtonStyle)
def field_engine_build_elements_on_block(fieldInfoDict, fieldDict, idevice): fieldCounter = 0 elementDict = {} for fieldInfoKey, fieldInfoArr in fieldInfoDict.items(): elementTypeName = fieldInfoArr[EXEFIELDINFO_TYPE] #check the field - if this is a new one or src code edit etc. then add this field... field_engine_check_field(fieldInfoKey, fieldInfoDict, fieldDict, idevice) newElement = "" if elementTypeName == 'image': newElement = ImageElement(fieldDict[fieldInfoKey]) elif elementTypeName == 'text': newElement = TextElement(fieldDict[fieldInfoKey]) elif elementTypeName == 'textarea': newElement = TextAreaElement(fieldDict[fieldInfoKey]) elif elementTypeName == 'choice': newElement = ChoiceElement(fieldDict[fieldInfoKey]) if newElement != "": elementDict[fieldInfoKey] = newElement return elementDict
class QuestionElement(object): """ QuestionElment is responsible for a block of question. Used by CasestudyBlock. """ def __init__(self, index, idevice, question): """ Initialize 'index' is our number in the list of questions 'idevice' is a case study idevice 'question' is a exe.engine.casestudyidevice.Question instance """ self.index = index self.id = "q" + unicode(index) + "b" + idevice.id self.idevice = idevice self.question = question self.quesId = "quesQuestion" + unicode(index) + "b" + idevice.id self.feedbackId = "quesFeedback" + unicode(index) + "b" + idevice.id self.imageElement = ImageElement(question.image) def process(self, request): """ Process arguments from the web server. Return any which apply to this element. """ log.debug("process " + repr(request.args)) if self.quesId in request.args: self.question.question = request.args[self.quesId][0] if self.feedbackId in request.args: self.question.feedback = request.args[self.feedbackId][0] self.imageElement.process(request) if "action" in request.args and request.args["action"][0] == self.id: self.idevice.questions.remove(self.question) def renderEdit(self): """ Returns an XHTML string for editing this question element """ html = "<tr><td><b>%s</b>\n" % _("Activity") html += common.elementInstruc(self.idevice.questionInstruc) html += common.richTextArea(self.quesId, self.question.question) html += self.imageElement.renderEdit() html += "<b>%s</b>\n" % _("Feedback") html += common.elementInstruc(self.idevice.feedbackInstruc) html += common.richTextArea(self.feedbackId, self.question.feedback) if self.imageElement.field.imageResource is None: self.imageElement.field.setDefaultImage() html += "</td><td>\n" html += common.submitImage(self.id, self.idevice.id, "/images/stock-cancel.png", _("Delete question")) html += "</td></tr>\n" return html def doRender(self, preview=False): """ Returns an XHTML string for viewing and previewing this question element depending on the value of 'preview'. """ log.debug("renderView called") html = self.question.question field = self.imageElement.field if not field.isDefaultImage or self.question.feedback != "" : html += '<div id="view%s" style="display:block;">' % self.id html += common.feedbackButton('btnshow' + self.id, _(u"Show Feedback"), onclick = "showAnswer('%s',1)" % self.id) html += '</div>' html += '<div id="hide%s" style="display:none;">' % self.id html += common.feedbackButton('btnhide' + self.id, _(u"Hide Feedback"), onclick = "showAnswer('%s',0)" % self.id) html += '<p>' if self.imageElement.field.imageResource is None: self.imageElement.field.setDefaultImage() if preview: html += self.imageElement.renderPreview() else: html += self.imageElement.renderView() html += '</p>' html += '</div>' html += '<div id="s%s" class="feedback" style=" ' % self.id html += 'display: none;">' html += self.question.feedback html += "</div><br/>\n" else: html += "<br/>\n" return html def renderView(self): """ Returns an XHTML string for viewing this question element """ return self.doRender(preview=False) def renderPreview(self): """ Returns an XHTML string for previewing this question element """ return self.doRender(preview=True)
class ImageWithTextBlock(Block): """ ImageWithTextBlock can render and process ImageWithTextIdevices as XHTML """ name = 'imageWithText' def __init__(self, parent, idevice): """ Initialize """ Block.__init__(self, parent, idevice) self.imageElement = ImageElement(idevice.image) self.textElement = TextAreaElement(idevice.text) def process(self, request): """ Process the request arguments from the web server to see if any apply to this block """ log.debug("process " + repr(request.args)) Block.process(self, request) if (u"action" not in request.args or request.args[u"action"][0] != u"delete"): self.imageElement.process(request) self.textElement.process(request) if "float"+self.id in request.args: self.idevice.float = request.args["float"+self.id][0] if "caption"+self.id in request.args: self.idevice.caption = request.args["caption"+self.id][0] def renderEdit(self, style): """ Returns an XHTML string with the form elements for editing this block """ log.debug("renderEdit") html = u"<div class=\"iDevice\">\n" html += self.imageElement.renderEdit() floatArr = [[_(u'Left'), 'left'], [_(u'Right'), 'right'], [_(u'None'), 'none']] html += common.formField('select', _("Align:"), "float" + self.id, '', '', floatArr, self.idevice.float) html += u'<div class="block"><b>%s</b></div>' % _(u"Caption:") html += common.textInput("caption" + self.id, self.idevice.caption) html += common.elementInstruc(self.idevice.captionInstruc) html += "<br/>" + self.textElement.renderEdit() html += self.renderEditButtons() html += u"</div>\n" return html def renderPreview(self, style): """ Returns an XHTML string for previewing this block """ log.debug("renderPreview") html = u"\n<!-- image with text iDevice -->\n" html = u"<div class=\"iDevice " html += u"emphasis"+unicode(self.idevice.emphasis)+"\" " html += "ondblclick=\"submitLink('edit',"+self.id+", 0);\">\n" html += u"<div class=\"image_text\" style=\"" html += u"width:" + str(self.idevice.image.width) + "px; " html += u"float:%s;\">\n" % self.idevice.float html += u"<div class=\"image\">\n" html += self.imageElement.renderPreview() html += u"" + self.idevice.caption + "</div>" html += u"</div>\n" html += self.textElement.renderPreview() html += u"<br/>\n" html += u"<div style=\"clear:both;\">" html += u"</div>\n" html += self.renderViewButtons() html += u"</div>\n" return html def renderView(self, style): """ Returns an XHTML string for viewing this block """ log.debug("renderView") html = u"\n<!-- image with text iDevice -->\n" html += u"<div class=\"iDevice " html += u"emphasis"+unicode(self.idevice.emphasis)+"\">\n" html += u"<div class=\"image_text\" style=\"" html += u"width:" + str(self.idevice.image.width) + "px; " html += u"float:%s;\">\n" % self.idevice.float html += u"<div class=\"image\">\n" html += self.imageElement.renderView() html += u"<br/>" + self.idevice.caption + "</div>" html += u"</div>\n" html += self.textElement.renderView() html += u"<div style=\"clear:both;\">" html += u"</div>\n" html += u"</div>\n" return html
class ImageWithTextBlock(Block): """ ImageWithTextBlock can render and process ImageWithTextIdevices as XHTML """ name = 'imageWithText' def __init__(self, parent, idevice): """ Initialize """ Block.__init__(self, parent, idevice) self.imageElement = ImageElement(idevice.image) # to compensate for the strange unpickling timing when objects are # loaded from an elp, ensure that proper idevices are set: # (only applies to the image-embeddable ones, not FlashMovieElement) if idevice.text.idevice is None: idevice.text.idevice = idevice self.textElement = TextAreaElement(idevice.text) def process(self, request): """ Process the request arguments from the web server to see if any apply to this block """ log.debug("process " + repr(request.args)) Block.process(self, request) if (u"action" not in request.args or request.args[u"action"][0] != u"delete"): self.imageElement.process(request) self.textElement.process(request) if "float"+self.id in request.args: self.idevice.float = request.args["float"+self.id][0] if "caption"+self.id in request.args: self.idevice.caption = request.args["caption"+self.id][0] def renderEdit(self, style): """ Returns an XHTML string with the form elements for editing this block """ log.debug("renderEdit") html = u"<div class=\"iDevice\">\n" html += self.imageElement.renderEdit() floatArr = [[_(u'Left'), 'left'], [_(u'Right'), 'right'], [_(u'None'), 'none']] this_package = None if self.idevice is not None and self.idevice.parentNode is not None: this_package = self.idevice.parentNode.package html += common.formField('select', this_package, _("Align:"), "float" + self.id, '', '', floatArr, self.idevice.float) html += u'<div class="block"><b>%s</b></div>' % _(u"Caption:") html += common.textInput("caption" + self.id, self.idevice.caption) html += common.elementInstruc(self.idevice.captionInstruc) html += "<br/>" + self.textElement.renderEdit() html += self.renderEditButtons() html += u"</div>\n" return html def renderPreview(self, style): """ Returns an XHTML string for previewing this block """ log.debug("renderPreview") html = u"\n<!-- image with text iDevice -->\n" html += u"<div class=\"iDevice " html += u"emphasis"+unicode(self.idevice.emphasis)+"\" " html += "ondblclick=\"submitLink('edit',"+self.id+", 0);\">\n" html += u"<div class=\"image_text\" style=\"" html += u"width:" + str(self.idevice.image.width) + "px; " html += u"float:%s;\">\n" % self.idevice.float html += u"<div class=\"image\">\n" html += self.imageElement.renderPreview() html += u"" + self.idevice.caption + "</div>" html += u"</div>\n" html += self.textElement.renderPreview() html += u"<br/>\n" html += u"<div style=\"clear:both;\">" html += u"</div>\n" html += self.renderViewButtons() html += u"</div>\n" return html def renderView(self, style): """ Returns an XHTML string for viewing this block """ log.debug("renderView") html = u"\n<!-- image with text iDevice -->\n" html += u"<div class=\"iDevice " html += u"emphasis"+unicode(self.idevice.emphasis)+"\">\n" html += u"<div class=\"image_text\" style=\"" html += u"width:" + str(self.idevice.image.width) + "px; " html += u"float:%s;\">\n" % self.idevice.float html += u"<div class=\"image\">\n" html += self.imageElement.renderView() html += u"<br/>" + self.idevice.caption + "</div>" html += u"</div>\n" html += self.textElement.renderView() html += u"<div style=\"clear:both;\">" html += u"</div>\n" html += u"</div>\n" return html