Download presentation
Presentation is loading. Please wait.
Published byRoberta Shields Modified over 6 years ago
1
PyKDE Tutorial Jonathan Riddell Ubuntu, KDE, Canonical
March 2011 | Bengaluru, India | conf.kde.in
2
Jonathan Riddell, Canonical
Python, Qt, Kubuntu Python Programming Language, Popular, not compiled, dynamic typing, easy, used by Ubuntu Qt GUI programming library, used by KDE, easy to learn, well documented, cross platform Kubuntu Awesome KDE based Linux distro from Ubuntu Conf.kde.in 2011 Jonathan Riddell, Canonical
3
First Python Application
#!/usr/bin/python # coding: UTF-8 print "ಹಲೊ" Save to 1-hello.py python 1-hello.py Or chmod hello.py ./1-hello.py Conf.kde.in 2011 Jonathan Riddell, Canonical
4
Jonathan Riddell, Canonical
PyQt Application import sys from PyQt4.QtCore import * from PyQt4.QtGui import * from PyQt4.QtWebKit import * app = QApplication(sys.argv) web = QWebView() web.load(QUrl(" web.show() sys.exit(app.exec_()) Conf.kde.in 2011 Jonathan Riddell, Canonical
5
Jonathan Riddell, Canonical
PyKDE Application from PyKDE4.kdecore import * from PyKDE4.kdeui import * appName = "python-kde-tutorial" catalog = "" programName = ki18n("PyKDE Tutorial") version = "1.0" description = ki18n("A Small Qt WebKit Example") license = KAboutData.License_GPL copyright = ki18n("(c) 2008 Canonical Ltd") text = ki18n("none") homePage = " bug = "" aboutData = KAboutData (appName, catalog, programName, version, description, license, copyright, text, homePage, bug ) KCmdLineArgs.init(sys.argv, aboutData) app = KApplication() Conf.kde.in 2011 Jonathan Riddell, Canonical
6
PyKDE Object Orientated
Add this after the import lines: class Tutorial(object): def __init__(self): self.web = QWebView() self.web.load(QUrl(" self.web.show() Remove the QWebView lines after creating the KApplication add this: app = KApplication() tutorial = Tutorial() Conf.kde.in 2011 Jonathan Riddell, Canonical
7
Jonathan Riddell, Canonical
Use a Layout Replace the __init__ method with: self.widget = QWidget() layout = QVBoxLayout(self.widget) self.web = QWebView(self.widget) self.web.load(QUrl(" layout.addWidget(self.web) self.widget.show() Conf.kde.in 2011 Jonathan Riddell, Canonical
8
Jonathan Riddell, Canonical
Use a KMainWindow At top of the __init__ method: self.window = KMainWindow() self.widget = QWidget() self.window.setCentralWidget(self.widget) Instead of showing the widget self.window.show() Conf.kde.in 2011 Jonathan Riddell, Canonical
9
Jonathan Riddell, Canonical
Add the address bar Now we can add our address bar. After creating the layout add: self.addressBar = QLineEdit(self.widget) layout.addWidget(self.addressBar) Conf.kde.in 2011 Jonathan Riddell, Canonical
10
Jonathan Riddell, Canonical
Use a Layout Below self.window.show() add this connect line and the following method: QObject.connect(self.addressBar, SIGNAL("returnPressed()"), self.loadUrl) def loadUrl(self): print "Loading " + self.addressBar.text() self.web.load( QUrl(self.addressBar.text()) ) Conf.kde.in 2011 Jonathan Riddell, Canonical
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.