from gi.repository import Gtk
from gi.repository import EvinceDocument
from gi.repository import EvinceView

EvinceDocument.init()

doc =  EvinceDocument.Document.factory_get_document('file:///home/gonzalo/Desktop/Libros/La_gran_manzana.pdf')

def job_finished_cb(job):
    print 'Read links job finished. model class:', job.model.__class__

view = EvinceView.View()

model = EvinceView.DocumentModel()
model.set_document(doc)
view.set_model(model)

if not doc.has_document_links():
    print 'The pdf file does not have a index'
else:
    jl = EvinceView.JobLinks.new(document=doc)
    jl.connect('finished', job_finished_cb)
    EvinceView.Job.scheduler_push_job(jl, EvinceView.JobPriority.PRIORITY_NONE)

win = Gtk.Window()
scrolled = Gtk.ScrolledWindow()
win.add(scrolled)
scrolled.add_with_viewport(view)

win.set_default_geometry(200, 300)
win.connect("destroy", Gtk.main_quit)

win.show_all()
Gtk.main()

