import papi, atexit # A simple AtkActionIface implementation. class SimpleAction (papi.AtkObject): def __init__ (self): # Create out AtkObject, but also let it implement the AtkAction # interface. papi.AtkObject.__init__ (self, papi.ATK_IFACE_ACTION) self._tracker = 0 # Override the necessary interfaces of the AtkAction. self.action_get_n_actions = self._get_n_actions self.action_get_description = self._get_description self.action_get_name = self._get_name self.action_do_action = self._do_action self.action_get_keybinding = self._get_keybinding def _do_action (self, i): if i == 0: print "The first action was executed." if i == 1: print "Another action was executed." if i == 2: self._tracker += 1 self.name = "Action with %d tracked executions" % self._tracker def _get_n_actions (self): return 3 def _get_keybinding (self, i): y = "Y" if (i == 0): return y return "" def _get_description (self, i): if i == 0: return "Prints a console message." if i == 1: return "Prints another console message." if i == 2: return "Modifies attributes." def _get_name (self, i): if i == 0: return "PrintMessage" if i == 1: return "PrintAnotherMessage" if i == 2: return "ChangeAttributes" # Create the main application application = papi.AtkObject () application.name = "AtkAction Application" application.description = "An AtkAction demonstration example." application.role = papi.ATK_ROLE_APPLICATION # Set the applicaiton object as root, register the shutdown method, so # all gets cleaned up nicely and start the ATK system. papi.set_atk_root (application) atexit.register (papi.shutdown) papi.init () # Create an action object and denote it as a button in the object hierarchy action = SimpleAction () action.name = "Simple AtkAction" action.description = "A simple AtkAction with three actions." action.role = papi.ATK_ROLE_PUSH_BUTTON # Set the parent of the action, so that it can be placed correctly # within the object hierarchy. action.parent = application print "Press CTRL-C to exit the application." while True: # Deal with the events by letting the ATK-System process them. papi.iterate ()