1 '''
2 Allows a user to switch between up to three languages of their choosing as
3 supported by the current speech engine.
4
5 @author: Peter Parente
6 @organization: IBM Corporation
7 @copyright: Copyright (c) 2005, 2007 IBM Corporation
8
9 @license: I{The BSD License}
10 All rights reserved. This program and the accompanying materials are made
11 available under the terms of the BSD license which accompanies
12 this distribution, and is available at
13 U{http://www.opensource.org/licenses/bsd-license.php}
14 '''
15
16 from AccessEngine import AEScript, AccessEngineAPI
17 from AccessEngine import AEConstants
18
19 from Tools.i18n import bind, _
20
21
22 __uie__ = dict(kind='script', tier=None, all_tiers=False)
23
25 '''
26 Defines three enumeration fields which allow the user to select three
27 different languages among which to choose.
28
29 Alt1Lang (enum): First language, defaults to current device setting
30
31 Alt2Lang (enum): Second language, defaults to current device setting
32
33 Alt3Lang (enum): Third language, defaults to current device setting
34 '''
36 '''
37 Create L{AEState} settings for this L{AEScript <AEScript.AEScript>}.
38 '''
39 self.newEnum('Alt1Lang', None, _('First language'), {_('None') : None},
40 _('First alternative language'), False)
41 self.newEnum('Alt2Lang', None, _('Second language'), {_('None') : None},
42 _('Second alternative language'), False)
43 self.newEnum('Alt3Lang', None, _('Third language'), {_('None') : None},
44 _('Third alternative language'), False)
45
47 '''
48 Gets configurable settings for this L{AEScript <AEScript.AEScript>}.
49
50 @return: Group of all configurable settings
51 @rtype: L{AEState.Setting.Group}
52 '''
53 g = self.newGroup()
54 g.extend(['Alt1Lang', 'Alt2Lang', 'Alt3Lang'])
55 return g
56
58 '''
59 Enables switching the active speech engine among up to three languages using
60 a hotkey press in the current application.
61 It defines the hotkey I{(Caps-Lock+L)} that switch the language.
62 '''
63 STATE = LanguageScriptState
64
89
91 '''
92 Provides the localized name of this L{AEScript <AEScript.AEScript>}.
93
94 @return: Human readable name of this script.
95 @rtype: string
96 '''
97 return _('Language switcher')
98
100 '''
101 Describe what this L{AEScript <AEScript.AEScript>} do.
102
103 @return: Human readable translated description of this script.
104 @rtype: string
105 '''
106 return _('Enables switching the active speech engine among up to three '
107 'languages using a hotkey press in the current application.')
108
109
110
111
113 '''
114 Cycles through the alternative languages.
115
116 @param kwargs: Arbitrary keyword arguments to pass to the task
117 @type kwargs: dictionary
118 '''
119 AccessEngineAPI.stopNow(self, cap='audio', role='output', **kwargs)
120
121 lang = AccessEngineAPI.getStyleVal(self, 'Language', **kwargs)
122
123 names = [s.name for s in self.state]
124 names.sort()
125
126 values = [s.value for s in (self.getScriptSetting(n) for n in names)]
127
128
129 try:
130 start = values.index(lang)
131 except ValueError:
132 start = 0
133
134 for i in xrange(start+1, start+len(names)):
135 n = i % len(names)
136 val = values[n]
137 if val != lang:
138
139 AccessEngineAPI.setStyleVal(self, 'Language', val, **kwargs)
140 text = _('speaking in %s')%self.getScriptSetting(names[n]).getLabel(val)
141 self.doTask('read message', 'BasicSpeechScript', text=text, **kwargs)
142 break
143