PyQt Application Development On Maemo

download PyQt Application Development On Maemo

If you can't read please download the document

Transcript of PyQt Application Development On Maemo

Slide 1

PyQt application development on Maemo

Attila [email protected] on talk.maemo.org

Components

Python

Qt

Python

Object oriented rapid prototyping languageNot just for scriptingEasy to read and learn, almost like pseudo-codeSuitable as first languageExtensible (add new modules) - C/C++/whateverEmbeddable in applicationsOpen Source License (OSI Certified)MatureLarge userbase and user communityPlenty of good documentation and books

Qt

Cross platform framework (Win/Mac/X11, soon S60)Native look and feelModular (Core, GUI, Network, OpenGL, SQL, WebKit, etc)MatureInternationalizationExcellent documentationAvailable under both commercial and Open Source licenses


Linux (Debian) based software platformDeveloped by NokiaOptimized for pocketable devicesCurrent (Maemo 5) UI based on GTK+/HildonNext generation UI (Maemo 6) based on Qt

How to connect these components ?

PyQt

PyMaemo

Maemo Qt4

PyMaemo

python-mafw - Python bindings for the Media Application Frameworkpython-hildondesktop - Python bindings for the home/status widgets APIpython-notify - Python bindings for libnotifypyclutter (0.8.0-1maemo2) - Python bindings for the Clutter API gnome-python (2.26.1-1maemo1)pygtk (2.12.1-6maemo7)pygamegst0.10-python - GStreamerpython-central (0.6.11.1maemo1)python-ossopython-hildon (0.9.0-1maemo10)etc...

http://pymaemo.garage.maemo.org

Current PyMaemo (Python for Maemo) is based on Python 2.5.4

Python Qt Bindings API Compatible !

PyQtimport PyQt4IndependentCommercial and GPLMatureQt3 and Qt4Binding generator: SIPMultiplatform (Win/Mac/Linux)Supports Pythons 2.3 - 3.1

PySideimport PySideNokia SponsoredLGPLNewQt4Boost::Python and ShibokenCurrently Linux only will be multiplatformPython 2.5-2.6Considerably larger disk and memory footprint

http://www.riverbankcomputing.co.uk

http://www.pyside.org

Maemo Qt4

Based on Linux/X11 version of QtHildon IM as default Input methodNative stylingHardcoded Keys in QMainWindow (Fullscreen, Menu, Zoom)Widget/QObject special properties...

http://qt4.garage.maemo.org

Maemo Qt API applies to PyQt applications, too !http://wiki.maemo.org/Qt4_Hildon#Maemo_Qt_API_Reference

Hello world

from PyQt4 import QtGui

import sys

app = QtGui.QApplication(sys.argv)

label = QtGui.QLabel(Hello world !)

label.show()

sys.exit(app.exec_())

More examples, tutorials

Official tutorials and examples have been ported from C++ to Python

python-qt4-dochttp://www.riverbankcomputing.co.uk/static/Downloads/PyQt4/PyQt-win-gpl-4.6.zip(in examples dir)

pyside-exampleshttp://qt.gitorious.org/pyside/pyside-examples/archive-tarball/master (tar.gz archive)

Integrated Development Environments

You already have a favourite Python IDE ? Use it !Multiplatform means you can use anything, Eric4, IDLE, Komodo, SPE...Downside Maemo specific APIs or modules are difficult to test

On device developmentGeanyiPython

Maemo oriented (can run and debug applications directly on a maemo device)

Eclipse (pluthon)

WingIDE Pro/OSS

PluThon

Three layers

Eclipse platform - popular and extensible framework for developing IDEs, http://www.eclipse.org

Maemo IDE Common Architecture (MICA), a plugin framework supporting both the ESbox and PluThon products, which provides an extensible platform for Maemo development (http://mica.garage.maemo.org/2nd_edition/):Unified project model, with C/C++ and Python implementationsLinux development (e.g. Debian packaging)Support for copying files or mounting a project to run, debug, and profile programs on Maemo devices

PluThon product - a targeted set of product plugins, providing the top-level project and import wizards, this help, graphics, and user interface modifications giving Pluthon its unique feel as a product.

http://pluthon.garage.maemo.org

PluThon

In PluThon 2nd edition, you can:Run on latest Ubuntu distribution, Windows XP/Vista and Mac OS X Leopard (Intel)

Easily connect to your device with predefined connections for USB, WLAN, and Bluetooth

SBRSH host support

Explore your device using the Remote System Explorer

Generate and install Debian packages

Templates for the most common type of maemo applications

Develop application directly on the Internet Tablet

Debug application on the Internet Tablet

Convert projects for PluThon or create new PluThon projects

Run PlutThon applications directly on Internet Tablet, through SSH and SCP, transparently

View the output of the application on the Console View

Profile applications with OProfile

Trace library and system calls with Ltrace

Pluthon in action

PluThon problems ?

Do you have Java installed ?Check Python version best if matching (=2.5)Have you installed maemo-pc-connectivity on the tablet ?Have you installed x11vnc on the tablet ?

Pyqtoreader

100% PyQtMultithreaded'Online' mindsetPlugin orientedQGraphicsView based

Pyqtoreader ebook mode

Maemo PyQt application considerations

Startup timeExecution speedSizePackaging

Startup time

C++ example startup: 3.48 sec

First run of python version: 7.6 sec

Subsequent runs: 6.5 sec

Using loader script: 5.8 sec

Startup time

Using a loader script

def main(): app = QtGui.QApplication(sys.argv) scene = QtGui.QGraphicsScene() view = QtGui.QGraphicsView(scene)... view.show() sys.exit(app.exec_())

app = QtGui.QApplication(sys.argv) scene = QtGui.QGraphicsScene()view = QtGui.QGraphicsView(scene)...view.show() sys.exit(app.exec_())

app.py

loader.py

app.py

import appapp.main()

Execution speed

How does native C++ code compare to Python ?

C++

Python

Execution speed

If not thought through, can be significatly slower is there a solution ?Use Qt calls and objects whenever possibleAvoid conversions between Python and Qt objects (like str vs QString)Avoid Python slots on high frequency callsUse OpenGL ES acceleration if availableIf still not good enough, use external code for critical functions

Execution speed

class quickQGraphicsView(QGraphicsView): def __init__(self, *arg): QGraphicsView.__init__(self, *arg) try: from PyQt4.QtOpenGL import QGLWidget glwidget = QGLWidget() if glwidget.isValid(): self.setViewport(glwidget) except Exception, e: logging.warning("OpenGL acceleration not available\n%s", e)

Don't need to know OpenGL ES to use hardware acceleration !

Application size

Python source is compact, your packages will be smallUsers need to download bindings (all modules ~50 MB)Use native format resources (jpg/png)

Deployment

Copy

PY2DEB

setup.py

Why choose Python + Qt on Maemo ?

No scratchbox neededNo SDK neededMultiplatform (win/mac/linux)No cross-compilationIDE supportNot niche technology

Fast development cycleFirst class Qt citizenFuture proofWell documentedAlready has a vibrant communityPython is fun !

Why NOT choose Python + QT on Maemo

Every last drop of CPU performance neededMemory requirementsStartup time is criticalUsing libraries without proper bindings

Questions ?

Thank you !


PyQt application development on Maemo

Attila [email protected] on talk.maemo.org

Company Confidential