Emerging Technologies
Fall Semester, 2005 Python for Series 60 p2 |
||
---|---|---|
© 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
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.
CS683 Fall 2005 | Doc 14, Python for Series 60 p2 Slide # 2 |
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
CS683 Fall 2005 | Doc 14, Python for Series 60 p2 Slide # 3 |
Required Keys
scroll up, down, left, right selection
left, right
send, end
Application Alphanumeric clear Edit Power |
CS683 Fall 2005 | Doc 14, Python for Series 60 p2 Slide # 4 |
Screen
176 x 208 pixels
Status Pane
Tabs in Nav Pane
CS683 Fall 2005 | Doc 14, Python for Series 60 p2 Slide # 5 |
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
CS683 Fall 2005 | Doc 14, Python for Series 60 p2 Slide # 6 |
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
CS683 Fall 2005 | Doc 14, Python for Series 60 p2 Slide # 7 |
Navigation
CS683 Fall 2005 | Doc 14, Python for Series 60 p2 Slide # 8 |
Highlighting
Menu List
Selection List
Markable List
Setting List
Form
CS683 Fall 2005 | Doc 14, Python for Series 60 p2 Slide # 9 |
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()
CS683 Fall 2005 | Doc 14, Python for Series 60 p2 Slide # 10 |
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
CS683 Fall 2005 | Doc 14, Python for Series 60 p2 Slide # 11 |
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()
CS683 Fall 2005 | Doc 14, Python for Series 60 p2 Slide # 12 |
Form items contain
Label - unicode text
Type
'text', 'number', 'date', 'time', 'combo'
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
CS683 Fall 2005 | Doc 14, Python for Series 60 p2 Slide # 13 |
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
CS683 Fall 2005 | Doc 14, Python for Series 60 p2 Slide # 14 |
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()
CS683 Fall 2005 | Doc 14, Python for Series 60 p2 Slide # 15 |
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
CS683 Fall 2005 | Doc 14, Python for Series 60 p2 Slide # 16 |
TextExample Continued
def exit_key_handler(self):
appuifw.app.exit_key_handler = None
self.script_lock.signal()
if __name__ == '__main__':
TextExample().run()
CS683 Fall 2005 | Doc 14, Python for Series 60 p2 Slide # 17 |
Text Attributes
color
focus
font
highlight_color
style
Text Methods
add(text)
bind(event_code, callback)
clear()
get_pos()
text_length len()
get([pos=0, len=len()])
set(text)
set_pos(cursor_pos)
See API Reference for Python section 5.4 (pp 22-24) for details
CS683 Fall 2005 | Doc 14, Python for Series 60 p2 Slide # 18 |
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
CS683 Fall 2005 | Doc 14, Python for Series 60 p2 Slide # 19 |
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()
Copyright ©, All rights reserved.
2005 SDSU & Roger Whitney, 5500 Campanile Drive, San Diego, CA 92182-7700 USA.
OpenContent license defines the copyright on this document.