version 1.20, 2004/06/02 19:01:36
|
version 1.25, 2004/06/04 16:07:49
|
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=''): |
def getString(self,key,default=''): |
Line 427 class zogiLib(Folder):
|
Line 428 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 463 class zogiLib(Folder):
|
Line 465 class zogiLib(Folder):
|
return pt() |
return pt() |
|
|
|
|
def createScalerImg(self, requestString = None): |
def createScalerImg(self, requestString = None, bottom = 0, side = 0): |
"""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) = 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.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>' |
Line 485 class zogiLib(Folder):
|
Line 499 class zogiLib(Folder):
|
tag += '</div>' |
tag += '</div>' |
return tag |
return tag |
|
|
|
def createScalerDiv(self, requestString = None, bottom = 0, side = 0): |
|
"""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) |
|
else: |
|
if self.REQUEST.SESSION.has_key('scalerDiv'): |
|
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() |
Line 563 class zogiLib(Folder):
|
Line 588 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') |
|
|
|
|
|
|
Line 577 class zogiLib(Folder):
|
Line 617 class zogiLib(Folder):
|
|
|
|
|
|
|
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: |
|
print "ouch!" |
|
# 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 596 class zogiLib(Folder):
|
Line 644 class zogiLib(Folder):
|
|
|
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): |
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 694 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 getPT(self): |
def getPT(self): |
Line 666 class zogiLib(Folder):
|
Line 727 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 int(ws)+1 |
else: |
except: |
return 2 |
return 2 |
|
|
|
|
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(int(ws)-1, 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 763 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_HMirror(self): |
def dl_HMirror(self): |
Line 728 class zogiLib(Folder):
|
Line 806 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 926 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 943 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') |