PyS60 Hacking

runner.py

runner.py is a small file (install it as a library) to make more efficient running processes in PyS60. I kept finding myself writing code like:

exit_flag = 0
 
def set_exit():
  global exit_flag
  exit flag = 1
 
appuifw.app.exit_key_handler = set_exit
 
def my_function():
  print "I am great!"
  e32.ao_sleep(1)
 
while not exit_flag:
  my_function()
  e32.ao_yield()

Runner automates that. Here's an example:

from runner import Runner
 
def my_function():
  print "I am great!"
  e32.ao_sleep(1)
 
r = Runner(my_function)
r.run()

Here's the code for runner.py:

import appuifw
import e32
 
class Runner(object):
  def __init__(self, to_run):
    appuifw.app.exit_key_handler = self.set_exit
    self.exit_flag = 0
    self.to_run = to_run 
 
  def run(self):
    while not self.exit_flag:
      self.to_run()
      e32.ao_yield()
 
  def set_exit(self):
    self.exit_flag = 1
people/dan/s60_python.txt · Last modified: 2007/07/03 09:52 (external edit)
chimeric.de = chi`s home Creative Commons License Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0