Changeset 25:e93fb8cadd3a in documentViewer
- Timestamp:
- Apr 7, 2006, 6:45:48 PM (19 years ago)
- Branch:
- default
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
documentViewer.py
r22 r25 18 18 import urllib 19 19 import zLOG 20 21 def getInt(number, default=0): 22 """returns always an int (0 in case of problems)""" 23 try: 24 return int(number) 25 except: 26 return default 27 20 28 21 29 def getTextFromNode(nodename): … … 80 88 81 89 82 def __init__(self,id,imageViewerUrl,title="",digilibBaseUrl=None ):90 def __init__(self,id,imageViewerUrl,title="",digilibBaseUrl=None,thumbcols=2,thumbrows=10): 83 91 """init document viewer""" 84 92 self.id=id 85 93 self.title=title 86 94 self.imageViewerUrl=imageViewerUrl 87 self.digilibBaseUrl = digilibBaseUrl 88 if not self.digilibBaseUrl: 95 if not digilibBaseUrl: 89 96 self.digilibBaseUrl = self.findDigilibUrl() 97 else: 98 self.digilibBaseUrl = digilibBaseUrl 99 self.thumbcols = thumbcols 100 self.thumbrows = thumbrows 90 101 # add template folder so we can always use template.something 91 102 self.manage_addFolder('template') … … 93 104 94 105 security.declareProtected('View','index_html') 95 def index_html(self,mode,url,start= 0,pn=1):106 def index_html(self,mode,url,start=None,pn=1): 96 107 ''' 97 108 view it … … 113 124 print "dlbaseurl:", self.digilibBaseUrl 114 125 115 docinfo = self.getDocinfo(mode=mode, 116 pageinfo = self.getPageinfo(start=start,current=pn )126 docinfo = self.getDocinfo(mode=mode,url=url) 127 pageinfo = self.getPageinfo(start=start,current=pn,docinfo=docinfo) 117 128 pt = getattr(self.template, 'viewer_main') 118 129 return pt(docinfo=docinfo,pageinfo=pageinfo) 119 130 120 131 121 def imageLink(self,nr): 122 """link hinter den images""" 123 paramsTmp=cgi.parse_qs(self.REQUEST['QUERY_STRING']) 124 params={} 125 for x in paramsTmp.iteritems(): 126 params[x[0]]=x[1][0] 127 128 params['pn']=nr 129 newUrl=self.REQUEST['URL']+"?"+urllib.urlencode(params) 130 return newUrl 131 132 def getLink(self,param=None,val=None): 133 """link to documentviewer with parameter param set to val""" 134 params=cgi.parse_qs(self.REQUEST['QUERY_STRING']) 135 if param is not None: 136 if val is None and params.has_key(param): 137 del params[param] 138 else: 139 params[param] = val 140 141 url=self.REQUEST['URL']+"?"+urllib.urlencode(params, doseq=True) 142 return url 143 144 132 145 def getStyle(self, idx, selected, style=""): 133 """returns a string with the given style +'sel' if path == selected."""146 """returns a string with the given style and append 'sel' if path == selected.""" 134 147 #zLOG.LOG("documentViewer (getstyle)", zLOG.INFO, "idx: %s selected: %s style: %s"%(idx,selected,style)) 135 148 if idx == selected: … … 137 150 else: 138 151 return style 139 140 141 def thumbruler(self,cols,rows,start,maximum):142 """ruler for thumbs"""143 ret=""144 paramsTmp=cgi.parse_qs(self.REQUEST['QUERY_STRING'])145 params={}146 for x in paramsTmp.iteritems():147 148 if not x[0]=="start":149 params[x[0]]=x[1][0]150 151 newUrlSelect=self.REQUEST['URL']+"?"+urllib.urlencode(params)152 if start>0:153 newStart=max(start-cols*rows,0)154 params['start']=newStart155 newUrl=self.REQUEST['URL']+"?"+urllib.urlencode(params)156 ret+="""<a href="%s">prev</a>"""%newUrl157 158 159 ret+="""<select onChange="location.href='%s&start='+this.options[this.selectedIndex].value">"""%newUrlSelect160 nr,rest=divmod(maximum,cols*rows)161 if rest > 0:162 nr+=1163 for i in range(nr):164 nr=i*cols*rows165 166 if (start >= nr) and (start < nr+cols*rows):167 ret+="""<option value="%s" selected>%s</option>"""%(nr,nr)168 else:169 ret+="""<option value="%s">%s</option>"""%(nr,nr)170 ret+="</select>"171 172 if start<maximum:173 newStart=min(start+cols*rows,maximum)174 params['start']=newStart175 newUrl=self.REQUEST['URL']+"?"+urllib.urlencode(params)176 ret+="""<a href="%s">next</a>"""%newUrl177 178 return ret179 180 152 181 153 … … 187 159 docinfo = {} 188 160 189 metaData=self.metadata.main.meta.bib190 161 if dom is None: 191 162 server="http://nausikaa.mpiwg-berlin.mpg.de/digitallibrary/servlet/Texter?fn=" … … 197 168 return docinfo 198 169 199 type=dom.xpath("//bib/@type") 200 if type and (len(type)>0): 201 type=type[0].value 170 metaData=self.metadata.main.meta.bib 171 bibtype=dom.xpath("//bib/@type") 172 if bibtype and (len(bibtype)>0): 173 bibtype=bibtype[0].value 202 174 else: 203 type="generic"204 type=type.replace("-"," ")# wrong typesiin index meta "-" instead of " "205 hash=metaData.generateMappingForType(type)206 207 docinfo['author']=getTextFromNode(dom.xpath("//bib/%s"%hash['author'][0])[0])208 docinfo['title']=getTextFromNode(dom.xpath("//bib/%s"%hash['title'][0])[0])209 docinfo['year']=getTextFromNode(dom.xpath("//bib/%s"%hash['year'][0])[0])175 bibtype="generic" 176 bibtype=bibtype.replace("-"," ") # wrong typesiin index meta "-" instead of " " (not wrong! ROC) 177 bibmap=metaData.generateMappingForType(bibtype) 178 if len(bibmap) > 0: 179 docinfo['author']=getTextFromNode(dom.xpath("//bib/%s"%bibmap['author'][0])[0]) 180 docinfo['title']=getTextFromNode(dom.xpath("//bib/%s"%bibmap['title'][0])[0]) 181 docinfo['year']=getTextFromNode(dom.xpath("//bib/%s"%bibmap['year'][0])[0]) 210 182 211 183 return docinfo … … 243 215 pt=getParamFromDigilib(image,'size') 244 216 docinfo['imagePath'] = image 245 docinfo['num berOfPages'] = pt217 docinfo['numPages'] = pt 246 218 247 219 viewerUrls=dom.xpath("//texttool/digiliburlprefix") … … 269 241 path=path.replace("/mpiwg/online","") 270 242 pt=getParamFromDigilib(path,'size') 271 docinfo['num berOfPages'] = pt243 docinfo['numPages'] = pt 272 244 imageUrl=genericDigilib+"/servlet/Scaler?fn=%s"%path 273 245 docinfo['imageURL'] = imageUrl … … 300 272 301 273 302 def getPageinfo(self, start, current):274 def getPageinfo(self, current, start=None, rows=None, cols=None, docinfo=None): 303 275 """returns pageinfo with the given parameters""" 304 276 pageinfo = {} 277 current = getInt(current) 278 pageinfo['current'] = current 279 rows = int(rows or self.thumbrows) 280 pageinfo['rows'] = rows 281 cols = int(cols or self.thumbcols) 282 pageinfo['cols'] = cols 283 grpsize = cols * rows 284 pageinfo['groupsize'] = grpsize 285 start = getInt(start, default=(int(current / grpsize) * grpsize +1)) 286 print "start3:", start 305 287 pageinfo['start'] = start 306 pageinfo['current'] = current 288 pageinfo['end'] = start + grpsize 289 if docinfo is not None: 290 np = int(docinfo['numPages']) 291 pageinfo['end'] = min(pageinfo['end'], np) 292 pageinfo['numgroups'] = int(np / grpsize) 293 if np % grpsize > 0: 294 pageinfo['numgroups'] += 1 295 307 296 return pageinfo 308 297 … … 361 350 # 362 351 363 def image(self,mode,url,pn):364 """give image out"""365 if mode=="texttool": #index.meta with texttool information366 (viewerUrl,imagepath,textpath)=parseUrlTextTool(url)367 if not viewerUrl:368 viewerUrl=self.imageViewerUrl369 url=viewerUrl+"pn=%s&fn=%s"%(pn,imagepath[0])370 ret="""<iframe height="100%%" width="100%%" src="%s"/>"""%url371 return url372 elif mode=="imagepath":373 url=url.replace("/mpiwg/online","")374 url=self.imageViewerUrl+"pn=%s&fn=%s"%(pn,url)375 ret="""<iframe height="100%%" width="100%%" src="%s"/>"""%url376 return url377 378 379 352 def findDigilibUrl(self): 380 353 """try to get the digilib URL from zogilib""" … … 386 359 return None 387 360 388 def changeDocumentViewer(self,imageViewerUrl,title="",digilibBaseUrl=None, RESPONSE=None):361 def changeDocumentViewer(self,imageViewerUrl,title="",digilibBaseUrl=None,thumbrows=2,thumbcols=10,RESPONSE=None): 389 362 """init document viewer""" 390 363 self.title=title 391 364 self.imageViewerUrl=imageViewerUrl 392 365 self.digilibBaseUrl = digilibBaseUrl 366 self.thumbrows = thumbrows 367 self.thumbcols = thumbcols 393 368 394 369 if RESPONSE is not None: -
zpt/changeDocumentViewer.zpt
r24 r25 12 12 <p class="form-text">This information can be automatically detected if the image viewer above is a Zogilib instance.<br/> 13 13 You must clear this field when you change the image viewer URL above.</p> 14 <p class="form-optional">Thumbnail rows</p> 15 <p class="form-element"><input size="3" tal:attributes="value here/thumbrows | default" name="thumbrows"></p> 16 <p class="form-optional">Thumbnail columns</p> 17 <p class="form-element"><input size="3" tal:attributes="value here/thumbcols | default" name="thumbcols"></p> 14 18 15 19 <p><input type="submit" value="change"></p> -
zpt/thumbs_main.zpt
r22 r25 1 <div tal:define="cols python:2; rows python:10; docinfo python:options['docinfo']; pageinfo python:options['pageinfo']; start python:pageinfo['start']; end python:min(start+cols*rows,int(docinfo['numberOfPages'])); current pageinfo/current; rowsCorrected python:divmod(end-start,cols);"> 2 <span tal:replace="structure python:here.thumbruler(cols,rows,start,int(docinfo['numberOfPages']))"/> 3 1 <div tal:define="docinfo options/docinfo; pageinfo options/pageinfo; 2 start pageinfo/start; end pageinfo/end; rows pageinfo/rows; cols pageinfo/cols; 3 current pageinfo/current; grpsize pageinfo/groupsize"> 4 <div class="thumbruler"> 5 <span tal:condition="python:(start>1)"> 6 <a tal:attributes="href python:here.getLink(param='start',val=max(start-grpsize,1))"><</a> 7 </span> 8 <select tal:attributes="onChange python:'location.href=\'%s&start=\'+this.options[this.selectedIndex].value'%here.getLink(param='start',val=None)"> 9 <option tal:repeat="grp python:range(pageinfo['numgroups'])" 10 tal:attributes="selected python:(start==grp*grpsize+1); value python:(grp*grpsize+1)" 11 tal:content="python:(grp*grpsize+1)"/> 12 </select> 13 <span tal:condition="python:(start+grpsize<docinfo['numPages'])"> 14 <a tal:attributes="href python:here.getLink(param='start',val=start+grpsize)">></a> 15 </span> 16 </div> 4 17 <table> 5 <tr tal:repeat="i python:range(rowsCorrected[0])"> 6 <td align="center" tal:repeat="j python:range(start+i*cols,start+(i+1)*cols)" 7 tal:attributes="class python:here.getStyle(str(j+1),current,'thumb')"> 8 <a tal:attributes="href python:here.imageLink(j+1)"> 9 <img class="thumbimg" border="0" tal:attributes="src python:docinfo['imageURL']+'&pn=%i&dw=100&dh=100'%(j+1)"/> 10 <div class="thumbcap" tal:content="python:(j+1)"/> 18 <tr tal:repeat="row python:range(rows)"> 19 <tal:block tal:repeat="idx python:range(start+row*cols,start+(row+1)*cols)"> 20 <td align="center" tal:condition="python:(idx <= end)" 21 tal:attributes="class python:here.getStyle(idx,current,'thumb')"> 22 <a tal:attributes="href python:here.getLink(param='pn',val=idx)"> 23 <img class="thumbimg" border="0" tal:attributes="src python:'%s&pn=%d&dw=100&dh=100'%(docinfo['imageURL'],idx)"/> 24 <div class="thumbcap" tal:content="idx"/> 11 25 </a> 12 </td> 13 </tr> 14 <tr tal:condition="python:rowsCorrected[1]>0"> 15 <td align="center" tal:repeat="j python:range(start+cols*rowsCorrected[0],int(docinfo['numberOfPages']))" 16 tal:attributes="class python:here.getStyle(str(j+1),current,'thumb')"> 17 <a tal:attributes="href python:here.imageLink(j+1)"> 18 <img class="thumbimg" border="0" tal:attributes="src python:docinfo['imageURL']+'&pn=%i&dw=100&dh=100'%(j+1)"/> 19 <div class="thumbcap" tal:content="python:(j+1)"/> 20 </a> 21 </td> 22 </tr> 26 </td> 27 </tal:block> 28 </tr> 23 29 </table> 24 30 </div>
Note: See TracChangeset
for help on using the changeset viewer.