Community: Blogs

你在这里: You Are Here: Olet tässä: Vous êtes ici: Sie befinden sich hier: Tu sei qui: 現在のページ: Você está aqui: Вы здесь: Usted está aquí:

Tasty Multimedia Journal's Forum Nokia Blog

Multi-view UI design in Python for S60

kevin_s2f | 11 July, 2007 02:06

What I started today expecting to be hard turned out to be easy, and what I expected to be easy I still haven't figured out ;-)

I began the day reading and learning from Lfd's code for taking a picture using the viewfinder. Since I want to call it from several places in my app, I want to load it as a library. I wrote a simple calling script, and installed Lfd's code in E:Pythonlib (note -- NOT E:Pythonlibs ). That all worked easily enough, so before I dug into modifying the camera code I wanted to embed the calling routine into my primary script.

That's where I ran into something that I still haven't figured out. The core of my simple UI right now is 10 lines of code that build a list box UI. 

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

The event handler is a function defined earlier in the script.
def handle_selection():
    appuifw.note(u"hello from inside handle_selection",)
    index = lb.current()
    appuifw.note(u"hello from after 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')

    elif code == "comment":
        appuifw.note(u"here is where we add a comment", 'info')
    else:
        appuifw.note(u"no valide code detected", 'info')
        lb.set_list(choices_labels)


Now here's the problem. Since I'll need to re-build the home screen upon returning from taking a picture (which uses Canvas), I factored out those 10 lines of code into a function, and simplified my "main" script into a single statement that calls the function.

def build_homescreen():
    appuifw.note(u"entered buildhomescreen fn",)
    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
build_homescreen()

Turns out that embedding the Listbox build in a function breaks the event handler, as the event handler no longer seems to have access to the pointer to the selected listbox element. I suspect I have a scope problem that I don't yet understand.

I'm over on the discussion boards trying to figure this out. If you have some insight into what I'm missing, or if you can recommend a resource that shows a good multi-view UI implementation, please point me to it. Either by posting a comment to this entry, or by replying to the DiBo question here.

 
 

Rate This

 
 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditFurlTechnocratiMagnoliaTwitter  Share this page Share this page Invite a friend Invite a friend
E-mail Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us Regional websites: Chinese Japanese © 2008 Nokia 
RDF Facets: qfnZtypeQUqfnTypeZBlogContentQ qfnZtypeQUqfnTypeZCommunityContentQ qfnZtypeQUqfnTypeZWebpageQ qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX