41
Introduction to Application Development in Python and Gtk+ / Hildon @ Maemo 5 + my very own experience by Amanda Lam Hong Kong Maemo / Moblin / MeeGo User Gro up

Introduction to Application Development in Python and Gtk+ / Hildon @ Maemo 5

Embed Size (px)

DESCRIPTION

Introduction to Application Development in Python and Gtk+ / Hildon @ Maemo 5 + my very own experience

Citation preview

Page 1: Introduction to Application Development in Python and Gtk+ / Hildon @ Maemo 5

Introduction to Application Development in Python and Gtk+ / Hildon @ Maemo 5

+ my very own experience

by Amanda LamHong Kong Maemo / Moblin / MeeGo User Group

Page 2: Introduction to Application Development in Python and Gtk+ / Hildon @ Maemo 5

Self Introduction

BEng Computer Systems Engineering, University of Warwick, UK

Technical Writer of a popular local website company

Founder of the Hong Kong Maemo / Moblin / MeeGo User Group @ facebook

Executive Committee Member and Podcaster of the Hong Kong PDA User Group (HKPUG)

Voluntary News Editor of UMPCFever.com / Digital.XY.HK

Author of the first Maemo 4.1 and Maemo 5 Traditional Chinese Language Pack

Application Developer of:– EeeToggle for Windows– eSpeak GUI Client for Maemo 5– Stroke Order Chinese Input Method ( 筆劃輸入法 ) for Maemo 5

Page 3: Introduction to Application Development in Python and Gtk+ / Hildon @ Maemo 5

Maemo Devices

Nokia Internet Tablets:– Nokia 770

Maemo 1.x/OS2005Maemo 2.x/OS2006

– Nokia N800 & N810Maemo 3.x / “Bora” / OS2007Maemo 4.0 / “Chinook” / OS2008 Maemo 4.1 / “Diablo” / OS2008

– Nokia N900Maemo 5 / “Fremantle” / OS2009

myInteractiveDevice (myID)– Maemo 4.x Compatible

ZhongYi 眾一 S101– Maemo 4.x Compatible

Page 4: Introduction to Application Development in Python and Gtk+ / Hildon @ Maemo 5

Maemo’s Application Frameworks

Maemo 1.x – 4.x– Based on the Gtk+ / Hildon application framework

Maemo 5– Based on the Gtk+ / Hildon application framework– Support of Qt 4.5 since PR1.0– Support of Qt 4.6 since PR1.2

i.e. ALL existing Maemo devices run Gtk+ and Hildon applications!

Page 5: Introduction to Application Development in Python and Gtk+ / Hildon @ Maemo 5

So, what is Gtk+?

Highly usable, feature rich toolkit for creating graphical user interfaces which boasts cross platform compatibility and an easy to use API.

– Windows– Buttons– Menus– Status Bars– Dialog boxes– …many other GUI controls

Written in C. Provide bindings to other programming languages. Based on 4 libraries:

– GLib: Low-level stuffs such as data structures, portability wrappers, event loop, threads, dynamic loading and an object system

– Pango: layout and rendering of text with an emphasis on internationalization.– Cairo: 2D graphics with support for multiple output devices – ATK: set of interfaces providing accessibility

Page 6: Introduction to Application Development in Python and Gtk+ / Hildon @ Maemo 5

Where did Gtk+ come from?

Originated from the GIMP (GNU Image Manipulation Program) project by Spencer Kimball and Peter Mattis, started in 1995

Initially, based on Motif…– Not good enough!– So…

Rewrote their own GUI toolkit – Gtk

– Released since GIMP 0.60– Renamed to Gtk+ since GI

MP 0.99

Page 7: Introduction to Application Development in Python and Gtk+ / Hildon @ Maemo 5

Language Bindings supported by Gtk+

Gtk+ is written in C Bindings are provided

for programmers of other programming languages

Official bindings include: C++, Vala, Ruby, Python, Java, .Net, PHP and Perl.

Page 8: Introduction to Application Development in Python and Gtk+ / Hildon @ Maemo 5

Who use Gtk+?

Environments GNOME, Xfce, LXDE… Access Linux Platform (ALP) Moblin / Maemo

Applications AbiWord Gnumeric Midori Evolution

Page 9: Introduction to Application Development in Python and Gtk+ / Hildon @ Maemo 5

Then, what is Hildon?

Application framework developed by Nokia Now part of GNOME Was used in Nokia Internet Tablet series and the Ub

untu Mobile and Embedded Edition Depends on Gtk+ (GUI components), GConf (setting

s) & libcanberra (sound) libraries Application Manager, Control Panel Desktop, Widgets Finger-friendly GUI components for Mobile Devic

es

Page 10: Introduction to Application Development in Python and Gtk+ / Hildon @ Maemo 5

Where Hildon sits in the Maemo Architecture?

Page 11: Introduction to Application Development in Python and Gtk+ / Hildon @ Maemo 5

Hildon 2.2 UI Components

Page 12: Introduction to Application Development in Python and Gtk+ / Hildon @ Maemo 5

Mixed use of Hildon and Gtk+ UI Components in Maemo

Most Hildon classes are inherited from Gtk+ classes

You can place both Gtk+ and Hildon UI components to your applications

…but, be aware of UI styles and user experience!

Page 13: Introduction to Application Development in Python and Gtk+ / Hildon @ Maemo 5

What programming languages can I use to develop Maemo applications?

C & C++ (GCC 4.2) Python 2.5.4 PHP 5 Ruby 1.8 Java (OpenJDK 1.8.x)

Page 14: Introduction to Application Development in Python and Gtk+ / Hildon @ Maemo 5

I use Python. But why Python?

Because…– I am C-phobic!– I am just a beginner of Linux application development– Python syntax is simple, code is fairly readable– Interpreter; easy to debug– Can be imperative, object-oriented, or functional– Dynamic types– Automatic memory management– Works well with Gtk+ and Hildon frameworks– Many code examples– Many existing Maemo applications are developed in Python– Code and run directly on my Internet Tablets!

Page 15: Introduction to Application Development in Python and Gtk+ / Hildon @ Maemo 5

Little History of

Since 1989 By Guido van Rossum, a Dutch computer

programmer, now a Google employee Successor to the ABC programming langu

age Vision:

– an easy and intuitive language just as powerful as major competitors

– open source, so anyone can contribute to its development

– code that is as understandable as plain English

– suitability for everyday tasks, allowing for short development times

Page 16: Introduction to Application Development in Python and Gtk+ / Hildon @ Maemo 5

Maemo Applications written in Python

gPodder Podcast Client Gonvert Hermes Panucci player PyGTKEditor Witter Zoutube

Page 17: Introduction to Application Development in Python and Gtk+ / Hildon @ Maemo 5

How does Python code look like?

Page 18: Introduction to Application Development in Python and Gtk+ / Hildon @ Maemo 5

Let’s run the Hello World program!

Page 19: Introduction to Application Development in Python and Gtk+ / Hildon @ Maemo 5

Class Definition Example

Page 20: Introduction to Application Development in Python and Gtk+ / Hildon @ Maemo 5

My Maemo Applications

Written in Python and Gtk+/Hildon, of course. Support both landscape and portrait mode. UI Internationalization. eSpeak GUI Client

– Provides a GUI for the eSpeak text-to-speech CLI utility

Stroke Order Input Method 筆劃輸入法– As the name suggests!

Page 21: Introduction to Application Development in Python and Gtk+ / Hildon @ Maemo 5

eSpeakGUI Client: UI ComponentsA set of hildon.PickerButtons in a gtk.HBox

A set of hildon.GtkButtons in a gtk.VBox

hildon.TextView in a hildon.PannableArea

hildon.AppMenuA set of hildon.GtkButtons in a gtk.HBox

Page 22: Introduction to Application Development in Python and Gtk+ / Hildon @ Maemo 5

eSpeakGUI Client: UI Components

hildon.TouchSelector

Page 23: Introduction to Application Development in Python and Gtk+ / Hildon @ Maemo 5

eSpeakGUI Client: How does it speak?

eSpeak is an open-source, command-line Text-to-Speech utility Works like this…

espeakcmd = "espeak -v " + currentlang + " -a " + currentAmp + " -p " + currentPitch + " -s " + currentSpeed + " -g " + currentWordGap + " \"" + textresult + "\" &"

os.system(espeakcmd)

Available in Maemo Extras Repository

The GUI client simply creates a command line to call the espeak utility via the os.system() method.

– Argument values obtained from Selected values of the hildon.Pi

ckerButtons Text to be spoken from the hildo

n.TextView

Page 24: Introduction to Application Development in Python and Gtk+ / Hildon @ Maemo 5

eSpeakGUI Client: Demonstration

Page 25: Introduction to Application Development in Python and Gtk+ / Hildon @ Maemo 5

Stroke Order Chinese Input Method:UI Components

hildon.StackWindow

hildon.TouchSelector

hildon.TextView in a hildon.PannableArea

gtk.Label

gtk.Label in hildon.PannableArea

hildon.TextView

hildon.GtkButtons in HBoxes and VBoxes

hildon.GtkButtons in HBoxes and VBoxes

hildon.GtkButton

hildon.GtkButtons in a VBoxhildon.AppMenu hildon.AppMenu

Page 26: Introduction to Application Development in Python and Gtk+ / Hildon @ Maemo 5

Stroke Order Chinese Input Method:UI Components

hildon.AppMenu containing hildon.GtkButtons

Page 27: Introduction to Application Development in Python and Gtk+ / Hildon @ Maemo 5

Stroke Order Chinese Input Method:The Use of

Characters and associated phrases are stored in a SQLite 3 database.

Why SQLite 3?– Full Unicode Support– Native Python API– Lightweight, and, FAST!– It’s built-in in N900!

Page 28: Introduction to Application Development in Python and Gtk+ / Hildon @ Maemo 5

Stroke Order Chinese Input Method: Accessing C-compiled libraries directly

Not all features are available via bindings You may import the ctypes library to get access to methods an

d properties in C-compiled libraries dynamically. Example: Accessing the N900 Address Book:

Page 29: Introduction to Application Development in Python and Gtk+ / Hildon @ Maemo 5

Stroke Order Chinese Input Method:Demonstration

Page 30: Introduction to Application Development in Python and Gtk+ / Hildon @ Maemo 5

Get your hands dirty!

Q: What tools do you need to develop Python applications on the Maemo platform?

A: Python! And…– A plain-text editor!

Of course, there are other easy-to-use options too.

Page 31: Introduction to Application Development in Python and Gtk+ / Hildon @ Maemo 5

Glade – Gtk+ RAD tool

Drag-and-drop controls to build up a GUI app

Not aware of Hildon controls and libraries!

Require extra dependency on apps generated

Page 32: Introduction to Application Development in Python and Gtk+ / Hildon @ Maemo 5

Illumination Software Creator

Define variables, GUI components and action blocks visually.

Generate Python code for desktop and Maemo.

Generate Flex code for Adobe Flash apps.

Great app for building a brief prototype and then fine-tune your code later.

Available in Microsoft Windows, Mac OS X and various Linux distributions.

Page 33: Introduction to Application Development in Python and Gtk+ / Hildon @ Maemo 5

PyGtkEditor on Maemo

Open, edit, and run Python code directly on your Maemo device!

Support syntax highlighting and Hildon text completion.

Support other programming languages as well.

It itself is written in Python and Gtk+/Hildon!

Page 34: Introduction to Application Development in Python and Gtk+ / Hildon @ Maemo 5

I decide to develop Maemo apps in Python, do I still need Maemo SDK?

You can write Python programs that run on Maemo devices directly, without using the Maemo 5 SDK.

– Transfer your Python scripts from your PC to your Maemo device.

– Code directly on your device.– Run!

However, you need Maemo SDK if you:– Want to make use of the device simulator instead of testing

your apps on real Maemo device.– Would like to package your Python apps.– Would like to upload your Python apps to the Maemo.org re

positories.

Page 35: Introduction to Application Development in Python and Gtk+ / Hildon @ Maemo 5

Will my Python/Gtk+/Hildon apps work in MeeGo?

Well, maybe. Expect modifications though. MeeGo is based on Qt instead of Gtk+/Hildon. From MeeGo.com FAQ:

“Will”. But when? We may get more clues in the forthcoming MeeGo Conference 2010.

Page 36: Introduction to Application Development in Python and Gtk+ / Hildon @ Maemo 5

MeeGo Architecture

Page 37: Introduction to Application Development in Python and Gtk+ / Hildon @ Maemo 5

Gtk+ Support in MeeGo Handset UX

Zwong tested a Gtk+ app on MeeGo Handset UX and confirmed that it somehow works partially. (http://zwong.de/?p=78)

Page 38: Introduction to Application Development in Python and Gtk+ / Hildon @ Maemo 5

I want to develop apps for the MeeGo platform – shall I choose Gtk+, or Qt?

Of course, the answer is…– Qt!– Because the entire GUI of MeeGo is based on Qt components.– Python binding for Qt is also available: PyQt

Then why shall we still bother with Gtk+?– All Maemo devices up to today are based on Gtk+/Hildon.– The current release of the Chinese Input Method Engine “MSCIM”

on N900 only supports Gtk+/Hildon apps, not Qt’s.– GNOME is available in nearly all mainstream Linux distributions.– Better to learn both!

Page 39: Introduction to Application Development in Python and Gtk+ / Hildon @ Maemo 5

References for you to get started

Python programming on Maemo http://wiki.maemo.org/PyMaemo http://wiki.maemo.org/PyMaemo/UI_tutorial http://pymaemo.garage.maemo.org/ http://library.gnome.org/devel/pygtk/stable/

Hildon and Gtk+ Application Frameworks http://maemo.org/api_refs/5.0/5.0-final/hildon/ http://www.forum.nokia.com/info/sw.nokia.com/id/eb8a68ba-6225-4d84-ba8f-a0

0e4a05ff6f/Hildon_2_2_UI_Style_Guide.html http://www.forum.nokia.com/info/sw.nokia.com/id/019c2b31-3777-49a0-9257-9

70d79580756/Hildon_2_2_Widget_UI_Specification.html

Source Code of existing Maemo applications http://maemo.org/packages/

Page 40: Introduction to Application Development in Python and Gtk+ / Hildon @ Maemo 5

Thank you!

Questions are welcome.

Please join the Hong Kong Maemo / Moblin / MeeGo User Group at http://groups.to/hkmaemo/

Visit my blog at http://amanda_hoic.mysinablog.com/

Page 41: Introduction to Application Development in Python and Gtk+ / Hildon @ Maemo 5

References

Pictures and some text of this presentation were obtained from:

– Gimp.org– Gnome.org– Gtk.org– Maemo.org– Meego.com– MyID.com.hk– Wikipedia.com– Zwong.de– Zy-mobile.com