home *** CD-ROM | disk | FTP | other *** search
Wrap
# Source Generated with Decompyle++ # File: in.pyc (Python 2.6) '''Manages the magnifier for orca. [[[TODO: WDW - this is very very early in development. One might even say it is pre-prototype.]]]''' __id__ = '$Id: mag.py 4607 2009-02-26 18:12:30Z wwalker $' __version__ = '$Revision: 4607 $' __date__ = '$Date: 2009-02-26 13:12:30 -0500 (Thu, 26 Feb 2009) $' __copyright__ = 'Copyright (c) 2005-2008 Sun Microsystems Inc.' __license__ = 'LGPL' import bonobo try: import gtk except: pass import time import pyatspi import debug import eventsynthesizer import settings import speech import orca_state from orca_i18n import _ _magnifierAvailable = False try: import ORBit ORBit.load_typelib('GNOME_Magnifier') import GNOME.Magnifier as GNOME _magnifierAvailable = True except: pass _initialized = False _magnifier = None _magnifierPBag = None _roiWidth = 0 _roiHeight = 0 _minROIX = 0 _maxROIX = 0 _minROIY = 0 _maxROIY = 0 _roi = None _sourceDisplayBounds = None _targetDisplayBounds = None _zoomer = None _zoomerPBag = None _lastMouseEventTime = time.time() _lastMouseEventWasRoute = False _pollMouseDisabled = False _fullScreenCapable = True _liveUpdatingMagnifier = False _originalSourceDisplayBounds = None _mouseTracking = None _controlTracking = None _textTracking = None _edgeMargin = None _pointerFollowsZoomer = None _pointerFollowsFocus = None def __setROI(rect): '''Sets the region of interest. Arguments: - rect: A GNOME.Magnifier.RectBounds object. ''' global _roi debug.println(debug.LEVEL_ALL, 'mag.py:__setROI: (%d, %d), (%d, %d)' % (rect.x1, rect.y1, rect.x2, rect.y2)) _roi = rect _zoomer.setROI(_roi) _zoomer.markDirty(_roi) def __setROICenter(x, y): '''Centers the region of interest around the given point. Arguments: - x: integer in unzoomed system coordinates representing x component - y: integer in unzoomed system coordinates representing y component ''' if not _initialized: return None if x < _minROIX: x = _minROIX elif x > _maxROIX: x = _maxROIX if y < _minROIY: y = _minROIY elif y > _maxROIY: y = _maxROIY x1 = x - _roiWidth / 2 y1 = y - _roiHeight / 2 x2 = x1 + _roiWidth y2 = y1 + _roiHeight __setROI(GNOME.Magnifier.RectBounds(x1, y1, x2, y2)) def __setROIPush(x, y): '''Nudges the ROI if the pointer bumps into the edge of it. The point given is assumed to be the point where the mouse pointer is. Arguments: - x: integer in unzoomed system coordinates representing x component - y: integer in unzoomed system coordinates representing y component ''' newROI = GNOME.Magnifier.RectBounds(_roi.x1, _roi.y1, _roi.x2, _roi.y2) if x < _roi.x1: newROI.x1 = x newROI.x2 = x + _roiWidth elif x > _roi.x2: newROI.x2 = x newROI.x1 = x - _roiWidth if y < _roi.y1: newROI.y1 = y newROI.y2 = y + _roiHeight elif y > _roi.y2: newROI.y2 = y newROI.y1 = y - _roiHeight if True: __setROI(newROI) def __setROICursorPush(x, y, width, height, edgeMargin = 0): '''Nudges the ROI if the caret or control is not visible. Arguments: - x: integer in unzoomed system coordinates representing x component - y: integer in unzoomed system coordinates representing y component - width: integer in unzoomed system coordinates representing the width - height: integer in unzoomed system coordinates representing the height - edgeMargin: a percentage representing how close to the edge we can get before we need to push ''' edgeMargin = min(edgeMargin, 50) / 100 edgeMarginX = edgeMargin * _sourceDisplayBounds.x2 / settings.magZoomFactor edgeMarginY = edgeMargin * _sourceDisplayBounds.y2 / settings.magZoomFactor leftOfROI = x - edgeMarginX <= _roi.x1 rightOfROI = x + width + edgeMarginX >= _roi.x2 aboveROI = y - edgeMarginY <= _roi.y1 belowROI = y + height + edgeMarginY >= _roi.y2 if not leftOfROI: pass visibleX = not rightOfROI if not aboveROI: pass visibleY = not belowROI if visibleX and visibleY: _zoomer.markDirty(_roi) x1 = _roi.x1 x2 = _roi.x2 y1 = _roi.y1 y2 = _roi.y2 if leftOfROI: x1 = max(_sourceDisplayBounds.x1, x - edgeMarginX) x2 = x1 + _roiWidth elif rightOfROI: x = min(_sourceDisplayBounds.x2, x + edgeMarginX) if width > _roiWidth: x1 = x x2 = x1 + _roiWidth else: x2 = x + width x1 = x2 - _roiWidth if aboveROI: y1 = max(_sourceDisplayBounds.y1, y - edgeMarginY) y2 = y1 + _roiHeight elif belowROI: y = min(_sourceDisplayBounds.y2, y + edgeMarginY) if height > _roiHeight: y1 = y y2 = y1 + _roiHeight else: y2 = y + height y1 = y2 - _roiHeight __setROI(GNOME.Magnifier.RectBounds(x1, y1, x2, y2)) def __setROIProportional(x, y): '''Positions the ROI proportionally to where the pointer is on the screen. Arguments: - x: integer in unzoomed system coordinates representing x component - y: integer in unzoomed system coordinates representing y component ''' if not _initialized: return None if not _sourceDisplayBounds: __setROICenter(x, y) else: halfScreenWidth = (_sourceDisplayBounds.x2 - _sourceDisplayBounds.x1) / 2 halfScreenHeight = (_sourceDisplayBounds.y2 - _sourceDisplayBounds.y1) / 2 proportionX = (halfScreenWidth - x) / halfScreenWidth proportionY = (halfScreenHeight - y) / halfScreenHeight centerX = x + int(proportionX * _roiWidth / 2) centerY = y + int(proportionY * _roiHeight / 2) __setROICenter(centerX, centerY) def __onMouseEvent(e): ''' Arguments: - e: at-spi event from the at-api registry ''' global _lastMouseEventTime, _lastMouseEventWasRoute, _lastMouseEventWasRoute isNewMouseMovement = time.time() - _lastMouseEventTime > 1 _lastMouseEventTime = time.time() x = e.detail1 y = e.detail2 if _pointerFollowsZoomer and isNewMouseMovement and not _lastMouseEventWasRoute: if x < x: pass elif x < _roi.x2: pass mouseIsVisible = None if y < y else y < _roi.y2 if not mouseIsVisible and orca_state.locusOfFocus: if _mouseTracking == settings.MAG_TRACKING_MODE_CENTERED: x = (_roi.x1 + _roi.x2) / 2 y = (_roi.y1 + _roi.y2) / 2 elif _mouseTracking != settings.MAG_TRACKING_MODE_NONE: try: extents = orca_state.locusOfFocus.queryComponent().getExtents(0) except: extents = None if extents: x = extents.x y = extents.y + extents.height - 1 eventsynthesizer.generateMouseEvent(x, y, 'abs') _lastMouseEventWasRoute = True if _pollMouseDisabled: _zoomer.setPointerPos(x, y) if _lastMouseEventWasRoute: _lastMouseEventWasRoute = False _zoomer.markDirty(_roi) return None if _mouseTracking == settings.MAG_TRACKING_MODE_PUSH: __setROIPush(x, y) elif _mouseTracking == settings.MAG_TRACKING_MODE_PROPORTIONAL: __setROIProportional(x, y) elif _mouseTracking == settings.MAG_TRACKING_MODE_CENTERED: __setROICenter(x, y) def __getValueText(slot, value): valueText = '' if slot == 'cursor-hotspot': valueText = '(%d, %d)' % (value.x, value.y) elif slot == 'source-display-bounds': valueText = '(%d, %d),(%d, %d)' % (value.x1, value.y1, value.x2, value.y2) elif slot == 'target-display-bounds': valueText = '(%d, %d),(%d, %d)' % (value.x1, value.y1, value.x2, value.y2) elif slot == 'viewport': valueText = '(%d, %d),(%d, %d)' % (value.x1, value.y1, value.x2, value.y2) return valueText def __dumpPropertyBag(obj): pbag = obj.getProperties() slots = pbag.getKeys('') print ' Available slots: ', pbag.getKeys('') for slot in slots: if slot in ('cursor-set', 'smoothing-type'): continue print " About '%s':" % slot print ' Doc Title:', pbag.getDocTitle(slot) print ' Type:', pbag.getType(slot) value = pbag.getDefault(slot).value() print ' Default value:', value, __getValueText(slot, value) value = pbag.getValue(slot).value() print ' Current value:', value, __getValueText(slot, value) print def __setupMagnifier(position, left = None, top = None, right = None, bottom = None, restore = None): '''Creates the magnifier in the position specified. Arguments: - position: the position/type of zoomer (full, left half, etc.) - left: the left edge of the zoomer (only applicable for custom) - top: the top edge of the zoomer (only applicable for custom) - right: the right edge of the zoomer (only applicable for custom) - bottom: the top edge of the zoomer (only applicable for custom) - restore: a dictionary of all of the settings which should be restored ''' global _fullScreenCapable, _magnifierPBag, _originalSourceDisplayBounds _magnifier.clearAllZoomRegions() if not restore: restore = { } try: _magnifier.TargetDisplay = settings.magTargetDisplay except: pass try: _magnifier.SourceDisplay = settings.magSourceDisplay except: pass try: _fullScreenCapable = _magnifier.fullScreenCapable() except: debug.printException(debug.LEVEL_WARNING) hideCursor = restore.get('magHideCursor', settings.magHideCursor) if hideCursor and _fullScreenCapable and _magnifier.SourceDisplay == _magnifier.TargetDisplay and position == settings.MAG_ZOOMER_TYPE_FULL_SCREEN: hideSystemPointer(True) else: hideSystemPointer(False) _magnifierPBag = _magnifier.getProperties() sdb = _magnifierPBag.getValue('source-display-bounds').value() if not _originalSourceDisplayBounds: _originalSourceDisplayBounds = sdb elif _liveUpdatingMagnifier: sdb = _originalSourceDisplayBounds if _fullScreenCapable and position == settings.MAG_ZOOMER_TYPE_FULL_SCREEN: prefLeft = 0 prefTop = 0 prefRight = sdb.x2 prefBottom = sdb.y2 elif position == settings.MAG_ZOOMER_TYPE_TOP_HALF: prefLeft = 0 prefTop = 0 prefRight = sdb.x2 prefBottom = sdb.y2 / 2 elif position == settings.MAG_ZOOMER_TYPE_BOTTOM_HALF: prefLeft = 0 prefTop = sdb.y2 / 2 prefRight = sdb.x2 prefBottom = sdb.y2 elif position == settings.MAG_ZOOMER_TYPE_LEFT_HALF: prefLeft = 0 prefTop = 0 prefRight = sdb.x2 / 2 prefBottom = sdb.y2 elif position == settings.MAG_ZOOMER_TYPE_RIGHT_HALF: prefLeft = sdb.x2 / 2 prefTop = 0 prefRight = sdb.x2 prefBottom = sdb.y2 elif not left: pass prefLeft = settings.magZoomerLeft if not top: pass prefTop = settings.magZoomerTop if not right: pass prefRight = settings.magZoomerRight if not bottom: pass prefBottom = settings.magZoomerBottom orca_state.zoomerType = position updateTarget = True if not _fullScreenCapable and _magnifier.SourceDisplay == _magnifier.TargetDisplay: magAlreadyRunning = False tdb = _magnifierPBag.getValue('target-display-bounds').value() if tdb.x1 and tdb.x2 and tdb.y1 or tdb.y2: magAlreadyRunning = True if magAlreadyRunning and tdb.x1 == sdb.x1 and tdb.x2 == sdb.x2 and tdb.y1 == sdb.y1: pass magFullScreen = tdb.y2 == sdb.y2 sourceArea = (sdb.x2 - sdb.x1) * (sdb.y2 - sdb.y1) prefArea = (prefRight - prefLeft) * (prefBottom - prefTop) if prefArea > sourceArea / 2: debug.println(debug.LEVEL_WARNING, 'Composite is not being used. The preferred target area is\ngreater than 50% of the source area. These settings can\nrender the contents of the screen inaccessible.') if not magAlreadyRunning or magFullScreen: debug.println(debug.LEVEL_WARNING, "Setting the target display to the screen's right half.") prefRight = sdb.x2 prefLeft = sdb.x2 / 2 prefTop = sdb.y1 prefBottom = sdb.y2 elif sdb.y2 > 0: updateTarget = False debug.println(debug.LEVEL_WARNING, 'Gnome-mag is already running. Using those settings.') if updateTarget: tdb = _magnifierPBag.getValue('target-display-bounds').value() _magnifierPBag.setValue('target-display-bounds', ORBit.CORBA.Any(ORBit.CORBA.TypeCode(tdb.__typecode__.repo_id), GNOME.Magnifier.RectBounds(prefLeft, prefTop, prefRight, prefBottom))) bonobo.pbclient_set_string(_magnifierPBag, 'cursor-set', 'default') enableCursor = restore.get('enableMagCursor', settings.enableMagCursor) explicitSize = restore.get('enableMagCursorExplicitSize', settings.enableMagCursorExplicitSize) size = restore.get('magCursorSize', settings.magCursorSize) setMagnifierCursor(enableCursor, explicitSize, size, False) value = restore.get('magCursorColor', settings.magCursorColor) setMagnifierObjectColor('cursor-color', value, False) value = restore.get('magCrossHairColor', settings.magCrossHairColor) setMagnifierObjectColor('crosswire-color', value, False) enableCrossHair = restore.get('enableMagCrossHair', settings.enableMagCrossHair) setMagnifierCrossHair(enableCrossHair, False) value = restore.get('enableMagCrossHairClip', settings.enableMagCrossHairClip) setMagnifierCrossHairClip(value, False) if not enableCursor: pass orca_state.mouseEnhancementsEnabled = enableCrossHair def __setupZoomer(restore = None): '''Creates a zoomer in the magnifier Arguments: - restore: a dictionary of all of the settings which should be restored ''' global _targetDisplayBounds, _sourceDisplayBounds, _fullScreenCapable, _sourceDisplayBounds, _targetDisplayBounds, _roiWidth, _roiHeight, _zoomer, _zoomerPBag, _pollMouseDisabled, _pollMouseDisabled if not restore: restore = { } _targetDisplayBounds = _magnifierPBag.getValue('target-display-bounds').value() debug.println(debug.LEVEL_ALL, 'Magnifier target bounds preferences: (%d, %d), (%d, %d)' % (settings.magZoomerLeft, settings.magZoomerTop, settings.magZoomerRight, settings.magZoomerBottom)) debug.println(debug.LEVEL_ALL, 'Magnifier target bounds actual: (%d, %d), (%d, %d)' % (_targetDisplayBounds.x1, _targetDisplayBounds.y1, _targetDisplayBounds.x2, _targetDisplayBounds.y2)) _sourceDisplayBounds = _magnifierPBag.getValue('source-display-bounds').value() debug.println(debug.LEVEL_ALL, 'Magnifier source bounds actual: (%d, %d), (%d, %d)' % (_sourceDisplayBounds.x1, _sourceDisplayBounds.y1, _sourceDisplayBounds.x2, _sourceDisplayBounds.y2)) if _sourceDisplayBounds.x2 - _sourceDisplayBounds.x1 == 0 or _sourceDisplayBounds.y2 - _sourceDisplayBounds.y1 == 0: debug.println(debug.LEVEL_SEVERE, 'There is nothing to magnify. This is usually caused\nby a preferences setting that tries to take up the\nfull screen for magnification, but the underlying\nsystem does not support full screen magnification.\nThe causes of that are generally that COMPOSITE\nsupport has not been enabled in gnome-mag or the\nX Window System Server. As a result of this issue,\ndefaulting to the right half of the screen.\n') _fullScreenCapable = False __setupMagnifier(settings.MAG_ZOOMER_TYPE_CUSTOM, _targetDisplayBounds.x1 / 2, _targetDisplayBounds.y1, _targetDisplayBounds.x2, _targetDisplayBounds.y2) _sourceDisplayBounds = _magnifierPBag.getValue('source-display-bounds').value() _targetDisplayBounds = _magnifierPBag.getValue('target-display-bounds').value() viewportWidth = _targetDisplayBounds.x2 - _targetDisplayBounds.x1 viewportHeight = _targetDisplayBounds.y2 - _targetDisplayBounds.y1 debug.println(debug.LEVEL_ALL, 'Magnifier zoomer viewport desired: (0, 0), (%d, %d)' % (viewportWidth, viewportHeight)) debug.println(debug.LEVEL_ALL, 'Magnifier source width: %d (viewport can show %d)' % (_sourceDisplayBounds.x2 - _sourceDisplayBounds.x1, viewportWidth / settings.magZoomFactor)) debug.println(debug.LEVEL_ALL, 'Magnifier source height: %d (viewport can show %d)' % (_sourceDisplayBounds.y2 - _sourceDisplayBounds.y1, viewportHeight / settings.magZoomFactor)) _roiWidth = min(_sourceDisplayBounds.x2 - _sourceDisplayBounds.x1, viewportWidth / settings.magZoomFactor) _roiHeight = min(_sourceDisplayBounds.y2 - _sourceDisplayBounds.y1, viewportHeight / settings.magZoomFactor) debug.println(debug.LEVEL_ALL, 'Magnifier zoomer ROI size desired: width=%d, height=%d)' % (_roiWidth, _roiHeight)) _zoomer = _magnifier.createZoomRegion(settings.magZoomFactor, settings.magZoomFactor, GNOME.Magnifier.RectBounds(0, 0, _roiWidth, _roiHeight), GNOME.Magnifier.RectBounds(0, 0, 1, 1)) _zoomerPBag = _zoomer.getProperties() bonobo.pbclient_set_boolean(_zoomerPBag, 'is-managed', True) value = restore.get('magZoomFactor', settings.magZoomFactor) setZoomerMagFactor(value, value, False) value = restore.get('enableMagZoomerColorInversion', settings.enableMagZoomerColorInversion) setZoomerColorInversion(value, False) brightness = restore.get('magBrightnessLevel', settings.magBrightnessLevel) r = brightness + restore.get('magBrightnessLevelRed', settings.magBrightnessLevelRed) g = brightness + restore.get('magBrightnessLevelGreen', settings.magBrightnessLevelGreen) b = brightness + restore.get('magBrightnessLevelBlue', settings.magBrightnessLevelBlue) setZoomerBrightness(r, g, b, False) contrast = restore.get('magContrastLevel', settings.magContrastLevel) r = contrast + restore.get('magContrastLevelRed', settings.magContrastLevelRed) g = contrast + restore.get('magContrastLevelGreen', settings.magContrastLevelGreen) b = contrast + restore.get('magContrastLevelBlue', settings.magContrastLevelBlue) setZoomerContrast(r, g, b, False) value = restore.get('magColorFilteringMode', settings.magColorFilteringMode) setZoomerColorFilter(value, False) value = restore.get('magZoomerType', settings.magZoomerType) if value == settings.MAG_ZOOMER_TYPE_FULL_SCREEN: size = 0 else: size = restore.get('magZoomerBorderSize', settings.magZoomerBorderSize) color = restore.get('magZoomerBorderColor', settings.magZoomerBorderColor) setZoomerObjectSize('border-size', size, False) setZoomerObjectColor('border-color', color, False) value = restore.get('magSmoothingMode', settings.magSmoothingMode) setZoomerSmoothingType(value, False) bounds = GNOME.Magnifier.RectBounds(0, 0, viewportWidth, viewportHeight) _zoomer.moveResize(bounds) try: bonobo.pbclient_set_boolean(_zoomerPBag, 'poll-mouse', False) _pollMouseDisabled = True except: _pollMouseDisabled = False __updateROIDimensions() _magnifier.addZoomRegion(_zoomer) def __updateROIDimensions(): '''Updates the ROI width, height, and maximum and minimum values. ''' global _roiWidth, _roiHeight, _minROIX, _minROIY, _maxROIX, _maxROIY viewport = _zoomerPBag.getValue('viewport').value() debug.println(debug.LEVEL_ALL, 'Magnifier viewport actual: (%d, %d), (%d, %d)' % (viewport.x1, viewport.y1, viewport.x2, viewport.y2)) magx = _zoomerPBag.getValue('mag-factor-x').value() magy = _zoomerPBag.getValue('mag-factor-y').value() _roiWidth = min(_sourceDisplayBounds.x2 - _sourceDisplayBounds.x1, (viewport.x2 - viewport.x1) / magx) _roiHeight = min(_sourceDisplayBounds.y2 - _sourceDisplayBounds.y1, (viewport.y2 - viewport.y1) / magy) debug.println(debug.LEVEL_ALL, 'Magnifier zoomer ROI size actual: width=%d, height=%d)' % (_roiWidth, _roiHeight)) _minROIX = _sourceDisplayBounds.x1 + _roiWidth / 2 _minROIY = _sourceDisplayBounds.y1 + _roiHeight / 2 _maxROIX = _sourceDisplayBounds.x2 - _roiWidth / 2 _maxROIY = _sourceDisplayBounds.y2 - _roiHeight / 2 debug.println(debug.LEVEL_ALL, 'Magnifier ROI min/max center: (%d, %d), (%d, %d)' % (_minROIX, _minROIY, _maxROIX, _maxROIY)) def applySettings(): '''Looks at the user settings and applies them to the magnifier.''' global _mouseTracking, _controlTracking, _textTracking, _edgeMargin, _pointerFollowsZoomer, _pointerFollowsFocus __setupMagnifier(settings.magZoomerType) __setupZoomer() _mouseTracking = settings.magMouseTrackingMode _controlTracking = settings.magControlTrackingMode _textTracking = settings.magTextTrackingMode _edgeMargin = settings.magEdgeMargin _pointerFollowsZoomer = settings.magPointerFollowsZoomer _pointerFollowsFocus = settings.magPointerFollowsFocus def magnifyAccessible(event, obj, extents = None): '''Sets the region of interest to the upper left of the given accessible, if it implements the Component interface. Otherwise, does nothing. Arguments: - event: the Event that caused this to be called - obj: the accessible ''' global _lastMouseEventWasRoute if not _initialized: return None currentTime = time.time() if currentTime - _lastMouseEventTime < 0.2: return None haveSomethingToMagnify = False if extents: (x, y, width, height) = extents haveSomethingToMagnify = True elif event and event.type.startswith('object:text-caret-moved'): try: text = obj.queryText() if text and text.caretOffset >= 0: offset = text.caretOffset if offset == text.characterCount: offset -= 1 (x, y, width, height) = text.getCharacterExtents(offset, 0) haveSomethingToMagnify = width + height > 0 except: _initialized haveSomethingToMagnify = False if haveSomethingToMagnify: if _textTracking == settings.MAG_TRACKING_MODE_CENTERED: __setROICenter(x, y) elif _textTracking == settings.MAG_TRACKING_MODE_PUSH: __setROICursorPush(x, y, width, height, _edgeMargin) return None if haveSomethingToMagnify: if _pointerFollowsFocus: _lastMouseEventWasRoute = True eventsynthesizer.generateMouseEvent(x, y + height - 1, 'abs') if _controlTracking == settings.MAG_TRACKING_MODE_CENTERED: centerX = x + width / 2 centerY = y + height / 2 if width > _roiWidth: centerX = x if height > _roiHeight: centerY = y __setROICenter(centerX, centerY) elif _controlTracking == settings.MAG_TRACKING_MODE_PUSH: __setROICursorPush(x, y, width, height) def init(): '''Initializes the magnifier, bringing the magnifier up on the display. Returns True if the initialization procedure was run or False if this module has already been initialized. ''' global _magnifier, _initialized, _initialized if not _magnifierAvailable: return False if _initialized: return False _magnifier = bonobo.get_object('OAFIID:GNOME_Magnifier_Magnifier:0.9', 'GNOME/Magnifier/Magnifier') try: _initialized = True applySettings() pyatspi.Registry.registerEventListener(__onMouseEvent, 'mouse:abs') __setROICenter(0, 0) return True except: _initialized _magnifierAvailable _initialized = False _magnifier.dispose() raise def shutdown(): '''Shuts down the magnifier module. Returns True if the shutdown procedure was run or False if this module has not been initialized. ''' global _magnifier, _initialized if not _magnifierAvailable: return False if not _initialized: return False pyatspi.Registry.deregisterEventListener(__onMouseEvent, 'mouse:abs') try: hideSystemPointer(False) _magnifier.clearAllZoomRegions() _magnifier.dispose() except: _initialized _magnifierAvailable debug.printException(debug.LEVEL_WARNING) _magnifier = None _initialized = False return True def setupMagnifier(position, left = None, top = None, right = None, bottom = None, restore = None): '''Creates the magnifier in the position specified. Arguments: - position: the position/type of zoomer (full, left half, etc.) - left: the left edge of the zoomer (only applicable for custom) - top: the top edge of the zoomer (only applicable for custom) - right: the right edge of the zoomer (only applicable for custom) - bottom: the top edge of the zoomer (only applicable for custom) - restore: a dictionary of all of the settings that should be restored ''' global _liveUpdatingMagnifier if not _initialized: return None _liveUpdatingMagnifier = True __setupMagnifier(position, left, top, right, bottom, restore) __setupZoomer(restore) def setMagnifierCursor(enabled, customEnabled, size, updateScreen = True): '''Sets the cursor. Arguments: - enabled: Whether or not the cursor should be enabled - customEnabled: Whether or not a custom size has been enabled - size: The size it should be set to - updateScreen: Whether or not to update the screen ''' if not _initialized: return None try: mag = _zoomerPBag.getValue('mag-factor-x').value() except: _initialized mag = settings.magZoomFactor if enabled: scale = 1 * mag else: scale = 0 if not enabled and customEnabled: size = 0 bonobo.pbclient_set_float(_magnifierPBag, 'cursor-scale-factor', scale) bonobo.pbclient_set_long(_magnifierPBag, 'cursor-size', size) if updateScreen: _zoomer.markDirty(_roi) def setMagnifierCrossHair(enabled, updateScreen = True): '''Sets the cross-hair. Arguments: - enabled: Whether or not the cross-hair should be enabled - updateScreen: Whether or not to update the screen ''' if not _initialized: return None size = 0 if enabled: size = settings.magCrossHairSize bonobo.pbclient_set_long(_magnifierPBag, 'crosswire-size', size) if updateScreen: _zoomer.markDirty(_roi) def setMagnifierCrossHairClip(enabled, updateScreen = True): '''Sets the cross-hair clip. Arguments: - enabled: Whether or not the cross-hair clip should be enabled - updateScreen: Whether or not to update the screen ''' if not _initialized: return None bonobo.pbclient_set_boolean(_magnifierPBag, 'crosswire-clip', enabled) if updateScreen: _zoomer.markDirty(_roi) def setZoomerColorInversion(enabled, updateScreen = True): '''Sets the color inversion. Arguments: - enabled: Whether or not color inversion should be enabled - updateScreen: Whether or not to update the screen ''' if not _initialized: return None bonobo.pbclient_set_boolean(_zoomerPBag, 'inverse-video', enabled) if updateScreen: _zoomer.markDirty(_roi) def setZoomerBrightness(red = 0, green = 0, blue = 0, updateScreen = True): '''Increases/Decreases the brightness level by the specified increments. Increments are floats ranging from -1 (black/no brightenss) to 1 (white/100% brightness). 0 means no change. Arguments: - red: The amount to alter the red brightness level - green: The amount to alter the green brightness level - blue: The amount to alter the blue brightness level - updateScreen: Whether or not to update the screen ''' if not _initialized: return None _zoomer.setBrightness(red, green, blue) if updateScreen: _zoomer.markDirty(_roi) def setZoomerContrast(red = 0, green = 0, blue = 0, updateScreen = True): '''Increases/Decreases the contrast level by the specified increments. Increments are floats ranging from -1 (grey/no contrast) to 1 (white/back/100% contrast). 0 means no change. Arguments: - red: The amount to alter the red contrast level - green: The amount to alter the green contrast level - blue: The amount to alter the blue contrast level - updateScreen: Whether or not to update the screen ''' if not _initialized: return None _zoomer.setContrast(red, green, blue) if updateScreen: _zoomer.markDirty(_roi) def setMagnifierObjectSize(magProperty, size, updateScreen = True): '''Sets the specified magnifier property to the specified size. Arguments: - magProperty: The property to set (as a string) - size: The size to apply - updateScreen: Whether or not to update the screen ''' if not _initialized: return None bonobo.pbclient_set_long(_magnifierPBag, magProperty, size) if updateScreen: _zoomer.markDirty(_roi) def setZoomerObjectSize(magProperty, size, updateScreen = True): '''Sets the specified zoomer property to the specified size. Arguments: - magProperty: The property to set (as a string) - size: The size to apply - updateScreen: Whether or not to update the screen ''' if not _initialized: return None if updateScreen: _zoomer.markDirty(_roi) def setZoomerObjectColor(magProperty, colorSetting, updateScreen = True): '''Sets the specified zoomer property to the specified color. Arguments: - magProperty: The property to set (as a string) - colorSetting: The Orca color setting to apply - updateScreen: Whether or not to update the screen ''' if not _initialized: return None colorPreference = gtk.gdk.color_parse(colorSetting) colorPreference.red = colorPreference.red >> 8 colorPreference.blue = colorPreference.blue >> 8 colorPreference.green = colorPreference.green >> 8 colorString = '0x%02X%02X%02X' % (colorPreference.red, colorPreference.green, colorPreference.blue) toChange = _zoomerPBag.getValue(magProperty) _zoomerPBag.setValue(magProperty, ORBit.CORBA.Any(toChange.typecode(), long(colorString, 0))) if updateScreen: _zoomer.markDirty(_roi) def setMagnifierObjectColor(magProperty, colorSetting, updateScreen = True): '''Sets the specified magnifier property to the specified color. Arguments: - magProperty: The property to set (as a string) - colorSetting: The Orca color setting to apply - updateScreen: Whether or not to update the screen ''' if not _initialized: return None colorPreference = gtk.gdk.color_parse(colorSetting) colorPreference.red = colorPreference.red >> 8 colorPreference.blue = colorPreference.blue >> 8 colorPreference.green = colorPreference.green >> 8 colorString = '0x%02X%02X%02X' % (colorPreference.red, colorPreference.green, colorPreference.blue) toChange = _magnifierPBag.getValue(magProperty) _magnifierPBag.setValue(magProperty, ORBit.CORBA.Any(toChange.typecode(), long(colorString, 0))) if updateScreen: _zoomer.markDirty(_roi) def setZoomerMagFactor(x, y, updateScreen = True): '''Sets the magnification level. Arguments: - x: The horizontal magnification level - y: The vertical magnification level - updateScreen: Whether or not to update the screen ''' global _minROIX, _minROIY if not _initialized: return None (oldX, oldY) = _zoomer.getMagFactor() _zoomer.setMagFactor(x, y) if updateScreen: __updateROIDimensions() if oldX > x and x < 1.5: _minROIX = _sourceDisplayBounds.x1 _minROIY = _sourceDisplayBounds.y1 __setROI(GNOME.Magnifier.RectBounds(_minROIX, _minROIY, _minROIX + _roiWidth, _minROIY + _roiHeight)) else: extents = orca_state.locusOfFocus.queryComponent().getExtents(0) __setROICenter(extents.x, extents.y) def setZoomerSmoothingType(smoothingType, updateScreen = True): """Sets the zoomer's smoothing type. Arguments: - smoothingType: The type of smoothing to use - updateScreen: Whether or not to update the screen """ if not _initialized: return None if smoothingType == settings.MAG_SMOOTHING_MODE_BILINEAR: string = 'bilinear' else: string = 'None' try: bonobo.pbclient_set_string(_zoomerPBag, 'smoothing-type', string) except: pass if updateScreen: _zoomer.markDirty(_roi) def setZoomerColorFilter(colorFilter, updateScreen = True): """Sets the zoomer's color filter. Arguments: - colorFilter: The color filter to apply - updateScreen: Whether or not to update the screen """ if not _initialized or not isFilteringCapable(): return None if colorFilter == settings.MAG_COLOR_FILTERING_MODE_SATURATE_RED: toApply = _zoomer.COLORBLIND_FILTER_T_SELECTIVE_SATURATE_RED elif colorFilter == settings.MAG_COLOR_FILTERING_MODE_SATURATE_GREEN: toApply = _zoomer.COLORBLIND_FILTER_T_SELECTIVE_SATURATE_GREEN elif colorFilter == settings.MAG_COLOR_FILTERING_MODE_SATURATE_BLUE: toApply = _zoomer.COLORBLIND_FILTER_T_SELECTIVE_SATURATE_BLUE elif colorFilter == settings.MAG_COLOR_FILTERING_MODE_DESATURATE_RED: toApply = _zoomer.COLORBLIND_FILTER_T_SELECTIVE_DESSATURATE_RED elif colorFilter == settings.MAG_COLOR_FILTERING_MODE_DESATURATE_GREEN: toApply = _zoomer.COLORBLIND_FILTER_T_SELECTIVE_DESSATURATE_GREEN elif colorFilter == settings.MAG_COLOR_FILTERING_MODE_DESATURATE_BLUE: toApply = _zoomer.COLORBLIND_FILTER_T_SELECTIVE_DESSATURATE_BLUE elif colorFilter == settings.MAG_COLOR_FILTERING_MODE_NEGATIVE_HUE_SHIFT: toApply = _zoomer.COLORBLIND_FILTER_T_HUE_SHIFT_NEGATIVE elif colorFilter == settings.MAG_COLOR_FILTERING_MODE_POSITIVE_HUE_SHIFT: toApply = _zoomer.COLORBLIND_FILTER_T_HUE_SHIFT_POSITIVE else: toApply = _zoomer.COLORBLIND_FILTER_T_NO_FILTER colorFilter = _zoomerPBag.getValue('color-blind-filter') _zoomerPBag.setValue('color-blind-filter', ORBit.CORBA.Any(colorFilter.typecode(), toApply)) if updateScreen: _zoomer.markDirty(_roi) def hideSystemPointer(hidePointer): '''Hide or show the system pointer. Arguments: -hidePointer: If True, hide the system pointer, otherwise show it. ''' try: if hidePointer: _magnifier.hideCursor() else: _magnifier.showCursor() except: debug.printException(debug.LEVEL_FINEST) def isFullScreenCapable(): '''Returns True if we are capable of doing full screen (i.e. whether composite is being used. ''' try: capable = _magnifier.fullScreenCapable() except: capable = False return capable def isFilteringCapable(): """Returns True if we're able to take advantage of libcolorblind's color filtering. """ try: capable = _magnifier.supportColorblindFilters() except: capable = False return capable def updateMouseTracking(newMode): '''Updates the mouse tracking mode. Arguments: -newMode: The new mode to use. ''' global _mouseTracking _mouseTracking = newMode def updateControlTracking(newMode): '''Updates the control tracking mode. Arguments: -newMode: The new mode to use. ''' global _controlTracking _controlTracking = newMode def updateTextTracking(newMode): '''Updates the text tracking mode. Arguments: -newMode: The new mode to use. ''' global _textTracking _textTracking = newMode def updateEdgeMargin(amount): '''Updates the edge margin Arguments: -amount: The new margin to use, in pixels. ''' global _edgeMargin _edgeMargin = amount def updatePointerFollowsFocus(enabled): '''Updates the pointer follows focus setting. Arguments: -enabled: whether or not pointer follows focus should be enabled. ''' global _pointerFollowsFocus _pointerFollowsFocus = enabled def updatePointerFollowsZoomer(enabled): '''Updates the pointer follows zoomer setting. Arguments: -enabled: whether or not pointer follows zoomer should be enabled. ''' global _pointerFollowsZoomer _pointerFollowsZoomer = enabled def finishLiveUpdating(): '''Restores things that were altered via a live update.''' global _liveUpdatingMagnifier, _mouseTracking, _controlTracking, _textTracking, _edgeMargin, _pointerFollowsFocus, _pointerFollowsZoomer _liveUpdatingMagnifier = False _mouseTracking = settings.magMouseTrackingMode _controlTracking = settings.magControlTrackingMode _textTracking = settings.magTextTrackingMode _edgeMargin = settings.magEdgeMargin _pointerFollowsFocus = settings.magPointerFollowsFocus _pointerFollowsZoomer = settings.magPointerFollowsZoomer if settings.enableMagnifier: setupMagnifier(settings.magZoomerType) init() else: shutdown() def toggleColorEnhancements(script = None, inputEvent = None): '''Toggles the color enhancements on/off.''' if not _initialized: return None (levelX, levelY) = _zoomer.getMagFactor() normal = { 'enableMagZoomerColorInversion': False, 'magBrightnessLevelRed': 0, 'magBrightnessLevelGreen': 0, 'magBrightnessLevelBlue': 0, 'magContrastLevelRed': 0, 'magContrastLevelGreen': 0, 'magContrastLevelBlue': 0, 'magColorFilteringMode': settings.MAG_COLOR_FILTERING_MODE_NONE, 'magSmoothingMode': settings.MAG_SMOOTHING_MODE_BILINEAR, 'magZoomerBorderColor': '#000000', 'magZoomFactor': levelX } if orca_state.colorEnhancementsEnabled: __setupZoomer(restore = normal) speech.speak(_('Color enhancements disabled.')) else: toRestore = { 'magZoomFactor': levelX } __setupZoomer(restore = toRestore) speech.speak(_('Color enhancements enabled.')) orca_state.colorEnhancementsEnabled = not (orca_state.colorEnhancementsEnabled) return True def toggleMouseEnhancements(script = None, inputEvent = None): '''Toggles the mouse enhancements on/off.''' if not _initialized: return None if orca_state.mouseEnhancementsEnabled: setMagnifierCrossHair(False, False) setMagnifierObjectColor('cursor-color', '#000000', False) setMagnifierCursor(True, False, 0) speech.speak(_('Mouse enhancements disabled.')) else: cursorEnable = settings.enableMagCursor crossHairEnable = settings.enableMagCrossHair if not cursorEnable or crossHairEnable: cursorEnable = True crossHairEnable = True setMagnifierCursor(cursorEnable, settings.enableMagCursorExplicitSize, settings.magCursorSize, False) setMagnifierObjectColor('cursor-color', settings.magCursorColor, False) setMagnifierObjectColor('crosswire-color', settings.magCrossHairColor, False) setMagnifierCrossHairClip(settings.enableMagCrossHairClip, False) setMagnifierCrossHair(crossHairEnable) speech.speak(_('Mouse enhancements enabled.')) orca_state.mouseEnhancementsEnabled = not (orca_state.mouseEnhancementsEnabled) return True def increaseMagnification(script = None, inputEvent = None): '''Increases the magnification level.''' if not _initialized: return None (levelX, levelY) = _zoomer.getMagFactor() if levelX <= levelX: pass elif levelX < 4: increment = 0.25 elif levelX <= levelX: pass elif levelX < 7: increment = 0.5 else: increment = 1 newLevel = levelX + increment if newLevel <= 16: setZoomerMagFactor(newLevel, newLevel) speech.speak(str(newLevel)) return True def decreaseMagnification(script = None, inputEvent = None): '''Decreases the magnification level.''' if not _initialized: return None (levelX, levelY) = _zoomer.getMagFactor() if levelX <= levelX: pass elif levelX < 4: increment = 0.25 elif levelX <= levelX: pass elif levelX < 7: increment = 0.5 else: increment = 1 newLevel = levelX - increment if newLevel >= 1: setZoomerMagFactor(newLevel, newLevel) speech.speak(str(newLevel)) return True def toggleMagnifier(script = None, inputEvent = None): '''Toggles the magnifier.''' if not _initialized: init() speech.speak(_('Magnifier enabled.')) else: shutdown() speech.speak(_('Magnifier disabled.')) return True def cycleZoomerType(script = None, inputEvent = None): '''Allows the user to cycle through the available zoomer types.''' if not _initialized: return None orca_state.zoomerType += 1 toRestore = { } (levelX, levelY) = _zoomer.getMagFactor() if levelX != settings.magZoomFactor: toRestore['magZoomFactor'] = levelX if not orca_state.colorEnhancementsEnabled: toRestore.update({ 'enableMagZoomerColorInversion': False, 'magBrightnessLevelRed': 0, 'magBrightnessLevelGreen': 0, 'magBrightnessLevelBlue': 0, 'magContrastLevelRed': 0, 'magContrastLevelGreen': 0, 'magContrastLevelBlue': 0, 'magColorFilteringMode': settings.MAG_COLOR_FILTERING_MODE_NONE, 'magSmoothingMode': settings.MAG_SMOOTHING_MODE_BILINEAR, 'magZoomerBorderColor': '#000000' }) setupMagnifier(orca_state.zoomerType, restore = toRestore) if not orca_state.mouseEnhancementsEnabled: setMagnifierCrossHair(False) setMagnifierObjectColor('cursor-color', settings.magCursorColor, False) setMagnifierCursor(False, False, 0) if orca_state.zoomerType == settings.MAG_ZOOMER_TYPE_FULL_SCREEN: if _fullScreenCapable: zoomerType = _('Full Screen') else: zoomerType = _('Full Screen mode unavailable') elif orca_state.zoomerType == settings.MAG_ZOOMER_TYPE_TOP_HALF: zoomerType = _('Top Half') elif orca_state.zoomerType == settings.MAG_ZOOMER_TYPE_BOTTOM_HALF: zoomerType = _('Bottom Half') elif orca_state.zoomerType == settings.MAG_ZOOMER_TYPE_LEFT_HALF: zoomerType = _('Left Half') elif orca_state.zoomerType == settings.MAG_ZOOMER_TYPE_RIGHT_HALF: zoomerType = _('Right Half') elif orca_state.zoomerType == settings.MAG_ZOOMER_TYPE_CUSTOM: zoomerType = _('Custom') else: zoomerType = '' speech.speak(zoomerType) return True