Mobile Programming in Python using PyS60: Getting Started - PyS60 Programming in the Real World
(Page 4 of 4 )
The application to be developed will have the following functionalities:
1. An Input box to accept the path for the file to be played.
2. The ability to play a selected file when entered by the user.
Here we go. First comes the imports. Since both UI and Sound are required, the appuifw and audio modules need to be imported.
from appuifw import *
import audio
Next we need to show the entry box to the user and get the path entered by him or her. To display the text box, we can use the query component. The first argument is the prompt to be shown and the second argument is the type of query. The type can be ‘text’, ’date’, ’time’, ’float’ etc. Here the type will be text as we need textual data i.e. a string. The value returned by the query component will be stored in a variable named data.
from appuifw import *
import audio
data=query(u’Enter the path of the file to be played’, ‘text’)
Now we need to load the file. For that we need to call the load method of sound. As discussed in the previous section every method in the sound module is static. We will also check whether the user clicked cancel. If cancel has been clicked, then data will contain null.
from appuifw import *
import audio
data=query(u’Enter the path of the file to be played’, ‘text’)
if data is not Null:
Sound.load(data)
else:
note(u’Give the path name’, ‘info’)
Next let us tell Symbian to play it.
from appuifw import *
import audio
data=query(u’Enter the path of the file to be played’, ‘text’)
if data is not Null:
Sound.load(data)
Sound.play()
else:
note(u’Give the path name’, ‘info’)
That completes our application. Though it is small, it introduces several important concepts of PyS60. In the coming discussions, I will go into more depth on each module. Till then…
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |