1 |
|
# Orca |
2 |
|
# |
3 |
|
# Copyright 2004-2007 Sun Microsystems Inc. |
4 |
|
# |
5 |
|
# This library is free software; you can redistribute it and/or |
6 |
|
# modify it under the terms of the GNU Library General Public |
7 |
|
# License as published by the Free Software Foundation; either |
8 |
|
# version 2 of the License, or (at your option) any later version. |
9 |
|
# |
10 |
|
# This library is distributed in the hope that it will be useful, |
11 |
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 |
|
# Library General Public License for more details. |
14 |
|
# |
15 |
|
# You should have received a copy of the GNU Library General Public |
16 |
|
# License along with this library; if not, write to the |
17 |
|
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 |
|
# Boston, MA 02111-1307, USA. |
19 |
|
|
20 |
1 |
"""Common utilities to manage the writing of the user preferences file.""" |
21 |
|
|
22 |
1 |
__id__ = "$Id: orca_prefs.py 2656 2007-08-16 00:52:23Z richb $" |
23 |
1 |
__version__ = "$Revision: 2656 $" |
24 |
1 |
__date__ = "$Date: 2007-08-15 20:52:23 -0400 (Wed, 15 Aug 2007) $" |
25 |
1 |
__copyright__ = "Copyright (c) 2005-2007 Sun Microsystems Inc." |
26 |
1 |
__license__ = "LGPL" |
27 |
|
|
28 |
1 |
import os |
29 |
1 |
import pprint |
30 |
|
|
31 |
1 |
import orca_state |
32 |
1 |
import pronunciation_dict |
33 |
1 |
import settings |
34 |
|
|
35 |
1 |
from orca_i18n import _ # for gettext support |
36 |
|
|
37 |
|
# The same fields than in orca_gui_prefs.py: |
38 |
1 |
(HANDLER, DESCRIP, MOD_MASK1, MOD_USED1, KEY1, TEXT1, MOD_MASK2, MOD_USED2, KEY2, TEXT2, MODIF, EDITABLE) = range(12) |
39 |
|
|
40 |
1 |
(ACTUAL, REPLACEMENT) = range(2) |
41 |
|
|
42 |
2 |
class OrcaPrefs: |
43 |
|
|
44 |
1 |
def __init__(self, prefsDict, keyBindingsTreeModel=None, |
45 |
1 |
pronunciationTreeModel=None): |
46 |
|
"""Creates a new OrcaPrefs instance that will be used to write out |
47 |
|
application specific preferences. |
48 |
|
|
49 |
|
Arguments: |
50 |
|
- prefsDict: a dictionary where the keys are orca preferences |
51 |
|
names and the values are the values for the preferences. |
52 |
|
- keyBindingsTreeModel - key bindings tree model, or None if we are |
53 |
|
writing out console preferences. |
54 |
|
- pronunciationTreeModel - pronunciation dictionary tree model, or |
55 |
|
None if we are writing out console preferences. |
56 |
|
""" |
57 |
|
|
58 |
0 |
self.prefsDict = prefsDict |
59 |
0 |
self.keyBindingsTreeModel = keyBindingsTreeModel |
60 |
0 |
self.pronunciationTreeModel = pronunciationTreeModel |
61 |
|
|
62 |
1 |
def _createDir(self, dirname): |
63 |
|
"""Creates the given directory if it doesn't already exist. |
64 |
|
""" |
65 |
|
|
66 |
0 |
try: |
67 |
0 |
os.chdir(dirname) |
68 |
0 |
except: |
69 |
0 |
os.mkdir(dirname) |
70 |
|
|
71 |
1 |
def _writePreferencesPreamble(self, prefs): |
72 |
|
"""Writes the preamble to the user-settings.py file.""" |
73 |
|
|
74 |
0 |
prefs.writelines("# -*- coding: utf-8 -*-\n") |
75 |
0 |
prefs.writelines("# user-settings.py - custom Orca settings\n") |
76 |
0 |
prefs.writelines("# Generated by orca. DO NOT EDIT THIS FILE!!!\n") |
77 |
0 |
prefs.writelines("# If you want permanent customizations that will not\n") |
78 |
0 |
prefs.writelines("# be overwritten, edit orca-customizations.py.\n") |
79 |
0 |
prefs.writelines("#\n") |
80 |
0 |
prefs.writelines("import re\n") |
81 |
0 |
prefs.writelines("import time\n") |
82 |
0 |
prefs.writelines("\n") |
83 |
0 |
prefs.writelines("import orca.debug\n") |
84 |
0 |
prefs.writelines("import orca.settings\n") |
85 |
0 |
prefs.writelines("import orca.acss\n") |
86 |
0 |
prefs.writelines("\n") |
87 |
0 |
prefs.writelines("# Set the logging level to INFO if you want to log\n") |
88 |
0 |
prefs.writelines("# Orca's output of speech and braille using the\n") |
89 |
0 |
prefs.writelines("# Python logging API. Note that setting the\n") |
90 |
0 |
prefs.writelines("# orca.debug.debugLevel to orca.debug.LEVEL_INFO\n") |
91 |
0 |
prefs.writelines("# will output the same information using Orca's\n") |
92 |
0 |
prefs.writelines("# debug facility.\n") |
93 |
0 |
prefs.writelines("#\n") |
94 |
0 |
prefs.writelines("# import logging\n") |
95 |
0 |
prefs.writelines("# orca.debug.log.setLevel(logging.INFO)\n") |
96 |
0 |
prefs.writelines("\n") |
97 |
|
|
98 |
0 |
prefs.writelines("#orca.debug.debugLevel = orca.debug.LEVEL_OFF\n") |
99 |
0 |
prefs.writelines("orca.debug.debugLevel = orca.debug.LEVEL_SEVERE\n") |
100 |
0 |
prefs.writelines("#orca.debug.debugLevel = orca.debug.LEVEL_WARNING\n") |
101 |
0 |
prefs.writelines("#orca.debug.debugLevel = orca.debug.LEVEL_INFO\n") |
102 |
0 |
prefs.writelines("#orca.debug.debugLevel = orca.debug.LEVEL_CONFIGURATION\n") |
103 |
0 |
prefs.writelines("#orca.debug.debugLevel = orca.debug.LEVEL_FINE\n") |
104 |
0 |
prefs.writelines("#orca.debug.debugLevel = orca.debug.LEVEL_FINER\n") |
105 |
0 |
prefs.writelines("#orca.debug.debugLevel = orca.debug.LEVEL_FINEST\n") |
106 |
0 |
prefs.writelines("#orca.debug.debugLevel = orca.debug.LEVEL_ALL\n") |
107 |
0 |
prefs.writelines("\n") |
108 |
0 |
prefs.writelines("#orca.debug.eventDebugLevel = orca.debug.LEVEL_OFF\n") |
109 |
0 |
prefs.writelines("#orca.debug.eventDebugFilter = None\n") |
110 |
0 |
prefs.writelines("#orca.debug.eventDebugFilter = re.compile('[\S]*focus|[\S]*activ')\n") |
111 |
0 |
prefs.writelines("#orca.debug.eventDebugFilter = re.compile('nomatch')\n") |
112 |
0 |
prefs.writelines("#orca.debug.eventDebugFilter = re.compile('[\S]*:accessible-name')\n") |
113 |
0 |
prefs.writelines("#orca.debug.eventDebugFilter = re.compile('[\S]*:(?!bounds-changed)')\n") |
114 |
|
|
115 |
0 |
prefs.writelines("\n") |
116 |
|
|
117 |
0 |
prefs.writelines("#orca.debug.debugFile = open(time.strftime('debug-%Y-%m-%d-%H:%M:%S.out'), 'w', 0)\n") |
118 |
0 |
prefs.writelines("#orca.debug.debugFile = open('debug.out', 'w', 0)\n") |
119 |
0 |
prefs.writelines("\n") |
120 |
|
|
121 |
0 |
prefs.writelines("#orca.settings.useBonoboMain=False\n") |
122 |
0 |
prefs.writelines("#orca.settings.debugEventQueue=True\n") |
123 |
0 |
prefs.writelines("#orca.settings.gilSleepTime=0\n") |
124 |
0 |
prefs.writelines("\n") |
125 |
|
|
126 |
0 |
prefs.writelines("if False:\n") |
127 |
0 |
prefs.writelines(" import sys\n") |
128 |
0 |
prefs.writelines(" import orca.debug\n") |
129 |
0 |
prefs.writelines(" sys.settrace(orca.debug.traceit)\n") |
130 |
0 |
prefs.writelines(" orca.debug.debugLevel = orca.debug.LEVEL_ALL\n") |
131 |
0 |
prefs.writelines("\n") |
132 |
|
|
133 |
1 |
def _writePreferencesPostamble(self, prefs): |
134 |
|
"""Writes the postamble to the user-settings.py file.""" |
135 |
|
|
136 |
0 |
prefs.writelines("\ntry:\n") |
137 |
0 |
prefs.writelines(" __import__(\"orca-customizations\")\n") |
138 |
0 |
prefs.writelines("except ImportError:\n") |
139 |
0 |
prefs.writelines(" pass\n") |
140 |
|
|
141 |
1 |
def _enableAccessibility(self): |
142 |
|
"""Enables the GNOME accessibility flag. Users need to log out and |
143 |
|
then back in for this to take effect. |
144 |
|
|
145 |
|
Returns True if an action was taken (i.e., accessibility was not |
146 |
|
set prior to this call). |
147 |
|
""" |
148 |
|
|
149 |
0 |
alreadyEnabled = settings.isAccessibilityEnabled() |
150 |
0 |
if not alreadyEnabled: |
151 |
0 |
settings.setAccessibilityEnabled(True) |
152 |
|
|
153 |
0 |
return not alreadyEnabled |
154 |
|
|
155 |
1 |
def _getDisplayString(self, display): |
156 |
|
"""Returns a string that represents the source or taget magnifier display. |
157 |
|
|
158 |
|
Arguments: |
159 |
|
- display: the magnifier source or taget display string. |
160 |
|
|
161 |
|
Returns a string suitable for the preferences file. |
162 |
|
""" |
163 |
|
|
164 |
0 |
if not display: |
165 |
0 |
return "''" |
166 |
|
else: |
167 |
0 |
return "'%s'" % display |
168 |
|
|
169 |
1 |
def _getSpeechServerFactoryString(self, factory): |
170 |
|
"""Returns a string that represents the speech server factory passed in. |
171 |
|
|
172 |
|
Arguments: |
173 |
|
- factory: the speech server factory |
174 |
|
|
175 |
|
Returns a string suitable for the preferences file. |
176 |
|
""" |
177 |
|
|
178 |
0 |
if not factory: |
179 |
0 |
return None |
180 |
0 |
elif isinstance(factory, basestring): |
181 |
0 |
return "'%s'" % factory |
182 |
|
else: |
183 |
0 |
return "'%s'" % factory.__name__ |
184 |
|
|
185 |
1 |
def _getSpeechServerString(self, server): |
186 |
|
"""Returns a string that represents the speech server passed in. |
187 |
|
|
188 |
|
Arguments: |
189 |
|
- server: a speech server |
190 |
|
|
191 |
|
Returns a string suitable for the preferences file. |
192 |
|
""" |
193 |
0 |
if not server: |
194 |
0 |
return None |
195 |
0 |
elif isinstance(server, [].__class__): |
196 |
0 |
return repr(server) |
197 |
|
else: |
198 |
0 |
return repr(server.getInfo()) |
199 |
|
|
200 |
1 |
def _getVoicesString(self, voices): |
201 |
|
"""Returns a string that represents the list of voices passed in. |
202 |
|
|
203 |
|
Arguments: |
204 |
|
- voices: a list of ACSS instances. |
205 |
|
|
206 |
|
Returns a string suitable for the preferences file. |
207 |
|
""" |
208 |
|
|
209 |
0 |
voicesStr = "{\n" |
210 |
0 |
for voice in voices: |
211 |
0 |
voicesStr += "'%s' : orca.acss.ACSS(" % voice |
212 |
0 |
voicesStr += pprint.pformat(voices[voice]) + "),\n" |
213 |
0 |
voicesStr += "}" |
214 |
|
|
215 |
0 |
return voicesStr |
216 |
|
|
217 |
1 |
def _getKeyboardLayoutString(self, keyboardLayout): |
218 |
|
"""Returns a string that represents the keyboard layout passed in.""" |
219 |
|
|
220 |
0 |
if keyboardLayout == settings.GENERAL_KEYBOARD_LAYOUT_DESKTOP: |
221 |
0 |
return "orca.settings.GENERAL_KEYBOARD_LAYOUT_DESKTOP" |
222 |
|
else: |
223 |
0 |
return "orca.settings.GENERAL_KEYBOARD_LAYOUT_LAPTOP" |
224 |
|
|
225 |
1 |
def _getOrcaModifierKeysString(self, orcaModifierKeys): |
226 |
|
"""Returns a string that represents the Orca modifier keys passed in.""" |
227 |
|
|
228 |
0 |
if orcaModifierKeys == settings.DESKTOP_MODIFIER_KEYS: |
229 |
0 |
return "orca.settings.DESKTOP_MODIFIER_KEYS" |
230 |
|
else: |
231 |
0 |
return "orca.settings.LAPTOP_MODIFIER_KEYS" |
232 |
|
|
233 |
1 |
def _getSpokenTextAttributesString(self, enabledSpokenTextAttributes): |
234 |
|
""" Returns a string that represents the enabled spoken text attributes |
235 |
|
passed in. |
236 |
|
""" |
237 |
|
|
238 |
0 |
return "\"" + enabledSpokenTextAttributes + "\"" |
239 |
|
|
240 |
1 |
def _getBrailledTextAttributesString(self, enabledBrailledTextAttributes): |
241 |
|
""" Returns a string that represents the enabled brailled text attributes |
242 |
|
passed in. |
243 |
|
""" |
244 |
|
|
245 |
0 |
return "\"" + enabledBrailledTextAttributes + "\"" |
246 |
|
|
247 |
1 |
def _getTextAttributesBrailleIndicatorString(self, brailleIndicator): |
248 |
|
"""Returns a string that represents the text attribute braille indicator |
249 |
|
value passed in.""" |
250 |
|
|
251 |
0 |
if brailleIndicator == settings.TEXT_ATTR_BRAILLE_NONE: |
252 |
0 |
return "orca.settings.TEXT_ATTR_BRAILLE_NONE" |
253 |
0 |
elif brailleIndicator == settings.TEXT_ATTR_BRAILLE_7: |
254 |
0 |
return "orca.settings.TEXT_ATTR_BRAILLE_7" |
255 |
0 |
elif brailleIndicator == settings.TEXT_ATTR_BRAILLE_8: |
256 |
0 |
return "orca.settings.TEXT_ATTR_BRAILLE_8" |
257 |
0 |
elif brailleIndicator == settings.TEXT_ATTR_BRAILLE_BOTH: |
258 |
0 |
return "orca.settings.TEXT_ATTR_BRAILLE_BOTH" |
259 |
|
else: |
260 |
0 |
return "orca.settings.TEXT_ATTR_BRAILLE_NONE" |
261 |
|
|
262 |
1 |
def _getBrailleSelectionIndicatorString(self, selectionIndicator): |
263 |
|
"""Returns a string that represents the braille selection indicator |
264 |
|
value passed in.""" |
265 |
|
|
266 |
0 |
if selectionIndicator == settings.BRAILLE_SEL_NONE: |
267 |
0 |
return "orca.settings.BRAILLE_SEL_NONE" |
268 |
0 |
elif selectionIndicator == settings.BRAILLE_SEL_7: |
269 |
0 |
return "orca.settings.BRAILLE_SEL_7" |
270 |
0 |
elif selectionIndicator == settings.BRAILLE_SEL_8: |
271 |
0 |
return "orca.settings.BRAILLE_SEL_8" |
272 |
0 |
elif selectionIndicator == settings.BRAILLE_SEL_BOTH: |
273 |
0 |
return "orca.settings.BRAILLE_SEL_BOTH" |
274 |
|
else: |
275 |
0 |
return "orca.settings.BRAILLE_SEL_NONE" |
276 |
|
|
277 |
1 |
def _getVerbosityString(self, verbosityLevel): |
278 |
|
"""Returns a string that represents the verbosity level passed in.""" |
279 |
|
|
280 |
0 |
if verbosityLevel == settings.VERBOSITY_LEVEL_BRIEF: |
281 |
0 |
return "orca.settings.VERBOSITY_LEVEL_BRIEF" |
282 |
0 |
elif verbosityLevel == settings.VERBOSITY_LEVEL_VERBOSE: |
283 |
0 |
return "orca.settings.VERBOSITY_LEVEL_VERBOSE" |
284 |
|
else: |
285 |
0 |
return "orca.settings.VERBOSITY_LEVEL_VERBOSE" |
286 |
|
|
287 |
1 |
def _getBrailleRolenameStyleString(self, rolenameStyle): |
288 |
|
"""Returns a string that represents the rolename style passed in.""" |
289 |
|
|
290 |
0 |
if rolenameStyle == settings.BRAILLE_ROLENAME_STYLE_SHORT: |
291 |
0 |
return "orca.settings.BRAILLE_ROLENAME_STYLE_SHORT" |
292 |
0 |
elif rolenameStyle == settings.BRAILLE_ROLENAME_STYLE_LONG: |
293 |
0 |
return "orca.settings.BRAILLE_ROLENAME_STYLE_LONG" |
294 |
|
else: |
295 |
0 |
return "orca.settings.BRAILLE_ROLENAME_STYLE_LONG" |
296 |
|
|
297 |
1 |
def _getVerbalizePunctuationStyleString(self, punctuationStyle): |
298 |
|
"""Returns a string that represents the punctuation style passed in.""" |
299 |
|
|
300 |
0 |
if punctuationStyle == settings.PUNCTUATION_STYLE_NONE: |
301 |
0 |
return "orca.settings.PUNCTUATION_STYLE_NONE" |
302 |
0 |
elif punctuationStyle == settings.PUNCTUATION_STYLE_SOME: |
303 |
0 |
return "orca.settings.PUNCTUATION_STYLE_SOME" |
304 |
0 |
elif punctuationStyle == settings.PUNCTUATION_STYLE_MOST: |
305 |
0 |
return "orca.settings.PUNCTUATION_STYLE_MOST" |
306 |
0 |
elif punctuationStyle == settings.PUNCTUATION_STYLE_ALL: |
307 |
0 |
return "orca.settings.PUNCTUATION_STYLE_ALL" |
308 |
|
else: |
309 |
0 |
return "orca.settings.PUNCTUATION_STYLE_ALL" |
310 |
|
|
311 |
1 |
def _getSayAllStyleString(self, sayAllStyle): |
312 |
|
"""Returns a string that represents the say all style passed in.""" |
313 |
|
|
314 |
0 |
if sayAllStyle == settings.SAYALL_STYLE_LINE: |
315 |
0 |
return "orca.settings.SAYALL_STYLE_LINE" |
316 |
0 |
elif sayAllStyle == settings.SAYALL_STYLE_SENTENCE: |
317 |
0 |
return "orca.settings.SAYALL_STYLE_SENTENCE" |
318 |
|
|
319 |
1 |
def _getMagCursorColorString(self, cursorColor): |
320 |
|
"""Returns a string that represents the magnification cursor color |
321 |
|
passed in. |
322 |
|
|
323 |
|
Arguments: |
324 |
|
- cursorColor: magnification cursor color |
325 |
|
|
326 |
|
Returns a string suitable for the preferences file. |
327 |
|
""" |
328 |
|
|
329 |
0 |
cursorColorStr = "'%s'" % cursorColor |
330 |
|
|
331 |
0 |
return cursorColorStr |
332 |
|
|
333 |
1 |
def _getMagSmoothingModeString(self, smoothingMode): |
334 |
|
"""Returns a string that represents the magnification smoothing mode |
335 |
|
passed in. |
336 |
|
|
337 |
|
Arguments: |
338 |
|
- smoothingMode: magnification smoothing mode. |
339 |
|
|
340 |
|
Returns a string suitable for the preferences file. |
341 |
|
""" |
342 |
|
|
343 |
0 |
if smoothingMode == settings.MAG_SMOOTHING_MODE_BILINEAR: |
344 |
0 |
return "orca.settings.MAG_SMOOTHING_MODE_BILINEAR" |
345 |
0 |
elif smoothingMode == settings.MAG_SMOOTHING_MODE_NONE: |
346 |
0 |
return "orca.settings.MAG_SMOOTHING_MODE_NONE" |
347 |
|
else: |
348 |
0 |
return "orca.settings.MAG_SMOOTHING_MODE_BILINEAR" |
349 |
|
|
350 |
1 |
def _getMagMouseTrackingModeString(self, mouseTrackingMode): |
351 |
|
"""Returns a string that represents the magnification mouse tracking |
352 |
|
mode passed in. |
353 |
|
|
354 |
|
Arguments: |
355 |
|
- mouseTrackingMode: magnification mouse tracking mode. |
356 |
|
|
357 |
|
Returns a string suitable for the preferences file. |
358 |
|
""" |
359 |
|
|
360 |
0 |
if mouseTrackingMode == settings.MAG_MOUSE_TRACKING_MODE_CENTERED: |
361 |
0 |
return "orca.settings.MAG_MOUSE_TRACKING_MODE_CENTERED" |
362 |
0 |
elif mouseTrackingMode == settings.MAG_MOUSE_TRACKING_MODE_NONE: |
363 |
0 |
return "orca.settings.MAG_MOUSE_TRACKING_MODE_NONE" |
364 |
0 |
elif mouseTrackingMode == settings.MAG_MOUSE_TRACKING_MODE_PROPORTIONAL: |
365 |
0 |
return "orca.settings.MAG_MOUSE_TRACKING_MODE_PROPORTIONAL" |
366 |
0 |
elif mouseTrackingMode == settings.MAG_MOUSE_TRACKING_MODE_PUSH: |
367 |
0 |
return "orca.settings.MAG_MOUSE_TRACKING_MODE_PUSH" |
368 |
|
else: |
369 |
0 |
return "orca.settings.MAG_MOUSE_TRACKING_MODE_CENTERED" |
370 |
|
|
371 |
1 |
def _writeKeyBindingsPreamble(self, prefs): |
372 |
|
"""Writes the preamble to the user-settings.py keyBindings section.""" |
373 |
|
|
374 |
0 |
prefs.writelines("\n") |
375 |
0 |
prefs.writelines("# Set up a user key-bindings profile\n") |
376 |
0 |
prefs.writelines("#\n") |
377 |
0 |
prefs.writelines('def overrideKeyBindings(script, keyB):\n') |
378 |
|
|
379 |
1 |
def _writeKeyBinding(self, prefs, tupl): |
380 |
|
"""Writes a single keyBinding to the user-settings.py keyBindings section. |
381 |
|
|
382 |
|
Arguments: |
383 |
|
- prefs: text string - file to write the key binding to. |
384 |
|
- tupl: tuple - a tuple with the values of the |
385 |
|
keybinding (gtk.TreeStore model columns) |
386 |
|
""" |
387 |
|
|
388 |
0 |
prefs.writelines(" keyB.removeByHandler(script.inputEventHandlers['"+str(tupl[HANDLER])+"'])\n") |
389 |
|
|
390 |
0 |
if (tupl[TEXT1]): |
391 |
0 |
prefs.writelines(" keyB.add(orca.keybindings.KeyBinding(\n") |
392 |
0 |
prefs.writelines(" '" + str(tupl[KEY1]) + "',\n") |
393 |
0 |
if tupl[MOD_MASK1] or tupl[MOD_USED1]: |
394 |
0 |
prefs.writelines(" " + str(tupl[MOD_MASK1]) + ",\n") |
395 |
0 |
prefs.writelines(" " + str(tupl[MOD_USED1]) + ",\n") |
396 |
|
else: |
397 |
0 |
prefs.writelines(" 0,\n") |
398 |
0 |
prefs.writelines(" 0,\n") |
399 |
0 |
prefs.writelines(' script.inputEventHandlers["'+ str(tupl[HANDLER]) +'"]))\n\n') |
400 |
|
|
401 |
0 |
if (tupl[TEXT2]): |
402 |
0 |
prefs.writelines(" keyB.add(orca.keybindings.KeyBinding(\n") |
403 |
0 |
prefs.writelines(" '" + str(tupl[KEY2]) + "',\n") |
404 |
0 |
if tupl[MOD_MASK2] or tupl[MOD_USED2]: |
405 |
0 |
prefs.writelines(" " + str(tupl[MOD_MASK2]) + ",\n") |
406 |
0 |
prefs.writelines(" " + str(tupl[MOD_USED2]) + ",\n") |
407 |
|
else: |
408 |
0 |
prefs.writelines(" 0,\n") |
409 |
0 |
prefs.writelines(" 0,\n") |
410 |
0 |
prefs.writelines(' script.inputEventHandlers["'+ str(tupl[HANDLER]) +'"]))\n\n') |
411 |
|
|
412 |
1 |
def _writeKeyBindingsPostamble(self, prefs): |
413 |
|
"""Writes the postamble to the user-settings.py keyBindings section.""" |
414 |
|
|
415 |
0 |
prefs.writelines(' return keyB') |
416 |
0 |
prefs.writelines("\n\n") |
417 |
0 |
prefs.writelines('orca.settings.overrideKeyBindings = overrideKeyBindings') |
418 |
0 |
prefs.writelines("\n") |
419 |
|
|
420 |
1 |
def _iterateKeyBindings(self, prefs, treeModel): |
421 |
|
"""Iterate over all the key bindings in the tree model and write |
422 |
|
out all that the user has modified. |
423 |
|
""" |
424 |
|
|
425 |
0 |
iter = treeModel.get_iter_first() |
426 |
0 |
while iter != None: |
427 |
0 |
iterChild = treeModel.iter_children(iter) |
428 |
0 |
while iterChild != None: |
429 |
0 |
values = treeModel.get(iterChild, 0,1,2,3,4,5,6,7,8,9,10,11) |
430 |
0 |
if values[MODIF]: |
431 |
0 |
self._writeKeyBinding(prefs, values) |
432 |
0 |
iterChild = treeModel.iter_next(iterChild) |
433 |
0 |
iter = treeModel.iter_next(iter) |
434 |
|
|
435 |
1 |
def _writeKeyBindingsMap(self, prefs, treeModel): |
436 |
|
"""Write to configuration file 'prefs' the key bindings passed in the |
437 |
|
model treeModel. |
438 |
|
""" |
439 |
|
|
440 |
0 |
self._writeKeyBindingsPreamble(prefs) |
441 |
0 |
self._iterateKeyBindings(prefs, treeModel) |
442 |
0 |
self._writeKeyBindingsPostamble(prefs) |
443 |
|
|
444 |
1 |
def _writePronunciationsPreamble(self, prefs): |
445 |
|
"""Writes the preamble to the ~/.orca/user-settings.py |
446 |
|
pronunciations section.""" |
447 |
|
|
448 |
0 |
prefs.writelines("\n") |
449 |
0 |
prefs.writelines("# User customized pronunciation dictionary settings\n") |
450 |
0 |
prefs.writelines("#\n") |
451 |
0 |
prefs.writelines("import orca.pronunciation_dict\n\n") |
452 |
0 |
prefs.writelines("orca.pronunciation_dict.pronunciation_dict={}\n") |
453 |
|
|
454 |
1 |
def _writePronunciation(self, prefs, word, value): |
455 |
|
"""Write out a single pronunciation entry to the |
456 |
|
~/.orca/user-setting.py settings file. |
457 |
|
|
458 |
|
Arguments: |
459 |
|
- prefs: file handle for user preferences. |
460 |
|
- word: the actual word to be pronunced. |
461 |
|
- value: the replacement string to use. |
462 |
|
""" |
463 |
|
|
464 |
0 |
prefs.writelines("orca.pronunciation_dict.setPronunciation(\"" + \ |
465 |
0 |
word + "\", \"" + value + "\")\n") |
466 |
|
|
467 |
1 |
def _iteratePronunciations(self, prefs, treeModel): |
468 |
|
"""Iterate over each of the entries in the tree model and write out |
469 |
|
a pronunciation diction entry for them. If any strings with an |
470 |
|
actual string of "" are found, they are ignored. |
471 |
|
""" |
472 |
|
|
473 |
0 |
iter = treeModel.get_iter_first() |
474 |
0 |
while iter != None: |
475 |
0 |
values = treeModel.get(iter, ACTUAL, REPLACEMENT) |
476 |
0 |
word = values[ACTUAL] |
477 |
0 |
value = values[REPLACEMENT] |
478 |
|
|
479 |
0 |
if word != "": |
480 |
0 |
self._writePronunciation(prefs, word, value) |
481 |
|
|
482 |
0 |
iter = treeModel.iter_next(iter) |
483 |
|
|
484 |
1 |
def _writePronunciationMap(self, prefs, treeModel): |
485 |
|
"""Write to configuration file 'prefs' the new pronunciation dictionary |
486 |
|
entries passed in the model treeModel. |
487 |
|
|
488 |
|
Arguments: |
489 |
|
- prefs: file handle for application preferences. |
490 |
|
- treeModel: pronunciation dictionary tree model. |
491 |
|
""" |
492 |
|
|
493 |
0 |
self._writePronunciationsPreamble(prefs) |
494 |
0 |
pronDict = pronunciation_dict.pronunciation_dict |
495 |
0 |
self._iteratePronunciations(prefs, treeModel) |
496 |
|
|
497 |
1 |
def _setupPreferencesDirs(self): |
498 |
|
"""Creates the directories and standard files to hold user preferences.""" |
499 |
|
|
500 |
|
# Set up the user's preferences directory (~/.orca by default). |
501 |
|
# |
502 |
0 |
orcaDir = settings.userPrefsDir |
503 |
0 |
self._createDir(orcaDir) |
504 |
|
|
505 |
|
# Set up ~/.orca/orca-scripts as a Python package |
506 |
|
# |
507 |
0 |
orcaScriptDir = os.path.join(orcaDir, "orca-scripts") |
508 |
0 |
self._createDir(orcaScriptDir) |
509 |
0 |
initFile = os.path.join(orcaScriptDir, "__init__.py") |
510 |
0 |
if not os.path.exists(initFile): |
511 |
0 |
os.close(os.open(initFile, os.O_CREAT, 0700)) |
512 |
|
|
513 |
|
# Set up ~/.orca/app-settings as a Python package. |
514 |
|
# |
515 |
0 |
orcaSettingsDir = os.path.join(orcaDir, "app-settings") |
516 |
0 |
self._createDir(orcaSettingsDir) |
517 |
0 |
initFile = os.path.join(orcaSettingsDir, "__init__.py") |
518 |
0 |
if not os.path.exists(initFile): |
519 |
0 |
os.close(os.open(initFile, os.O_CREAT, 0700)) |
520 |
|
|
521 |
1 |
def _getValueForKey(self, prefsDict, key): |
522 |
|
"""Return the value associated with this preferences dictionary key |
523 |
|
|
524 |
|
Arguments: |
525 |
|
- prefsDict: a dictionary where the keys are orca preferences |
526 |
|
names and the values are the values for the preferences. |
527 |
|
- key: the preferences dictionary key. |
528 |
|
|
529 |
|
Return the value of the given preferences dictionary key. |
530 |
|
""" |
531 |
|
|
532 |
0 |
value = None |
533 |
0 |
if prefsDict.has_key(key): |
534 |
0 |
if key == "voices": |
535 |
0 |
value = self._getVoicesString(prefsDict[key]) |
536 |
0 |
elif key == "speechServerInfo": |
537 |
0 |
value = self._getSpeechServerString(prefsDict[key]) |
538 |
0 |
elif key == "speechServerFactory": |
539 |
0 |
value = self._getSpeechServerFactoryString(prefsDict[key]) |
540 |
0 |
elif key.endswith("VerbosityLevel"): |
541 |
0 |
value = self._getVerbosityString(prefsDict[key]) |
542 |
0 |
elif key == "brailleRolenameStyle": |
543 |
0 |
value = self._getBrailleRolenameStyleString(prefsDict[key]) |
544 |
0 |
elif key == "brailleSelectorIndicator": |
545 |
0 |
value = self._getBrailleSelectionIndicatorString(prefsDict[key]) |
546 |
0 |
elif key == "verbalizePunctuationStyle": |
547 |
0 |
value = self._getVerbalizePunctuationStyleString(prefsDict[key]) |
548 |
0 |
elif key == "sayAllStyle": |
549 |
0 |
value = self._getSayAllStyleString(prefsDict[key]) |
550 |
0 |
elif key == "magCursorColor": |
551 |
0 |
value = self._getMagCursorColorString(prefsDict[key]) |
552 |
0 |
elif key == "magSmoothingMode": |
553 |
0 |
value = self._getMagSmoothingModeString(prefsDict[key]) |
554 |
0 |
elif key == "magMouseTrackingMode": |
555 |
0 |
value = self._getMagMouseTrackingModeString(prefsDict[key]) |
556 |
0 |
elif key == "magSourceDisplay" or key == "magTargetDisplay": |
557 |
0 |
value = self._getDisplayString(prefsDict[key]) |
558 |
0 |
elif key == "keyboardLayout": |
559 |
0 |
value = self._getKeyboardLayoutString(prefsDict[key]) |
560 |
0 |
elif key == "orcaModifierKeys": |
561 |
0 |
value = self._getOrcaModifierKeysString(prefsDict[key]) |
562 |
0 |
elif key == "enabledSpokenTextAttributes": |
563 |
0 |
value = self._getSpokenTextAttributesString(prefsDict[key]) |
564 |
0 |
elif key == "enabledBrailledTextAttributes": |
565 |
0 |
value = self._getBrailledTextAttributesString(prefsDict[key]) |
566 |
0 |
elif key == "textAttributesBrailleIndicator": |
567 |
0 |
value = self._getTextAttributesBrailleIndicatorString( \ |
568 |
0 |
prefsDict[key]) |
569 |
|
else: |
570 |
0 |
value = prefsDict[key] |
571 |
|
|
572 |
0 |
return value |
573 |
|
|
574 |
1 |
def _writePreferences(self): |
575 |
|
"""Creates the directory and files to hold user preferences. Note |
576 |
|
that callers of this method may want to consider using an ordered |
577 |
|
dictionary so that the keys are output in a deterministic order. |
578 |
|
|
579 |
|
Returns True if accessibility was enabled as a result of this |
580 |
|
call.""" |
581 |
|
|
582 |
0 |
self._setupPreferencesDirs() |
583 |
|
|
584 |
|
# Write ~/.orca/user-settings.py |
585 |
|
# |
586 |
0 |
orcaDir = settings.userPrefsDir |
587 |
0 |
prefs = open(os.path.join(orcaDir, "user-settings.py"), "w") |
588 |
0 |
self._writePreferencesPreamble(prefs) |
589 |
|
|
590 |
0 |
for key in settings.userCustomizableSettings: |
591 |
0 |
value = self._getValueForKey(self.prefsDict, key) |
592 |
0 |
if value != None: |
593 |
0 |
prefs.writelines("orca.settings.%s = %s\n" % (key, value)) |
594 |
|
|
595 |
0 |
if self.keyBindingsTreeModel: |
596 |
0 |
self._writeKeyBindingsMap(prefs, self.keyBindingsTreeModel) |
597 |
|
|
598 |
0 |
if self.pronunciationTreeModel: |
599 |
0 |
self._writePronunciationMap(prefs, self.pronunciationTreeModel) |
600 |
|
|
601 |
0 |
self._writePreferencesPostamble(prefs) |
602 |
0 |
prefs.close() |
603 |
|
|
604 |
|
# Return True if this caused accessibility to be enabled |
605 |
|
# as a result of this call. |
606 |
|
# |
607 |
0 |
return self._enableAccessibility() |
608 |
|
|
609 |
1 |
def readPreferences(): |
610 |
|
"""Returns a dictionary containing the names and values of the |
611 |
|
customizable features of Orca.""" |
612 |
|
|
613 |
2 |
prefsDict = {} |
614 |
104 |
for key in settings.userCustomizableSettings: |
615 |
102 |
if settings.__dict__.has_key(key): |
616 |
102 |
prefsDict[key] = settings.__dict__[key] |
617 |
|
|
618 |
2 |
return prefsDict |
619 |
|
|
620 |
1 |
def writePreferences(prefsDict, keyBindingsTreeModel=None, |
621 |
1 |
pronunciationTreeModel=None): |
622 |
|
"""Creates the directory and files to hold application specific |
623 |
|
user preferences. Write out any preferences that are different |
624 |
|
from the generic Orca preferences for this user. Note that callers |
625 |
|
of this method may want to consider using an ordered dictionary so |
626 |
|
that the keys are output in a deterministic order. |
627 |
|
|
628 |
|
Arguments: |
629 |
|
- prefsDict: a dictionary where the keys are orca preferences |
630 |
|
names and the values are the values for the preferences. |
631 |
|
- keyBindingsTreeModel - key bindings tree model, or None if we are |
632 |
|
writing out console preferences. |
633 |
|
- pronunciationTreeModel - pronunciation dictionary tree model, or |
634 |
|
None if we are writing out console preferences. |
635 |
|
""" |
636 |
|
|
637 |
0 |
OP = OrcaPrefs(prefsDict, keyBindingsTreeModel, pronunciationTreeModel) |
638 |
0 |
OP._writePreferences() |