Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # PyS60 Examples
- http://www.ia.hiof.no/~haraldh/pub/pys60_examples.pdf
- 1 Setting up the phone
- https://garage.maemo.org/frs/?group_id=854\&release_id=3264
- Installed the folllowing from certificate_error_fixed:
- • Python_2.0.0.sis
- • PythonScriptShell_2.0.0_high_capas.sis
- And this dependency from the ordinary PythonForS60:
- • pips.sis
- The high capabilities script shell gives access to location and position-
- ing, as well as to other capabilities.
- This little (blocking) example now works:
- import positioning
- positioning.set_requestors([{"type":"service","format":"application","data":"test_app"}])
- positioning.position()
- 2 Setting up the bluetooth console
- (Appropriated from http://wiki.opensource.nokia.com/projects/PyS60_
- Bluetooth_console)
- Register a serial port (use channel 2. For some reason, channel 1 and
- channel 3 might not let the connection through)
- $ sdptool add --channel=2 SP
- Now listen to the channel:
- $ rfcomm listen rfcomm2 2
- Then start the bluetooth console from the Python app on the phone,
- search and connect to your linux host. You should see something like
- this:
- Waiting for connection on channel 2
- Connection from 00:11:9F:BE:47:CA to /dev/rfcomm2
- Press CTRL-C for hangup
- Now open a new shell terminal and execute:
- $ cu -l /dev/rfcomm2
- You’re now in control of your mobile’s python console :)
- 3 User interface
- 3.1 Messages to the user
- import appuifw
- appuifw.note(u'Forty-two', 'info')
- appuifw.note(u'Doh!', 'error')
- appuifw.note(u'Okay', 'conf')
- 3.2 Get user input
- s = appuifw.query(u'Your name:', 'text')
- appuifw.note(s, 'conf')
- Possible data types are 'text', 'code', 'number', 'date', 'time',
- 'query', 'float'
- res = appuifw.query(u'Delete the internet?', 'query')
- appuifw.note(unicode(str(res)), 'conf')
- 3.3 Lists
- def testSelection() :
- choices = [u'foo', u'bar', u'zot', u'bip']
- index = appuifw.selection_list(choices)
- appuifw.note(choices[index], 'conf')
- testSelection()
- 3.4 Tabs
- tabs = [u'post', u'web', u'term', u'misc']
- def tab_cb(index):
- appuifw.note(tabs[index], 'info')
- appuifw.app.set_tabs(tabs, tab_cb)
- 3.5 Menus
- def mc_foo():
- return
- menu = [
- (u'File',
- ((u'Open', mc_foo), (u'Close', mc_foo), (u'New', mc_foo))),
- (u'View',
- ((u'Full', mc_foo), (u'Normal', mc_foo), (u'Large', mc_foo))]
- appuifw.app.menu = menu
- 3.6 Screen size
- appuifw.app.screen = 'normal'
- # 'normal', 'large', 'full'
- 4 Phone features
- 4.1 Dialing out
- Note: this requires a valid subscriptions for phone calls . . .
- import telephone
- telephone.dial('91193486')
- telephone.hang_up()
- 4.2 SMS / Inbox
- # Reading messages in inbox
- import inbox
- ib = inbox.Inbox()
- ids = ib.sms_messages()
- for id in ids:
- print ib.address(id), ib.time(id)
- # ib.content(id)
- # Listen for new messages
- def message_cb(id):
- ib = inbox.Inbox()
- print 'New message received from ' + ib.address(id)
- # Note, the text is shown on the console, not the phone
- ib.bind(message_cb)
- 4.3 Location
- Location (and positioning) needs extra permissions to work properly.
- import location
- loc = location.gsm_location()
- # Example:
- # 242 = Country -> Norway
- # 1 = Mobile network code -> Telenor
- # 13901 = Local area code
- # 7116 = CellID
- 4.4 Camera
- import camera
- img = camera.take_photo()
- c = appuifw.Canvas()
- appuifw.app.body = c
- c.blit(img)
- # Alt. use the appuifw.Content_handler
- img.save(u'E:\\tmp_snapshot.jpg')
- ch = appuifw.Content_handler()
- ch.open(u'E:\\tmp_snapshot.jpg')
- 4.5 Internet
- import urllib
- t = appuifw.Text()
- appuifw.app.body = t
- f = urllib.urlopen("http://www.ia.hiof.no/~haraldh/misc/hello.txt")
- res = f.read()
- t.set(unicode(res))
- f.close()
- 4.6 Bluetooth
- # Reading from a serial port. First set up serial port on the linux box:
- # sdptool add --channel=11 sp
- # rfcomm listen rfcomm3 11
- import socket
- s = socket.socket(socket.AF_BT, socket.SOCK_STREAM)
- s.connect(("00:22:5F:1F:D4:BC", 11))
- # cu -l /dev/rfcomm3
- s.close()
- # Sending a file using OBEX
- import socket
- socket.bt_obex_send_file("00:10:C6:EE:B7:45", 4, u"E:\\temp\\snapshots\\1.jpg")
- 5 And there is more
- • Database
- • Audio
- • Contacts
- • Calender
- • sysinfo.imei()
- • os.makedirs(<dirname>)
Add Comment
Please, Sign In to add comment