3.3. Messages

Let's introduce a second PyS60 module: messaging. It handles the sending of SMS (Short Message Service) and MMS (Multimedia Messaging Service) messages. Here we use only one function from the module: messaging.sms_send().

import messaging
messaging.sms_send("+14874323981", u"Greetings from PyS60")

To be able to send an SMS we need to import the module messaging at the beginning of our script. We only need to pass two parameters to the function sms_send (): the telephone number of the recipient as a string and the body of the message as a Unicode string.

In this concluding example (Example 8), we combine the UI elements learned in this chapter and the function for sending SMS messages into a useful little program.

Imagine you are at home, your fridge is empty and your friend is on the way home passing a grocery store. He does not know which items to buy. You want to send him a list of items by SMS while standing in front of the fridge checking what is needed. Typing all the stuff into the phone is just too much hassle and takes too much time.

This is where your PyS60 program, the Shopping List Assistant, comes in. From a pre-defined list of items on your screen, you can select the items needed using a selection_list() dialog. A text input field lets you type an additional greeting. After this, your shopping list is on its way to your friend by SMS.

Example 3.7. Shopping list assistant
import appuifw, messaging foods = [u"cheese", u"sausage", u"milk", u"banana", u"bread"] ...

Get Mobile Python: Rapid Prototyping of Applications on the Mobile Platform now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.