#!/usr/bin/python
''' 
1) Move the mouse over the table in gtk-demo, Editable Cells demo.
2) Every time a new accessible is encountered, it will be printed.
Press Ctrl-C to quit this test.

Generic test template using pyLinAcc. Overide TestCase.init with code to be
executed on run. All lines up to the first blank line in this doc string 
will be printed at runtime.

@author: Peter Parente
@organization: IBM Corporation
@copyright: Copyright (c) 2006 IBM Corporation
@license: Common Public License 1.0

All rights reserved. This program and the accompanying materials are made 
available under the terms of the Common Public License v1.0 which accompanies
this distribution, and is available at
U{http://www.opensource.org/licenses/cpl1.0.php}
'''
import sys, traceback, signal, bonobo
sys.path.insert(0, 'pyLinAcc.zip')
from pyLinAcc import *
 
class TestCase(object):
  def __init__(self):
    self.em = Event.Manager()
    self.desktop = Registry.getDesktop(0)
    a = lambda acc: acc.name == 'gtk-demo'
    b = lambda acc: acc.name == 'Shopping list'
    for i in xrange(self.desktop.childCount):
      child = self.desktop.getChildAtIndex(i)
      if a(child):
        for i in xrange(child.childCount):
          self.frame = child.getChildAtIndex(i)
          if b(self.frame):
            break
    self.table = self.frame.getChildAtIndex(0).getChildAtIndex(1).getChildAtIndex(0)
    print self.frame
    
  def init(self):
    self.em.addClient(self.onEvent, 'mouse:abs')

  def onEvent(self, event):
    x, y = event.detail1, event.detail2
    acc = Interfaces.IComponent(self.table)
    print x, y, acc.getAccessibleAtPoint(x, y, 0)
    
  def onKey(self, event): pass
    
  def start(self):
    self.init()
    self.em.addClient(self.onKey, 'keyboard')
    signal.signal(signal.SIGINT, self.stop)
    for line in globals()['__doc__'].split('\n'):
      if line: 
        print line
      else:
        break
    bonobo.main()
    
  def stop(self, *args, **kwargs):
    self.em.close()
    bonobo.main_quit()
  
if __name__ == '__main__':
  t = TestCase()
  t.start()
