本文介绍了嵌入evince Python GI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过使用gi存储库将它嵌入到Python中来查看pdf文档。我正在尝试

 #!/ usr / bin / env python 

from gi.repository import gtk,gio
from gi.repository import EvinceDocument
from gi.repository import EvinceView
$ b $ 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)
$ b $ if if __name__ ==__main__:
app = HelloWorldApp()
app.run无)

但是我收到错误

  Traceback(最近一次调用最后一次):
在on_activate
doc = EvinceDocument.Document.factory_get_document('file :///home/user/test.pdf')
AttributeError:类型对象'Document'没有属性'factory_get_document'

显然没有'factory_get_document'方法。那么替代方案是什么......?如何使用python和gtk + 3嵌入pdf文档...?

解决方案

您需要更新版本的Evince。



在最新的Evince 3.3.3.1中,使用Fedora 17(rawhide),并且在使用Fedora 16的Evince 3.2.1中不起作用。 p>

也许你可以编译Evince来让绑定工作。


I want to view a pdf document by embedding it in Python using the gi repository. I am trying to follow the code here which is

#!/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)

But I get the error

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'

It is obvious that there is no 'factory_get_document' method. What then is the alternative...? How can one embed a pdf document using python and gtk+3...?

解决方案

You need a newer version of Evince.

This is working for me in latest Evince, 3.3.3.1, using Fedora 17 (rawhide), and is not working in Evince 3.2.1 using Fedora 16.

Maybe you can compile Evince to get the bindings working.

这篇关于嵌入evince Python GI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 03:46