Developing MeeGo apps with Python and QML

VIP免费
2025-02-27 0 0 851.31KB 28 页 5.9玖币
侵权投诉
Developing MeeGo apps
with Python and QML
by Thomas Perl <m@thp.io>
http://thp.io/2010/meego-python/
Table of Contents
Introduction.....................................................................................................3
Why should I use Python to develop MeeGo apps?......................................3
Links.............................................................................................................3
Setting up the environment.............................................................................3
Getting the build scripts...............................................................................4
Building PySide and installing into $HOME...................................................4
Setting up environment variables................................................................5
Testing the installations...............................................................................5
Basic QML tutorial examples............................................................................6
Hello World...................................................................................................6
The Python source (HelloMeeGo.py).........................................................6
The QML UI file (HelloMeeGo.qml)............................................................8
Displaying HTML content in a QML WebView...............................................9
The Python source code (WebKitView.py).................................................9
The QML content (WebKitView.qml).......................................................11
The HTML page (WebKitView.html).........................................................11
Writing a new QML UI for existing apps for MeeGo........................................13
A QML UI for gPodder.................................................................................13
The glue layer in Python (gpodder-qml.py)............................................14
The QML main UI file (gpodder-qml.qml)................................................18
The QML file for displaying a list of podcasts (PodcastList.qml).............21
The QML file for displaying a list of episodes (EpisodeList.qml).............24
Packaging a Python application for MeeGo....................................................25
Installing the required dependencies.........................................................25
Creating the required metadata files.........................................................25
The desktop entry: gpodder-qml.desktop...............................................25
The icon for the app menu: gpodder-qml.png........................................25
The Spectacle YAML file: gpodder-qml.yaml...........................................26
The Python distutils file: setup.py..........................................................26
Changes in the gpodder-qml.py script.......................................................26
Creating the RPM sources..........................................................................27
Building the RPM package from source......................................................27
Installing and testing the RPM package.....................................................27
Introduction
This tutorial will guide you through how to set up a PySide environment on your
MeeGo Netbook and then show you some basics through examples, and finally
we'll create a QML UI for an existing application (gPodder) that can be used on
MeeGo Netbook and MeeGo Handset.
Why should I use Python to develop MeeGo apps?
Low barrier to entry: Python is a very easy to learn language, so you can
get quickly up to speed – independent of whether or not you are already
familiar with other languages
Garbage collection: You don't have to manually manage the memory of
the objects you create – the Python garbage collector takes care of
removing no longer needed objects
No compiling: Python is an interpreted language, so you can run your
application right after saving the source in an editor. No need to wait for
code to compile. This is especially important on low-powered netbooks.
Full access to the Qt libraries: PySide bindings allow access to all modules
of Qt. And because it uses the native Qt libraries, library functions run at
native (compiled) speed.
Shorter code: In my experience, C++ applications using Qt have about 3
times as much lines of code as the equivalent Python applications – using
the same libraries and Qt classes!
Prototyping: Even if you plan on writing a C++ Qt application, Python and
PySide are a great combination for quickly prototyping your ideas. This
could be useful to prototype a C++ backend of your QML application.
Later on, you just exchange the Python backend with a C++ backend and
can reuse the QML files from the Python app.
Development on the go: As Python is an interpreted language, the
runtime already contains all the necessary tools to develop applications,
so you don't have to install a compiler, development libraries and header
files just to create apps – it's instant, and some people even develop
Python GUI apps directly on handset devices like the N900.
Links
PySide Homepage: http://www.pyside.org/
MeeGo Homepage: http://www.meego.com/
PySide Wiki: http://developer.qt.nokia.com/wiki/PySide
Tutorial homepage: http://thp.io/2010/meego-python/
Setting up the environment
First, make sure to have MeeGo Netbook installed – either directly on your
netbook or in a virtual machine. How to do this is out of scope for this
document, so please refer to the MeeGo Wiki.
As you probably want to start developing with PySide right now, and given the
agile state of PySide at this moment (lots of bugfixes being integrated before
the 1.0 release), it's a good idea to build PySide from source. This will not be
necessary in the future (when PySide packages are hopefully integrated into
MeeGo), but you might nevertheless use an up-to-date version for
development.
Getting the build scripts
I've created a set of build scripts that will automate the building of PySide from
the Git repositories, including installing required build dependencies, so you
can get up to speed quickly.
1. Click on the red “Applications” icon on MeeGo
2. Search for “Terminal” and start the application
3. Install Git via “sudo zypper install git”
4. Create a “pyside” folder in your $HOME with “mkdir pyside”
5. Change into the “pyside” folder: “cd pyside”
6. Check out the source: “git clone git://gitorious.org/pyside/buildscripts.git”
7. Change into the “buildscripts” folder: “cd buildscripts”
8. Fetch the sources: “git submodule init” and “git submodule update”
9. Fetching the sources will take a while – grab a coffee or a tea :)
After the buildscripts have been downloaded, you can use them to build PySide
for MeeGo Netbook.
Building PySide and installing into $HOME
Now that you have gotten all the sources, you can build PySide for your
netbook and install it into your home directory so that it does not conflict with
any system-wide installations you might have in place. That's a safe way to
install PySide from Git, as you can always just remove it from $HOME or
reinstall it as often as you wish without cluttering up your system directories.
1. Open another Terminal (or use the one you still have open from the
previous step)
2. Go into the PySide buildscripts folder: “cd ~/pyside/buildscripts”
3. Install the build dependencies: “sudo ./dependencies.meego.sh”
4. Before the next step, make sure to close down any other apps you might
have running – building PySide takes a lot of RAM. If you have problems
building PySide, consider adding some RAM or adding a swapfile
5. (started 14;28) Build and install everything using “./build_and_install”
6. This will take about 2.5 hours (on an Atom single-core netbook) – yes,
that's a lot, but the upside of using Python for development on your
MeeGo netbook is that your applications do not have to be compiled, so
instead of a develop-compile-run cycle, your have a develop-run cycle.
This is especially nice on low-powered netbooks and saves you time and
battery power on the go.
Setting up environment variables
Because we installed PySide into your $HOME, you have to set up some
environment variables for that PySide version to become the active one for
Python to use. Luckily, the “environment.sh” script in the PySide buildscripts
takes care of that. You can either use
source ~/pyside/buildscripts/environment.sh
every time you want to do PySide development, or add this command to your
~/.bashrc file, so it gets executed every time you open a shell or terminal
window (that's the recommended way to do it, so you don't forget to source the
“environment.sh” file when trying out the examples).
Testing the installations
Before we can start to write great PySide apps for MeeGo, let's see if
everything was installed correctly. Fire up another terminal window and enter
“pythonto start the interactive Python shell. Now, enter “from PySide import
QtGui” to check if the QtGui module was correctly installed. After that, try
from PySide import QtDeclarative” to check if the QtDeclarative module is
working. We need the QtGui for basic UI classes (non-QML), and QtDeclarative
for loading and displaying QML content.
摘要:

DevelopingMeeGoappswithPythonandQMLbyThomasPerlhttp://thp.io/2010/meego-python/TableofContentsIntroduction.....................................................................................................3WhyshouldIusePythontodevelopMeeGoapps?......................................3Links.............

展开>> 收起<<
Developing MeeGo apps with Python and QML.pdf

共28页,预览5页

还剩页未读, 继续阅读

声明:本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。玖贝云文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知玖贝云文库,我们立即给予删除!
分类:计算机 价格:5.9玖币 属性:28 页 大小:851.31KB 格式:PDF 时间:2025-02-27

开通VIP享超值会员特权

  • 多端同步记录
  • 高速下载文档
  • 免费文档工具
  • 分享文档赚钱
  • 每日登录抽奖
  • 优质衍生服务
/ 28
客服
关注