Attachment 'button_collection.py'

Download

   1 #!/usr/bin/env python
   2 from simple_at import *
   3 
   4 def run(acc):
   5   # try to query to the collection interface on the app
   6   col = acc.queryInterface('IDL:Accessibility/Collection:1.0')
   7   if col is None:
   8     raise NotImplementedError('%s does not implement collection' % acc.name)
   9 
  10   # define roles to collect
  11   # I believe a Python list of roles will be marshalled properly since the doc
  12   # at http://gnome.org/%7Ebillh/at-spi-new-idl/html/html/namespaceAccessibility.html#a2
  13   # says it is a sequence<Role>
  14   roles = [Accessibility.ROLE_PUSH_BUTTON]
  15 
  16   # create a match rule for our query, making invalid params None and MATCH_ANY
  17   rule = col.createMatchRule(None, Accessibility.MATCH_ANY, 
  18                            None, Accessibility.MATCH_ANY,
  19                            roles, Acccessibility.MATCH_ANY,
  20                            None, Accessibility.MATCH_ANY,
  21                            False) # don't negate the logic
  22 
  23   # get the first few, recursing into descendants past the immediate children
  24   # not sure how an inOut param will be treated by pyORBit; guessing that the 
  25   # backfilled param will be returned as a second return value in Python
  26   buttons, total = col.getChildren(rule, Accessibility.SORT_ORDER_CANONICAL, True, 5)
  27 
  28   # check if unbounded
  29   if total == -1:
  30     print 'collection unbounded'
  31 
  32   # keep track of how many we got back
  33   size = len(buttons)
  34 
  35   # fetch more buttons if we don't have them all
  36   if size != total:
  37     # start at the last returned button and get all that remain
  38     more, total = col.getNextChildren(buttons[-1], rule, Accessibility.SORT_ORDER_CANONICAL, 
  39                                     True, total-size)
  40     buttons += more
  41     
  42   # free the match rule
  43   col.freeMatchRule(rule)
  44   
  45   # these should be all the buttons
  46   return buttons
  47 
  48 if __name__ == '__main__':
  49   d = registry.getDesktop(0)
  50   for i in xrange(d.childCount):
  51     c = d.getChildAtIndex(i)
  52     if c is not None and c.name == 'gcalctool':
  53       run(c)
  54       return
  55   raise RuntimeError('start gcalc')

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2021-02-25 09:41:35, 2.0 KB) [[attachment:button_collection.py]]
  • [get | view] (2021-02-25 09:41:35, 7.0 KB) [[attachment:collection.scm]]
  • [get | view] (2021-02-25 09:41:35, 2.7 KB) [[attachment:firefox.py]]
  • [get | view] (2021-02-25 09:41:35, 1.8 KB) [[attachment:gcalc.py]]
  • [get | view] (2021-02-25 09:41:35, 6.0 KB) [[attachment:match-rule-test.scm]]
  • [get | view] (2021-02-25 09:41:35, 0.6 KB) [[attachment:simple_at.py]]
  • [get | view] (2021-02-25 09:41:35, 0.6 KB) [[attachment:simple_at.pyc]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.