Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Korakot Chaovavanich http://korakot.stumbleupon.com

« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS 

Discover bluetooth devices around you

Pys60 has good bluetooth support from the beginning.
However, to discover another device, it require you to
interact with the app, choosing a device from the list.
PDIS has a library that help you list all devices silently.
   1  
   2  # need to install these 2 modules from PDIS first
   3  import aosocketnativenew
   4  from aosocket.symbian.bt_device_discoverer import *
   5  
   6  def callback(error, devices, cb_param=None):
   7      for address, name in devices:      
   8          print "Found: ", name, address
   9  # You can get more data by importing socket and try 
  10  # bt_discover(address) or bt_obex_discover(address)
  11  # see details in official pys60 doc on socket module
  12  
  13  lister = BtDeviceLister()
  14  lister.discover_all(callback, None)

I summarize the code above from thejamo's example here.
His code is more complete with error checking.

Getting key press

In Pys60 1.2 there are 3 types for app.body, namely
- Canvas
- Text
- Listbox
They can recieve and process key press.
In older versions, they all have a bind method:
   1  bind(event_code, callback)

event codes are defined in key_codes module
You can import some or all of them
   1  from key_codes import EKeyLeftArrow, EKeySelect, EKey9, EKeyEdit
See diagram for 6630.

In the latest version, Canvas gains ability to respond
to events in more details. You can give it 2 callbacks
when creating a Canvas object.
   1  c = Canvas(redraw_callback=None, event_callback=None)

event_callback will get a dict of the key event containing:
- 'type': one of EEventKeyDown, EEventKey, or EEventKeyUp
- 'keycode': the logical key
- 'scancode': the physical key
- 'modifier': probably about Shift, Ctrl ?

The simplest use is to detect when type=EEventKey
and use the 'keycode' value.
For advanced use, look at keyviewer.py example.

Nokia platform version

The way Nokia names their phone versions is rather confusing.
For example.
   1  Series 60 Platform 2nd edition feature pack 2


I wonder why don't they just use s60.2.2
Now, at least they have renamed 'Series 60' to 'S60'
which is a good step in the right direction.

So, I will tag all new python for series 60 scripts with
'python, s60' instead of the old 'python, series60'.
« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS