Scheible and Ville Tuulos
Total Page:16
File Type:pdf, Size:1020Kb
Mobile Python Rapid Prototyping of Applications on the Mobile Platform Jurgen¨ Scheible and Ville Tuulos Reviewed by Panos Asproulis, Mal Minhas, Tim Ocock, Mark Shackman, Ian Weston Head of Symbian Press Freddie Gjertsen Managing Editor Satu McNabb Mobile Python Rapid Prototyping of Applications on the Mobile Platform Mobile Python Rapid Prototyping of Applications on the Mobile Platform Jurgen¨ Scheible and Ville Tuulos Reviewed by Panos Asproulis, Mal Minhas, Tim Ocock, Mark Shackman, Ian Weston Head of Symbian Press Freddie Gjertsen Managing Editor Satu McNabb Copyright ¤ 2007 John Wiley & Sons Ltd, The Atrium, Southern Gate, Chichester, West Sussex PO19 8SQ, England Telephone (+44) 1243 779777 Email (for orders and customer service enquiries): [email protected] Visit our Home Page on www.wileyeurope.com or www.wiley.com All Rights Resersvg. No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except under the terms of the Copyright, Designs and Patents Act 1988 or under the terms of a licence issued by the Copyright Licensing Agency Ltd, 90 Tottenham Court Road, London W1T 4LP, UK, without the permission in writing of the Publisher. Requests to the Publisher should be addressed to the Permissions Department, John Wiley & Sons Ltd, The Atrium, Southern Gate, Chichester, West Sussex PO19 8SQ, England, or emailed to [email protected], or faxed to (+44) 1243 770620. Designations used by companies to distinguish their products are often claimed as trademarks. All brand names and product names used in this book are trade names, service marks, trademarks or registered trademarks of their respective owners. The Publisher is not associated with any product or vendor mentioned in this book. This publication is designed to provide accurate and authoritative information in regard to the subject matter covered. It is sold on the understanding that the Publisher is not engaged in rendering professional services. If professional advice or other expert assistance is required, the services of a competent professional should be sought. Other Wiley Editorial Offices John Wiley & Sons Inc., 111 River Street, Hoboken, NJ 07030, USA Jossey-Bass, 989 Market Street, San Francisco, CA 94103-1741, USA Wiley-VCH Verlag GmbH, Boschstr. 12, D-69469 Weinheim, Germany John Wiley & Sons Australia Ltd, 42 McDougall Street, Milton, Queensland 4064, Australia John Wiley & Sons (Asia) Pte Ltd, 2 Clementi Loop #02-01, Jin Xing Distripark, Singapore 129809 John Wiley & Sons Canada Ltd, 6045 Freemont Blvd, Mississauga, Ontario, L5R 4J3, Canada Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books. Anniversary Logo Design: Richard J. Pacifico British Library Cataloguing in Publication Data A catalogue record for this book is available from the British Library ISBN: 978-0-470-51505-1 Typeset in 10/12pt Optima by Laserwords Private Limited, Chennai, India Printed and bound in Great Britain by Bell & Bain, Glasgow This book is printed on acid-free paper responsibly manufactured from sustainable forestry in which at least two trees are planted for each one used for paper production. Contents Contributors ix About the Authors xi Authors’ Acknowledgments xiii Symbian Press Acknowledgments xvii Forewords xix 1 Introduction and Basics 1 1.1 Why Does Python Make a Difference? 3 1.2 How to Use this Book 4 1.3 Who Is this Book For? 5 1.4 What Are Symbian OS, S60 and Python for S60? 6 1.5 Python Terminology in this Book 7 1.6 Democratizing Innovation on the Mobile Platform 8 1.7 The Process of Rapid Prototyping with Python S60 10 1.8 Summary 11 2 Getting Started 13 2.1 Installing Python for S60 on 3rd Edition Devices 14 2.2 Installing Python for S60 on 2nd Edition Devices 21 2.3 Writing a Program in Python for S60 27 2.4 White Space in Python Code 28 2.5 Troubleshooting 29 2.6 Summary 30 vi CONTENTS 3 Graphical User Interface Basics 31 3.1 Using Modules 31 3.2 Native UI Elements – Dialogs, Menus and Selection Lists 32 3.3 Messages 45 3.4 Summary 47 4 Application Building and SMS Inbox 49 4.1 Functions 49 4.2 Application Structure 52 4.3 String Handling 60 4.4 SMS Inbox 64 4.5 SMS Game Server 70 4.6 Summary 76 5 Sound, Interactive Graphics and Camera 77 5.1 Sound 77 5.2 Keyboard Keys 84 5.3 Graphics 92 5.4 Camera 100 5.5 Mobile Game: UFO Zapper 104 5.6 Summary 110 6 Data Handling 111 6.1 File Basics 112 6.2 Reading and Writing Text 117 6.3 Local Database 121 6.4 GSM and GPS Positioning 123 6.5 Vocabulector: A Language-Learning Tool 127 6.6 Summary 131 7 Bluetooth and Telephone Functionality 133 7.1 Bluetooth Pairing 134 7.2 OBEX and RFCOMM 134 7.3 Phone-to-Phone Communication 136 7.4 Phone-to-PC Communication 141 7.5 Communication with GPS and Other Devices 148 7.6 Telephone Functionality and Contacts 151 7.7 System Information 152 7.8 Summary 154 8 Mobile Networking 155 8.1 Simple Web Tasks 156 8.2 Setting up the Development Environment 158 CONTENTS vii 8.3 Communication Protocols 166 8.4 Server Software 172 8.5 Pushing Data to a Phone 177 8.6 Peer-to-Peer Networking 183 8.7 Using a Phone as a Web Service 193 8.8 Summary 197 9 Web Services 199 9.1 Basic Principles 200 9.2 MopyMaps! Mobile Yahoo! Maps 201 9.3 EventFu: Finding Eventful Events 207 9.4 InstaFlickr: Shoot and Upload Photos to Flickr 215 9.5 Summary 224 10 Effective Python for S60 227 10.1 Powerful Language Constructs 227 10.2 Introspection 231 10.3 Custom Modules and Automatic Updating 234 10.4 Program Patterns 239 10.5 Summary 241 11 Combining Art and Engineering 245 11.1 MobiLenin 245 11.2 Manhattan Story Mashup 252 11.3 MobileArtBlog – Image-Composition Tool 256 11.4 ArduinoBT Micro-Controller Board 261 11.5 Controlling Max/MSP with a Phone 266 11.6 OpenSound Control 273 11.7 Robotics 274 11.8 Summary 277 Appendix A: Platform Security 279 Appendix B: Bluetooth Console 289 Appendix C: Debugging 295 Appendix D: How to Use the Emulator 301 References 303 Glossary 305 Examples 309 viii CONTENTS Python Language Lessons 315 Python for S60 Modules 317 Index 321 Contributors Head of Symbian Press Freddie Gjertsen Authors J¨urgen Scheible Ville Tuulos Symbian Press Editorial Managing Editor Satu McNabb Reviewers and Additional Contributors Panos Asproulis Jukka Laurila Joe McCarthy Timo Ojala Mark Shackman About the Authors Jurgen¨ Scheible J¨urgen Scheible is a designer, media artist and musician who holds a degree in telecommunications from Karlsruhe, Germany. After graduating, he worked for eight years at Nokia in Finland pursuing various positions such as programmer, product manager and competence transfer manager. Besides his occupation, he performed and produced music as well as media art under the pseudonym Lenin’s Godson. In 2003, he left his engineering career to concentrate full-time on his creative career, because he felt his heart was much more in his artistic works than in engineering. In 2004, he became a doctoral student at the Media Lab at the University of Art and Design, Helsinki, where he established the Mobile Hub, a prototype development environment for mobile client and server applications. It has a strong focus on artistic approaches and creative design, and serves as a resource to art and design students who use mobile technology as part of their projects. His doctoral research focuses on designing multimodal user interfaces for creating and sharing interactive artistic experiences. Since 2004, he has been evangelizing Python for S60 as one of its pioneers. He is internationally active having given talks and taught innovation workshops in both academic and professional settings on more than 40 occasions, in places such as Stanford University, MIT, NTU Taiwan, Yahoo Research Berkeley, Tsinghua University Beijing, Nokia and Nokia Siemens Networks, in more than 17 countries. His focus is on rapid mobile application prototyping using creative approaches for innovation. In 2006, he spent several months as a visiting scientist at MIT, Boston in the Computer Science and Artificial Intelligence Laboratory (CSAIL). xii ABOUT THE AUTHORS J¨urgen was recognized as a Forum Nokia Champion in 2006 and 2007 for his driving vision of building bridges between art, engineering and research. He was one of the winners of the ACM Computers in Entertain- ment Scholarship Award in 2006 and of the Best Arts Paper Award at ACM Multimedia 2005 conference. The philosophy behind his works is to bring back the depth of human feelings and emotional aspects to the digital world which, in his opinion, were lost with the arrival of the fast-paced digital production technology. By inspiring others with his works, he gets inspired himself. This leads him to many new ideas for designing new kinds of interactive experiences for people, especially in the area of mobile phone applications that fuse the real and the virtual worlds. He believes this era will change the way we live and communicate in the future and it will transform societies. Therefore it is important, in his opinion, to design for these coming applications. Ville Tuulos Ville Tuulos is currently a researcher in the Department of Computer Science, University of Helsinki, Finland. He has more than 15 years’ experience of creative hacking, including data visualization, web search engines, and machine-learning algorithms. He has been an enthusiastic Pythonista since 2000 and he has been exploring and extending the limits of Python for S60 since 2005.