Iframe-idevice

From WikiEducator
Jump to: navigation, search

This is a very simple iDevice that uses the iframe html tag in-order to embed a webpage. It demonstrates the use of multiple text fields, and using the values entered as parameters in formated XHTML. It could, for example be used to embed a shared Scribblar white board into an exercise.

The same results can be achieved much more simply by choosing to modify the html in free text fields, but the features demonstrated can be applied to other situations.

iframeidevice.py

# ===========================================================================
# eXe 
# Copyright 2004-2005, 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
# ===========================================================================

"""
Allows the embedding of a webpage within the eXe page, using the iframe html tag.
Produced by Educational Develoment Unit, University of Derby
"""

import logging
from exe.engine.idevice import Idevice
from exe.engine.field   import TextField
log = logging.getLogger(__name__)

# ===========================================================================
class iFrameIdevice(Idevice):
    """
    This is an example of a user created iDevice plugin.  If it is copied
    into the user's ~/.exe/idevices dircectory it will be loaded along with
    the system idevices.
    """
    def __init__(self, content=""):
        Idevice.__init__(self, _(u"iFrame"), 
                         _(u"University of Derby"), 
                         _(u"""Embeds an external website within your page."""), "", "")
        
        self.emphasis = Idevice.NoEmphasis
        
        self.url  = TextField(_(u"URL"), 
                              _(u"Enter the site's URL here"), 
                              "http://")
        self.width  = TextField(_(u"Width"), 
                                _(u"Width of the iFrame"), 
                                "850")
        self.height  = TextField(_(u"Height"), 
                                 _(u"Height of the iFrame"), 
                                 "650")
        
        self.url.idevice = self
        self.width.idevice = self
        self.height.idevice = self


# ===========================================================================
def register(ideviceStore):
    """Register with the ideviceStore"""
    ideviceStore.extended.append(iFrameIdevice())
    

# ===========================================================================

iframeblock.py

# ===========================================================================
# eXe 
# Copyright 2004-2005, 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
# ===========================================================================
"""
iFrameBlock can render and process iFrameIdevices as XHTML
"""

import logging
from exe.webui.block            import Block
from exe.webui.element          import TextElement

log = logging.getLogger(__name__)


# ===========================================================================
class iFrameBlock(Block):
    """
    ExampleBlock can render and process ExampleIdevices as XHTML
    GenericBlock will replace it..... one day
    """
    def __init__(self, parent, idevice):
        Block.__init__(self, parent, idevice)
        
        self.urlElement = TextElement(idevice.url)
        self.widthElement = TextElement(idevice.width)
        self.heightElement = TextElement(idevice.height)


    def process(self, request):
        """
        Process the request arguments from the web server to see if any
        apply to this block
        """
        Block.process(self, request)
        
        url = self.urlElement.process(request)
        if url:
            self.idevice.url = url
            
        width = self.widthElement.process(request)
        if width:
            self.idevice.width = width
            
        height = self.heightElement.process(request)
        if height:
            self.idevice.height = height


    def renderEdit(self, style):
        """
        Returns an XHTML string with the form element for editing this block
        """
        html  = u"<div>\n"
        html += self.urlElement.renderEdit()
        html += self.widthElement.renderEdit()
        html += self.heightElement.renderEdit()
        html += self.renderEditButtons()
        html += u"</div>\n"
        return html


    def renderPreview(self, style):
        """
        Returns an XHTML string for previewing this block
        """
        html  = u"<div class=\"iDevice "
        html += u"emphasis"+unicode(self.idevice.emphasis)+"\" "
        html += u"ondblclick=\"submitLink('edit',"+self.id+", 0);\">\n"
        html += "<iframe src='%s'" % self.urlElement.renderView()
        html += " style='width: %spx; height: %spx' " % (self.widthElement.renderView(), self.heightElement.renderView())
        html += "scrolling='no' marginwidth='0' marginheight='0' frameborder='0' vspace='0' hspace='0'></iframe>\n"
        html += self.renderViewButtons()
        html += "</div>\n"
        return html


    def renderView(self, style):
        """
        Returns an XHTML string for viewing this block
        """
        html  = u"<div class=\"iDevice "
        html += u"emphasis"+unicode(self.idevice.emphasis)+"\">\n"
        html += "<iframe src='%s'" % self.urlElement.renderView()
        html += " style='width: %spx; height: %spx' " % (self.widthElement.renderView(), self.heightElement.renderView())
        html += "scrolling='no' marginwidth='0' marginheight='0' frameborder='0' vspace='0' hspace='0'></iframe>\n"
        html += u"</div>\n"
        return html
    

# ===========================================================================
def register():
    """Register this block with the BlockFactory"""
    from iframeidevice import iFrameIdevice
    from exe.webui.blockfactory     import g_blockFactory
    g_blockFactory.registerBlockType(iFrameBlock, iFrameIdevice)    

# ===========================================================================