PyQt for Desktop and Embedded Devices - … · PyQt for Desktop and Embedded Devices David Boddie ...
Transcript of PyQt for Desktop and Embedded Devices - … · PyQt for Desktop and Embedded Devices David Boddie ...
![Page 1: PyQt for Desktop and Embedded Devices - … · PyQt for Desktop and Embedded Devices David Boddie PyCon Tre, Firenze, 8th–10th May 2009 • Not just](https://reader030.fdocuments.us/reader030/viewer/2022021622/5b99afe009d3f29c338cc09a/html5/thumbnails/1.jpg)
PyQt for Desktop and Embedded Devices
David Boddie<[email protected]>
PyCon Tre, Firenze, 8th–10th May 2009
![Page 2: PyQt for Desktop and Embedded Devices - … · PyQt for Desktop and Embedded Devices David Boddie PyCon Tre, Firenze, 8th–10th May 2009 • Not just](https://reader030.fdocuments.us/reader030/viewer/2022021622/5b99afe009d3f29c338cc09a/html5/thumbnails/2.jpg)
• Not just a widget toolkit – other features
About Qt
• Also available under a Commercial License
• Linux, Windows, Mac OS X, other Unixes
• Available under the GPL (version 3)
• Cross-platform C++ framework
• Available under the LGPL (version 2·1)
• Developed by Qt Software (Nokia)
• Embedded Linux, Windows CE, Series 60
![Page 3: PyQt for Desktop and Embedded Devices - … · PyQt for Desktop and Embedded Devices David Boddie PyCon Tre, Firenze, 8th–10th May 2009 • Not just](https://reader030.fdocuments.us/reader030/viewer/2022021622/5b99afe009d3f29c338cc09a/html5/thumbnails/3.jpg)
• Also available under a Commercial License• Available under the GPL (version 2 and 3)
• Developed by Riverbank Computing Ltd.
• Includes most features of Qt
About PyQt
• Set of Python bindings to Qt
• Bindings are generated using SIP • Upcoming PyQt 4.5 will support Python 3
![Page 4: PyQt for Desktop and Embedded Devices - … · PyQt for Desktop and Embedded Devices David Boddie PyCon Tre, Firenze, 8th–10th May 2009 • Not just](https://reader030.fdocuments.us/reader030/viewer/2022021622/5b99afe009d3f29c338cc09a/html5/thumbnails/4.jpg)
QtGuiQtDesigner
QtHelp
QtCore
QtOpenGL
QtScript QtSql QtSvg
QtNetwork
QtWebKit QtXmlPatterns Phonon
PyQt exposes many of Qt's 21 modules.
PyQt Modules
We'll take a quick look at these:
![Page 5: PyQt for Desktop and Embedded Devices - … · PyQt for Desktop and Embedded Devices David Boddie PyCon Tre, Firenze, 8th–10th May 2009 • Not just](https://reader030.fdocuments.us/reader030/viewer/2022021622/5b99afe009d3f29c338cc09a/html5/thumbnails/5.jpg)
QtGuiQtDesigner
QtHelp
QtCore
QtOpenGL
QtScript QtSql QtSvg
QtNetwork
QtWebKit QtXmlPatterns Phonon
PyQt exposes many of Qt's 21 modules.
PyQt Modules
We'll take a quick look at these:
![Page 6: PyQt for Desktop and Embedded Devices - … · PyQt for Desktop and Embedded Devices David Boddie PyCon Tre, Firenze, 8th–10th May 2009 • Not just](https://reader030.fdocuments.us/reader030/viewer/2022021622/5b99afe009d3f29c338cc09a/html5/thumbnails/6.jpg)
import sysfrom PyQt4.QtGui import *
app = QApplication(sys.argv)
checkBox = QCheckBox("C&ase sensitive")checkBox.show()
pushButton = QPushButton("Cancel")pushButton.show()
calendar = QCalendarWidget()calendar.show()
sys.exit(app.exec_())
Graphical User Interfaces
QComboBox
PyQt includes a comprehensive set of widgets:
QSpinBox
QPushButton QSlider QRadioButton
QCheckBox
QCalendarWidget QTableWidget QTextEdit
![Page 7: PyQt for Desktop and Embedded Devices - … · PyQt for Desktop and Embedded Devices David Boddie PyCon Tre, Firenze, 8th–10th May 2009 • Not just](https://reader030.fdocuments.us/reader030/viewer/2022021622/5b99afe009d3f29c338cc09a/html5/thumbnails/7.jpg)
import sysfrom PyQt4.QtGui import *
app = QApplication(sys.argv)
checkBox = QCheckBox("C&ase sensitive")checkBox.show()
pushButton = QPushButton("Cancel")pushButton.show()
calendar = QCalendarWidget()calendar.show()
sys.exit(app.exec_())
Graphical User Interfaces
QComboBox
PyQt includes a comprehensive set of widgets:
QSpinBox
QPushButton QSlider QRadioButton
QCheckBox
QCalendarWidget QTableWidget QTextEdit
![Page 8: PyQt for Desktop and Embedded Devices - … · PyQt for Desktop and Embedded Devices David Boddie PyCon Tre, Firenze, 8th–10th May 2009 • Not just](https://reader030.fdocuments.us/reader030/viewer/2022021622/5b99afe009d3f29c338cc09a/html5/thumbnails/8.jpg)
self.fieldCombo = QComboBox() self.fieldCombo.addItems(["name", "version", "author", "author_email", "maintainer", "maintainer_email", "home_page", "license", "summary", "description", "keywords", "platform", "download_url"]) self.termsEdit = QLineEdit()
layout = QFormLayout() layout.addRow(self.tr("Search &field:"), self.fieldCombo) layout.addRow(self.tr("Search &terms:"), self.termsEdit)
class PyPIWidget(QWidget):
def __init__(self, parent = None):
QWidget.__init__(self, parent)
self.treeWidget = QTreeWidget() self.treeWidget.setAlternatingRowColors(True) self.treeWidget.setRootIsDecorated(False) self.treeWidget.setHeaderLabels( [self.tr("Name"), self.tr("Description")])
mainLayout = QVBoxLayout() mainLayout.addLayout(layout) mainLayout.addWidget(self.treeWidget) self.connect(self.termsEdit, SIGNAL("returnPressed()"), self.search)
Widgets and Layouts
![Page 9: PyQt for Desktop and Embedded Devices - … · PyQt for Desktop and Embedded Devices David Boddie PyCon Tre, Firenze, 8th–10th May 2009 • Not just](https://reader030.fdocuments.us/reader030/viewer/2022021622/5b99afe009d3f29c338cc09a/html5/thumbnails/9.jpg)
self.fieldCombo = QComboBox() self.fieldCombo.addItems(["name", "version", "author", "author_email", "maintainer", "maintainer_email", "home_page", "license", "summary", "description", "keywords", "platform", "download_url"]) self.termsEdit = QLineEdit()
layout = QFormLayout() layout.addRow(self.tr("Search &field:"), self.fieldCombo) layout.addRow(self.tr("Search &terms:"), self.termsEdit)
class PyPIWidget(QWidget):
def __init__(self, parent = None):
QWidget.__init__(self, parent)
self.treeWidget = QTreeWidget() self.treeWidget.setAlternatingRowColors(True) self.treeWidget.setRootIsDecorated(False) self.treeWidget.setHeaderLabels( [self.tr("Name"), self.tr("Description")])
mainLayout = QVBoxLayout() mainLayout.addLayout(layout) mainLayout.addWidget(self.treeWidget) self.connect(self.termsEdit, SIGNAL("returnPressed()"), self.search)
Widgets and Layouts
![Page 10: PyQt for Desktop and Embedded Devices - … · PyQt for Desktop and Embedded Devices David Boddie PyCon Tre, Firenze, 8th–10th May 2009 • Not just](https://reader030.fdocuments.us/reader030/viewer/2022021622/5b99afe009d3f29c338cc09a/html5/thumbnails/10.jpg)
self.fieldCombo = QComboBox() self.fieldCombo.addItems(["name", "version", "author", "author_email", "maintainer", "maintainer_email", "home_page", "license", "summary", "description", "keywords", "platform", "download_url"]) self.termsEdit = QLineEdit()
layout = QFormLayout() layout.addRow(self.tr("Search &field:"), self.fieldCombo) layout.addRow(self.tr("Search &terms:"), self.termsEdit)
class PyPIWidget(QWidget):
def __init__(self, parent = None):
QWidget.__init__(self, parent)
self.treeWidget = QTreeWidget() self.treeWidget.setAlternatingRowColors(True) self.treeWidget.setRootIsDecorated(False) self.treeWidget.setHeaderLabels( [self.tr("Name"), self.tr("Description")])
mainLayout = QVBoxLayout() mainLayout.addLayout(layout) mainLayout.addWidget(self.treeWidget) self.connect(self.termsEdit, SIGNAL("returnPressed()"), self.search)
Widgets and Layouts
![Page 11: PyQt for Desktop and Embedded Devices - … · PyQt for Desktop and Embedded Devices David Boddie PyCon Tre, Firenze, 8th–10th May 2009 • Not just](https://reader030.fdocuments.us/reader030/viewer/2022021622/5b99afe009d3f29c338cc09a/html5/thumbnails/11.jpg)
self.fieldCombo = QComboBox() self.fieldCombo.addItems(["name", "version", "author", "author_email", "maintainer", "maintainer_email", "home_page", "license", "summary", "description", "keywords", "platform", "download_url"]) self.termsEdit = QLineEdit()
layout = QFormLayout() layout.addRow(self.tr("Search &field:"), self.fieldCombo) layout.addRow(self.tr("Search &terms:"), self.termsEdit)
class PyPIWidget(QWidget):
def __init__(self, parent = None):
QWidget.__init__(self, parent)
self.treeWidget = QTreeWidget() self.treeWidget.setAlternatingRowColors(True) self.treeWidget.setRootIsDecorated(False) self.treeWidget.setHeaderLabels( [self.tr("Name"), self.tr("Description")])
mainLayout = QVBoxLayout() mainLayout.addLayout(layout) mainLayout.addWidget(self.treeWidget) self.connect(self.termsEdit, SIGNAL("returnPressed()"), self.search)
Widgets and Layouts
![Page 12: PyQt for Desktop and Embedded Devices - … · PyQt for Desktop and Embedded Devices David Boddie PyCon Tre, Firenze, 8th–10th May 2009 • Not just](https://reader030.fdocuments.us/reader030/viewer/2022021622/5b99afe009d3f29c338cc09a/html5/thumbnails/12.jpg)
The Graphics View framework provides a canvas:
Graphics View
• Animation
• Printing
• Interactive items (drag and drop)• Nested items and groups
• OpenGL rendering• Embedded widgets
![Page 13: PyQt for Desktop and Embedded Devices - … · PyQt for Desktop and Embedded Devices David Boddie PyCon Tre, Firenze, 8th–10th May 2009 • Not just](https://reader030.fdocuments.us/reader030/viewer/2022021622/5b99afe009d3f29c338cc09a/html5/thumbnails/13.jpg)
def play(self):
if self.player.isPlaying(): self.player.stop() else: url = QUrl(self.urlEdit.text()) self.player.play(MediaSource(url))
class Player(QWidget):
def __init__(self, parent = None):
QWidget.__init__(self, parent)
self.player = VideoPlayer(VideoCategory)
# ...
Multimedia Support
Phonon handles audio and video:
![Page 14: PyQt for Desktop and Embedded Devices - … · PyQt for Desktop and Embedded Devices David Boddie PyCon Tre, Firenze, 8th–10th May 2009 • Not just](https://reader030.fdocuments.us/reader030/viewer/2022021622/5b99afe009d3f29c338cc09a/html5/thumbnails/14.jpg)
<sun rise="2009-05-01T05:32:17" set="2009-05-01T20:23:58" /><forecast> <tabular> <time from="2009-05-01T06:00:00" to="2009-05-01T12:00:00" period="1"> <symbol number="2" name="Fair" /> <precipitation value="0.0" /> <windDirection deg="114.6" code="ESE" name="East-southeast" /> <windSpeed mps="0.8" name="Light air" /> <temperature unit="celcius" value="8" /> <pressure unit="hPa" value="1022.2" /> </time> ...declare variable $url external;(string(doc($url)//sun/@rise),string(doc($url)//sun/@set), for $time in doc($url)//tabular/timeorder by $time/@fromreturn (string($time/@from), string($time/symbol/@name), string($time/symbol/@number), string($time/temperature/@value), string($time/temperature/@unit)))
def fetchForecast(self, place):
url = "http://www.yr.no/place/" + \ place + "/forecast.xml"
b = QBuffer() b.setData(query_string) b.open(QBuffer.ReadOnly)
query = QXmlQuery() query.bindVariable("url", QXmlItem(QVariant(url))) query.setQuery(b) b.close()
if query.isValid():
self.results.clear() query.evaluateTo(self.results) self.updateTable()
XML Processing
Use XPath, XQuery and XSLT to process XML:
Could be useful if combined with GPS...
![Page 15: PyQt for Desktop and Embedded Devices - … · PyQt for Desktop and Embedded Devices David Boddie PyCon Tre, Firenze, 8th–10th May 2009 • Not just](https://reader030.fdocuments.us/reader030/viewer/2022021622/5b99afe009d3f29c338cc09a/html5/thumbnails/15.jpg)
<sun rise="2009-05-01T05:32:17" set="2009-05-01T20:23:58" /><forecast> <tabular> <time from="2009-05-01T06:00:00" to="2009-05-01T12:00:00" period="1"> <symbol number="2" name="Fair" /> <precipitation value="0.0" /> <windDirection deg="114.6" code="ESE" name="East-southeast" /> <windSpeed mps="0.8" name="Light air" /> <temperature unit="celcius" value="8" /> <pressure unit="hPa" value="1022.2" /> </time> ...declare variable $url external;(string(doc($url)//sun/@rise),string(doc($url)//sun/@set), for $time in doc($url)//tabular/timeorder by $time/@fromreturn (string($time/@from), string($time/symbol/@name), string($time/symbol/@number), string($time/temperature/@value), string($time/temperature/@unit)))
def fetchForecast(self, place):
url = "http://www.yr.no/place/" + \ place + "/forecast.xml"
b = QBuffer() b.setData(query_string) b.open(QBuffer.ReadOnly)
query = QXmlQuery() query.bindVariable("url", QXmlItem(QVariant(url))) query.setQuery(b) b.close()
if query.isValid():
self.results.clear() query.evaluateTo(self.results) self.updateTable()
XML Processing
Use XPath, XQuery and XSLT to process XML:
Could be useful if combined with GPS...
![Page 16: PyQt for Desktop and Embedded Devices - … · PyQt for Desktop and Embedded Devices David Boddie PyCon Tre, Firenze, 8th–10th May 2009 • Not just](https://reader030.fdocuments.us/reader030/viewer/2022021622/5b99afe009d3f29c338cc09a/html5/thumbnails/16.jpg)
• JavaScript, SVG, CSS, SSL, etc.
WebKit is integrated into Qt:
Web Browser Engine
• Support for in-page editing• Python/C++ objects can be added to pages
• Web browser widget
• Support for Netscape and native Qt plugins• Control over browser settings and history
• Client-side storage
![Page 17: PyQt for Desktop and Embedded Devices - … · PyQt for Desktop and Embedded Devices David Boddie PyCon Tre, Firenze, 8th–10th May 2009 • Not just](https://reader030.fdocuments.us/reader030/viewer/2022021622/5b99afe009d3f29c338cc09a/html5/thumbnails/17.jpg)
• JavaScript, SVG, CSS, SSL, etc.
WebKit is integrated into Qt:
Web Browser Engine
• Support for in-page editing• Python/C++ objects can be added to pages
• Web browser widget
• Support for Netscape and native Qt plugins• Control over browser settings and history
• Client-side storage
![Page 18: PyQt for Desktop and Embedded Devices - … · PyQt for Desktop and Embedded Devices David Boddie PyCon Tre, Firenze, 8th–10th May 2009 • Not just](https://reader030.fdocuments.us/reader030/viewer/2022021622/5b99afe009d3f29c338cc09a/html5/thumbnails/18.jpg)
We can also use them on embedded hardware.
Intermission
These features are nice on the desktop!
![Page 19: PyQt for Desktop and Embedded Devices - … · PyQt for Desktop and Embedded Devices David Boddie PyCon Tre, Firenze, 8th–10th May 2009 • Not just](https://reader030.fdocuments.us/reader030/viewer/2022021622/5b99afe009d3f29c338cc09a/html5/thumbnails/19.jpg)
Embedded Platforms
• Different architectures• Limited storage (≈ 128MB)• Cut down environments
• Can be portable
• Cameras
• Accelerometers• Touch screens
• GSM, Wi-Fi, Bluetooth• GPS
Where is Embedded Linux used:
• Phones, media players
http://www.linuxdevices.com/
• GPS devices, Web tablets• Set top boxes• Routers, plug computing• Handhelds, toys, kit computing
• Qt runs on Embedded Linux, Windows CE, Series 60• Python runs on Embedded Linux, Windows CE, Series 60
• Windows CE?, Series 60?
Disadvantages: Advantages:• Small screens (≈ 240 × 320)• Low memory (≈ 64 MB)• Slow processors (≈ 300 MHz)• PyQt runs on Embedded Linux
![Page 20: PyQt for Desktop and Embedded Devices - … · PyQt for Desktop and Embedded Devices David Boddie PyCon Tre, Firenze, 8th–10th May 2009 • Not just](https://reader030.fdocuments.us/reader030/viewer/2022021622/5b99afe009d3f29c338cc09a/html5/thumbnails/20.jpg)
Embedded Platforms
• Different architectures• Limited storage (≈ 128MB)• Cut down environments
• Can be portable
• Cameras
• Accelerometers• Touch screens
• GSM, Wi-Fi, Bluetooth• GPS
Where is Embedded Linux used:
• Phones, media players
http://www.linuxdevices.com/
• GPS devices, Web tablets• Set top boxes• Routers, plug computing• Handhelds, toys, kit computing
• Qt runs on Embedded Linux, Windows CE, Series 60• Python runs on Embedded Linux, Windows CE, Series 60
• Windows CE?, Series 60?
Disadvantages: Advantages:• Small screens (≈ 240 × 320)• Low memory (≈ 64 MB)• Slow processors (≈ 300 MHz)• PyQt runs on Embedded Linux
![Page 21: PyQt for Desktop and Embedded Devices - … · PyQt for Desktop and Embedded Devices David Boddie PyCon Tre, Firenze, 8th–10th May 2009 • Not just](https://reader030.fdocuments.us/reader030/viewer/2022021622/5b99afe009d3f29c338cc09a/html5/thumbnails/21.jpg)
Embedded Platforms
• Different architectures• Limited storage (≈ 128MB)• Cut down environments
• Can be portable
• Cameras
• Accelerometers• Touch screens
• GSM, Wi-Fi, Bluetooth• GPS
Where is Embedded Linux used:
• Phones, media players
http://www.linuxdevices.com/
• GPS devices, Web tablets• Set top boxes• Routers, plug computing• Handhelds, toys, kit computing
• Qt runs on Embedded Linux, Windows CE, Series 60• Python runs on Embedded Linux, Windows CE, Series 60
• Windows CE?, Series 60?
Disadvantages: Advantages:• Small screens (≈ 240 × 320)• Low memory (≈ 64 MB)• Slow processors (≈ 300 MHz)• PyQt runs on Embedded Linux
![Page 22: PyQt for Desktop and Embedded Devices - … · PyQt for Desktop and Embedded Devices David Boddie PyCon Tre, Firenze, 8th–10th May 2009 • Not just](https://reader030.fdocuments.us/reader030/viewer/2022021622/5b99afe009d3f29c338cc09a/html5/thumbnails/22.jpg)
...
Embedded Python
Nice things about Python (2.x):
• Portable C implementation• Fairly small (compared to all the Qt libraries)• Few dependencies
Not so nice things about Python (2.x):
• Annoying to cross-compile (despite a good foundation)• Relies on a native interpreter at various points • Runs setup.py using the built interpreter • Needs a native interpreter to build a parser generator• Package-specific checks
• Batteries included (even old ones) • OpenSSL, Curses, pyexpat, Tkinter
Ways to build Python for Linux Devices:
• OpenEmbedded• Scratchbox
• Distribution packages (e.g., Debian)
• Buildroot• Crosstool
Used to create toolchains and/or whole systems.
Ways I built Python for Linux Devices:
• Scratchbox • Used to try PyQt on Maemo • There are packages available now
• Used to try PyQt on a Greenphone• Crosstool• Batteries included
![Page 23: PyQt for Desktop and Embedded Devices - … · PyQt for Desktop and Embedded Devices David Boddie PyCon Tre, Firenze, 8th–10th May 2009 • Not just](https://reader030.fdocuments.us/reader030/viewer/2022021622/5b99afe009d3f29c338cc09a/html5/thumbnails/23.jpg)
...
Embedded Python
Nice things about Python (2.x):
• Portable C implementation• Fairly small (compared to all the Qt libraries)• Few dependencies
Not so nice things about Python (2.x):
• Annoying to cross-compile (despite a good foundation)• Relies on a native interpreter at various points • Runs setup.py using the built interpreter • Needs a native interpreter to build a parser generator• Package-specific checks
• Batteries included (even old ones) • OpenSSL, Curses, pyexpat, Tkinter
Ways to build Python for Linux Devices:
• OpenEmbedded• Scratchbox
• Distribution packages (e.g., Debian)
• Buildroot• Crosstool
Used to create toolchains and/or whole systems.
Ways I built Python for Linux Devices:
• Scratchbox • Used to try PyQt on Maemo • There are packages available now
• Used to try PyQt on a Greenphone• Crosstool• Batteries included
![Page 24: PyQt for Desktop and Embedded Devices - … · PyQt for Desktop and Embedded Devices David Boddie PyCon Tre, Firenze, 8th–10th May 2009 • Not just](https://reader030.fdocuments.us/reader030/viewer/2022021622/5b99afe009d3f29c338cc09a/html5/thumbnails/24.jpg)
...
Embedded Python
Nice things about Python (2.x):
• Portable C implementation• Fairly small (compared to all the Qt libraries)• Few dependencies
Not so nice things about Python (2.x):
• Annoying to cross-compile (despite a good foundation)• Relies on a native interpreter at various points • Runs setup.py using the built interpreter • Needs a native interpreter to build a parser generator• Package-specific checks
• Batteries included (even old ones) • OpenSSL, Curses, pyexpat, Tkinter
Ways to build Python for Linux Devices:
• OpenEmbedded• Scratchbox
• Distribution packages (e.g., Debian)
• Buildroot• Crosstool
Used to create toolchains and/or whole systems.
Ways I built Python for Linux Devices:
• Scratchbox • Used to try PyQt on Maemo • There are packages available now
• Used to try PyQt on a Greenphone• Crosstool• Batteries included
![Page 25: PyQt for Desktop and Embedded Devices - … · PyQt for Desktop and Embedded Devices David Boddie PyCon Tre, Firenze, 8th–10th May 2009 • Not just](https://reader030.fdocuments.us/reader030/viewer/2022021622/5b99afe009d3f29c338cc09a/html5/thumbnails/25.jpg)
...
Embedded Python
Nice things about Python (2.x):
• Portable C implementation• Fairly small (compared to all the Qt libraries)• Few dependencies
Not so nice things about Python (2.x):
• Annoying to cross-compile (despite a good foundation)• Relies on a native interpreter at various points • Runs setup.py using the built interpreter • Needs a native interpreter to build a parser generator• Package-specific checks
• Batteries included (even old ones) • OpenSSL, Curses, pyexpat, Tkinter
Ways to build Python for Linux Devices:
• OpenEmbedded• Scratchbox
• Distribution packages (e.g., Debian)
• Buildroot• Crosstool
Used to create toolchains and/or whole systems.
Ways I built Python for Linux Devices:
• Scratchbox • Used to try PyQt on Maemo • There are packages available now
• Used to try PyQt on a Greenphone• Crosstool• Batteries included
![Page 26: PyQt for Desktop and Embedded Devices - … · PyQt for Desktop and Embedded Devices David Boddie PyCon Tre, Firenze, 8th–10th May 2009 • Not just](https://reader030.fdocuments.us/reader030/viewer/2022021622/5b99afe009d3f29c338cc09a/html5/thumbnails/26.jpg)
• Care must be taken with the widgets used:
Qt and PyQt on Linux Devices
• Fairly standard procedure for building Qt and PyQt
Which graphics system to use?
X11 (Qt for X11):
• Not all that common to cross-compile Qt for X11• Qt works better with X extensions (Render)• Develop using PyQt for X11 QWS (Qt for Embedded Linux):• Fairly easy to build Qt for Embedded Linux
• Qt uses the framebuffer• PyQt needs patching for cross-compilation
Developing and Simulating
• Develop using PyQt derived from PyQt for X11
X11-based devices:• Use Xephyr (nested X server) to simulate a small screen• Run or simulate the device's window system
• Beware of version differences• Possible to use system PyQt to prototype applications• The Maemo SDK emulates the device environment• Need to build your own libraries for desktop and device
• Run or simulate the device's window system• No need for a dedicated window manager
• Use a virtual framebuffer or VNC to simulate the screenQWS-based devices:
• Obviously, look and feel may be a bit different• The APIs should be the same
• Applications can be developed on desktops using PyQt
Common approach:
• Scrollbars on a small screen... • Input widgets without a keyboard...
Xephyr -ac -extension Composite -screen 800x480 :1DISPLAY=:1 python application.pypython application.py -qws -display VNC:0:size=240x320vncviewer :0
![Page 27: PyQt for Desktop and Embedded Devices - … · PyQt for Desktop and Embedded Devices David Boddie PyCon Tre, Firenze, 8th–10th May 2009 • Not just](https://reader030.fdocuments.us/reader030/viewer/2022021622/5b99afe009d3f29c338cc09a/html5/thumbnails/27.jpg)
• Care must be taken with the widgets used:
Qt and PyQt on Linux Devices
• Fairly standard procedure for building Qt and PyQt
Which graphics system to use?
X11 (Qt for X11):
• Not all that common to cross-compile Qt for X11• Qt works better with X extensions (Render)• Develop using PyQt for X11 QWS (Qt for Embedded Linux):• Fairly easy to build Qt for Embedded Linux
• Qt uses the framebuffer• PyQt needs patching for cross-compilation
Developing and Simulating
• Develop using PyQt derived from PyQt for X11
X11-based devices:• Use Xephyr (nested X server) to simulate a small screen• Run or simulate the device's window system
• Beware of version differences• Possible to use system PyQt to prototype applications• The Maemo SDK emulates the device environment• Need to build your own libraries for desktop and device
• Run or simulate the device's window system• No need for a dedicated window manager
• Use a virtual framebuffer or VNC to simulate the screenQWS-based devices:
• Obviously, look and feel may be a bit different• The APIs should be the same
• Applications can be developed on desktops using PyQt
Common approach:
• Scrollbars on a small screen... • Input widgets without a keyboard...
Xephyr -ac -extension Composite -screen 800x480 :1DISPLAY=:1 python application.pypython application.py -qws -display VNC:0:size=240x320vncviewer :0
![Page 28: PyQt for Desktop and Embedded Devices - … · PyQt for Desktop and Embedded Devices David Boddie PyCon Tre, Firenze, 8th–10th May 2009 • Not just](https://reader030.fdocuments.us/reader030/viewer/2022021622/5b99afe009d3f29c338cc09a/html5/thumbnails/28.jpg)
• Care must be taken with the widgets used:
Qt and PyQt on Linux Devices
• Fairly standard procedure for building Qt and PyQt
Which graphics system to use?
X11 (Qt for X11):
• Not all that common to cross-compile Qt for X11• Qt works better with X extensions (Render)• Develop using PyQt for X11 QWS (Qt for Embedded Linux):• Fairly easy to build Qt for Embedded Linux
• Qt uses the framebuffer• PyQt needs patching for cross-compilation
Developing and Simulating
• Develop using PyQt derived from PyQt for X11
X11-based devices:• Use Xephyr (nested X server) to simulate a small screen• Run or simulate the device's window system
• Beware of version differences• Possible to use system PyQt to prototype applications• The Maemo SDK emulates the device environment• Need to build your own libraries for desktop and device
• Run or simulate the device's window system• No need for a dedicated window manager
• Use a virtual framebuffer or VNC to simulate the screenQWS-based devices:
• Obviously, look and feel may be a bit different• The APIs should be the same
• Applications can be developed on desktops using PyQt
Common approach:
• Scrollbars on a small screen... • Input widgets without a keyboard...
Xephyr -ac -extension Composite -screen 800x480 :1DISPLAY=:1 python application.pypython application.py -qws -display VNC:0:size=240x320vncviewer :0
![Page 29: PyQt for Desktop and Embedded Devices - … · PyQt for Desktop and Embedded Devices David Boddie PyCon Tre, Firenze, 8th–10th May 2009 • Not just](https://reader030.fdocuments.us/reader030/viewer/2022021622/5b99afe009d3f29c338cc09a/html5/thumbnails/29.jpg)
• Care must be taken with the widgets used:
Qt and PyQt on Linux Devices
• Fairly standard procedure for building Qt and PyQt
Which graphics system to use?
X11 (Qt for X11):
• Not all that common to cross-compile Qt for X11• Qt works better with X extensions (Render)• Develop using PyQt for X11 QWS (Qt for Embedded Linux):• Fairly easy to build Qt for Embedded Linux
• Qt uses the framebuffer• PyQt needs patching for cross-compilation
Developing and Simulating
• Develop using PyQt derived from PyQt for X11
X11-based devices:• Use Xephyr (nested X server) to simulate a small screen• Run or simulate the device's window system
• Beware of version differences• Possible to use system PyQt to prototype applications• The Maemo SDK emulates the device environment• Need to build your own libraries for desktop and device
• Run or simulate the device's window system• No need for a dedicated window manager
• Use a virtual framebuffer or VNC to simulate the screenQWS-based devices:
• Obviously, look and feel may be a bit different• The APIs should be the same
• Applications can be developed on desktops using PyQt
Common approach:
• Scrollbars on a small screen... • Input widgets without a keyboard...
Xephyr -ac -extension Composite -screen 800x480 :1DISPLAY=:1 python application.pypython application.py -qws -display VNC:0:size=240x320vncviewer :0
![Page 30: PyQt for Desktop and Embedded Devices - … · PyQt for Desktop and Embedded Devices David Boddie PyCon Tre, Firenze, 8th–10th May 2009 • Not just](https://reader030.fdocuments.us/reader030/viewer/2022021622/5b99afe009d3f29c338cc09a/html5/thumbnails/30.jpg)
Demonstrations
Two devices:
Screen: 800 × 480
Nokia N800:
CPU: 400 MHz OMAP2420 CPU: 312 MHz Intel PXA270Screen: 240 × 320
Greenphone:
![Page 31: PyQt for Desktop and Embedded Devices - … · PyQt for Desktop and Embedded Devices David Boddie PyCon Tre, Firenze, 8th–10th May 2009 • Not just](https://reader030.fdocuments.us/reader030/viewer/2022021622/5b99afe009d3f29c338cc09a/html5/thumbnails/31.jpg)
At this point we show some demonstrations...
![Page 32: PyQt for Desktop and Embedded Devices - … · PyQt for Desktop and Embedded Devices David Boddie PyCon Tre, Firenze, 8th–10th May 2009 • Not just](https://reader030.fdocuments.us/reader030/viewer/2022021622/5b99afe009d3f29c338cc09a/html5/thumbnails/32.jpg)
Cutting Out Features
On desktops, we want as many features as possible......but......on embedded devices, we might not want everything.
Inappropriate features:• Classic dialogs too large for small screen devices
• Specialized displays don't need all the widget styles
• Menu bars, dock windows follow the wrong paradigm
Redundant features:
Unnecessary features:• Devices with touch screens don't need cursors
• We don't really need: • four sets of XML classes, • two JavaScript engines,
Configuring Qt for Embedded Linux:
• two ways to access networked resourcesQConfig lets you remove features from an embedded build
![Page 33: PyQt for Desktop and Embedded Devices - … · PyQt for Desktop and Embedded Devices David Boddie PyCon Tre, Firenze, 8th–10th May 2009 • Not just](https://reader030.fdocuments.us/reader030/viewer/2022021622/5b99afe009d3f29c338cc09a/html5/thumbnails/33.jpg)
Cutting Out Features
On desktops, we want as many features as possible......but......on embedded devices, we might not want everything.
Inappropriate features:• Classic dialogs too large for small screen devices
• Specialized displays don't need all the widget styles
• Menu bars, dock windows follow the wrong paradigm
Redundant features:
Unnecessary features:• Devices with touch screens don't need cursors
• We don't really need: • four sets of XML classes, • two JavaScript engines,
Configuring Qt for Embedded Linux:
• two ways to access networked resourcesQConfig lets you remove features from an embedded build
![Page 34: PyQt for Desktop and Embedded Devices - … · PyQt for Desktop and Embedded Devices David Boddie PyCon Tre, Firenze, 8th–10th May 2009 • Not just](https://reader030.fdocuments.us/reader030/viewer/2022021622/5b99afe009d3f29c338cc09a/html5/thumbnails/34.jpg)
Cutting Out Features
On desktops, we want as many features as possible......but......on embedded devices, we might not want everything.
Inappropriate features:• Classic dialogs too large for small screen devices
• Specialized displays don't need all the widget styles
• Menu bars, dock windows follow the wrong paradigm
Redundant features:
Unnecessary features:• Devices with touch screens don't need cursors
• We don't really need: • four sets of XML classes, • two JavaScript engines,
Configuring Qt for Embedded Linux:
• two ways to access networked resourcesQConfig lets you remove features from an embedded build
![Page 35: PyQt for Desktop and Embedded Devices - … · PyQt for Desktop and Embedded Devices David Boddie PyCon Tre, Firenze, 8th–10th May 2009 • Not just](https://reader030.fdocuments.us/reader030/viewer/2022021622/5b99afe009d3f29c338cc09a/html5/thumbnails/35.jpg)
• Take advantage of interactivity to prototype on devices
• Write code that works on different (embedded) platforms
• Build on top of existing pure-Python code• Write portable, deployable applications
• You get to work around those at a high level• Prototype applications on the desktop
Python makes it possible to• Ignore problems like cross-compiling
Finishing Up
• Despite allowances for differences between devices
PyQt makes it possible to
![Page 36: PyQt for Desktop and Embedded Devices - … · PyQt for Desktop and Embedded Devices David Boddie PyCon Tre, Firenze, 8th–10th May 2009 • Not just](https://reader030.fdocuments.us/reader030/viewer/2022021622/5b99afe009d3f29c338cc09a/html5/thumbnails/36.jpg)
• Take advantage of interactivity to prototype on devices
• Write code that works on different (embedded) platforms
• Build on top of existing pure-Python code• Write portable, deployable applications
• You get to work around those at a high level• Prototype applications on the desktop
Python makes it possible to• Ignore problems like cross-compiling
Finishing Up
• Despite allowances for differences between devices
PyQt makes it possible to
![Page 37: PyQt for Desktop and Embedded Devices - … · PyQt for Desktop and Embedded Devices David Boddie PyCon Tre, Firenze, 8th–10th May 2009 • Not just](https://reader030.fdocuments.us/reader030/viewer/2022021622/5b99afe009d3f29c338cc09a/html5/thumbnails/37.jpg)
http://www.qtsoftware.com/
Resources
Qt
by Mark Summerfield
PyQthttp://www.riverbankcomputing.com/
PyQt and PyKDE Wikihttp://www.diotavelli.net/PyQtWiki/
Develerhttp://www.develer.com/
Rapid GUI Programming with Python and Qt