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 

Mobile timeout app

   1  
   2  from appuifw import *
   3  from key_codes import *
   4  from graphics import Image
   5  from audio import *
   6  import e32, miso
   7  
   8  def change_duration():
   9      global duration
  10      answer = query(u'How long?', 'time', 18000.0)
  11      if answer:
  12          duration = int(answer/60)
  13          if duration <= 200:
  14              if query(u'Change to hr:min ?', 'query'):
  15                  duration *= 60
  16  
  17  im = Image.new((60,48))
  18  def showtime(rect=None):
  19      im.clear()
  20      im.text((5,28), u"%02d:%02d" % divmod(duration,60), font='title')
  21      c.blit(im, target=(0,0,180,144), scale=1)    # triple size
  22  
  23  duration = 300
  24  running = 0
  25  app.body = c = Canvas(showtime)
  26  alert = Sound.open(u'Z:\\Nokia\\Sounds\\Digital\\Cuckoo.awb')
  27  showtime()
  28  
  29  def start():
  30      global duration, running
  31      running = 1
  32      while running:
  33          duration -= 1
  34          showtime()
  35          if duration <= 0:
  36              alert.play(-2)  # repeat play
  37              break
  38          if duration % 10 == 0:
  39              miso.reset_inactivity_time()
  40          e32.ao_sleep(1)
  41  
  42  def toggle():
  43      global running
  44      if alert.state() == EPlaying:
  45          alert.stop()
  46          return
  47      running = 1 - running
  48      if running:
  49          start()
  50  
  51  def quit():
  52      global running
  53      running = 0
  54      if alert.state() == EPlaying:
  55          alert.stop()
  56      lock.signal()
  57  
  58  lock = e32.Ao_lock()
  59  c.bind(EKeySelect, toggle)  # start, pause, resume
  60  app.menu = [(u'Duration', change_duration),(u'Close', quit)]
  61  app.exit_key_handler = quit
  62  lock.wait()

Remind yourself of how fast time fly with this app.
You should change the sound file to the one you like.
(I use cuckoo.awb)
The duration input abues the time input by treating input
as minutes and seconds instead of hours and minutes.
But if the duration is too short, it will ask you if you mean
hours and minutes.

Make a phone vibrating periodically

Some of my friends who practise mindfulness meditation
use an alarm device that vibrate every 2 minutes and
he will become mindful then.
Danny O'Brien of Life Hacks fame asked me about this too.
So, here's a short example (without parameter setting GUI)
that does exactly this.

You need to have miso library install. Only Series 60
2nd Ed FP2 device (Nokia 6630, Nokia 6680) can be used.
See vibrate(...) in miso documentation
http://pdis.hiit.fi/pdis/download/miso/miso-1.40-api.html
   1  
   2  import appuifw, miso, e32
   3  
   4  # run-and-break type of app
   5  running = 1
   6  def set_exit():
   7      global running
   8      running = 0
   9  appuifw.app.exit_key_handler= set_exit
  10  
  11  # main loop
  12  while running:
  13      miso.vibrate(500, 100)  # vibrate for 500 millisec, at full speed
  14      e32.ao_sleep(10)   # vibrate every 10 seconds

I don't have a FP2 phone to test this. Though the code is
pretty straight forward, please report if there is a problem.
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS