# =========================================================================== # eXe # Copyright 2004-2006, University of Auckland # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # =========================================================================== """ A ImageWithText Idevice is one built up from an image and free text. """ import logging from exe.engine.idevice import Idevice from exe.engine.field import TextAreaField, ImageField from exe.engine.translate import lateTranslate from exe.engine.freetextidevice import FreeTextIdevice from exe import globals as G import os log = logging.getLogger(__name__) # =========================================================================== class ImageWithTextIdevice(Idevice): """ A ImageWithText Idevice is one built up from an image and free text. """ persistenceVersion = 8 def __init__(self, defaultImage = None): Idevice.__init__(self, x_(u"Image with Text"), x_(u"University of Auckland"), x_(u"""

The image with text iDevice can be used in a number of ways to support both the emotional (affective) and learning task (cognitive) dimensions of eXe content.

Integrating visuals with verbal summaries

Cognitive psychologists indicate that presenting learners with a representative image and corresponding verbal summary (that is presented simultaneously) can reduce cognitive load and enhance learning retention. This iDevice can be used to present an image (photograph, diagram or graphic) with a brief verbal summary covering the main points relating to the image. For example, if you were teaching the functions of a four-stroke combustion engine, you could have a visual for each of the four positions of the piston with a brief textual summary of the key aspects of each visual.

"""), u"", u"") self.emphasis = Idevice.NoEmphasis self.image = ImageField(x_(u"Image"), u"") self.image.idevice = self self.image.defaultImage = defaultImage self.text = TextAreaField(x_(u"Text"), x_("""Enter the text you wish to associate with the image.""")) self.text.idevice = self self.float = u"left" self.caption = u"" self._captionInstruc = x_(u"""Provide a caption for the image you have just inserted.""") # Properties captionInstruc = lateTranslate('captionInstruc') def upgradeToVersion1(self): """ Called to upgrade from 0.5 release """ self.float = u"left" def upgradeToVersion2(self): """ Called to upgrade from 0.6 release """ self.caption = u"" self.emphasis = Idevice.NoEmphasis def upgradeToVersion3(self): """ Upgrades v0.6 to v0.7. """ self.lastIdevice = False def upgradeToVersion4(self): """ Upgrades to exe v0.10 """ self._upgradeIdeviceToVersion1() def upgradeToVersion5(self): """ Upgrades to v0.12 """ log.debug("upgrade to version 5") self._upgradeIdeviceToVersion2() self.image._upgradeFieldToVersion2() def upgradeToVersion6(self): """ Called to upgrade from 0.13 release """ self._captionInstruc = x_(u"""Provide a caption for the image you have just inserted.""") def upgradeToVersion7(self): """ Called to upgrade to version 0.24 """ self.image.isFeedback = False def upgradeToVersion8(self): """ Converting ImageWithTextIdevice -> FreeTextIdevice, now that FreeText can hold embeddded images. BUT - due to the inconsistent loading of the objects via unpickling, since the resources aren't necessarily properly loaded and upgraded, NOR is the package necessarily, as it might not even have a list of resources yet, all of this conversion code must be done in an afterUpgradeHandler """ G.application.afterUpgradeHandlers.append(self.convertToFreeText) def convertToFreeText(self): """ Actually do the Converting of ImageWithTextIdevice -> FreeTextIdevice, now that FreeText can hold embeddded images. """ new_content = "" # ensure that an image resource still exists on this ImageWithText, # before trying to add it into the FreeText idevice. # Why? corrupt packages have been seen missing resources... # (usually in with extra package objects as well, probably # from old code doing faulty Extracts, or somesuch nonesense) imageResource_exists = False if self.image.imageResource: # also ensure that it has the correct md5 checksum, since there was # a period in which resource checksums were being created before # the resource zip file was fully closed, and not flushed out: self.image.imageResource.checksumCheck() if os.path.exists(self.image.imageResource.path) and \ os.path.isfile(self.image.imageResource.path): imageResource_exists = True else: log.warn("Couldn't find ImageWithText image when upgrading "\ + self.image.imageResource.storageName) if imageResource_exists: new_content += " including resources path, # but still need the actual image resource: if imageResource_exists: # Not sure why this can't be imported up top, but it gives # ImportError: cannot import name GalleryImages, # so here it be: from exe.engine.galleryidevice import GalleryImage full_image_path = self.image.imageResource.path new_GalleryImage = GalleryImage(replacementIdev.content, \ self.caption, full_image_path, mkThumbnail=False) # and move it up to the position following this node! while ( self.parentNode.idevices.index(replacementIdev) \ > ( (self.parentNode.idevices.index(self) + 1))): replacementIdev.movePrev() # finally: delete THIS idevice itself, deleting it from the node self.delete() def getResourcesField(self, this_resource): """ implement the specific resource finding mechanism for this iDevice: """ # be warned that before upgrading, this iDevice field could not exist: if hasattr(self, 'image') and hasattr(self.image, 'imageResource'): if this_resource == self.image.imageResource: return self.image # be warned that before upgrading, this iDevice field could not exist: if hasattr(self, 'text') and hasattr(self.text, 'images'): for this_image in self.text.images: if hasattr(this_image, '_imageResource') \ and this_resource == this_image._imageResource: return self.text return None def getRichTextFields(self): """ Like getResourcesField(), a general helper to allow nodes to search through all of their fields without having to know the specifics of each iDevice type. """ fields_list = [] if hasattr(self, 'text'): fields_list.append(self.text) return fields_list # ===========================================================================