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-2 of 2 total  RSS 

Using google map on mobile phone

Download the tile images for testing
   1  
   2  from urllib import urlretrieve
   3  turl =  'http://mt.google.com/mt?v=w2.4&x=%s&y=%s&zoom=%s'
   4  tfile = '%s-%s-%s.gif'
   5  z = 12
   6  for x in range(5,10):
   7    for y in range(10,14):
   8      urlretrieve(turl % (x,y,z), tfile % (z,y,x))

Then put the images in the phone. Then use the following code
to browse around the images (and zoom in/out)
   1  
   2  from appuifw import *
   3  from key_codes import *
   4  from graphics import Image
   5  import e32
   6  
   7  app.screen = 'full'
   8  app.body = c= Canvas()
   9  
  10  x, y, z = 10*256, 24*256, 11
  11  dirname = u'C:\\system\\data\\gmap\\'  # where I save the tile images
  12  
  13  def draw():
  14      gx, ox = divmod(x, 256)
  15      gy, oy = divmod(y, 256)
  16      f = dirname + '%s-%s-%s.gif' % (z,gy,gx)
  17      c.blit(Image.open(f), target=(-ox,-oy))
  18  
  19      if ox > 80:
  20          f = dirname + '%s-%s-%s.gif' % (z,gy,gx+1)
  21          c.blit(Image.open(f), target=(256-ox,-oy))
  22      if oy > 48:
  23          f = dirname + '%s-%s-%s.gif' % (z,gy+1,gx)
  24          c.blit(Image.open(f), target=(-ox,256-oy))
  25      if ox > 80 and oy > 48:
  26          f = dirname + '%s-%s-%s.gif' % (z,gy+1,gx+1)
  27          c.blit(Image.open(f), target=(256-ox,256-oy))
  28  
  29  def move(dx,dy):
  30      global x, y
  31      x += dx * 50
  32      y += dy * 50
  33      draw()
  34  
  35  def zoomin():
  36      global x,y,z
  37      x = x*2 + 88
  38      y = y*2 + 104
  39      z = z-1
  40      draw()
  41  
  42  def zoomout():
  43      global x,y,z
  44      x = x/2 - 44
  45      y = y/2 - 52
  46      z = z+1
  47      draw()
  48  
  49  c.bind(EKeyRightArrow,lambda:move(1, 0))
  50  c.bind(EKeyLeftArrow,lambda:move(-1, 0))
  51  c.bind(EKeyUpArrow,lambda:move(0, -1))
  52  c.bind(EKeyDownArrow,lambda:move(0, 1))
  53  c.bind(EKeySelect, zoomin)
  54  c.bind(EKeyStar, zoomout)
  55  
  56  running = 1
  57  def quit():
  58      global running
  59      running = 0
  60  app.exit_key_handler= quit
  61  
  62  draw()
  63  while running:
  64      e32.ao_sleep(0.1)

I put a bit more explanation in Nokia's forum here. (Newer version is available)
http://discussion.forum.nokia.com/forum/showthread.php?s=&postid=153609
Also see the screenshot here
http://flickr.com/photos/korakot/30189624/

New camera module

A few days ago, I posted an example of how to take
a photo with py_s60 1.1.0. But now, a new and better
version (1.1.3) is released. The camera module has
improved significantly.

Now it can
- use different sizes (640x480 and 160x120 in my case)
- use zoom (0 or 1 in my case)
- take photos at 12, 16 or 24-bit color ('RGB12', 'RGB16', 'RGB')
- using flash ('none', 'auto', 'forced', 'fill_in', 'red_eye_reduce')
- set white-balance and exposure (I use 'auto' for both,
but sometimes I may use 'night' exposure)
- return an image object which can save in 'jpg' or 'png' format

You can see that these have good default values
   1   # copy from camera.py
   2  def take_photo(
   3    mode='RGB16',
   4    size=(640, 480),
   5    zoom=0,
   6    flash='none',
   7    exposure='auto',
   8    white_balance='auto'):

So the simplest example is
   1  
   2  import camera
   3  im = camera.take_photo()  # use all default values
   4  im.save(u'C:\\test.jpg')

You can see what you can set on your phone
   1  
   2  from camera import *
   3  print image_modes()
   4  print image_sizes()
   5  print max_zoom()
   6  print flash_modes()
   7  print exposure_modes()
   8  print white_balance_modes()

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