Coverage Report - orca.settings

ModuleCoverage %
orca.settings
97%
1
# Orca
2
#
3
# Copyright 2004-2006 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
"""Manages the settings for Orca.  This will defer to user settings first, but
21
fallback to local settings if the user settings doesn't exist (e.g., in the
22 1
case of gdm) or doesn't have the specified attribute."""
23
24 1
__id__        = "$Id: settings.py 2077 2007-03-02 23:42:02Z wwalker $"
25 1
__version__   = "$Revision: 2077 $"
26 1
__date__      = "$Date: 2007-03-02 15:42:02 -0800 (Fri, 02 Mar 2007) $"
27 1
__copyright__ = "Copyright (c) 2005-2006 Sun Microsystems Inc."
28 1
__license__   = "LGPL"
29
30 1
import os
31 1
import re
32 1
import sys
33
34 1
screenWidth = 640
35 1
screenHeight = 480
36 1
tty = 7
37
38 1
try:
39
    # This can fail due to gtk not being available.  We want to
40
    # be able to recover from that if possible.  The main driver
41
    # for this is to allow "orca --text-setup" to work even if
42
    # the desktop is not running.
43
    #
44 1
    import gtk.gdk
45 1
    _display = gtk.gdk.display_get_default()
46 1
    _screen = _display.get_default_screen()
47 1
    _root_window = _screen.get_root_window()
48
49
    # These are used for placing the magnifier zoomer.
50
    #
51 1
    screenWidth = _screen.get_width()
52 1
    screenHeight = _screen.get_height()
53
54
    # We want to know what the tty is so we can send it to BrlAPI
55
    # if possible.
56
    #
57 1
    (atom, format, data) = _root_window.property_get("XFree86_VT")
58 1
    tty = data[0]
59 0
except:
60 0
    pass
61
62 1
import debug
63 1
from acss import ACSS
64 1
from orca_i18n import _           # for gettext support
65
66
# These are the settings that Orca supports the user customizing.
67
#
68 1
userCustomizableSettings = [
69
    "orcaModifierKeys",
70
    "enableSpeech",
71
    "speechServerFactory",
72
    "speechServerInfo",
73
    "voices",
74
    "speechVerbosityLevel",
75
    "readTableCellRow",
76
    "enableSpeechIndentation",
77
    "enableEchoByWord",
78
    "enableKeyEcho",
79
    "enablePrintableKeys",
80
    "enableModifierKeys",
81
    "enableLockingKeys",
82
    "enableFunctionKeys",
83
    "enableActionKeys",
84
    "enableBraille",
85
    "enableBrailleGrouping",
86
    "brailleVerbosityLevel",
87
    "brailleRolenameStyle",
88
    "enableBrailleMonitor",
89
    "enableMagnifier",
90
    "enableMagCursor",
91
    "enableMagCursorExplicitSize",
92
    "magCursorSize",
93
    "magCursorColor",
94
    "enableMagCrossHair",
95
    "enableMagCrossHairClip",
96
    "magCrossHairSize",
97
    "magZoomerLeft",
98
    "magZoomerRight",
99
    "magZoomerTop",
100
    "magZoomerBottom",
101
    "magZoomFactor",
102
    "enableMagZoomerColorInversion",
103
    "magSmoothingMode",
104
    "magMouseTrackingMode",
105
    "magSourceDisplay",
106
    "magTargetDisplay",
107
    "verbalizePunctuationStyle",
108
    "showMainWindow",
109
    "keyboardLayout",
110
    "speakBlankLines",
111
]
112
113
# The name of the module that hold the user interface for the main window
114
# for Orca. This module is expected to have two methods, showMainUI and
115
# hideMainUI, which will show and hide the main window GUI.
116
#
117 1
mainWindowModule = "orca_gui_main"
118
119
# The name of the modules that hold the user interface for setting
120
# Orca preferences.  Each module is expected to have the method,
121
# showPreferencesUI, which will prompt the user for preferences.
122
#
123 1
guiPreferencesModule    = "orca_gui_prefs"
124 1
consolePreferencesModule= "orca_console_prefs"
125
126
# The name of the module that hold the user interface for quitting Orca.
127
# This module is expected to have the method, showQuitUI, which will
128
# display the quit GUI.
129
#
130 1
quitModule = "orca_quit"
131
132
# The name of the module that holds the user interface for performing a
133
# flat review find.
134
#
135 1
findModule = "orca_gui_find"
136
137
# A list of keys that can serve as the Orca modifier key.  The list is
138
# so we can provide better cross platform support (e.g., Sun keyboard
139
# vs. PC-104 keyboard layouts).  When any of these keys is pressed,
140
# the orca.MODIFIER_ORCA bit will be set in the 'modifiers' field of
141
# a KeyboardEvent input event.  The keys are currently compared to the
142
# event_string of a keyboard input event from AT-SPI.
143
#
144
# The initial set of modifier keys is dependant upon whether the user
145
# has specified a desktop or a laptop keyboard layout.
146
#
147 1
DESKTOP_MODIFIER_KEYS = ["Insert", "KP_Insert"]
148 1
LAPTOP_MODIFIER_KEYS  = ["Caps_Lock"]
149 1
orcaModifierKeys      = DESKTOP_MODIFIER_KEYS
150
151
# A new modifier to use (set by the press of any key in the
152
# orcaModifierKeys list) to represent the Orca modifier.
153
#
154 1
MODIFIER_ORCA = 8
155
156
# Verbosity levels (see setBrailleVerbosityLevel and
157
# setSpeechVerbosityLevel).  These will have an impact on the various
158
# individual verbosity levels for rolenames, accelerators, etc.
159
#
160 1
VERBOSITY_LEVEL_BRIEF   = 0
161 1
VERBOSITY_LEVEL_VERBOSE = 1
162 1
speechVerbosityLevel    = VERBOSITY_LEVEL_VERBOSE
163 1
brailleVerbosityLevel   = VERBOSITY_LEVEL_VERBOSE
164
165 1
BRAILLE_ROLENAME_STYLE_SHORT = 0 # three letter abbreviations
166 1
BRAILLE_ROLENAME_STYLE_LONG  = 1 # full rolename
167 1
brailleRolenameStyle    = BRAILLE_ROLENAME_STYLE_LONG
168
169
# Speech punctuation levels (see verbalizePunctuationStyle).
170
#
171 1
PUNCTUATION_STYLE_NONE = 3
172 1
PUNCTUATION_STYLE_SOME = 2
173 1
PUNCTUATION_STYLE_MOST = 1
174 1
PUNCTUATION_STYLE_ALL  = 0
175 1
verbalizePunctuationStyle = PUNCTUATION_STYLE_MOST
176
177
# The absolue amount to change the speech rate when
178
# increasing or decreasing speech.  This is a numerical
179
# value that represents an ACSS rate value.
180
#
181 1
speechRateDelta         = 5
182
183
# The absolue amount to change the speech pitch when
184
# increasing or decreasing pitch.  This is a numerical
185
# value that represents an ACSS pitch value.
186
#
187 1
speechPitchDelta        = 0.5
188
189
# The port to listen on if orca is to act as an HTTP server
190
# (mainly as a speech server for self-voicing applications).
191
#
192 1
httpServerPort          = 20433
193
194
# If True, enable speech.
195
#
196 1
enableSpeech            = True
197 1
enableSpeechCallbacks   = True
198
199
# If True, speech has been temporarily silenced.
200
#
201 1
silenceSpeech           = False
202
203
# Settings that apply to the particular speech engine to
204
# use as well details on the default voices to use.
205
#
206 1
speechFactoryModules    = ["espeechfactory","gnomespeechfactory"]
207 1
speechServerFactory     = "gnomespeechfactory"
208 1
speechServerInfo        = None # None means let the factory decide.
209
210 1
DEFAULT_VOICE           = "default"
211 1
UPPERCASE_VOICE         = "uppercase"
212 1
HYPERLINK_VOICE         = "hyperlink"
213
214 1
voices = {
215
    DEFAULT_VOICE   : ACSS({}),
216
    UPPERCASE_VOICE : ACSS({ACSS.AVERAGE_PITCH : 6}),
217
    HYPERLINK_VOICE : ACSS({})
218
}
219
220
# If True, enable speaking of speech indentation and justification.
221
#
222 1
enableSpeechIndentation = False
223
224
# If True, enable braille.
225
#
226 1
enableBraille           = True
227
228
# If True, enable the grouping of children on the braille display.
229
# This is for things like displaying all items of a menu, tab list,
230
# menu bar, etc., on a single line of the braille display.
231
#
232 1
enableBrailleGrouping   = False
233
234
# If True, enable braille monitor.
235
#
236 1
enableBrailleMonitor    = False
237
238
# If True, enable magnification.
239
#
240 1
enableMagnifier                  = False
241
242
# If True, show the magnification cursor.
243
#
244 1
enableMagCursor                  = True
245
246
# If True, allow an explicit size for the magnification cursor.
247
#
248 1
enableMagCursorExplicitSize      = False
249
250
# Size of the magnification cursor (in pixels).
251
#
252 1
magCursorSize                    = 32
253
254
# Magnification cursor color value (hex color spec).
255
#
256 1
magCursorColor                   = '#000000'
257
258
# If True, show the magnification cross-hairs.
259
#
260 1
enableMagCrossHair               = True
261
262
# If True, enable magnification cross-hair clipping.
263
#
264 1
enableMagCrossHairClip           = False
265
266
# Size of the magnification cross-hairs (in pixels).
267
#
268 1
magCrossHairSize                 = 16
269
270
# Magnification zoomer region placement.
271
#
272 1
magZoomerLeft                    = screenWidth / 2
273 1
magZoomerRight                   = screenWidth
274 1
magZoomerTop                     = 0
275 1
magZoomerBottom                  = screenHeight
276
277
# Magnification zoom factor.
278
#
279 1
magZoomFactor                    = 4.0
280
281
# If True, invert the magnification zoomer colors.
282
#
283 1
enableMagZoomerColorInversion    = False
284
285
# Magnification smoothing mode (see magSmoothingMode).
286
#
287 1
MAG_SMOOTHING_MODE_BILINEAR      = 0
288 1
MAG_SMOOTHING_MODE_NONE          = 1
289 1
magSmoothingMode                 = MAG_SMOOTHING_MODE_BILINEAR
290
291
# Magnification mouse tracking mode (see magMouseTrackingMode).
292
#
293 1
MAG_MOUSE_TRACKING_MODE_CENTERED     = 0
294 1
MAG_MOUSE_TRACKING_MODE_NONE         = 1
295 1
MAG_MOUSE_TRACKING_MODE_PROPORTIONAL = 2
296 1
MAG_MOUSE_TRACKING_MODE_PUSH         = 3
297 1
magMouseTrackingMode                 = MAG_MOUSE_TRACKING_MODE_CENTERED
298
299
# Magnification source display
300
#
301 1
magSourceDisplay                 = ''
302
303
# Magnification target display
304
#
305 1
magTargetDisplay                 = ''
306
307
# if True, enable word echo.
308
# Note that it is allowable for both enableEchoByWord and enableKeyEcho
309
# to be True
310
#
311 1
enableEchoByWord        = False
312
313
# If True, enable key echo.
314
# Note that it is allowable for both enableEchoByWord and enableKeyEcho
315
# to be True
316
#
317 1
enableKeyEcho           = False
318
319
# If True and key echo is enabled, echo Alphanumeric and punctuation keys.
320
#
321 1
enablePrintableKeys     = True
322
323
# If True and key echo is enabled, echo Modifier keys.
324
#
325 1
enableModifierKeys      = True
326
327
# If True and key echo is enabled, echo Locking keys.
328
#
329 1
enableLockingKeys       = True
330
331
# If True and key echo is enabled, echo Function keys.
332
#
333 1
enableFunctionKeys      = True
334
335
# If True and key echo is enabled, echo Action keys.
336
#
337 1
enableActionKeys        = True
338
339
# If True, show the main Orca window.
340
#
341 1
showMainWindow          = True
342
343
# Keyboard layout options (see keyboardLayout).
344
#
345 1
GENERAL_KEYBOARD_LAYOUT_DESKTOP = 1
346 1
GENERAL_KEYBOARD_LAYOUT_LAPTOP  = 2
347 1
keyboardLayout                  = GENERAL_KEYBOARD_LAYOUT_DESKTOP
348
349
# If True, speak blank lines.
350
#
351 1
speakBlankLines         = True
352
353
# If True, reads all the table cells in the current row rather than just
354
# the current one.
355
#
356 1
readTableCellRow    = True
357
358
# The default set of text attributes to speak to the user. Specific
359
# application scripts (or individual users can override these values if
360
# so desired. Each of these text attributes is of the form <key>:<value>;
361
# The <value> part will be the "default" value for that attribute. In
362
# other words, if the attribute for a given piece of text has that value,
363
# it won't be spoken. If no value part is given, then that attribute will
364
# always be spoken.
365
366 1
enabledTextAttributes = "size:; family-name:; weight:400; indent:0; underline:none; strikethrough:false; justification:left; style:normal;"
367
368
# The limit to enable a repeat character count to be spoken.
369
# If set to 0, then there will be no repeat character count.
370
# Each character will be spoken singularly (i.e. "dash dash
371
# dash dash dash" instead of "five dash characters").
372
# If the value is set to 1, 2 or 3 then it's treated as if it was
373
# zero. In other words, no repeat character count is given.
374
#
375 1
repeatCharacterLimit = 4
376
377
# Script developer feature.  If False, just the default script
378
# will be used.  Helps determine difference between custom
379
# scripts and the default script behavior.
380
#
381 1
enableCustomScripts     = True
382
383
# Latent support to allow the user to override/define keybindings
384
# and braille bindings.  Unsupported and undocumented for now.
385
# Use at your own risk.
386
#
387 1
keyBindingsMap          = {}
388 1
brailleBindingsMap      = {}
389
390
# Script developer feature.  If False, no AT-SPI object values
391
# will be cached locally.  Helps determine if there might be a
392
# problem related to the cache being out of sync with the real
393
# objects.
394
#
395 1
cacheValues             = True
396 1
cacheDescriptions       = True
397
398
# Script developer feature.  If False, no AT-SPI objects
399
# will be cached locally.  Helps determine if there might be a
400
# problem related to the cache being out of sync with the real
401
# objects.
402
#
403 1
cacheAccessibles        = True
404
405
# Assists with learn mode (what you enter when you press Insert+F1
406
# and exit when you press escape.
407
#
408 1
learnModeEnabled        = False
409
410
# The location of the user's preferences. By default this is ~/.orca.
411
# It can be overridden by the Orca -d command line option.
412
#
413 1
userPrefsDir = os.path.join(os.environ["HOME"], ".orca")
414
415
# If non-zero, we use time.sleep() in various places to attempt to
416
# free up the global interpreter lock.  Take a look at the following
417
# URLs for more information:
418
#
419
# http://mail.python.org/pipermail/python-list/2002-October/126632.html
420
# http://twistedmatrix.com/pipermail/twisted-python/2005-July/011052.html
421
# http://www.pyzine.com/Issue001/Section_Articles/article_ThreadingGlobalInterpreter.html
422
#
423 1
gilSleepTime            = 0.00001
424
425
# If True, use the gidle __blockPreventor() code in atspi.py.
426
#
427 1
useBlockPreventor       = False
428
429
# If True, we use the bonobo main loop provided by bonobo to handle
430
# all events in atspi.py.  If False, we create our own loop.
431
#
432 1
useBonoboMain           = True
433
434
# If True, we output debug information for the event queue.  We
435
# use this in addition to log level to prevent debug logic from
436
# bogging down event handling.
437
#
438 1
debugEventQueue         = False
439
440
# The timeout value (in seconds) and callback used to determine if
441
# Orca has hung or not.  The only setting one should muck with here is
442
# the timeoutTime unless you want to create a custom callback handler
443
# for the timeout.  See braille.py, atspi.py, and orca.py:init for how
444
# these are used.
445
#
446 1
timeoutTime             = 10   # a value of 0 means don't do hang checking
447 1
timeoutCallback         = None # Set by orca.py:init to orca.timeout
448
449
# Keyboard double-click period. If the same key is pressed within
450
# this time period, it's considered to be a double-click and might
451
# provide different functionality (for example, Numpad 5 double-click
452
# spells the current word rather than speaks it).
453
#
454 1
doubleClickTimeout = 0.5
455
456
# Allow for the customization of key bindings.
457
#
458 1
def overrideKeyBindings(script, keyBindings):
459 63
    return keyBindings
460
461
# Which packages to search, and the order in which to search,
462
# for application settings.  These packages are expected to be on
463
# the PYTHONPATH and/or subpackages of the "orca" package.
464
# REMEMBER: to make something a package, the directory has to
465
# have a __init__.py file in it.
466
#
467 1
settingsPackages          = ["app-settings"]
468
469
# Which packages to search, and the order in which to search,
470
# for custom scripts.  These packages are expected to be on
471
# the PYTHONPATH and/or subpackages of the "orca" package.
472
# REMEMBER: to make something a package, the directory has to
473
# have a __init__.py file in it.
474
#
475 1
scriptPackages          = ["orca-scripts", "scripts"]
476
477
# A list that helps us map application names to script module
478
# names.  The key is the name of an application, and the value is
479
# the name of a script module.  There are some default values here,
480
# but one may call the setScriptMapping method of this module to
481
# extend or override any mappings.
482
#
483 1
_scriptMappings = []
484
485 1
def setScriptMapping(regExpression, moduleName):
486
    """Tells this module what script module to look for a given
487
    application name.  The mappings are stored as a list and each
488
    new mapping is added to the beginning of the list, meaning it
489
    takes precedence over all other mappings.
490
491
    Arguments:
492
    - regExpression: a regular expression used to match against an
493
                     application name
494
    - moduleName:    the name of the Python module containing the script
495
                     class definition for the application
496
    """
497
498 11
    _scriptMappings.insert(0, [regExpression, moduleName])
499
500 1
def getScriptModuleName(app):
501
    """Returns the module name of the script to use for a given
502
    application.  Any script mapping set via the setScriptMapping
503
    method is searched first, with the ultimate fallback being the
504
    name of the application itself.
505
506
    Arguments:
507
    - app: the application to find a script module name for
508
    """
509
510 252
    if not app.name:
511 0
        return None
512
513 3002
    for mapping in _scriptMappings:
514 2761
        regExpression = mapping[0]
515 2761
        moduleName = mapping[1]
516 2761
        if regExpression.match(app.name):
517 11
            debug.println(
518
                debug.LEVEL_FINEST,
519 11
                "Script mapping for %s is %s" % (app.name, moduleName))
520 11
            return moduleName
521
522 241
    return app.name
523
524
# Note to translators: the regular expression here represents a
525
# string to match in the localized application name as seen by
526
# at-poke.  For most cases, the application name is the name of
527
# the binary used to start the application, but this is an
528
# unreliable assumption.  The only reliable way to do the
529
# translation is by running the application and then viewing its
530
# name in the main window of at-poke.
531
#
532 1
setScriptMapping(re.compile(_('[\S\s]*StarOffice[\s\S]*')), "StarOffice")
533 1
setScriptMapping(re.compile(_('soffice.bin')), "StarOffice")
534 1
setScriptMapping(re.compile(_('[Ee]volution')), "Evolution")
535 1
setScriptMapping(re.compile(_('Deer Park')), "Mozilla")
536 1
setScriptMapping(re.compile(_('yelp')), "Mozilla")
537 1
setScriptMapping(re.compile(_('Bon Echo')), "Mozilla")
538 1
setScriptMapping(re.compile(_('Minefield')), "Mozilla")
539 1
setScriptMapping(re.compile(_('Mail/News')), "Thunderbird")
540 1
setScriptMapping(re.compile(_('bug-buddy')), "gnome_segv2")
541 1
setScriptMapping(re.compile(_('vte')), "gnome-terminal")
542 1
setScriptMapping(re.compile(_('time-admin')), "users-admin")