如何在Python Qt应用程序中使用KDE Okular的文档视图小部件?

时间:2015-10-06 15:55:26

标签: python pyqt kde pykde okular

我正在使用Qt(4.8)和PyQt在Linux上用Python(3.4)编写桌面应用程序。

有没有办法使用/导入Okular的pdf视图功能作为小部件?如果是,怎么样?

2 个答案:

答案 0 :(得分:3)

这对我有用:

import sys
from PyKDE4.kdecore import ki18n, KAboutData, KCmdLineArgs
from PyKDE4.kdecore import KLibLoader as ll
from PyKDE4.kdeui import KApplication
import PyKDE4.kparts as kp


appName     = "KApplication"
catalog     = ""
programName = ki18n ("KApplication")
version     = "1.0"
description = ki18n ("KApplication")
license     = KAboutData.License_GPL
copyright   = ki18n ("(c) 2007 John Doe")
text        = ki18n ("none")
homePage    = "www.johndoe.com"
bugEmail    = "johndoe@nowhere.com "

aboutData   = KAboutData(
    appName, catalog, programName, version, description,
    license, copyright, text, homePage, bugEmail
)

KCmdLineArgs.init( sys.argv, aboutData)

app = KApplication()
win= kp.KParts.MainWindow()
okupart= ll.self().factory( 'okularpart').create()
win.setCentralWidget( okupart.widget())
win.show()

app.exec_()

答案 1 :(得分:-1)

pykde 可以提供所需的功能。不过,我还没弄明白。

获取最新版本的pykde:

git clone git://anongit.kde.org/pykde4

文件:
https://techbase.kde.org/Development/Languages/Python
http://api.kde.org/pykde-4.3-api/install.html

构建它需要PyQt4和CMAKE。一些Linux发行版发布了一个过时的FindPyQt.py版本(导致Python importerror : pyqtconfig行的错误)。功能可以在这里找到:
https://github.com/qgis/QGIS/blob/master/cmake/FindPyQt.py
将其放在/ usr / share / kde4 / apps / cmake / modules /

要将UI文件编译为Python代码,请使用pykdeuic4而不是pyuic4:

pykdeuic4 file.ui > file.py