I want the tasting journal application to open with a UI that presents two simple options:
- record an experience
- view past experiences
The easiest way that I’ve seen to do that in PyS60 is with a listbox control. The UI in PyS60 is implemented in the appuifw module, which according to the documentation available at sourceforge:
The appuifw module offers an interface to the S60 UI application framework. Figure 5.1 provides an
overview of the Python for S60 environment for UI application programming.
Note: The services of this interface may only be used in the context of the main thread, that is, the
initial thread of a UI application script.
So whether you are new to Python (like me) or just new to Python on S60, this module will be new to you. As I was downloading and installing the execution environment on the N93 and the SDK on my PC, I also downloaded and extracted the source files. Unzipping that package revealed a hidden treasure of example files that I found in directory …srcextrasexamples*.py. Three of the examples in that directory provide good UI overviews – I began with GUI_exaple_2.py, extracted all the peripheral material, and came up with a basic skeleton of a UI for the journal: a list box with two options. I posted that skeleton in the Wiki
here.
Then I went in to the Wiki to find the most basic multimedia functionality – quickly snap a pic
(here) and record a track
(here). Inserting those snippets into the UI skeleton results in this code:
import e32
import appuifw
choices =[(u"New experience", "new"),
(u"Add comment", "comment")]
choices_labels = [x[0] for x in choices]
def takepic(filename):
import camera
im = camera.take_photo() # use all default values
im.save(filename)
def recordaudio(filename):
import e32, audio
print(u"Hello from inside recordaudio fn")
s = audio.Sound.open(filename) # if file exists, append sound to end
s.record() # start recording
e32.ao_sleep(5) # do if for 5 seconds
s.stop() # stop recording
# the file is now created, ready to be played
s.play()
def handle_selection():
index = lb.current()
code = choices[index][1]
lb.set_list([u"Please wait..."])
if code == "new":
appuifw.note(u"here is where we process a new experience", 'info')
takepic (u"e:test.jpg")
recordaudio (u"e:test.amr")
elif code == "comment":
appuifw.note(u"here is where we add a comment", 'info')
recordaudio (u"e:test.amr")
else:
appuifw.note(u"no valide code detected", 'info')
lb.set_list(choices_labels)
def handle_add():
pass
def handle_delete():
pass
def exit_key_handler():
app_lock.signal()
lb = appuifw.Listbox(choices_labels, handle_selection)
old_title = appuifw.app.title
appuifw.app.title = u"Tasty Multimedia Journal"
appuifw.app.body = lb
appuifw.app.menu = [(u"Add new item", handle_add),
(u"Delete item", handle_delete)]
appuifw.app.exit_key_handler = exit_key_handler
app_lock = e32.Ao_lock()
app_lock.wait()
appuifw.app.title = old_title
Next steps:
- Work with a more sophisticated image capture script (here) which provides viewfinder functionality.
- Control media filenames to associate audio tracks with the images they describe.