1 #Copyright (C) 2008 Codethink Ltd
3 #This library is free software; you can redistribute it and/or
4 #modify it under the terms of the GNU Lesser General Public
5 #License version 2 as published by the Free Software Foundation.
7 #This program is distributed in the hope that it will be useful,
8 #but WITHOUT ANY WARRANTY; without even the implied warranty of
9 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 #GNU General Public License for more details.
11 #You should have received a copy of the GNU Lesser General Public License
12 #along with this program; if not, write to the Free Software
13 #Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 from base import BaseProxy, Enum
17 from factory import accessible_factory
25 #------------------------------------------------------------------------------
28 def __new__(cls, name, id):
29 list.__new__(cls, (name, id))
30 def __init__(self, name, id):
31 list.__init__(self, (name, id))
35 def _set_name(self, val):
37 name = property(fget=_get_name, fset=_set_name)
40 def _set_id(self, val):
42 id = property(fget=_get_id, fset=_set_id)
44 #------------------------------------------------------------------------------
46 class CommandListener(BaseProxy):
48 An interface which should be implemented by assistive technologies
49 or other clients of the Selector interface, over which notifications
50 to the list of available commands is made. The notifyCommands()
51 method of the client is then called by the Selector instance.
53 def notifyCommands(self, *args, **kwargs):
55 Notify the CommandListener instance of changes to the currently
56 available commands, by sending the current CommandList.
58 The newly-available list of Command objects which may be invoked
61 func = self.get_dbus_method("notifyCommands")
62 return func(*args, **kwargs)
64 #------------------------------------------------------------------------------
66 class Selector(BaseProxy):
68 This interface is intended for use by assistive technologies
69 and related user-agents. Via this interface, an assistive technology
70 or user agent may expose a series of choices or selections in
71 textual form, which can be activated on demand by a client of
72 the Selector interface.
73 Examples of the use of this interface include voice-command and
74 remote-control applications, in which the user interaction is
75 wholly or partly delegated by the implementor to an external
79 def activateCommand(self, *args, **kwargs):
81 Request that the Selector invoke the specified Command.
83 the Command to activate/invoke.
84 @return a CommandResult indicating whether the request was honored,
85 and the reason for failure if the Command could not be activated
88 func = self.get_dbus_method("activateCommand")
89 return func(*args, **kwargs)
91 def deregisterChangeListener(self, *args, **kwargs):
93 Tell the Selector instance to cease notifying the specified CommandListener
94 of changes to the command list.
96 the CommandListener to remove from the notification list.
98 func = self.get_dbus_method("deregisterChangeListener")
99 return func(*args, **kwargs)
101 def getCommands(self, *args, **kwargs):
103 Query the Selector for the current CommandList.
104 @return the currently available CommandList
106 func = self.get_dbus_method("getCommands")
107 return func(*args, **kwargs)
109 def refreshCommands(self, *args, **kwargs):
111 Ask the Selector to re-calculate its CommandList.
112 @return TRUE if the CommandList changed.
114 func = self.get_dbus_method("refreshCommands")
115 return func(*args, **kwargs)
117 def registerChangeListener(self, *args, **kwargs):
119 Register a :CommandListener instance for notification of changes
122 the CommandListener to be notified of changes.
124 func = self.get_dbus_method("registerChangeListener")
125 return func(*args, **kwargs)
127 def replaceCommands(self, *args, **kwargs):
129 @return TRUE if the replacement request was successful, FALSE
130 if the request could not be honored.
132 func = self.get_dbus_method("replaceCommands")
133 return func(*args, **kwargs)
135 def get_supportsReplace(self):
136 return self._pgetter(self._dbus_interface, "supportsReplace")
137 def set_supportsReplace(self, value):
138 self._psetter(self._dbus_interface, "supportsReplace", value)
139 _supportsReplaceDoc = \
141 This attribute is TRUE if this Selector allows its CommandList
142 to be specified by the client
144 supportsReplace = property(fget=get_supportsReplace, fset=set_supportsReplace, doc=_supportsReplaceDoc)
146 class CommandResult(Enum):
148 A code returned by a call to activateCommand, indicating the
149 result of the activation request.
152 0:'COMMAND_RESULT_INVALID',
153 1:'COMMAND_RESULT_SUCCESS',
154 2:'COMMAND_RESULT_FAILED',
155 3:'COMMAND_RESULT_OBSOLETE',
156 4:'COMMAND_RESULT_LAST_DEFINED',
159 COMMAND_RESULT_FAILED = CommandResult(2)
160 COMMAND_RESULT_INVALID = CommandResult(0)
161 COMMAND_RESULT_LAST_DEFINED = CommandResult(4)
162 COMMAND_RESULT_OBSOLETE = CommandResult(3)
163 COMMAND_RESULT_SUCCESS = CommandResult(1)
165 # Register the accessible class with the factory.
166 accessible_factory.register_accessible_class(interfaces.ATSPI_SELECTOR, Selector)
168 #END----------------------------------------------------------------------------