Diff for /zogiLib/zogiLib.py between versions 1.20 and 1.26

version 1.20, 2004/06/02 19:01:36 version 1.26, 2004/06/07 17:56:55
Line 12  import os Line 12  import os
 import re  import re
 import string  import string
 import urllib  import urllib
   import types
 from Globals import package_home  from Globals import package_home
   
 def getString(self,key,default=''):  
     try:  
         return self.REQUEST[key]  
     except:  
         return default  
   
 def sendFile(self, filename, type):  def sendFile(self, filename, type):
     """sends an object or a local file (in the product) as response"""      """sends an object or a local file (in the product) as response"""
     paths = filename.split('/')      paths = filename.split('/')
Line 41  def sendFile(self, filename, type): Line 36  def sendFile(self, filename, type):
     self.REQUEST.RESPONSE.write(file(fn).read())      self.REQUEST.RESPONSE.write(file(fn).read())
     return      return
   
 class BrowserCheck:  def browserCheck(self):
     """check the browsers request to find out the browser type"""      """check the browsers request to find out the browser type"""
           bt = {}
     def __init__(self, zope):      ua = self.REQUEST.get_header("HTTP_USER_AGENT")
     self.ua = zope.REQUEST.get_header("HTTP_USER_AGENT")      bt['ua'] = ua
     self.isIE = string.find(self.ua, 'MSIE') > -1      bt['isIE'] = string.find(ua, 'MSIE') > -1
     self.isN4 = (string.find(self.ua, 'Mozilla/4.') > -1) and not self.isIE      bt['isN4'] = (string.find(ua, 'Mozilla/4.') > -1) and not bt['isIE']
     self.nav = self.ua[string.find(self.ua, '('):]      nav = ua[string.find(ua, '('):]
     ie = string.split(self.nav, "; ")[1]      ie = string.split(nav, "; ")[1]
     if string.find(ie, "MSIE") > -1:      if string.find(ie, "MSIE") > -1:
         self.versIE = string.split(ie, " ")[1]          bt['versIE'] = string.split(ie, " ")[1]
     self.isMac = string.find(self.ua, 'Macintosh') > -1      bt['isMac'] = string.find(ua, 'Macintosh') > -1
     self.isWin = string.find(self.ua, 'Windows') > -1      bt['isWin'] = string.find(ua, 'Windows') > -1
     self.isIEWin = self.isIE and self.isWin      bt['isIEWin'] = bt['isIE'] and bt['isWin']
     self.isIEMac = self.isIE and self.isMac      bt['isIEMac'] = bt['isIE'] and bt['isMac']
       bt['staticHTML'] = False
   
       return bt
   
 def manage_addZogiLibMainTemplateForm(self):  def manage_addZogiLibMainTemplateForm(self):
     """Form for adding"""      """Form for adding"""
Line 427  class zogiLib(Folder): Line 424  class zogiLib(Folder):
             {'label':'Main Config','action':'changeZogiLibForm'},              {'label':'Main Config','action':'changeZogiLibForm'},
             )              )
   
     def __init__(self, id,title,digilibBaseUrl, localFileBase,version="book"):      def __init__(self, id, title, digilibBaseUrl, localFileBase, version="book", basePath=""):
         """init"""          """init"""
   
         self.id=id          self.id=id
         self.title=title          self.title=title
         self.digilibBaseUrl=digilibBaseUrl          self.digilibBaseUrl=digilibBaseUrl
         self.localFileBase=localFileBase          self.localFileBase=localFileBase
           self.basePath=basePath
         self.layout=version          self.layout=version
   
   
Line 454  class zogiLib(Folder): Line 452  class zogiLib(Folder):
   
     def createHeadJS(self):      def createHeadJS(self):
         """generate all javascript tags for head"""          """generate all javascript tags for head"""
       self.checkQuery()
       bt = self.REQUEST.SESSION['browserType']
           if bt['staticHTML']:
               return
           
         pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/zogilib_head_js')).__of__(self)          pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/zogilib_head_js')).__of__(self)
         return pt()          return pt()
   
     def createParamJS(self):      def createParamJS(self):
         """generate javascript for parameters only"""          """generate javascript for parameters only"""
       self.checkQuery()
       bt = self.REQUEST.SESSION['browserType']
           if bt['staticHTML']:
               return
   
         pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/zogilib_param_js')).__of__(self)          pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/zogilib_param_js')).__of__(self)
         return pt()          return pt()
                   
                                                   
     def createScalerImg(self, requestString = None):      def createScalerImg(self, requestString=None, bottom=0, side=0, width=500, height=500):
         """generate Scaler IMG Tag"""          """generate Scaler IMG Tag"""
     self.checkQuery()      self.checkQuery()
     bt = self.REQUEST.SESSION['browserType']      bt = self.REQUEST.SESSION['browserType']
           # override with parameters from session
           if  self.REQUEST.SESSION.has_key('scalerDiv'):
               (requestString, bottom, side, width, height) = self.REQUEST.SESSION['scalerDiv']
           # if not explicitly defined take normal request
         if not requestString:          if not requestString:
             requestString = self.REQUEST.QUERY_STRING              requestString = self.getAllDLParams()
         url = self.digilibBaseUrl+requestString          url = self.digilibBaseUrl+requestString
           # construct bottom and side insets
           b_par = ""
           s_par = ""
           if (bottom != 0) or (side != 0):
               b_par = "-" + str(int(bottom))
               s_par = "-" + str(int(side))
         tag = ""          tag = ""
         if bt.isN4:          if bt['staticHTML']:
               tag += '<div id="scaler"><img id="pic" src="%s&dw=%i&dh=%i" /></div>'%(url, int(width-side), int(height-bottom))
           else:
               if bt['isN4']:
                   # N4 needs layers
             tag += '<ilayer id="scaler">'              tag += '<ilayer id="scaler">'
         else:          else:
             tag += '<div id="scaler">'              tag += '<div id="scaler">'
         tag += '<script type="text/javascript">'          tag += '<script type="text/javascript">'
         tag += "var ps = bestPicSize(getElement('scaler'));"          tag += "var ps = bestPicSize(getElement('scaler'));"
         tag += 'document.write(\'<img id="pic" src="%s&dw=\'+ps.width+\'&dh=\'+ps.height+\'" />\')'%url              # write img tag with javascript
               tag += 'document.write(\'<img id="pic" src="%s&dw=\'+(ps.width%s)+\'&dh=\'+(ps.height%s)+\'" />\');'%(url, s_par, b_par)
         tag += '</script>'          tag += '</script>'
         if bt.isN4:              if bt['isN4']:
             tag += '</ilayer>'              tag += '</ilayer>'
         else:          else:
             tag += '</div>'              tag += '</div>'
         return tag          return tag
   
       def createScalerDiv(self, requestString = None, bottom = 0, side = 0, width=500, height=500):
           """generate scaler img and table with navigation arrows"""
       self.checkQuery()
           if requestString != None or bottom != 0 or side != 0:
               self.REQUEST.SESSION['scalerDiv'] = (requestString, bottom, side, width, height)
           else:
               if self.REQUEST.SESSION.has_key('scalerDiv'):
                   # make shure to remove unused parameter
                   del self.REQUEST.SESSION['scalerDiv']
                   
           pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt/zogilib_img_div')).__of__(self)
           return pt()
   
     def createAuxDiv(self):      def createAuxDiv(self):
         """generate other divs"""          """generate other divs"""
     self.checkQuery()      self.checkQuery()
     bt = self.REQUEST.SESSION['browserType']      bt = self.REQUEST.SESSION['browserType']
         if bt.isN4:          if bt['staticHTML']:
               return
           if bt['isN4']:
             f = 'zpt/zogilib_divsN4.zpt'              f = 'zpt/zogilib_divsN4.zpt'
         else:          else:
             f = 'zpt/zogilib_divs.zpt'              f = 'zpt/zogilib_divs.zpt'
Line 512  class zogiLib(Folder): Line 550  class zogiLib(Folder):
   
     def optionwindow(self):      def optionwindow(self):
         """showoptions"""          """showoptions"""
       self.checkQuery()
       bt = self.REQUEST.SESSION['browserType']
           if bt['staticHTML']:
               pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/optionwindow_static.zpt')).__of__(self)
           else:
         pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/optionwindow.zpt')).__of__(self)          pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/optionwindow.zpt')).__of__(self)
         return pt()          return pt()
   
Line 563  class zogiLib(Folder): Line 606  class zogiLib(Folder):
         """mark image"""          """mark image"""
         return sendFile(self, 'images/urechts.gif', 'image/gif')          return sendFile(self, 'images/urechts.gif', 'image/gif')
   
       def up_img(self):
           """mark image"""
           return sendFile(self, 'images/up.gif', 'image/gif')
   
       def down_img(self):
           """mark image"""
           return sendFile(self, 'images/down.gif', 'image/gif')
   
       def left_img(self):
           """mark image"""
           return sendFile(self, 'images/left.gif', 'image/gif')
   
       def right_img(self):
           """mark image"""
           return sendFile(self, 'images/right.gif', 'image/gif')
   
   
                           
     def index_html(self):      def index_html(self):
         """main action"""          """main action"""
       self.checkQuery()
       bt = self.REQUEST.SESSION['browserType']
         tp = "zogiLibMainTemplate"          tp = "zogiLibMainTemplate"
         if hasattr(self, tp):          if hasattr(self, tp):
         pt = getattr(self, tp)          pt = getattr(self, tp)
         else:          else:
             pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/zogiLibMain_%s'%self.layout)).__of__(self)              tpt = self.layout
               if bt['staticHTML']:
                   tpt = "static"
                   
               pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/zogiLibMain_%s'%tpt)).__of__(self)
               
         return pt()          return pt()
   
   
   
     def storeQuery(self):      def storeQuery(self, more = None):
         """storeQuery in session"""          """storeQuery in session"""
         dlParams = {}          dlParams = {}
         for fm in self.REQUEST.form.keys():          for fm in self.REQUEST.form.keys():
             dlParams[fm] = self.REQUEST.form[fm]              dlParams[fm] = self.REQUEST.form[fm]
           # look for more
           if more:
               for fm in more.split('&'):
                   try:
                       pv = fm.split('=')
                       dlParams[pv[0]] = pv[1]
                   except:
                       pass
   
           # parse digilib mode parameter
         if 'mo' in dlParams:          if 'mo' in dlParams:
             if len(dlParams['mo']) > 0:              if len(dlParams['mo']) > 0:
                 modes=dlParams['mo'].split(',')                  modes=dlParams['mo'].split(',')
Line 592  class zogiLib(Folder): Line 666  class zogiLib(Folder):
         self.REQUEST.SESSION['query'] = dlParams          self.REQUEST.SESSION['query'] = dlParams
         self.REQUEST.SESSION['dlModes'] = modes          self.REQUEST.SESSION['dlModes'] = modes
         self.REQUEST.SESSION['dlInfo'] = self.getDLInfo()          self.REQUEST.SESSION['dlInfo'] = self.getDLInfo()
         self.REQUEST.SESSION['browserType'] = BrowserCheck(self)          if not self.REQUEST.SESSION.has_key('browserType'):
               self.REQUEST.SESSION['browserType'] = browserCheck(self)
               
           return
   
     def checkQuery(self):      def checkQuery(self):
     """check if the query has been stored"""      """check if the query has been stored"""
     if not (self.REQUEST.SESSION and 'query' in self.REQUEST.SESSION):      if not (self.REQUEST.SESSION and self.REQUEST.SESSION.has_key('query')) :
         print "ZOGILIB: have to store query!!"          print "ZOGILIB: have to store query!!"
         storeQuery(self)          self.storeQuery()
           return
   
       def zogilibPath(self, otherbase=None):
           """returns an URL to the zogiLib instance"""
           url = self.REQUEST['URL1']
           # should end with "/"
           if len(url) > 0 and url[-1] != '/':
               url += '/'
           if type(otherbase) is str:
               url += otherbase
           else:
               url += self.basePath
           # should end with "/"
           if len(url) > 0 and url[-1] != '/':
               url += '/'
           return url
                   
     def getDLParam(self,param):      def getDLParam(self,param):
         """returns parameter"""          """returns parameter"""
         try:          try:
             return self.REQUEST.SESSION['query'][param]              return self.REQUEST.SESSION['query'][param]
         except:          except:
             return None              return
   
     def setDLParam(self, param, value):      def setDLParam(self, param, value):
         """sets parameter"""          """sets parameter"""
Line 630  class zogiLib(Folder): Line 723  class zogiLib(Folder):
                   
     def setDLParams(self,pn=None,ws=None,rot=None,brgt=None,cont=None):      def setDLParams(self,pn=None,ws=None,rot=None,brgt=None,cont=None):
         """setze Parameter"""          """setze Parameter"""
         ret=""  
   
         if brgt:  
             self.setDLParam('brgt', brgt)              self.setDLParam('brgt', brgt)
   
         if cont:  
             self.setDLParam('cont', cont)              self.setDLParam('cont', cont)
           self.setDLParam('ws', ws)
           self.setDLParam('rot', rot)
   
         if pn:          if pn:
               # unmark
               self.setDLParam('mk', None)
             self.setDLParam('pn', pn)              self.setDLParam('pn', pn)
   
         if ws:  
             self.setDLParam('ws', ws)  
   
         if rot:  
             self.setDLParam('rot', rot)  
               
         return self.display()          return self.display()
   
   
     def display(self):      def display(self):
         """(re)display page"""          """(re)display page"""
         params = self.getAllDLParams()          params = self.getAllDLParams()
           if self.basePath:
               self.REQUEST.RESPONSE.redirect(self.REQUEST['URL2']+'?'+params)
           else:
         self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'?'+params)          self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'?'+params)
   
   
       def setStaticHTML(self, static=True):
           """sets the preference to static HTML"""
           self.checkQuery()
       self.REQUEST.SESSION['browserType']['staticHTML'] = static
           return
   
       def isStaticHTML(self):
           """returns if the page is using static HTML only"""
           self.checkQuery()
       return self.REQUEST.SESSION['browserType']['staticHTML']
   
     def getPT(self):      def getPT(self):
         """pagenums"""          """pagenums"""
         di = self.REQUEST.SESSION['dlInfo']          di = self.REQUEST.SESSION['dlInfo']
Line 666  class zogiLib(Folder): Line 768  class zogiLib(Folder):
     def getPN(self):      def getPN(self):
         """Pagenum"""          """Pagenum"""
         pn = self.getDLParam('pn')          pn = self.getDLParam('pn')
         if pn:          try:
             return int(pn)              return int(pn)
         else:          except:
             return 1              return 1
   
     def getBiggerWS(self):      def getBiggerWS(self):
         """ws+1"""          """ws+1"""
         ws=self.getDLParam('ws')          ws=self.getDLParam('ws')
         if ws:          try:
             return int(ws)+1              return float(ws)+0.5
         else:          except:
             return 2              return 1.5
   
                   
     def getSmallerWS(self):      def getSmallerWS(self):
         """ws-1"""          """ws-1"""
         ws=self.getDLParam('ws')          ws=self.getDLParam('ws')
         if ws:          try:
             if int(ws)==1:              return max(float(ws)-0.5, 1)
                 return 1          except:
             else:  
                 return int(ws)-1  
         else:  
             return 1              return 1
   
     def hasMode(self, mode):      def hasMode(self, mode):
Line 706  class zogiLib(Folder): Line 804  class zogiLib(Folder):
         pn = self.getPN()          pn = self.getPN()
         return (pn > 1)          return (pn > 1)
   
       def canMoveLeft(self):
           """returns if its possible to move left"""
           wx = float(self.getDLParam('wx') or 0)
           return (wx > 0)
   
       def canMoveRight(self):
           """returns if its possible to move right"""
           wx = float(self.getDLParam('wx') or 0)
           ww = float(self.getDLParam('ww') or 1)
           return (wx + ww < 1)
   
       def canMoveUp(self):
           """returns if its possible to move up"""
           wy = float(self.getDLParam('wy') or 0)
           return (wy > 0)
   
       def canMoveDown(self):
           """returns if its possible to move down"""
           wy = float(self.getDLParam('wy') or 0)
           wh = float(self.getDLParam('wh') or 1)
           return (wy + wh < 1)
         
                   
       def dl_StaticHTML(self):
           """set rendering to static HTML"""
           self.checkQuery()
           self.REQUEST.SESSION['browserType']['staticHTML'] = True
           return self.display()
   
       def dl_DynamicHTML(self):
           """set rendering to dynamic HTML"""
           self.checkQuery()
           self.REQUEST.SESSION['browserType']['staticHTML'] = False
           return self.display()
           
     def dl_HMirror(self):      def dl_HMirror(self):
         """mirror action"""          """mirror action"""
         modes = self.REQUEST.SESSION['dlModes']          modes = self.REQUEST.SESSION['dlModes']
Line 728  class zogiLib(Folder): Line 859  class zogiLib(Folder):
   
         return self.display()          return self.display()
   
       def dl_Zoom(self, z):
           """general zoom action"""
           ww1 = float(self.getDLParam('ww') or 1)
           wh1 = float(self.getDLParam('wh') or 1)
           wx = float(self.getDLParam('wx') or 0)
           wy = float(self.getDLParam('wy') or 0)
           ww2 = ww1 * z
           wh2 = wh1 * z
           wx += (ww1 - ww2) / 2
           wy += (wh1 - wh2) / 2
           ww2 = max(min(ww2, 1), 0)
           wh2 = max(min(wh2, 1), 0)
           wx = max(min(wx, 1), 0)
           wy = max(min(wy, 1), 0)
           self.setDLParam('ww', ww2)
           self.setDLParam('wh', wh2)
           self.setDLParam('wx', wx)
           self.setDLParam('wy', wy)
           return self.display()
           
       def dl_ZoomIn(self):
           """zoom in action"""
           z = 0.7071
           return self.dl_Zoom(z)
   
       def dl_ZoomOut(self):
           """zoom out action"""
           z = 1.4142
           return self.dl_Zoom(z)
   
       def dl_Move(self, dx, dy):
           """general move action"""
           ww = float(self.getDLParam('ww') or 1)
           wh = float(self.getDLParam('wh') or 1)
           wx = float(self.getDLParam('wx') or 0)
           wy = float(self.getDLParam('wy') or 0)
           wx += dx * 0.5 * ww
           wy += dy * 0.5 * wh
           wx = max(min(wx, 1), 0)
           wy = max(min(wy, 1), 0)
           self.setDLParam('wx', wx)
           self.setDLParam('wy', wy)
           return self.display()
           
       def dl_MoveLeft(self):
           """move left action"""
           return self.dl_Move(-1, 0)
       
       def dl_MoveRight(self):
           """move left action"""
           return self.dl_Move(1, 0)
       
       def dl_MoveUp(self):
           """move left action"""
           return self.dl_Move(0, -1)
       
       def dl_MoveDown(self):
           """move left action"""
           return self.dl_Move(0, 1)
       
     def dl_WholePage(self):      def dl_WholePage(self):
         """zoom out action"""          """zoom out action"""
         self.setDLParam('ww', 1)          self.setDLParam('ww', 1)
Line 788  class zogiLib(Folder): Line 979  class zogiLib(Folder):
         pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/changeZogiLibForm.zpt')).__of__(self)          pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/changeZogiLibForm.zpt')).__of__(self)
         return pt()          return pt()
           
     def changeZogiLib(self,title,digilibBaseUrl, localFileBase, version, RESPONSE=None):      def changeZogiLib(self,title,digilibBaseUrl, localFileBase, version, basePath, RESPONSE=None):
         """change it"""          """change it"""
         self.title=title          self.title=title
         self.digilibBaseUrl=digilibBaseUrl          self.digilibBaseUrl=digilibBaseUrl
         self.localFileBase=localFileBase          self.localFileBase=localFileBase
           self.basePath = basePath
         self.layout=version          self.layout=version
   
         if RESPONSE is not None:          if RESPONSE is not None:
Line 804  def manage_addZogiLibForm(self): Line 996  def manage_addZogiLibForm(self):
     pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/addZogiLibForm')).__of__(self)      pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/addZogiLibForm')).__of__(self)
     return pt()      return pt()
   
 def manage_addZogiLib(self,id,title,digilibBaseUrl, localFileBase,version="book",RESPONSE=None):  def manage_addZogiLib(self,id,title,digilibBaseUrl, localFileBase,version="book",basePath="",RESPONSE=None):
     """add dgilib"""      """add dgilib"""
     newObj=zogiLib(id,title,digilibBaseUrl, localFileBase, version)      newObj=zogiLib(id,title,digilibBaseUrl, localFileBase, version, basePath)
     self.Destination()._setObject(id,newObj)      self.Destination()._setObject(id,newObj)
     if RESPONSE is not None:      if RESPONSE is not None:
         RESPONSE.redirect('manage_main')          RESPONSE.redirect('manage_main')

Removed from v.1.20  
changed lines
  Added in v.1.26


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>