Programmierung von Mobiltelefonen mit Python

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Notes on slide 1

    © 2009 Andreas Schreiber , Deutsches Zentrum für Luft- und Raumfahrt e.V., Köln-Porz http://www.dlr.de/sc/abteilung/verteiltesysteme

    1 Group

    Programmierung von Mobiltelefonen mit Python - Presentation Transcript

    1. Programmierung von Mobiltelefonen mit Python Symbian S60 Andreas Schreiber <Andreas.Schreiber@dlr.de> PyCologne – Python User Group Köln, 11.02.2009
    2. Smartphones
      • Kombination aus
      • Mobiltelefon („Handy“)
      • Personal Digital Assistant (PDA)
      • Viele Funktionen und Protokolle
      • Telefonie, PIM, Web-Browser, SMS, MMS, E-Mail, VoIP, Multimedia, Radio, Digitalkamera, GPS, DVB-H, …
      • GSM, UMTS, GRPS, HSCSD, WLAN, Bluetooth, IR, USB, …
      • Betriebssystem
      • Smartphones haben vollständige, erweiterbare Betriebssysteme
      • Handys haben vordefinierte Oberfläche; nur begrenzt erweiterbar (z.B. durch Java)
    3. Betriebssysteme für Smartphones
      • Liste: http://de.wikipedia.org/wiki/Smartphone#Betriebssysteme
      • Linux
        • Android
        • Openmoko
      • Mac OS X (Apple iPhone)
      • Palm OS
      • RIM BlackBerry
      • Symbian OS
        • UIQ (Sony Ericsson)
        • Series 80 (Nokia Communicator)
        • Series 60 (Nokia N-series & E-series, Siemens, Samsung, Motorola, Panasonic)
      • Windows
    4. Symbian OS und S60
      • Symbian OS
      • Betriebssystem für Smartphones und PDAs
      • Microkernel, 32bit, Single User
      • GUI-zentriertes Applikations-Framework
      • S60
      • Benutzeroberfläche für Smartphones
      • Aktuell: S60 3rd Edition
      • Entwicklungsumgebungen
      • C++, Java, Web Widgets
      • (Flash Lite), (Python)
      Quelle: S60 Platform: Introductory Guide. Nokia Corporation, 2007. http://www.s60.com/business/developers/documents A schematic diagram of the S60 platform architecture.
    5. Python for S60 (PyS60)
      • Portierung von Python auf S60-Plattform
      • Entwicklung von NOKIA
      • Open-Source-Lizenz (Apache Version 2 und Python)
      • Stable Release
        • Aktuelle Version: 1.4.5 (03.12.2008)
        • Verfügbar bei Sourceforge http://sourceforge.net/projects/pys60
      • Development Release
        • Aktuelle Version: 1.9.1 (24.01.2009)
        • Verfügbar bei maemo.org https://garage.maemo.org/projects/pys60
    6. Installation von PyS60 Version 1.9.1 unter Windows
      • Herunterladen des Installationspaketes (für Windows: PythonForS60_1.9.1_Setup.exe )
      • Der Installer installiert:
        • PyS60 Application Packager Ensymble
        • Python Dokumentation
        • Symbian Installationsdateien
      • Installation der Python Runtime und der Dependencies auf dem Smartphone
    7.  
    8. “ Hello World” import appuifw appuifw.app.title = u „Hello World&quot; appuifw.note(u &quot;Hello World!&quot; , 'info' )
    9. Start des Python-Interpreters
    10. Ausführen von Python-Code (1) Skripte (“Run script”)
    11. Ausführen von Python-Code (2) Interaktive Konsole
    12. Ausführen von Python-Code (3) Bluetooth-Konsole
    13. Bluetooth Console Microsoft HyperTerminal
    14. Python API Typen und Bibliotheken von PyS60
      • Alle Built-In-Typen von Python 2.5.1 sind vorhanden
      • Python Standard Library
        • Viele der Standard-Module laufen
      • Python-Extensions für S60: Native C++-Erweiterungen
        • Built-in Extensions:
        • e32 : API für die Services der Symbian OS Platform
        • appuifw : API für das UI Application Framework
        • Dynamisch nachladbare Extensions:
        • sysinfo, graphics, camera, keycapture, topwindow, gles, glcanvas, sensor, audio, telephone, messaging, inbox, location, positioning, calendar, contacts, e32db, logs
        • Entwicklung eigener Extensions per Python/C API möglich
    15. Python S60-Module (1) Betriebssystem-Zugriff und -Information
      • e32
      • Zugriff auf Betriebssystem-Funktion von Symbian, die nicht durch GUI-Module oder die Python Standard Library abgedeckt sind, z.B. Scheduler, Process-Management, Drive-Liste, (Py-)S60-Versionen
      • sysinfo
      • Systeminformationen, z.B. aktiviertes Profil, Batteriestatus, Displaygröße, gesamter und freier Speicherplatz, OS Version, Signalstärke
    16. Python S60-Module (2) Benutzerschnittstelle und Grafik (I)
      • appuifw
      • API für das S60 GUI Application Framework
      • graphics
      • Grafik- und Bildfunktionen, z.B. Laden, Speichern, Rotieren & Skalieren von Bildern, Erstellen von Grafiken mit Grafikprimitiven und Screenshots
      • camera
      • Aufnahme von Fotos und Video, Einstellen der Kamera-Parameter
      • keycapture
      • Abfangen von Tastatur-Events
      • topwindow
      • Einblenden von Fenstern über Applikationen, dargestellt wird ein graphics.Image
    17. Python S60-Module (3) Benutzerschnittstelle und Grafik (II)
      • gles
      • Python API für OpenGL ES 2D/3D Grafik. Siehe OpenGL ES Standard bei Khronos ( http://www.khronos.org/opengles / )
      • glcanvas
      • UI Steuerung für OpenGL ES Grafik
      • sensor
      • Zugriff auf physikalische Sensoren (Bewegung/Acceleration, Antippen/Tapping, Rotation)
    18. Python S60-Module (4) Audio und Kommunikation
      • audio
      • Audio-Funktionen, z.B. Aufnahme, Abspielen von Audio-Dateien, Lautstärkeregelung, Sprachausgabe ( text-to-speech )
      • telephone
      • Telefonie-Funktionen: Wählen, Auflegen und Rückruf
      • messaging
      • Senden von SMS und MMS
      • inbox
      • Zugriff auf Message-Folder (Inbox, Outbox, Sent und Draft)
      • location
      • Abfrage der GSM-Funkzellen-Informationen
      • positioning
      • Zugriff auf GPS-Empfänger
    19. Python S60-Module (5) Datenmanagement
      • contacts
      • Zugriff auf Adressbuch ( ContactDb ), z.B. Suchen nach Kontakten, Anzeigen von Gruppen, Ändern von Kontaktinformationen, Import/Export von vCards
      • calendar
      • Zugriff auf die Kalender-Datenbank ( CalendarDb ), z.B. Hinzufügen und Ändern von Terminen, Ereignissen, Geburtstagen und Aufgaben, Behandlung wiederholender Einträge, Import/Export des vCalendar-Formats
      • e32db
      • Schnittstelle zur nativen Symbian Datenbank, z.B. Anlegen von Datenbanken und SQL-Abfragen
      • logs
      • Zugriff auf Telefon-Protokolle, z.B. Anrufe, SMS, Daten, Faxe, Mails
    20. Struktur von Applikationen (1) Visuelles Layout
      • Typisches visuelles Layout von S60-Applikationen
      Title Navigation Tabs Body Menu Exit Dialog
    21. Struktur von Applikationen (2) Source-Code-Template
      • Import von Modulen
      • Screen Size setzen
      • Applications Menu
      • Exit key handler setzen (Callback function)
      • Application title setzen
      • Application body
      • Active Objects
      • Main Loop
      import appuifw import e32 appuifw.app.screen = 'normal' def item1(): print &quot; item1 was selected.” appuifw.app.menu = [(u&quot;item 1&quot;, item1)] def quit(): appuifw.app.set_exit() app.exit_key_handler=quit appuifw.app.title = u 'Simple Application' app_lock = e32.Ao_lock() # starts scheduler -> event processing app_lock.wait() Ausführliches Template unter: http://www.mobilenin.com/pys60/resources/app_skeleton_with_mainloop.py
    22. Graphical User Interface ( appuifw ) Basiselemente
      • Dialoge
        • note : popup note
        • query : Texteingabe mit einem Feld
        • multi_query : Texteingabe mit zwei Feldern
      • Menus
        • popup_menu : Einfaches Menu
      • Auswahllisten
        • selection_list : Einfache Listenauswahl (vgl. „Radio buttons“)
        • multi_selection_list : Mehrfachauswahl (vgl. „Check boxes“)
    23. Graphical User Interface ( appuifw ) Screen Size
      • Drei Formate für Applikationen
      • Rotation der Anzeige ist möglich (portrait, landscape)
      normal large full
    24. Packaging Ensymble Developer Utilities
      • Aufgaben
      • Erzeugung von SIS-Packages
      • Merge von SIS-Packages
      • Signing von Packages
      • Implementierung
      • Python-Module und command line tools
      • GUI „PyS60 Application Packager“ (Qt)
    25. Beispiele
    26. Beispiel „Versenden einer SMS“ (1) Source Code import appuifw import messaging data = appuifw.query(u &quot;what are you doing?&quot; , &quot;text&quot; ) receiver = &quot;+49172940****&quot; if appuifw.query(u &quot;Send message?&quot; , &quot;query&quot; ) == True : messaging.sms_send(receiver, data) appuifw.note(u &quot;Message sent.&quot; , &quot;info&quot; ) else : appuifw.note( u&quot;Messages not sent!&quot; , &quot;info&quot; ) send_sms.py
    27. Beispiel „Versenden einer SMS“ (2) Ausführung
    28. Beispiel „Versenden einer SMS“ (3) Erfolgskontrolle beim Empfänger
    29. Beispiel „SMS-Empfang und Sound“ (1) Funktionen
      • Empfang von Befehlen per SMS ( „record“ , „stop“ , „play“ , „clear“ )
      • Aufzeichnen und Abspielen von Audio
      sms_sound_demo.py
    30. Beispiel „SMS-Empfang und Sound“ (2) Source Code: Sound-Operationen class SoundRecorder: filename = 'e:\boo.wav' # Drive E: is SD card mySound = None def record(self): self.mySound = audio.Sound.open(self.filename) self.mySound.record() def play(self): try : self.mySound = audio.Sound.open(self.filename) self.mySound.play() except : appuifw.note(u &quot;No sound recorded!&quot; , &quot;error&quot; ) def stop(self): if self.mySound: self.mySound.stop() self.mySound.close() def clear(self): self.stop() os.remove(self.filename)
    31. Beispiel „SMS-Empfang und Sound“ (3) Source Code: SMS-Empfang recorder = SoundRecorder() def message_received(msg_id): box = inbox.Inbox() sms_text = box.content(msg_id) appuifw.note(u &quot;sms content: &quot; + sms_text , &quot;info&quot; ) if sms_text == &quot;play&quot; : recorder.play() elif sms_text == &quot;record&quot; : recorder.record() elif sms_text == &quot;stop&quot; : recorder.stop() elif sms_text == &quot;clear&quot; : recorder.clear() app_lock.signal() box = inbox.Inbox() box.bind(message_received)
    32. Beispiel „Kontakte-Datenbank“ import contacts db = contacts.open() print u &quot;Searching contacts…&quot; found = db.find( 'guy' ) # search in name, email, etc. for guy in found: firstname = guy.find( 'first_name' )[0].value company = guy.find( 'company_name' )[0].value email_address = guy.find( 'email_address' )[0].value print u &quot;%s %s %s&quot; % (firstname, company, email_address) contacts_demo.py
    33. Beispiel „Kamera und File-Upload“ (1) Aufnahme von Bildern import time import appuifw import camera filename = time.strftime( &quot;n95-%Y%m%d%H%M%S.jpg&quot; , time.gmtime()) image = camera.take_photo() image.save(filename) appuifw.note(u &quot;Photo saved to %s&quot; % filename, 'info' ) if imageToURL(filename) == 200: appuifw.note(u &quot;Photo uploaded successfully.&quot; , 'info' ) else : appuifw.note(u &quot;Photo upload failed!&quot; , 'error' ) camera_upload.py
    34. Kamera-Einstellungen Optionen von camera.take_photo() def take_photo( mode= 'RGB16' , size=(640, 480), zoom=0, flash= 'none' , exposure= 'auto' , white_balance= 'auto' ):
    35. Beispiel „Kamera und File-Upload“ (2) Hochladen auf Server mit httplib import httplib, urllib, base64, os.path def imageToURL(aPath): data = open(aPath, 'rb' ).read() # read binary data of picture encodedData = base64.encodestring(data) # encoded it to base64 headers = { &quot;Content-type&quot; : &quot;application/x-www-form-urlencoded&quot; , &quot;Accept&quot; : &quot;text/plain&quot; ,} params = urllib.urlencode({u 'fileName' : os.path.split(aPath)[1], u 'data' :encodedData}) conn = httplib.HTTPConnection( &quot;www.onyame.de&quot; ) conn.request( &quot;POST&quot; , &quot;/image_uploader.php&quot; , params, headers) response = conn.getresponse() conn.close() return response.status Quelle: http://wiki.forum.nokia.com/index.php/How_to_upload_a_file_to_server_with_application/x-www-form-urlencoded
    36. Beispiel „Kamera und File-Upload“ (3) Hochladen auf Server
    37. Beispiel „Kamera und File-Upload“ (4) Erfolgskontrolle
      • http://www.onyame.de/upload/fb.php
    38. Beispiel „Mandelbrot-Menge“ (1) Rahmenprogramm import e32 from appuifw import * app.screen = 'full' app.body = canvas = Canvas() width, height = canvas.size xaxis = width/2 yaxis = height/1.5 scale = 60 iterations = 25 # <<iteration>> lock = e32.Ao_lock() app.exit_key_handler = lock.signal lock.wait() mandelbrot.py
    39. Beispiel „Mandelbrot-Menge“ (2) Iterationsschleife for y in range(height): for x in range(width): magnitude = 0 z = 0+0j c = complex(float(y-yaxis)/scale, float(x-xaxis)/scale) for i in range(iterations): z = z**2+c if abs(z) > 2: v = 765*i/iterations if v > 510: color = (255, 255, v%255) elif v > 255: color = (255, v%255, 0) else : color = (v%255, 0, 0) break else : color = (0, 0, 0) canvas.point((x, y), color) e32.ao_yield()
    40. Beispiel „Bewegungssensor“ (1) Abfrage der Beschleunigungssensoren import sensor sensors = sensor.sensors() # Does this device have Accelerator Sensor if sensors.has_key( 'AccSensor' ): SENSOR_ACC = True sensor_data = sensors[ 'AccSensor' ] sensor_acc = sensor.Sensor(sensor_data[ 'id' ], sensor_data[ 'category' ]) sensor_acc.connect(handle_sensor_raw) def handle_sensor_raw(a_data): if a_data.has_key( 'data_1' ): acc_data_1 = a_data[ 'data_1' ] acc_data_2 = a_data[ 'data_2' ] acc_data_3 = a_data[ 'data_3' ]
    41. Beispiel „Bewegungssensor“ (2) Graphische Aufbereitung: „Sensor Analyzer“
      • http://jouni.miettunen.googlepages.com/sensoranalyzer
    42. Beispiel „Location Based Service“ Auswertung der GSM Cell ID
      • Send SMS to someone if caretan cell is near
      import location HOME_CELL_ID = u&quot;98521779&quot; WIFE = u&quot;+49173247****“ entries = [u &quot;freu mich auf Dich!&quot; , u &quot;hab Hunger.&quot; , u &quot;hab schlechte Laune.&quot; ] listbox = appuifw.Listbox(entries, shout) home = 0 while home == 0: country, provider, lac, cell = location.gsm_location() if (cell== HOME_CELL_ID): home = 1 message = u &quot;Bin gleich zuhause und %s&quot; % mood messaging.sms_send(WIFE, message) cell_id_demo.py
    43. Beispiel „OpenGL“
      • http://tinyurl.com/pys60cube
    44. Links
      • Python for S60
      • http://opensource.nokia.com/projects/pythonfors60/index.html
      • http://sourceforge.net/projects/pys60 (Version 1.4.x)
      • https://garage.maemo.org/projects/pys60 (Version 1.9.x)
      • http://wiki.opensource.nokia.com/projects/Python_for_S60
      • Symbian S60
      • http://www.s60.com
    45. Anlaufstellen für Hilfe
      • Python for S60 discussion board at Forum Nokia
      • http:// discussion.forum.nokia.com/forum/forumdisplay.php?forumid =102
      • IRC channel #pys60 bei Freenode.net
      • irc://chat.freenode.net/pys60
      • Google Group Python for S60
      • http://groups.google.com/group/py4S60
      • Google Group PythonS60
      • http://groups.google.com/group/pythons60
      • Beispiele / Code-Snippets
      • http://wiki.forum.nokia.com/index.php/Category:Python#Code_Examples_for_Python
      • http://snippets.dzone.com/tags/series60
    46. Python für andere mobile Geräte
      • Übersicht Python for Mobile Devices
      • http://www.awaretek.com/pymo.html
    47. Literatur
      • Jürgen Scheible, Ville Tuulos. Mobile Python: Rapid Prototyping of Applications on the Mobile Platform http://www.mobilepythonbook.org
    48. Fragen?
    SlideShare Zeitgeist 2009

    + Andreas SchreiberAndreas Schreiber Nominate

    custom

    1812 views, 0 favs, 2 embeds more stats

    Programmierung von Mobiltelefonen mit S60-Betriebss more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 1812
      • 1801 on SlideShare
      • 11 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 7
    Most viewed embeds
    • 10 views on http://www.onyame.de
    • 1 views on http://feeds2.feedburner.com

    more

    All embeds
    • 10 views on http://www.onyame.de
    • 1 views on http://feeds2.feedburner.com

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories

    Groups / Events