2012-01-20 36 views
1

我想通過使用gi存儲庫將它嵌入到Python中來查看pdf文檔。我試圖按照代碼here這是嵌入顯示Python GI

#!/usr/bin/env python 

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

class HelloWorldApp(Gtk.Application): 
    def __init__(self): 
     Gtk.Application.__init__(self, application_id="apps.test.helloevince", flags=Gio.ApplicationFlags.FLAGS_NONE) 
     self.connect("activate", self.on_activate) 

    def on_activate(self, data=None): 
     window = Gtk.Window(type=Gtk.WindowType.TOPLEVEL) 
     window.set_title("Evince Gtk3 Python Example") 
     window.set_border_width(24) 
     scroll = Gtk.ScrolledWindow() 
     window.add(scroll) 
     EvinceDocument.init() 
     doc = EvinceDocument.Document.factory_get_document('file:///home/user/test.pdf') 
     view = EvinceView.View() 
     model = EvinceView.DocumentModel() 
     model.set_document(doc) 
     view.set_model(model) 
     scroll.add(view) 
     window.show_all() 
     self.add_window(window) 

if __name__ == "__main__": 
    app = HelloWorldApp() 
    app.run(None) 

但我得到的錯誤

Traceback (most recent call last): 
    File "./pdfViewer_pygi.py", line 19, in on_activate 
    doc = EvinceDocument.Document.factory_get_document('file:///home/user/test.pdf') 
AttributeError: type object 'Document' has no attribute 'factory_get_document' 

很明顯,沒有「factory_get_document」的方法。那麼替代方案是什麼......?如何使用python和gtk + 3嵌入pdf文檔...?

回答

1

您需要更新版本的Evince。

這是爲我工作在最新的了Evince,3.3.3.1,使用的Fedora 17(生皮),並在3.2.1了Evince使用的Fedora 16

也許你可以編譯了Evince獲得綁定不工作加工。

+0

謝謝。我在Ubuntu 11.10上顯示3.2版本。除了從源代碼編譯以外,我沒有看到一個簡單的方法來獲得版本3.3。 –