changeset 591:5850689ecfac

ocrsearch layer for images.
author casties
date Fri, 16 Nov 2012 13:41:02 +0100
parents ed4485d2748e
children d6bfaea5bdf9
files documentViewer.py version.txt zpt/layer_image_ocrsearch.zpt
diffstat 3 files changed, 72 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/documentViewer.py	Fri Nov 16 11:44:21 2012 +0100
+++ b/documentViewer.py	Fri Nov 16 13:41:02 2012 +0100
@@ -66,6 +66,14 @@
     
     return default
 
+def getPfForPn(docinfo, pn, default=None):
+    """returns image file name for image number or default"""
+    if 'imgFileIndexes' in docinfo:
+        pn = docinfo['imgFileIndexes'].get(pn, default)
+        return pn
+    
+    return default
+
 
 ##
 ## documentViewer class
@@ -104,6 +112,7 @@
     layer_text_gis = PageTemplateFile('zpt/layer_text_gis', globals())
     layer_text_pundit = PageTemplateFile('zpt/layer_text_pundit', globals())
     layer_image_annotator = PageTemplateFile('zpt/layer_image_annotator', globals())
+    layer_image_ocrsearch = PageTemplateFile('zpt/layer_image_ocrsearch', globals())
     layer_index_extended = PageTemplateFile('zpt/layer_index_extended', globals())
     # toc templates
     toc_thumbs = PageTemplateFile('zpt/toc_thumbs', globals())
@@ -777,12 +786,15 @@
             
         # save list of image names and numbers
         imgNames = {}
+        imgIndexes = {}
         for f in dir:
             fn = f.findtext('name')
-            pn = f.findtext('index')
-            imgNames[fn] = getInt(pn)
+            pn = getInt(f.findtext('index'))
+            imgNames[fn] = pn
+            imgIndexes[pn] = fn
             
         docinfo['imgFileNames'] = imgNames
+        docinfo['imgFileIndexes'] = imgIndexes
         return docinfo
             
             
@@ -848,6 +860,8 @@
             self.REQUEST.form['pn'] = pn
         else:
             pn = getInt(pn, 1)
+            pf = getPfForPn(docinfo, pn)
+            pageinfo['pf'] = pf
             
         pageinfo['pn'] = pn
         rows = int(rows or self.thumbrows)
@@ -890,10 +904,10 @@
                 pageinfo['pageNumberOrigNorm'] = pageNumber['non']
         
         # cache search results
-        pageinfo['resultPageSize'] = getInt(self.REQUEST.get('resultPageSize', 10))
         query = self.REQUEST.get('query',None)
         pageinfo['query'] = query
-        if query:
+        if query and viewMode == 'text':
+            pageinfo['resultPageSize'] = getInt(self.REQUEST.get('resultPageSize', 10))
             queryType = self.REQUEST.get('queryType', 'fulltextMorph')
             pageinfo['queryType'] = queryType
             pageinfo['resultStart'] = getInt(self.REQUEST.get('resultStart', '1'))
@@ -910,7 +924,7 @@
 
 
     def getPageBatch(self, start=1, rows=10, cols=2, pageFlowLtr=True, pageZero=False, minIdx=1, maxIdx=0):
-        """returns dict with array of page informations for one screenfull of thumbnails"""
+        """returns dict with array of page information for one screenfull of thumbnails"""
         batch = {}
         grpsize = rows * cols
         if maxIdx == 0:
--- a/version.txt	Fri Nov 16 11:44:21 2012 +0100
+++ b/version.txt	Fri Nov 16 13:41:02 2012 +0100
@@ -1,1 +1,1 @@
-DocumentViewer 2.2.8
\ No newline at end of file
+DocumentViewer 2.2.9
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/zpt/layer_image_ocrsearch.zpt	Fri Nov 16 13:41:02 2012 +0100
@@ -0,0 +1,52 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<metal:block metal:define-macro="html_head" tal:condition="python:'ocrsearch' in viewLayers">
+  <!--  ocrsearch for digilib -->
+  <script type="text/javascript" tal:attributes="src string:$dlBaseUrl/jquery/showdown.js"></script>
+  <script type="text/javascript" tal:attributes="src string:$dlBaseUrl/jquery/annotator-dl.js"></script>
+  <script type="text/javascript" tal:attributes="src string:$dlBaseUrl/jquery/jquery.digilib.annotator.js"></script>
+  <link rel="stylesheet" type="text/css" tal:attributes="href string:$dlBaseUrl/jquery/annotator.min.css"/>
+
+  <script type="text/javascript" 
+    tal:define="global annServerUrl string:http://tuxserve03.mpiwg-berlin.mpg.de/AnnotationManager;
+    global query pageinfo/query | nothing;
+    annUri docinfo/documentPath;
+    annPf pageinfo/pf | nothing;"
+    tal:content="structure string:
+    dlOpts.digilibFrontendPath='/jquery/digilib-ann.html';
+    dlOpts.annotationServerUrl='$annServerUrl/annotator';
+    dlOpts.annotationsReadOnly=true;
+    dlOpts.annotatorPlugins=['Store','Markdown','DigilibIntegrator'];
+    dlOpts.annotatorPluginSettings={'Store':{'loadFromSearch':{'uri':'$annUri','pf':'$annPf','query':'$query'}}};
+    "></script>
+</metal:block>
+
+</head>
+<body>
+  <!-- right-side options -->
+  <div class="col buttons">
+    <!-- LAYER DISPLAY OPTION  -->
+    <ul>
+      <li metal:define-macro="layer_select_li">
+        <input type="checkbox" class="autosubmit" name="viewLayer" value="ocrsearch"
+          tal:attributes="checked python:'ocrsearch' in viewLayers" /> Search results
+      </li>
+    </ul>
+  </div>
+
+  <metal:block metal:define-macro="options_box" tal:condition="python:'ocrsearch' in viewLayers">
+    <!-- BEGIN OCRSEARCH -->
+    <div class="options">
+      <h4>OCR Search</h4>
+      <p>
+        Query: "<span tal:replace="query"/>".
+      </p>
+    </div>
+    <!-- END OCRSEARCH -->
+  </metal:block>
+
+</body>
+
+</html>