How to use KDE Okular's document view widget in a Python Qt app?

前提是你 提交于 2019-12-10 23:12:17

问题


I am writing a desktop application in Python (3.4) on Linux using Qt (4.8) and PyQt.

Is there a way to use/import Okular's pdf view functionality as a widget? If yes, how?


回答1:


This works for me:

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_()



回答2:


pykde could provide the required functionality. I have not figured out how, though.


Get the latest version of pykde:

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

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

Building it required PyQt4 and CMAKE. Some linux distributions ship an outdated version of FindPyQt.py (causing an error along the lines of Python importerror : pyqtconfig). A functional one can be found here:
https://github.com/qgis/QGIS/blob/master/cmake/FindPyQt.py
Place it in /usr/share/kde4/apps/cmake/modules/

For compiling your UI files into Python code, use pykdeuic4 instead of pyuic4:

pykdeuic4 file.ui > file.py


来源:https://stackoverflow.com/questions/32974374/how-to-use-kde-okulars-document-view-widget-in-a-python-qt-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!