#!/usr/bin/env python
# -*- coding: UTF-8 -*-



##################################################
## DEPENDENCIES
import sys
import os
import os.path
from os.path import getmtime, exists
import time
import types
import __builtin__
from Cheetah.Version import MinCompatibleVersion as RequiredCheetahVersion
from Cheetah.Version import MinCompatibleVersionTuple as RequiredCheetahVersionTuple
from Cheetah.Template import Template
from Cheetah.DummyTransaction import DummyTransaction
from Cheetah.NameMapper import NotFound, valueForName, valueFromSearchList, valueFromFrameOrSearchList
from Cheetah.CacheRegion import CacheRegion
import Cheetah.Filters as Filters
import Cheetah.ErrorCatchers as ErrorCatchers
from MainTemplate import MainTemplate

##################################################
## MODULE CONSTANTS
try:
    True, False
except NameError:
    True, False = (1==1), (1==0)
VFFSL=valueFromFrameOrSearchList
VFSL=valueFromSearchList
VFN=valueForName
currentTime=time.time
__CHEETAH_version__ = '2.0.1'
__CHEETAH_versionTuple__ = (2, 0, 1, 'final', 0)
__CHEETAH_genTime__ = 1225031612.6596849
__CHEETAH_genTimestamp__ = 'Sun Oct 26 14:33:32 2008'
__CHEETAH_src__ = 'ToolboxTemplate.tmpl'
__CHEETAH_srcLastModified__ = 'Fri Jan 26 16:14:34 2007'
__CHEETAH_docstring__ = 'Autogenerated by CHEETAH: The Python-Powered Template Engine'

if __CHEETAH_versionTuple__ < RequiredCheetahVersionTuple:
    raise AssertionError(
      'This template was compiled with Cheetah version'
      ' %s. Templates compiled before version %s must be recompiled.'%(
         __CHEETAH_version__, RequiredCheetahVersion))

##################################################
## CLASSES

class ToolboxTemplate(MainTemplate):

    ##################################################
    ## CHEETAH GENERATED METHODS


    def __init__(self, *args, **KWs):

        MainTemplate.__init__(self, *args, **KWs)
        if not self._CHEETAH__instanceInitialized:
            cheetahKWArgs = {}
            allowedKWs = 'searchList namespaces filter filtersLib errorCatcher'.split()
            for k,v in KWs.items():
                if k in allowedKWs: cheetahKWArgs[k] = v
            self._initCheetahInstance(**cheetahKWArgs)
        

    def add_tool(self, tool, **KWS):



        ## CHEETAH: generated from #def add_tool($tool) at line 46, col 1.
        trans = KWS.get("trans")
        if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
            trans = self.transaction # is None unless self.awake() was called
        if not trans:
            trans = DummyTransaction()
            _dummyTrans = True
        else: _dummyTrans = False
        write = trans.response().write
        SL = self._CHEETAH__searchList
        _filter = self._CHEETAH__currentFilter
        
        ########################################
        ## START - generated method body
        
        write('''    <table width="300" cellspacing="0" cellpadding="0" border="0">
      <tr>
        <td><img src="''')
        _v = VFFSL(SL,"imagefolder",True) # '$imagefolder' on line 49, col 23
        if _v is not None: write(_filter(_v, rawExpr='$imagefolder')) # from line 49, col 23.
        write('''/toolbox/module-bar-start.gif" alt="" /></td>
''')
        if VFFSL(SL,"tool.icon",True): # generated from line 50, col 1
            write('''        <td style="background-image:url(\'''')
            _v = VFFSL(SL,"imagefolder",True) # '$imagefolder' on line 51, col 42
            if _v is not None: write(_filter(_v, rawExpr='$imagefolder')) # from line 51, col 42.
            write('''/toolbox/module-bar-fill.gif\'); background-repeat: repeat-x; width: 50px;"><a href="''')
            _v = VFFSL(SL,"tool.uri",True) # '$tool.uri' on line 51, col 138
            if _v is not None: write(_filter(_v, rawExpr='$tool.uri')) # from line 51, col 138.
            write('''"><img src="''')
            _v = VFFSL(SL,"tool.icon",True) # '$tool.icon' on line 51, col 159
            if _v is not None: write(_filter(_v, rawExpr='$tool.icon')) # from line 51, col 159.
            write('''" border="0" alt="" /></a></td>
''')
        else: # generated from line 52, col 1
            write('''        <td style="background-image:url(\'''')
            _v = VFFSL(SL,"imagefolder",True) # '$imagefolder' on line 53, col 42
            if _v is not None: write(_filter(_v, rawExpr='$imagefolder')) # from line 53, col 42.
            write('''/toolbox/module-bar-fill.gif\'); background-repeat: repeat-x; width: 50px;"><img src="''')
            _v = VFFSL(SL,"imagefolder",True) # '$imagefolder' on line 53, col 139
            if _v is not None: write(_filter(_v, rawExpr='$imagefolder')) # from line 53, col 139.
            write('''/blank.gif" width="47" height="54" alt="" /></td>
''')
        write('''        <td width="250" style="background-image:url(\'''')
        _v = VFFSL(SL,"imagefolder",True) # '$imagefolder' on line 55, col 54
        if _v is not None: write(_filter(_v, rawExpr='$imagefolder')) # from line 55, col 54.
        write('''/toolbox/module-bar-fill.gif\'); background-repeat: repeat-x; padding: 1px 0px 0px 5px;" nowrap="nowrap"><a class="navbar" href="''')
        _v = VFFSL(SL,"tool.uri",True) # '$tool.uri' on line 55, col 194
        if _v is not None: write(_filter(_v, rawExpr='$tool.uri')) # from line 55, col 194.
        write('''">''')
        _v = VFFSL(SL,"tool.name",True) # '$tool.name' on line 55, col 205
        if _v is not None: write(_filter(_v, rawExpr='$tool.name')) # from line 55, col 205.
        write('''</a></td>
        <td><img src="''')
        _v = VFFSL(SL,"imagefolder",True) # '$imagefolder' on line 56, col 23
        if _v is not None: write(_filter(_v, rawExpr='$imagefolder')) # from line 56, col 23.
        write('''/toolbox/module-bar-end.gif" alt="" /></td>
      </tr>
      <tr valign="top" style="height: 5em;">
        <td style="background-image:url(\'''')
        _v = VFFSL(SL,"imagefolder",True) # '$imagefolder' on line 59, col 42
        if _v is not None: write(_filter(_v, rawExpr='$imagefolder')) # from line 59, col 42.
        write('''/toolbox/module-fill-start.gif\'); background-repeat: repeat-y; "></td>
        <td colspan="2" style="background-image:url(\'''')
        _v = VFFSL(SL,"imagefolder",True) # '$imagefolder' on line 60, col 54
        if _v is not None: write(_filter(_v, rawExpr='$imagefolder')) # from line 60, col 54.
        write('''/toolbox/module-fill.gif\'); background-repeat: repeat; font-size: 13px; padding: 0px 0px 0px 10px">
          ''')
        _v = VFFSL(SL,"tool.description",True) # '$tool.description' on line 61, col 11
        if _v is not None: write(_filter(_v, rawExpr='$tool.description')) # from line 61, col 11.
        write('''
        </td>
        <td style="background-image:url(\'''')
        _v = VFFSL(SL,"imagefolder",True) # '$imagefolder' on line 63, col 42
        if _v is not None: write(_filter(_v, rawExpr='$imagefolder')) # from line 63, col 42.
        write('''/toolbox/module-fill-end.gif\'); background-repeat: repeat-y; "></td>
      </tr>
      <tr>
        <td><img src="''')
        _v = VFFSL(SL,"imagefolder",True) # '$imagefolder' on line 66, col 23
        if _v is not None: write(_filter(_v, rawExpr='$imagefolder')) # from line 66, col 23.
        write('''/toolbox/module-footer-start.gif" alt="" /></td>
        <td colspan="2" width="100%" style="background-image:url(\'''')
        _v = VFFSL(SL,"imagefolder",True) # '$imagefolder' on line 67, col 67
        if _v is not None: write(_filter(_v, rawExpr='$imagefolder')) # from line 67, col 67.
        write('''/toolbox/module-footer-fill.gif\'); background-repeat: repeat-x; "></td>
        <td><img src="''')
        _v = VFFSL(SL,"imagefolder",True) # '$imagefolder' on line 68, col 23
        if _v is not None: write(_filter(_v, rawExpr='$imagefolder')) # from line 68, col 23.
        write('''/toolbox/module-footer-end.gif" alt="" /></td>
      </tr>
    </table>
''')
        
        ########################################
        ## END - generated method body
        
        return _dummyTrans and trans.response().getvalue() or ""
        

    def content(self, **KWS):



        ## CHEETAH: generated from #block content at line 73, col 1.
        trans = KWS.get("trans")
        if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
            trans = self.transaction # is None unless self.awake() was called
        if not trans:
            trans = DummyTransaction()
            _dummyTrans = True
        else: _dummyTrans = False
        write = trans.response().write
        SL = self._CHEETAH__searchList
        _filter = self._CHEETAH__currentFilter
        
        ########################################
        ## START - generated method body
        
        write('''<table cellspacing="0" cellpadding="0" border="0">
''')
        rowplace = 0
        for tool in VFFSL(SL,"tools",True): # generated from line 76, col 1
            rowplace = VFFSL(SL,"rowplace",True) + 1
            if VFFSL(SL,"rowplace",True) == 1: # generated from line 78, col 1
                write('''  <tr>
''')
            write('''    <td>
''')
            _v = VFFSL(SL,"add_tool",False)(VFFSL(SL,"tool",True)) # '$add_tool($tool)' on line 82, col 1
            if _v is not None: write(_filter(_v, rawExpr='$add_tool($tool)')) # from line 82, col 1.
            write('''
    </td>
''')
            if VFFSL(SL,"rowplace",True) == VFFSL(SL,"boxesPerRow",True): # generated from line 84, col 1
                write('''  </tr>
''')
                rowplace = 0
        if VFFSL(SL,"rowplace",True) != VFFSL(SL,"boxesPerRow",True): # generated from line 89, col 1
            for i in range(VFFSL(SL,"boxesPerRow",True) - VFFSL(SL,"rowplace",True)): # generated from line 90, col 3
                write('''    <td></td>
''')
            write('''  </tr>
''')
        write('''</table>
''')
        
        ########################################
        ## END - generated method body
        
        return _dummyTrans and trans.response().getvalue() or ""
        

    def content_OLD_FLOAT(self, **KWS):



        ## CHEETAH: generated from #block content_OLD_FLOAT at line 100, col 1.
        trans = KWS.get("trans")
        if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
            trans = self.transaction # is None unless self.awake() was called
        if not trans:
            trans = DummyTransaction()
            _dummyTrans = True
        else: _dummyTrans = False
        write = trans.response().write
        SL = self._CHEETAH__searchList
        _filter = self._CHEETAH__currentFilter
        
        ########################################
        ## START - generated method body
        
        numtools = len(VFFSL(SL,"tools",True))
        i = 0
        for tool in VFFSL(SL,"tools",True): # generated from line 103, col 1
            i = VFFSL(SL,"i",True) + 1
            if VFFSL(SL,"i",True) == VFFSL(SL,"numtools",True): # generated from line 105, col 1
                write('''  <div>
''')
            else: # generated from line 107, col 1
                write('''  <div style="float: left">
''')
            _v = VFFSL(SL,"add_tool",False)(VFFSL(SL,"tool",True)) # '$add_tool($tool)' on line 110, col 1
            if _v is not None: write(_filter(_v, rawExpr='$add_tool($tool)')) # from line 110, col 1.
            write('''
  </div>
''')
        
        ########################################
        ## END - generated method body
        
        return _dummyTrans and trans.response().getvalue() or ""
        

    def writeBody(self, **KWS):



        ## CHEETAH: main method generated for this template
        trans = KWS.get("trans")
        if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
            trans = self.transaction # is None unless self.awake() was called
        if not trans:
            trans = DummyTransaction()
            _dummyTrans = True
        else: _dummyTrans = False
        write = trans.response().write
        SL = self._CHEETAH__searchList
        _filter = self._CHEETAH__currentFilter
        
        ########################################
        ## START - generated method body
        
        #  $Id: ToolboxTemplate.tmpl 3828 2007-01-26 16:14:34Z jodal $
        #   
        #  Copyright 2003, 2004 Norwegian University of Science and Technology
        # 
        #  This file is part of Network Administration Visualized (NAV)
        # 
        #  NAV 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.
        # 
        #  NAV 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 NAV; if not, write to the Free Software
        #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
        # 
        # 
        #  Author: Magnar Sveen <magnars@idi.ntnu.no>
        # 
        write('''
''')
        # 
        #  Extends the MainTemplate for header-information, nav-logo and
        #  navigation-bar.
        # 
        #  Builds html for the Toolbox with data in this form:
        # 
        #  $tools                              :: array of tools
        #    +-- name                          :: name of the tool
        #    +-- uri                           :: location of the tool
        #    +-- icon                          :: uri to the tools' icon
        #    +-- description                   :: explanation of the tools purpose or function
        #  
        #  The template uses images in $imagefolder/toolbox/, where $imagefolder
        #  is inherited from MainTemplate and defaults to "/images".
        # 
        write('''



''')
        self.content(trans=trans)
        write('''
''')
        #  This function was used to make the toolboxes float on the page to better use the width of the screen.
        #  This did not work out so well in all browsers, so it was scrapped. 
        self.content_OLD_FLOAT(trans=trans)
        
        ########################################
        ## END - generated method body
        
        return _dummyTrans and trans.response().getvalue() or ""
        
    ##################################################
    ## CHEETAH GENERATED ATTRIBUTES


    _CHEETAH__instanceInitialized = False

    _CHEETAH_version = __CHEETAH_version__

    _CHEETAH_versionTuple = __CHEETAH_versionTuple__

    _CHEETAH_genTime = __CHEETAH_genTime__

    _CHEETAH_genTimestamp = __CHEETAH_genTimestamp__

    _CHEETAH_src = __CHEETAH_src__

    _CHEETAH_srcLastModified = __CHEETAH_srcLastModified__

    boxesPerRow = 3

    _mainCheetahMethod_for_ToolboxTemplate= 'writeBody'

## END CLASS DEFINITION

if not hasattr(ToolboxTemplate, '_initCheetahAttributes'):
    templateAPIClass = getattr(ToolboxTemplate, '_CHEETAH_templateClass', Template)
    templateAPIClass._addCheetahPlumbingCodeToClass(ToolboxTemplate)


# CHEETAH was developed by Tavis Rudd and Mike Orr
# with code, advice and input from many other volunteers.
# For more information visit http://www.CheetahTemplate.org/

##################################################
## if run from command line:
if __name__ == '__main__':
    from Cheetah.TemplateCmdLineIface import CmdLineIface
    CmdLineIface(templateObj=ToolboxTemplate()).run()


