dump_accessibility_tree_auralinux.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/usr/bin/env python
  2. # Copyright 2015 The Chromium Authors. All rights reserved.
  3. # Use of this source code is governed by a BSD-style license that can be
  4. # found in the LICENSE file.
  5. """Dump Chrome's ATK accessibility tree to the command line.
  6. Accerciser is slow and buggy. This is a quick way to check that Chrome is
  7. exposing its interface to ATK from the command line.
  8. """
  9. from __future__ import print_function
  10. import pyatspi
  11. # Helper function to check application name
  12. def AppNameFinder(name):
  13. if (name.lower().find('chromium') !=0 and
  14. name.lower().find('chrome') !=0 and
  15. name.lower().find('google chrome') != 0):
  16. return False
  17. return True
  18. def Dump(obj, indent):
  19. if not obj:
  20. return
  21. indent_str = ' ' * indent
  22. role = obj.get_role_name()
  23. name = obj.get_name()
  24. bounds = obj.get_extents(pyatspi.DESKTOP_COORDS)
  25. bounds_str = '(%d, %d) size (%d x %d)' % (
  26. bounds.x, bounds.y, bounds.width, bounds.height)
  27. print('%s%s name="%s" %s' % (indent_str, role, name, bounds_str))
  28. # Don't recurse into applications other than Chrome
  29. if role == 'application':
  30. if (not AppNameFinder(name)):
  31. return
  32. for i in range(obj.get_child_count()):
  33. Dump(obj.get_child_at_index(i), indent + 1)
  34. desktop = pyatspi.Registry.getDesktop(0)
  35. Dump(desktop, 0)