python-evince: how to search and highlight?



I tried to use the python-evince binding to do pdf search. But there were
nothing highlighted. I didn't know if the search failed or highlighting 
failed.

What I do was basically:

  eview.find_set_highlight_search(True)
  find_job = evince.JobFind(edoc, start_page=start, n_pages=n_pages,
      text=searchtext, case_sensitive=False)
  evince.job_scheduler_push_job(find_job, evince.JOB_PRIORITY_NONE)

What else need to be done to make the search works and result
highlighted? 

Attached is an sample program.
#!/usr/bin/python
# vim:ts=8:sw=4:expandtab:encoding=utf-8

import sys
import os
import gtk
import evince

def on_find_update(job, page):
    result = job.has_results()
    #print result

def main():
    if len(sys.argv) != 3:
        print 'Usage: %s file.pdf search_text' % sys.argv[0]
        return
    fname = sys.argv[1]
    searchtext = sys.argv[2]

    w = gtk.Window(); w.resize(500, 700)
    sw = gtk.ScrolledWindow(); w.add(sw)

    e = evince.View(); sw.add(e); w.show_all()

    dpi = gtk.settings_get_default().get_property('gtk-xft-dpi')/1024
    e.set_screen_dpi(dpi)
    e.props.sizing_mode = evince.SIZING_FREE

    e.find_set_highlight_search(True)

    url = 'file://' + fname
    doc = evince.factory_get_document(url)
    e.set_document(doc)

    cache = doc.get_page_cache()
    cache.set_current_page(0)
    
    start = 0; n_pages = doc.get_n_pages()

    print "Searching...", start, n_pages, searchtext

    find_job = evince.JobFind(doc, start_page=start, 
            n_pages=n_pages, text=searchtext, case_sensitive=False)
    #find_job.connect('updated', on_find_update)
    evince.job_scheduler_push_job(find_job, evince.JOB_PRIORITY_NONE)

    gtk.main()

if __name__ == '__main__':
    main()



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]