SDSU Emerging Technologies
Fall Semester, 2005
Python for Series 60 p2
Previous     Lecture Notes Index     Next     
© 2005 All Rights Reserved, SDSU & Roger Whitney
San Diego State University -- This page last updated 25 Oct 2005

Doc 13 Python for Series 60 p2

Contents

 

Series 60 Hardware    

UI Components    

Lists Types    

List Example    

Menu & Form Example    

Forms    

Text Example    

Graphics Example    

 

Copyright ©, All rights reserved. 2005 SDSU & Roger Whitney, 5500 Campanile Drive, San Diego, CA 92182-7700 USA. OpenContent ( http://www.opencontent.org/opl.shtml ) license defines the copyright on this document.

 

References

 

Series 60 UI Style Guide

Python for Series 60 Platform API Reference, version 1.1.5

Programming with Python Series 60 Platform, version  1.1.5

 

Series 60 Hardware

 

Required Keys

 

  1. Navigation

scroll up, down, left, right

selection

  1. softkeys

left, right

  1. call handling

send, end

  1. Other

Application

Alphanumeric

clear

Edit Power

 

 

 

 

 

 

Screen

176 x 208 pixels

droppedImage.pdf

 

Status Pane

droppedImage.pdf

 

Tabs in Nav Pane

 

droppedImage.pdf

 

 

 

Hiding Parts of the Screen

 

  

appuifw.app.screen = 'normal'    #normal screen

appuifw.app.screen = 'normal'    #no status pane

appuifw.app.screen = 'full'    #no status or control pane

 

droppedImage.pdf

 

 

Sample Program

class HelloWorld:

    def __init__(self):

        self.lock = e32.Ao_lock()

        appuifw.app.exit_key_handler = self.exit_key_handler

        appuifw.app.title = u"Hello World"

       appuifw.app.screen = 'full'

        

    def run(self):

        self.lock.wait()

        self.close()

        

    def exit_key_handler(self):

        self.lock.signal()

 

    def close(self):

        appuifw.app.exit_key_handler = None

 

 

Navigation

 

droppedImage.pdf

 

 

 

UI Components

Highlighting

droppedImage.pdf

 

Lists Types

  1. Menu List

  1. Selection List

  1. Markable List

  1. Setting List

  1. Form

 

 

 

 

List Example

import appuifw

import e32

 

class ListExample:

    def __init__(self):

        self.script_lock = e32.Ao_lock()

 

    def setup(self):

        self.old_title = appuifw.app.title

        

    def run(self):

           self.setup()

        from key_codes import EKeyLeftArrow

        entries = [u'a', u'b', u'c']

        self.list_box = appuifw.Listbox(entries, self.lbox_observe)

        self.list_box.bind(EKeyLeftArrow, lambda: self.lbox_observe(0))

        self.refresh()

        self.script_lock.wait()

        self.tear_down()

 

    def refresh(self):

        appuifw.app.title = u"List Example"

        appuifw.app.menu = []

        appuifw.app.exit_key_handler = self.exit_key_handler

        appuifw.app.body = self.list_box

 

    def exit_key_handler(self):

        appuifw.app.exit_key_handler = None

        self.script_lock.signal()

 

    def lbox_observe(self, index = None):

        selected = self.list_box.current()

        entries = [u'a', u'b', u'c', unicode(str(selected))]

        self.list_box.set_list(entries, selected)

        self.refresh()

 

 

 

List Example Continued

      

    def tear_down(self):

        appuifw.app.title = self.old_title

        appuifw.app.body = None

        self.list_box = None

 

if __name__ == '__main__':

    ListExample().run()

 

See 5.5 Listbox Type in API Reference for Python for details of Listbox

 

 

 

Menu & Form Example

import appuifw

import e32

 

class FormExample:

    def __init__(self):

        self.script_lock = e32.Ao_lock()

 

    def setup(self):

        self.old_title = appuifw.app.title

        

    def run(self):

        self.setup()

        self.menu = [(u'a', self.do_a), (u'b', self.do_b)]

        self.refresh()

        self.script_lock.wait()

        

    def tear_down(self):

        appuifw.app.title = self.old_title

        appuifw.app.body = None

 

    def refresh(self):

        appuifw.app.title = u"Form Example"

        appuifw.app.menu = self.menu

        appuifw.app.exit_key_handler = self.exit_key_handler

 

    def do_a(self):

        name_form = appuifw.Form([(u'First', 'text', u'Roger'), (u'Last', 'text')])

        name_form.execute()

        print name_form[0][2]

    

    def do_b(self):

        print 'b'

 

    def exit_key_handler(self):

        appuifw.app.exit_key_handler = None

        self.script_lock.signal()

 

if __name__ == '__main__':

    FormExample().run()

 

 

Forms

Form items contain

  1. Label - unicode text

  1. Type

 'text', 'number', 'date', 'time', 'combo'

  1. value

 

name_form = appuifw.Form([(u'First', 'text', u'Roger'), (u'Last', 'text')])

 

name_form[0]         # first form item

name_form[0][0]     # label of first form item

name_form[0][1]     # type of first form item

name_form[0][2]     # value of first form item

 

 

 

Some Form Options                    

import appuifw

import e32

 

class FormExample:

    def __init__(self):

        self.script_lock = e32.Ao_lock()

 

    def setup(self):

        self.old_title = appuifw.app.title

        

    def run(self):

        self.setup()

        self.menu = [(u'a', self.do_a)]

        self.refresh()

        self.script_lock.wait()

        

    def refresh(self):

        appuifw.app.title = u"Form Example"

        appuifw.app.menu = self.menu

        appuifw.app.exit_key_handler = self.exit_key_handler

 

    def do_a(self):

        name_form = appuifw.Form([(u'First', 'text', u'Roger'), (u'Last', 'text')])

        name_form.flags = appuifw.FFormDoubleSpaced

        name_form.menu = [(u'b', self.do_b)]

        name_form.save_hook = self.form_check

        name_form.execute()

        print name_form[1][2]

    

    def do_b(self):

        print 'b'

 

    def form_check(self, form):

        print 'form-check'

        if form[1][2] == u'':

                form[1] = (u'Last', 'text', u'Enter a last name')

        print 'end form'

        return True

        

 

 

Form Options Continued

   def tear_down(self):

        appuifw.app.title = self.old_title

        appuifw.app.body = None

 

    def exit_key_handler(self):

        appuifw.app.exit_key_handler = None

        self.script_lock.signal()

 

if __name__ == '__main__':

    FormExample().run()

 

 

 

Text Example

import appuifw

import e32

 

class TextExample:

    def __init__(self):

        self.script_lock = e32.Ao_lock()

 

    def setup(self):

        self.old_title = appuifw.app.title

        

    def run(self):

        self.setup()

        self.text = appuifw.Text()

        self.text.font = u"LatinBold17"

        self.text.style = appuifw.STYLE_BOLD

        self.text.set(u'Hello\nWorld')

        appuifw.app.body = self.text

        self.refresh()

        self.script_lock.wait()

        self.tear_down()

        

    def tear_down(self):

        appuifw.app.title = self.old_title

        appuifw.app.body = None

 

    def refresh(self):

        appuifw.app.title = u"Text Example"

        appuifw.app.exit_key_handler = self.exit_key_handler

 

 

 

TextExample Continued

    def exit_key_handler(self):

        appuifw.app.exit_key_handler = None

        self.script_lock.signal()

 

if __name__ == '__main__':

    TextExample().run()

 

 

Text Attributes

  1. color

  1. focus

  1. font

  1. highlight_color

  1. style

 

Text Methods

  1. add(text)

  1. bind(event_code, callback)

  1. clear()

  1. get_pos()

  1. text_length len()  

  1. get([pos=0, len=len()])

  1. set(text)

  1. set_pos(cursor_pos)

 

See API Reference for Python section 5.4 (pp 22-24) for details

 

 

 

Graphics Example

import appuifw

import e32

from graphics import *

 

class GraphicsExample:

    def __init__(self):

        self.script_lock = e32.Ao_lock()

 

    def setup(self):

        self.old_title = appuifw.app.title

        appuifw.app.exit_key_handler = self.exit_key_handler

        appuifw.app.screen='full'

        self.image=Image.new((176,208))

        self.canvas = \

             appuifw.Canvas(event_callback=self.handle_event,

                                 redraw_callback=self.handle_redraw)

        appuifw.app.body=self.canvas

        

    def run(self):

        self.setup()

        self.move_ball()

        self.script_lock.wait()

        self.tear_down()

 

    def move_ball(self):

        location=[75.,50.]

        ball_size=16

        for k in range(240):

            self.image.clear(0)

             self.image.point((location[0]+ball_size/2,location[1]+ball_size/2),

                  0x00ff00,width=ball_size)

            self.handle_redraw(())

            e32.ao_yield()

            location[1] += 0.5

        

 

Graphics Example Continued

    def handle_event(self, event):

        pass

 

    def handle_redraw(self, rect):

        self.canvas.blit(self.image)

    

    def tear_down(self):

        appuifw.app.title = self.old_title

        appuifw.app.body = None        

    

    def exit_key_handler(self):

        appuifw.app.exit_key_handler = None

        self.script_lock.signal()

 

if __name__ == '__main__':

    GraphicsExample().run()

Previous     visitors since 25 Oct 2005     Next