here2share

# PyS60 Examples

May 10th, 2018
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # PyS60 Examples
  2.  
  3. http://www.ia.hiof.no/~haraldh/pub/pys60_examples.pdf
  4.  
  5.  
  6. 1 Setting up the phone
  7.  
  8. https://garage.maemo.org/frs/?group_id=854\&release_id=3264
  9. Installed the folllowing from certificate_error_fixed:
  10. • Python_2.0.0.sis
  11. • PythonScriptShell_2.0.0_high_capas.sis
  12. And this dependency from the ordinary PythonForS60:
  13. • pips.sis
  14.  
  15. The high capabilities script shell gives access to location and position-
  16. ing, as well as to other capabilities.
  17.  
  18. This little (blocking) example now works:
  19.  
  20. import positioning
  21. positioning.set_requestors([{"type":"service","format":"application","data":"test_app"}])
  22. positioning.position()
  23.  
  24.  
  25. 2 Setting up the bluetooth console
  26.  
  27. (Appropriated from http://wiki.opensource.nokia.com/projects/PyS60_
  28. Bluetooth_console)
  29. Register a serial port (use channel 2. For some reason, channel 1 and
  30. channel 3 might not let the connection through)
  31.  
  32. $ sdptool add --channel=2 SP
  33.  
  34. Now listen to the channel:
  35. $ rfcomm listen rfcomm2 2
  36.  
  37. Then start the bluetooth console from the Python app on the phone,
  38. search and connect to your linux host. You should see something like
  39. this:
  40. Waiting for connection on channel 2
  41. Connection from 00:11:9F:BE:47:CA to /dev/rfcomm2
  42. Press CTRL-C for hangup
  43. Now open a new shell terminal and execute:
  44. $ cu -l /dev/rfcomm2
  45.  
  46. You’re now in control of your mobile’s python console :)
  47.  
  48.  
  49. 3 User interface
  50.  
  51. 3.1 Messages to the user
  52. import appuifw
  53. appuifw.note(u'Forty-two', 'info')
  54. appuifw.note(u'Doh!', 'error')
  55. appuifw.note(u'Okay', 'conf')
  56.  
  57.  
  58. 3.2 Get user input
  59. s = appuifw.query(u'Your name:', 'text')
  60. appuifw.note(s, 'conf')
  61. Possible data types are 'text', 'code', 'number', 'date', 'time',
  62. 'query', 'float'
  63. res = appuifw.query(u'Delete the internet?', 'query')
  64. appuifw.note(unicode(str(res)), 'conf')
  65.  
  66.  
  67. 3.3 Lists
  68. def testSelection() :
  69. choices = [u'foo', u'bar', u'zot', u'bip']
  70. index = appuifw.selection_list(choices)
  71. appuifw.note(choices[index], 'conf')
  72. testSelection()
  73.  
  74.  
  75. 3.4 Tabs
  76. tabs = [u'post', u'web', u'term', u'misc']
  77. def tab_cb(index):
  78.     appuifw.note(tabs[index], 'info')
  79. appuifw.app.set_tabs(tabs, tab_cb)
  80.  
  81.  
  82. 3.5 Menus
  83. def mc_foo():
  84.     return
  85. menu = [
  86.     (u'File',
  87.     ((u'Open', mc_foo), (u'Close', mc_foo), (u'New', mc_foo))),
  88.     (u'View',
  89.     ((u'Full', mc_foo), (u'Normal', mc_foo), (u'Large', mc_foo))]
  90. appuifw.app.menu = menu
  91.  
  92.  
  93. 3.6 Screen size
  94. appuifw.app.screen = 'normal'
  95. # 'normal', 'large', 'full'
  96.  
  97.  
  98. 4 Phone features
  99.  
  100. 4.1 Dialing out
  101. Note: this requires a valid subscriptions for phone calls . . .
  102. import telephone
  103. telephone.dial('91193486')
  104. telephone.hang_up()
  105.  
  106.  
  107. 4.2 SMS / Inbox
  108. # Reading messages in inbox
  109. import inbox
  110. ib = inbox.Inbox()
  111. ids = ib.sms_messages()
  112. for id in ids:
  113.     print ib.address(id), ib.time(id)
  114. # ib.content(id)
  115. # Listen for new messages
  116. def message_cb(id):
  117.     ib = inbox.Inbox()
  118.     print 'New message received from ' + ib.address(id)
  119. # Note, the text is shown on the console, not the phone
  120. ib.bind(message_cb)
  121.  
  122.  
  123. 4.3 Location
  124. Location (and positioning) needs extra permissions to work properly.
  125. import location
  126. loc = location.gsm_location()
  127. # Example:
  128. # 242 = Country -> Norway
  129. # 1 = Mobile network code -> Telenor
  130. # 13901 = Local area code
  131. # 7116 = CellID
  132.  
  133.  
  134. 4.4 Camera
  135. import camera
  136. img = camera.take_photo()
  137. c = appuifw.Canvas()
  138. appuifw.app.body = c
  139. c.blit(img)
  140. # Alt. use the appuifw.Content_handler
  141. img.save(u'E:\\tmp_snapshot.jpg')
  142. ch = appuifw.Content_handler()
  143. ch.open(u'E:\\tmp_snapshot.jpg')
  144.  
  145.  
  146. 4.5 Internet
  147. import urllib
  148. t = appuifw.Text()
  149. appuifw.app.body = t
  150. f = urllib.urlopen("http://www.ia.hiof.no/~haraldh/misc/hello.txt")
  151. res = f.read()
  152. t.set(unicode(res))
  153. f.close()
  154.  
  155.  
  156. 4.6 Bluetooth
  157. # Reading from a serial port. First set up serial port on the linux box:
  158. # sdptool add --channel=11 sp
  159. # rfcomm listen rfcomm3 11
  160. import socket
  161. s = socket.socket(socket.AF_BT, socket.SOCK_STREAM)
  162. s.connect(("00:22:5F:1F:D4:BC", 11))
  163. # cu -l /dev/rfcomm3
  164. s.close()
  165. # Sending a file using OBEX
  166. import socket
  167. socket.bt_obex_send_file("00:10:C6:EE:B7:45", 4, u"E:\\temp\\snapshots\\1.jpg")
  168. 5 And there is more
  169. • Database
  170. • Audio
  171. • Contacts
  172. • Calender
  173. sysinfo.imei()
  174. os.makedirs(<dirname>)
Add Comment
Please, Sign In to add comment