Mobile application development with QML & PySide



Similar documents
Writing standalone Qt & Python applications for Android

Developing MeeGo apps with Python and QML by Thomas Perl

The Most Popular UI/Apps Framework For IVI on Linux

Best Practices in Qt Quick/QML. Langston Ball Senior Qt Developer ICS, Inc.

Mobile Development with Qt

Qt Quick Application Developer Guide for Desktop

latest Release 0.2.6

SysPatrol - Server Security Monitor

Building a Python Plugin

KIVY - A Framework for Natural User Interfaces

Systemd for Embedded Linux. Challenges and Opportunities

Andreas Burghart 6 October 2014 v1.0

PaaS Operation Manual

You're reading an excerpt. Click here to read official APPLE REMOTE DESKTOP 1.2 user guide

Configuring the Active Directory Plug-in

Contents First Time Setup... 2 Setting up the Legal Vault Client (KiteDrive)... 3 Setting up the KiteDrive Outlook Plugin Using the Legal Vault

Android App User Guide

Wireless Security Camera with the Arduino Yun

Adafruit's Raspberry Pi Lesson 7. Remote Control with VNC

Workday Mobile Security FAQ

Bitrix Site Manager ASP.NET. Installation Guide

GO!Enterprise MDM Device Application User Guide Installation and Configuration for ios Devices

Handle Tool. User Manual

VPN: Virtual Private Network Setup Instructions

WatchDox Administrator's Guide. Application Version 3.7.5

E-Commerce: Designing And Creating An Online Store

QVD Client for Android. QVD Client for Android

Web Developer Toolkit for IBM Digital Experience

Git - Working with Remote Repositories

Creating a DUO MFA Service in AWS

Qsync Install Qsync utility Login the NAS The address is :8080 bfsteelinc.info:8080

Copyright 2012 Trend Micro Incorporated. All rights reserved.

NAS 242 Using AiMaster on Your Mobile Devices

AkrutoSync 4.0 User Guide

Novell Filr. Mobile Client

When enterprise mobility strategies are discussed, security is usually one of the first topics

APPLICATION NOTE. How to build pylon applications for ARM

Product Manual. MDM On Premise Installation Version 8.1. Last Updated: 06/07/15

GO!Enterprise MDM Device Application User Guide Installation and Configuration for Android

Surface and Volumetric Data Rendering and Visualisation

1. Digital Asset Management User Guide Digital Asset Management Concepts Working with digital assets Importing assets in

GO!Enterprise MDM Device Application User Guide Installation and Configuration for Android with TouchDown

SparkLab May 2015 An Introduction to

VERSION 9.02 INSTALLATION GUIDE.

Installation and Deployment

Store & Share Quick Start

User Guide. Version R91. English

GO!Enterprise MDM Device Application User Guide Installation and Configuration for ios with TouchDown

Seagate NAS OS 4 Reviewers Guide: NAS / NAS Pro / Business Storage Rackmounts

SPC Connect Configuration Manual V1.0

IceWarp Server. Log Analyzer. Version 10

1. Digital Asset Management User Guide Digital Asset Management Concepts Working with digital assets Importing assets in

Log Analyzer Reference

FOR PARALLELS / PLESK PANEL

Python for Series 60 Platform

Introduction to Stanford Box

Copyright 2013 Trend Micro Incorporated. All rights reserved.

BogDan Vatra and Andy Gryc. Qt on Android: Is it right for you?

SFTP Server User Login Instructions. Open Internet explorer and enter the following url:

Kaspersky Password Manager

How To Package In Composer (Amd64)

Configuring Eduroam on Microsoft Windows Vista and 7 (all editions, 32 and 64 bits)

Getting Started Android + Linux. February 27 th, 2014

Table of Contents. Description of the BlackVue App 3. Supported Devices 4. Screen Description 5. Home Screen 5. Video List Screen 6

Sophos Mobile Control SaaS startup guide. Product version: 6

GoAnywhere Director to GoAnywhere MFT Upgrade Guide. Version: Publication Date: 07/09/2015

24x7 Scheduler Multi-platform Edition 5.2

Smart Card Setup Guide

SmartWatch Eco/Eco Compact

How To Secure Your Computer With Libreware Libreroview (Windows) And Libreros (Windows 2) (Windows 3.5) (For Windows) (Powerpoint) (Networking)

To install Multifront you need to have familiarity with Internet Information Services (IIS), Microsoft.NET Framework and SQL Server 2008.

Features of AnyShare

Net 2. NetApp Electronic Library. User Guide for Net 2 Client Version 6.0a

EVALUATION ONLY. WA2088 WebSphere Application Server 8.5 Administration on Windows. Student Labs. Web Age Solutions Inc.

PaperClip Audit System Installation Guide

Extending Remote Desktop for Large Installations. Distributed Package Installs

Administering Jive Mobile Apps

Omnixx Client Installer for TXDPS

BlackBerry Desktop Software User Guide

OneDrive for Business from Desktop or Laptop Windows devices

Volume SYNAMETRICS TECHNOLOGIES. A Division of IndusSoft Technologies, Inc. DeltaCopy User s Guide

Mobile Labs Plugin for IBM Urban Code Deploy

Configuring the WT-4 for ftp (Ad-hoc Mode)

Manage CE. Version 1

RemoteLab 2.0 Admin Guide

User s Manual. Management Software for ATS

UAG4100 Support Notes

Mercury User Guide v1.1

Some Experiences With Python For Android (Py4A) Nik Klever University of Applied Sciences Augsburg

Getting Started with Clearlogin A Guide for Administrators V1.01

Kerberos + Android. A Tale of Opportunity. Slide 1 / 39. Copyright 2012 yassl

2X SecureRemoteDesktop. Version 1.1

Sophos Mobile Control Startup guide. Product version: 3

The HTTP Plug-in. Table of contents

Quick Start Guide 0514US

Kony MobileFabric. Sync Windows Installation Manual - WebSphere. On-Premises. Release 6.5. Document Relevance and Accuracy

Ciphermail Gateway Separate Front-end and Back-end Configuration Guide

WatchGuard SSL v3.2 Update 1 Release Notes. Introduction. Windows 8 and 64-bit Internet Explorer Support. Supported Devices SSL 100 and 560

Active Directory Requirements and Setup

Transcription:

Mobile application development with QML & PySide Martin Kolman, Faculty of Informatics, Masaryk University slides: http://www.modrana.org/om2012 example program: https://github.com/m4rtink/expyside

What is PySide a project that provides Python bindings for Qt basically a LGPL alternative to the older PyQt project PySide recently became part of the Qt Project officially available for Fremantle (N900) and Harmattan (N9) there is an unofficial port for Android and of course it also works on desktop :)

Advantages Python is easy to use :) no need to (cross-)compile code can be easily tweaked on the go in combination with Rsync makes for very rapid change-test cycles big standard library and boatloads of third-party modules

Disadvantages bindings don't cover all available libraries no Qt Creator support no Qt 5 support yet

Setting up the environment on a PC install PySide :) install Qt Components from the Forum Nokia PPA on a mobile device N900, N950 and N9 are supported by PySide out of the box just install the python-pyside metapackage and you are ready to go :) on the N900 you might need the qt-components-10 package

Basic application harness Python code #!/usr/bin/env python # A simple PySide example import sys import os from PySide.QtGui import * from PySide.QtDeclarative import * WINDOW_TITLE = "PySide Example" # enable running this program from absolute path os.chdir(os.path.dirname(os.path.abspath( file ))) if name == ' main ': app = QApplication(sys.argv) # create the application view = QDeclarativeView() # create the declarative view view.setsource("main.qml") view.setwindowtitle(window_title) view.resize(854,480) view.show() app.exec_()

Basic application harness QML code import QtQuick 1.1 Rectangle { anchors.fill : parent Text { text: "Hello World" anchors.centerin: parent } }

Exporting Python properties to QML to export python functions to QML: 1. create a class that instantiates QObject 2. add functions you want to export to this class 3. annotate them 4. instantiate the class an set it as a context property of the declarative view the property name ins exported to the global QML namespace, so watch out for collisions

Exporting Python properties to QML Python property code class PropertyExample(QObject): def init (self): QObject. init (self) self.rootobject = None #NOTE: the root object is needed only by Python properties # that call QML code directly @QtCore.Slot(result=str) def getdate(self): """ return current date & time """ return str(datetime.datetime.now()) @QtCore.Slot(str) def notify(self, text): """ trigger a notification using the Qt Quick Components InfoBanner """ #NOTE: QML uses <br> instead of \n for linebreaks self.rootobject.notify(text)

Exporting Python properties to QML property export code # add the example property property = PropertyExample() rc.setcontextproperty("example", property)

Exporting Python properties to QML QML code Text { text: example.getdate() anchors.horizontalcenter: parent.horizontalcenter } Button { anchors.horizontalcenter: parent.horizontalcenter width : 100 id : startbutton text : "notification" onclicked : { example.notify("entry filed content:<br>" + entryfield.text) } }

Manipulating QML from Python instantiated QML Elements can be directly manipulated from Python the easiest way is probably through the root object the root object is created from the file that was set as the declarative view source at startup, in our example this is the main.qml file but be careful this ties Python very closely to the (usually ever-changing) QML code

Manipulating QML from Python Python code def notify(self, text): """ trigger a notification using the Qt Quick Components InfoBanner """ rootobject = view.rootobject() rootobject.notify(text)

Manipulating QML from Python QML code InfoBanner { id: notification timershowtime : 5000 height : rootwindow.height/5.0 } function notify(text) { notification.text = text; notification.show() }

Notifications notifications can be easily implemented using the QML InfoBanner element the InfoBanner element is instantiated in the main.qml file there is also a notify(text) function this function can be called both from QML and from Python code EX: handling more notifications at once

Loading images QML supports loading images from files or network but what if we want to load an image from raw data in memory or do custom image processing? QDeclarativeImageProvider provides an interface for loading images to QML returns QImage or QPixmap does not update the Image.progress property reloading an might be a bit problematic due to how image caching works

Loading images image provider example class ImagesFromPython(QDeclarativeImageProvider): def init (self): # this image provider supports QImage, # as specified by the ImageType QdeclarativeImageProvider. init (self, QdeclarativeImageProvider.ImageType.Image) def requestimage(self, pathid, size, requestedsize): # we draw the text provided from QML on the image text = pathid # for an example image, PySide logo in SVG is used image = QImage("pyside.svg") image.scaled(requestedsize.width(),requestedsize.height()) painter = QtGui.QPainter(image) painter.setpen("white") painter.drawtext(20, 20, text) return image

Loading images registering the image provider provider = ImagesFromPython() view.engine().addimageprovider("from_python", provider) # NOTE: view.engine().addimageprovider("from_python", # ImagesFromPython()) # doesn't work for some reason

Loading images using the image provider from QML Image { anchors.horizontalcenter: parent.horizontalcenter width : 200 height : 200 smooth : true // NOTE: the image provider name in the Image.source // URL is automatically lower-cased!! source : "image://from_python/" + entryfield.text }

Persistent configuration can be easily achieved on the Python side just export a property with properly annotated get/set methods on the Python side, it can be as simple as dictionary that is loaded from file with Marshal on startup and saved back on shutdown or other backends like configparser, configobj, csv, sqlite, etc. can be used

Simple rapid prototyping Python has a big advantage - you don't have to compile the source code the same source can be used to run an application both on your desktop computer or your mobile device this can be used for a very rapid on-device testing develop anywhere! the only thing you need is IP connectivity between your desktop/laptop and your mobile device basically any wireless AP will do also works with the built-in mobile hotspot! :)

Simple rapid prototyping requirements rsync on your mobile device scp might be used as a less-effective alternative SSH-PKY authentication (so that you don't have to enter the password on every sync) the IP address of your computer and your mobile device

The rsync script app_rsync.sh #!/bin/bash IP=$1 # NOTE: this deletes any on-device changes to the # application source files on every sync # also, the.git folder is not synced (if present) rsync -avzsh --delete --progress -e 'ssh' my_username@$ {IP}:/home/my_username/coding/app /home/user/coding --exclude '.git'

The startup script app_start.sh #!/bin/bash cd software/coding/app python main.py

The sync & run script run_app.sh #!/bin/sh # optional automatic IP address detection #source_ip=`sh get_source.sh` # place dependent IP addresses source_ip=192.168.1.2 #source_ip=192.168.0.3 #source_ip=192.168.1.4 #source_ip=192.168.1.5 sh app_rsync.sh $source_ip #sh temp_rsync.sh $source_ip sh app_start.sh

Installation & usage installation place the scripts to a convenient folder on your mobile device usage log-in to your mobile device set your PC IP in the main script (optional) run the the scripts as appropriate

Why 3 scripts? better readability flexibility the individual scripts can be used separately: sync & start the application just sync just start the application

Packaging is not really needed during development unless you are developing for Harmattan and need Aegis tokens programs using PySide can be accepted to the Nokia store (formerly Ovi Store) Python applications already in the store: Mieru GPodder RePho (?) and others

How to create packages for Harmattan & Fremantle with PySide assistant http://wiki.meego.com/python/pyside-assistant with Khertan's sdist_maemo module http://www.khertan.net/softwares/sdist_maemo/ with my packaging script that uses modified sdist_maemo and OBS to create Nokia Storecompatible packages http://www.modrana.org/misc/mieru_build_example.zip using merlin1991's bdist_hdeb module http://forum.meego.com/showthread.php?t=5523

PySide applications Mieru, RePho, modrana https://github.com/m4rtink Gpodder https://github.com/gpodder gotovienna https://github.com/kelvan/gotovienna AGTL https://github.com/webhamster/advancedcaching

Thank you! Questions? :) Want to contact me? :) Martin Kolman email: martin.kolman@gmail.com jabber: m4rtink@jabbim.cz github: https://github.com/m4rtink