home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / var / lib / python-support / python2.6 / orca / mag.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  37.8 KB  |  1,223 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. '''Manages the magnifier for orca.  [[[TODO: WDW - this is very very
  5. early in development.  One might even say it is pre-prototype.]]]'''
  6. __id__ = '$Id: mag.py 4607 2009-02-26 18:12:30Z wwalker $'
  7. __version__ = '$Revision: 4607 $'
  8. __date__ = '$Date: 2009-02-26 13:12:30 -0500 (Thu, 26 Feb 2009) $'
  9. __copyright__ = 'Copyright (c) 2005-2008 Sun Microsystems Inc.'
  10. __license__ = 'LGPL'
  11. import bonobo
  12.  
  13. try:
  14.     import gtk
  15. except:
  16.     pass
  17.  
  18. import time
  19. import pyatspi
  20. import debug
  21. import eventsynthesizer
  22. import settings
  23. import speech
  24. import orca_state
  25. from orca_i18n import _
  26. _magnifierAvailable = False
  27.  
  28. try:
  29.     import ORBit
  30.     ORBit.load_typelib('GNOME_Magnifier')
  31.     import GNOME.Magnifier as GNOME
  32.     _magnifierAvailable = True
  33. except:
  34.     pass
  35.  
  36. _initialized = False
  37. _magnifier = None
  38. _magnifierPBag = None
  39. _roiWidth = 0
  40. _roiHeight = 0
  41. _minROIX = 0
  42. _maxROIX = 0
  43. _minROIY = 0
  44. _maxROIY = 0
  45. _roi = None
  46. _sourceDisplayBounds = None
  47. _targetDisplayBounds = None
  48. _zoomer = None
  49. _zoomerPBag = None
  50. _lastMouseEventTime = time.time()
  51. _lastMouseEventWasRoute = False
  52. _pollMouseDisabled = False
  53. _fullScreenCapable = True
  54. _liveUpdatingMagnifier = False
  55. _originalSourceDisplayBounds = None
  56. _mouseTracking = None
  57. _controlTracking = None
  58. _textTracking = None
  59. _edgeMargin = None
  60. _pointerFollowsZoomer = None
  61. _pointerFollowsFocus = None
  62.  
  63. def __setROI(rect):
  64.     '''Sets the region of interest.
  65.  
  66.     Arguments:
  67.     - rect: A GNOME.Magnifier.RectBounds object.
  68.     '''
  69.     global _roi
  70.     debug.println(debug.LEVEL_ALL, 'mag.py:__setROI: (%d, %d), (%d, %d)' % (rect.x1, rect.y1, rect.x2, rect.y2))
  71.     _roi = rect
  72.     _zoomer.setROI(_roi)
  73.     _zoomer.markDirty(_roi)
  74.  
  75.  
  76. def __setROICenter(x, y):
  77.     '''Centers the region of interest around the given point.
  78.  
  79.     Arguments:
  80.     - x: integer in unzoomed system coordinates representing x component
  81.     - y: integer in unzoomed system coordinates representing y component
  82.     '''
  83.     if not _initialized:
  84.         return None
  85.     if x < _minROIX:
  86.         x = _minROIX
  87.     elif x > _maxROIX:
  88.         x = _maxROIX
  89.     
  90.     if y < _minROIY:
  91.         y = _minROIY
  92.     elif y > _maxROIY:
  93.         y = _maxROIY
  94.     
  95.     x1 = x - _roiWidth / 2
  96.     y1 = y - _roiHeight / 2
  97.     x2 = x1 + _roiWidth
  98.     y2 = y1 + _roiHeight
  99.     __setROI(GNOME.Magnifier.RectBounds(x1, y1, x2, y2))
  100.  
  101.  
  102. def __setROIPush(x, y):
  103.     '''Nudges the ROI if the pointer bumps into the edge of it.  The point
  104.     given is assumed to be the point where the mouse pointer is.
  105.  
  106.     Arguments:
  107.     - x: integer in unzoomed system coordinates representing x component
  108.     - y: integer in unzoomed system coordinates representing y component
  109.     '''
  110.     newROI = GNOME.Magnifier.RectBounds(_roi.x1, _roi.y1, _roi.x2, _roi.y2)
  111.     if x < _roi.x1:
  112.         newROI.x1 = x
  113.         newROI.x2 = x + _roiWidth
  114.     elif x > _roi.x2:
  115.         newROI.x2 = x
  116.         newROI.x1 = x - _roiWidth
  117.     
  118.     if y < _roi.y1:
  119.         newROI.y1 = y
  120.         newROI.y2 = y + _roiHeight
  121.     elif y > _roi.y2:
  122.         newROI.y2 = y
  123.         newROI.y1 = y - _roiHeight
  124.     
  125.     if True:
  126.         __setROI(newROI)
  127.     
  128.  
  129.  
  130. def __setROICursorPush(x, y, width, height, edgeMargin = 0):
  131.     '''Nudges the ROI if the caret or control is not visible.
  132.  
  133.     Arguments:
  134.     - x: integer in unzoomed system coordinates representing x component
  135.     - y: integer in unzoomed system coordinates representing y component
  136.     - width: integer in unzoomed system coordinates representing the width
  137.     - height: integer in unzoomed system coordinates representing the height
  138.     - edgeMargin: a percentage representing how close to the edge we can get
  139.                   before we need to push
  140.     '''
  141.     edgeMargin = min(edgeMargin, 50) / 100
  142.     edgeMarginX = edgeMargin * _sourceDisplayBounds.x2 / settings.magZoomFactor
  143.     edgeMarginY = edgeMargin * _sourceDisplayBounds.y2 / settings.magZoomFactor
  144.     leftOfROI = x - edgeMarginX <= _roi.x1
  145.     rightOfROI = x + width + edgeMarginX >= _roi.x2
  146.     aboveROI = y - edgeMarginY <= _roi.y1
  147.     belowROI = y + height + edgeMarginY >= _roi.y2
  148.     if not leftOfROI:
  149.         pass
  150.     visibleX = not rightOfROI
  151.     if not aboveROI:
  152.         pass
  153.     visibleY = not belowROI
  154.     if visibleX and visibleY:
  155.         _zoomer.markDirty(_roi)
  156.     
  157.     x1 = _roi.x1
  158.     x2 = _roi.x2
  159.     y1 = _roi.y1
  160.     y2 = _roi.y2
  161.     if leftOfROI:
  162.         x1 = max(_sourceDisplayBounds.x1, x - edgeMarginX)
  163.         x2 = x1 + _roiWidth
  164.     elif rightOfROI:
  165.         x = min(_sourceDisplayBounds.x2, x + edgeMarginX)
  166.         if width > _roiWidth:
  167.             x1 = x
  168.             x2 = x1 + _roiWidth
  169.         else:
  170.             x2 = x + width
  171.             x1 = x2 - _roiWidth
  172.     
  173.     if aboveROI:
  174.         y1 = max(_sourceDisplayBounds.y1, y - edgeMarginY)
  175.         y2 = y1 + _roiHeight
  176.     elif belowROI:
  177.         y = min(_sourceDisplayBounds.y2, y + edgeMarginY)
  178.         if height > _roiHeight:
  179.             y1 = y
  180.             y2 = y1 + _roiHeight
  181.         else:
  182.             y2 = y + height
  183.             y1 = y2 - _roiHeight
  184.     
  185.     __setROI(GNOME.Magnifier.RectBounds(x1, y1, x2, y2))
  186.  
  187.  
  188. def __setROIProportional(x, y):
  189.     '''Positions the ROI proportionally to where the pointer is on the screen.
  190.  
  191.     Arguments:
  192.     - x: integer in unzoomed system coordinates representing x component
  193.     - y: integer in unzoomed system coordinates representing y component
  194.     '''
  195.     if not _initialized:
  196.         return None
  197.     if not _sourceDisplayBounds:
  198.         __setROICenter(x, y)
  199.     else:
  200.         halfScreenWidth = (_sourceDisplayBounds.x2 - _sourceDisplayBounds.x1) / 2
  201.         halfScreenHeight = (_sourceDisplayBounds.y2 - _sourceDisplayBounds.y1) / 2
  202.         proportionX = (halfScreenWidth - x) / halfScreenWidth
  203.         proportionY = (halfScreenHeight - y) / halfScreenHeight
  204.         centerX = x + int(proportionX * _roiWidth / 2)
  205.         centerY = y + int(proportionY * _roiHeight / 2)
  206.         __setROICenter(centerX, centerY)
  207.  
  208.  
  209. def __onMouseEvent(e):
  210.     '''
  211.     Arguments:
  212.     - e: at-spi event from the at-api registry
  213.     '''
  214.     global _lastMouseEventTime, _lastMouseEventWasRoute, _lastMouseEventWasRoute
  215.     isNewMouseMovement = time.time() - _lastMouseEventTime > 1
  216.     _lastMouseEventTime = time.time()
  217.     x = e.detail1
  218.     y = e.detail2
  219.     if _pointerFollowsZoomer and isNewMouseMovement and not _lastMouseEventWasRoute:
  220.         if x < x:
  221.             pass
  222.         elif x < _roi.x2:
  223.             pass
  224.         mouseIsVisible = None if y < y else y < _roi.y2
  225.         if not mouseIsVisible and orca_state.locusOfFocus:
  226.             if _mouseTracking == settings.MAG_TRACKING_MODE_CENTERED:
  227.                 x = (_roi.x1 + _roi.x2) / 2
  228.                 y = (_roi.y1 + _roi.y2) / 2
  229.             elif _mouseTracking != settings.MAG_TRACKING_MODE_NONE:
  230.                 
  231.                 try:
  232.                     extents = orca_state.locusOfFocus.queryComponent().getExtents(0)
  233.                 except:
  234.                     extents = None
  235.  
  236.                 if extents:
  237.                     x = extents.x
  238.                     y = extents.y + extents.height - 1
  239.                 
  240.             
  241.             eventsynthesizer.generateMouseEvent(x, y, 'abs')
  242.             _lastMouseEventWasRoute = True
  243.         
  244.     
  245.     if _pollMouseDisabled:
  246.         _zoomer.setPointerPos(x, y)
  247.     
  248.     if _lastMouseEventWasRoute:
  249.         _lastMouseEventWasRoute = False
  250.         _zoomer.markDirty(_roi)
  251.         return None
  252.     if _mouseTracking == settings.MAG_TRACKING_MODE_PUSH:
  253.         __setROIPush(x, y)
  254.     elif _mouseTracking == settings.MAG_TRACKING_MODE_PROPORTIONAL:
  255.         __setROIProportional(x, y)
  256.     elif _mouseTracking == settings.MAG_TRACKING_MODE_CENTERED:
  257.         __setROICenter(x, y)
  258.     
  259.  
  260.  
  261. def __getValueText(slot, value):
  262.     valueText = ''
  263.     if slot == 'cursor-hotspot':
  264.         valueText = '(%d, %d)' % (value.x, value.y)
  265.     elif slot == 'source-display-bounds':
  266.         valueText = '(%d, %d),(%d, %d)' % (value.x1, value.y1, value.x2, value.y2)
  267.     elif slot == 'target-display-bounds':
  268.         valueText = '(%d, %d),(%d, %d)' % (value.x1, value.y1, value.x2, value.y2)
  269.     elif slot == 'viewport':
  270.         valueText = '(%d, %d),(%d, %d)' % (value.x1, value.y1, value.x2, value.y2)
  271.     
  272.     return valueText
  273.  
  274.  
  275. def __dumpPropertyBag(obj):
  276.     pbag = obj.getProperties()
  277.     slots = pbag.getKeys('')
  278.     print '  Available slots: ', pbag.getKeys('')
  279.     for slot in slots:
  280.         if slot in ('cursor-set', 'smoothing-type'):
  281.             continue
  282.         
  283.         print "    About '%s':" % slot
  284.         print '    Doc Title:', pbag.getDocTitle(slot)
  285.         print '    Type:', pbag.getType(slot)
  286.         value = pbag.getDefault(slot).value()
  287.         print '    Default value:', value, __getValueText(slot, value)
  288.         value = pbag.getValue(slot).value()
  289.         print '    Current value:', value, __getValueText(slot, value)
  290.         print 
  291.     
  292.  
  293.  
  294. def __setupMagnifier(position, left = None, top = None, right = None, bottom = None, restore = None):
  295.     '''Creates the magnifier in the position specified.
  296.  
  297.     Arguments:
  298.     - position: the position/type of zoomer (full, left half, etc.)
  299.     - left:     the left edge of the zoomer (only applicable for custom)
  300.     - top:      the top edge of the zoomer (only applicable for custom)
  301.     - right:    the right edge of the zoomer (only applicable for custom)
  302.     - bottom:   the top edge of the zoomer (only applicable for custom)
  303.     - restore:  a dictionary of all of the settings which should be restored
  304.     '''
  305.     global _fullScreenCapable, _magnifierPBag, _originalSourceDisplayBounds
  306.     _magnifier.clearAllZoomRegions()
  307.     if not restore:
  308.         restore = { }
  309.     
  310.     
  311.     try:
  312.         _magnifier.TargetDisplay = settings.magTargetDisplay
  313.     except:
  314.         pass
  315.  
  316.     
  317.     try:
  318.         _magnifier.SourceDisplay = settings.magSourceDisplay
  319.     except:
  320.         pass
  321.  
  322.     
  323.     try:
  324.         _fullScreenCapable = _magnifier.fullScreenCapable()
  325.     except:
  326.         debug.printException(debug.LEVEL_WARNING)
  327.  
  328.     hideCursor = restore.get('magHideCursor', settings.magHideCursor)
  329.     if hideCursor and _fullScreenCapable and _magnifier.SourceDisplay == _magnifier.TargetDisplay and position == settings.MAG_ZOOMER_TYPE_FULL_SCREEN:
  330.         hideSystemPointer(True)
  331.     else:
  332.         hideSystemPointer(False)
  333.     _magnifierPBag = _magnifier.getProperties()
  334.     sdb = _magnifierPBag.getValue('source-display-bounds').value()
  335.     if not _originalSourceDisplayBounds:
  336.         _originalSourceDisplayBounds = sdb
  337.     elif _liveUpdatingMagnifier:
  338.         sdb = _originalSourceDisplayBounds
  339.     
  340.     if _fullScreenCapable and position == settings.MAG_ZOOMER_TYPE_FULL_SCREEN:
  341.         prefLeft = 0
  342.         prefTop = 0
  343.         prefRight = sdb.x2
  344.         prefBottom = sdb.y2
  345.     elif position == settings.MAG_ZOOMER_TYPE_TOP_HALF:
  346.         prefLeft = 0
  347.         prefTop = 0
  348.         prefRight = sdb.x2
  349.         prefBottom = sdb.y2 / 2
  350.     elif position == settings.MAG_ZOOMER_TYPE_BOTTOM_HALF:
  351.         prefLeft = 0
  352.         prefTop = sdb.y2 / 2
  353.         prefRight = sdb.x2
  354.         prefBottom = sdb.y2
  355.     elif position == settings.MAG_ZOOMER_TYPE_LEFT_HALF:
  356.         prefLeft = 0
  357.         prefTop = 0
  358.         prefRight = sdb.x2 / 2
  359.         prefBottom = sdb.y2
  360.     elif position == settings.MAG_ZOOMER_TYPE_RIGHT_HALF:
  361.         prefLeft = sdb.x2 / 2
  362.         prefTop = 0
  363.         prefRight = sdb.x2
  364.         prefBottom = sdb.y2
  365.     elif not left:
  366.         pass
  367.     prefLeft = settings.magZoomerLeft
  368.     if not top:
  369.         pass
  370.     prefTop = settings.magZoomerTop
  371.     if not right:
  372.         pass
  373.     prefRight = settings.magZoomerRight
  374.     if not bottom:
  375.         pass
  376.     prefBottom = settings.magZoomerBottom
  377.     orca_state.zoomerType = position
  378.     updateTarget = True
  379.     if not _fullScreenCapable and _magnifier.SourceDisplay == _magnifier.TargetDisplay:
  380.         magAlreadyRunning = False
  381.         tdb = _magnifierPBag.getValue('target-display-bounds').value()
  382.         if tdb.x1 and tdb.x2 and tdb.y1 or tdb.y2:
  383.             magAlreadyRunning = True
  384.         
  385.         if magAlreadyRunning and tdb.x1 == sdb.x1 and tdb.x2 == sdb.x2 and tdb.y1 == sdb.y1:
  386.             pass
  387.         magFullScreen = tdb.y2 == sdb.y2
  388.         sourceArea = (sdb.x2 - sdb.x1) * (sdb.y2 - sdb.y1)
  389.         prefArea = (prefRight - prefLeft) * (prefBottom - prefTop)
  390.         if prefArea > sourceArea / 2:
  391.             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.')
  392.             if not magAlreadyRunning or magFullScreen:
  393.                 debug.println(debug.LEVEL_WARNING, "Setting the target display to the screen's right half.")
  394.                 prefRight = sdb.x2
  395.                 prefLeft = sdb.x2 / 2
  396.                 prefTop = sdb.y1
  397.                 prefBottom = sdb.y2
  398.             elif sdb.y2 > 0:
  399.                 updateTarget = False
  400.                 debug.println(debug.LEVEL_WARNING, 'Gnome-mag is already running.  Using those settings.')
  401.             
  402.         
  403.     
  404.     if updateTarget:
  405.         tdb = _magnifierPBag.getValue('target-display-bounds').value()
  406.         _magnifierPBag.setValue('target-display-bounds', ORBit.CORBA.Any(ORBit.CORBA.TypeCode(tdb.__typecode__.repo_id), GNOME.Magnifier.RectBounds(prefLeft, prefTop, prefRight, prefBottom)))
  407.     
  408.     bonobo.pbclient_set_string(_magnifierPBag, 'cursor-set', 'default')
  409.     enableCursor = restore.get('enableMagCursor', settings.enableMagCursor)
  410.     explicitSize = restore.get('enableMagCursorExplicitSize', settings.enableMagCursorExplicitSize)
  411.     size = restore.get('magCursorSize', settings.magCursorSize)
  412.     setMagnifierCursor(enableCursor, explicitSize, size, False)
  413.     value = restore.get('magCursorColor', settings.magCursorColor)
  414.     setMagnifierObjectColor('cursor-color', value, False)
  415.     value = restore.get('magCrossHairColor', settings.magCrossHairColor)
  416.     setMagnifierObjectColor('crosswire-color', value, False)
  417.     enableCrossHair = restore.get('enableMagCrossHair', settings.enableMagCrossHair)
  418.     setMagnifierCrossHair(enableCrossHair, False)
  419.     value = restore.get('enableMagCrossHairClip', settings.enableMagCrossHairClip)
  420.     setMagnifierCrossHairClip(value, False)
  421.     if not enableCursor:
  422.         pass
  423.     orca_state.mouseEnhancementsEnabled = enableCrossHair
  424.  
  425.  
  426. def __setupZoomer(restore = None):
  427.     '''Creates a zoomer in the magnifier
  428.     Arguments:
  429.     - restore:  a dictionary of all of the settings which should be restored
  430.     '''
  431.     global _targetDisplayBounds, _sourceDisplayBounds, _fullScreenCapable, _sourceDisplayBounds, _targetDisplayBounds, _roiWidth, _roiHeight, _zoomer, _zoomerPBag, _pollMouseDisabled, _pollMouseDisabled
  432.     if not restore:
  433.         restore = { }
  434.     
  435.     _targetDisplayBounds = _magnifierPBag.getValue('target-display-bounds').value()
  436.     debug.println(debug.LEVEL_ALL, 'Magnifier target bounds preferences: (%d, %d), (%d, %d)' % (settings.magZoomerLeft, settings.magZoomerTop, settings.magZoomerRight, settings.magZoomerBottom))
  437.     debug.println(debug.LEVEL_ALL, 'Magnifier target bounds actual: (%d, %d), (%d, %d)' % (_targetDisplayBounds.x1, _targetDisplayBounds.y1, _targetDisplayBounds.x2, _targetDisplayBounds.y2))
  438.     _sourceDisplayBounds = _magnifierPBag.getValue('source-display-bounds').value()
  439.     debug.println(debug.LEVEL_ALL, 'Magnifier source bounds actual: (%d, %d), (%d, %d)' % (_sourceDisplayBounds.x1, _sourceDisplayBounds.y1, _sourceDisplayBounds.x2, _sourceDisplayBounds.y2))
  440.     if _sourceDisplayBounds.x2 - _sourceDisplayBounds.x1 == 0 or _sourceDisplayBounds.y2 - _sourceDisplayBounds.y1 == 0:
  441.         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')
  442.         _fullScreenCapable = False
  443.         __setupMagnifier(settings.MAG_ZOOMER_TYPE_CUSTOM, _targetDisplayBounds.x1 / 2, _targetDisplayBounds.y1, _targetDisplayBounds.x2, _targetDisplayBounds.y2)
  444.         _sourceDisplayBounds = _magnifierPBag.getValue('source-display-bounds').value()
  445.         _targetDisplayBounds = _magnifierPBag.getValue('target-display-bounds').value()
  446.     
  447.     viewportWidth = _targetDisplayBounds.x2 - _targetDisplayBounds.x1
  448.     viewportHeight = _targetDisplayBounds.y2 - _targetDisplayBounds.y1
  449.     debug.println(debug.LEVEL_ALL, 'Magnifier zoomer viewport desired: (0, 0), (%d, %d)' % (viewportWidth, viewportHeight))
  450.     debug.println(debug.LEVEL_ALL, 'Magnifier source width: %d (viewport can show %d)' % (_sourceDisplayBounds.x2 - _sourceDisplayBounds.x1, viewportWidth / settings.magZoomFactor))
  451.     debug.println(debug.LEVEL_ALL, 'Magnifier source height: %d (viewport can show %d)' % (_sourceDisplayBounds.y2 - _sourceDisplayBounds.y1, viewportHeight / settings.magZoomFactor))
  452.     _roiWidth = min(_sourceDisplayBounds.x2 - _sourceDisplayBounds.x1, viewportWidth / settings.magZoomFactor)
  453.     _roiHeight = min(_sourceDisplayBounds.y2 - _sourceDisplayBounds.y1, viewportHeight / settings.magZoomFactor)
  454.     debug.println(debug.LEVEL_ALL, 'Magnifier zoomer ROI size desired: width=%d, height=%d)' % (_roiWidth, _roiHeight))
  455.     _zoomer = _magnifier.createZoomRegion(settings.magZoomFactor, settings.magZoomFactor, GNOME.Magnifier.RectBounds(0, 0, _roiWidth, _roiHeight), GNOME.Magnifier.RectBounds(0, 0, 1, 1))
  456.     _zoomerPBag = _zoomer.getProperties()
  457.     bonobo.pbclient_set_boolean(_zoomerPBag, 'is-managed', True)
  458.     value = restore.get('magZoomFactor', settings.magZoomFactor)
  459.     setZoomerMagFactor(value, value, False)
  460.     value = restore.get('enableMagZoomerColorInversion', settings.enableMagZoomerColorInversion)
  461.     setZoomerColorInversion(value, False)
  462.     brightness = restore.get('magBrightnessLevel', settings.magBrightnessLevel)
  463.     r = brightness + restore.get('magBrightnessLevelRed', settings.magBrightnessLevelRed)
  464.     g = brightness + restore.get('magBrightnessLevelGreen', settings.magBrightnessLevelGreen)
  465.     b = brightness + restore.get('magBrightnessLevelBlue', settings.magBrightnessLevelBlue)
  466.     setZoomerBrightness(r, g, b, False)
  467.     contrast = restore.get('magContrastLevel', settings.magContrastLevel)
  468.     r = contrast + restore.get('magContrastLevelRed', settings.magContrastLevelRed)
  469.     g = contrast + restore.get('magContrastLevelGreen', settings.magContrastLevelGreen)
  470.     b = contrast + restore.get('magContrastLevelBlue', settings.magContrastLevelBlue)
  471.     setZoomerContrast(r, g, b, False)
  472.     value = restore.get('magColorFilteringMode', settings.magColorFilteringMode)
  473.     setZoomerColorFilter(value, False)
  474.     value = restore.get('magZoomerType', settings.magZoomerType)
  475.     if value == settings.MAG_ZOOMER_TYPE_FULL_SCREEN:
  476.         size = 0
  477.     else:
  478.         size = restore.get('magZoomerBorderSize', settings.magZoomerBorderSize)
  479.     color = restore.get('magZoomerBorderColor', settings.magZoomerBorderColor)
  480.     setZoomerObjectSize('border-size', size, False)
  481.     setZoomerObjectColor('border-color', color, False)
  482.     value = restore.get('magSmoothingMode', settings.magSmoothingMode)
  483.     setZoomerSmoothingType(value, False)
  484.     bounds = GNOME.Magnifier.RectBounds(0, 0, viewportWidth, viewportHeight)
  485.     _zoomer.moveResize(bounds)
  486.     
  487.     try:
  488.         bonobo.pbclient_set_boolean(_zoomerPBag, 'poll-mouse', False)
  489.         _pollMouseDisabled = True
  490.     except:
  491.         _pollMouseDisabled = False
  492.  
  493.     __updateROIDimensions()
  494.     _magnifier.addZoomRegion(_zoomer)
  495.  
  496.  
  497. def __updateROIDimensions():
  498.     '''Updates the ROI width, height, and maximum and minimum values.
  499.     '''
  500.     global _roiWidth, _roiHeight, _minROIX, _minROIY, _maxROIX, _maxROIY
  501.     viewport = _zoomerPBag.getValue('viewport').value()
  502.     debug.println(debug.LEVEL_ALL, 'Magnifier viewport actual: (%d, %d), (%d, %d)' % (viewport.x1, viewport.y1, viewport.x2, viewport.y2))
  503.     magx = _zoomerPBag.getValue('mag-factor-x').value()
  504.     magy = _zoomerPBag.getValue('mag-factor-y').value()
  505.     _roiWidth = min(_sourceDisplayBounds.x2 - _sourceDisplayBounds.x1, (viewport.x2 - viewport.x1) / magx)
  506.     _roiHeight = min(_sourceDisplayBounds.y2 - _sourceDisplayBounds.y1, (viewport.y2 - viewport.y1) / magy)
  507.     debug.println(debug.LEVEL_ALL, 'Magnifier zoomer ROI size actual: width=%d, height=%d)' % (_roiWidth, _roiHeight))
  508.     _minROIX = _sourceDisplayBounds.x1 + _roiWidth / 2
  509.     _minROIY = _sourceDisplayBounds.y1 + _roiHeight / 2
  510.     _maxROIX = _sourceDisplayBounds.x2 - _roiWidth / 2
  511.     _maxROIY = _sourceDisplayBounds.y2 - _roiHeight / 2
  512.     debug.println(debug.LEVEL_ALL, 'Magnifier ROI min/max center: (%d, %d), (%d, %d)' % (_minROIX, _minROIY, _maxROIX, _maxROIY))
  513.  
  514.  
  515. def applySettings():
  516.     '''Looks at the user settings and applies them to the magnifier.'''
  517.     global _mouseTracking, _controlTracking, _textTracking, _edgeMargin, _pointerFollowsZoomer, _pointerFollowsFocus
  518.     __setupMagnifier(settings.magZoomerType)
  519.     __setupZoomer()
  520.     _mouseTracking = settings.magMouseTrackingMode
  521.     _controlTracking = settings.magControlTrackingMode
  522.     _textTracking = settings.magTextTrackingMode
  523.     _edgeMargin = settings.magEdgeMargin
  524.     _pointerFollowsZoomer = settings.magPointerFollowsZoomer
  525.     _pointerFollowsFocus = settings.magPointerFollowsFocus
  526.  
  527.  
  528. def magnifyAccessible(event, obj, extents = None):
  529.     '''Sets the region of interest to the upper left of the given
  530.     accessible, if it implements the Component interface.  Otherwise,
  531.     does nothing.
  532.  
  533.     Arguments:
  534.     - event: the Event that caused this to be called
  535.     - obj: the accessible
  536.     '''
  537.     global _lastMouseEventWasRoute
  538.     if not _initialized:
  539.         return None
  540.     currentTime = time.time()
  541.     if currentTime - _lastMouseEventTime < 0.2:
  542.         return None
  543.     haveSomethingToMagnify = False
  544.     if extents:
  545.         (x, y, width, height) = extents
  546.         haveSomethingToMagnify = True
  547.     elif event and event.type.startswith('object:text-caret-moved'):
  548.         
  549.         try:
  550.             text = obj.queryText()
  551.             if text and text.caretOffset >= 0:
  552.                 offset = text.caretOffset
  553.                 if offset == text.characterCount:
  554.                     offset -= 1
  555.                 
  556.                 (x, y, width, height) = text.getCharacterExtents(offset, 0)
  557.                 haveSomethingToMagnify = width + height > 0
  558.         except:
  559.             _initialized
  560.             haveSomethingToMagnify = False
  561.  
  562.         if haveSomethingToMagnify:
  563.             if _textTracking == settings.MAG_TRACKING_MODE_CENTERED:
  564.                 __setROICenter(x, y)
  565.             elif _textTracking == settings.MAG_TRACKING_MODE_PUSH:
  566.                 __setROICursorPush(x, y, width, height, _edgeMargin)
  567.             
  568.             return None
  569.     
  570.     if haveSomethingToMagnify:
  571.         if _pointerFollowsFocus:
  572.             _lastMouseEventWasRoute = True
  573.             eventsynthesizer.generateMouseEvent(x, y + height - 1, 'abs')
  574.         
  575.         if _controlTracking == settings.MAG_TRACKING_MODE_CENTERED:
  576.             centerX = x + width / 2
  577.             centerY = y + height / 2
  578.             if width > _roiWidth:
  579.                 centerX = x
  580.             
  581.             if height > _roiHeight:
  582.                 centerY = y
  583.             
  584.             __setROICenter(centerX, centerY)
  585.         elif _controlTracking == settings.MAG_TRACKING_MODE_PUSH:
  586.             __setROICursorPush(x, y, width, height)
  587.         
  588.     
  589.  
  590.  
  591. def init():
  592.     '''Initializes the magnifier, bringing the magnifier up on the
  593.     display.
  594.  
  595.     Returns True if the initialization procedure was run or False if this
  596.     module has already been initialized.
  597.     '''
  598.     global _magnifier, _initialized, _initialized
  599.     if not _magnifierAvailable:
  600.         return False
  601.     if _initialized:
  602.         return False
  603.     _magnifier = bonobo.get_object('OAFIID:GNOME_Magnifier_Magnifier:0.9', 'GNOME/Magnifier/Magnifier')
  604.     
  605.     try:
  606.         _initialized = True
  607.         applySettings()
  608.         pyatspi.Registry.registerEventListener(__onMouseEvent, 'mouse:abs')
  609.         __setROICenter(0, 0)
  610.         return True
  611.     except:
  612.         _initialized
  613.         _magnifierAvailable
  614.         _initialized = False
  615.         _magnifier.dispose()
  616.         raise 
  617.  
  618.  
  619.  
  620. def shutdown():
  621.     '''Shuts down the magnifier module.
  622.     Returns True if the shutdown procedure was run or False if this
  623.     module has not been initialized.
  624.     '''
  625.     global _magnifier, _initialized
  626.     if not _magnifierAvailable:
  627.         return False
  628.     if not _initialized:
  629.         return False
  630.     pyatspi.Registry.deregisterEventListener(__onMouseEvent, 'mouse:abs')
  631.     
  632.     try:
  633.         hideSystemPointer(False)
  634.         _magnifier.clearAllZoomRegions()
  635.         _magnifier.dispose()
  636.     except:
  637.         _initialized
  638.         _magnifierAvailable
  639.         debug.printException(debug.LEVEL_WARNING)
  640.  
  641.     _magnifier = None
  642.     _initialized = False
  643.     return True
  644.  
  645.  
  646. def setupMagnifier(position, left = None, top = None, right = None, bottom = None, restore = None):
  647.     '''Creates the magnifier in the position specified.
  648.  
  649.     Arguments:
  650.     - position: the position/type of zoomer (full, left half, etc.)
  651.     - left:     the left edge of the zoomer (only applicable for custom)
  652.     - top:      the top edge of the zoomer (only applicable for custom)
  653.     - right:    the right edge of the zoomer (only applicable for custom)
  654.     - bottom:   the top edge of the zoomer (only applicable for custom)
  655.     - restore:  a dictionary of all of the settings that should be restored
  656.     '''
  657.     global _liveUpdatingMagnifier
  658.     if not _initialized:
  659.         return None
  660.     _liveUpdatingMagnifier = True
  661.     __setupMagnifier(position, left, top, right, bottom, restore)
  662.     __setupZoomer(restore)
  663.  
  664.  
  665. def setMagnifierCursor(enabled, customEnabled, size, updateScreen = True):
  666.     '''Sets the cursor.
  667.  
  668.     Arguments:
  669.     - enabled:        Whether or not the cursor should be enabled
  670.     - customEnabled:  Whether or not a custom size has been enabled
  671.     - size:           The size it should be set to
  672.     - updateScreen:   Whether or not to update the screen
  673.     '''
  674.     if not _initialized:
  675.         return None
  676.     
  677.     try:
  678.         mag = _zoomerPBag.getValue('mag-factor-x').value()
  679.     except:
  680.         _initialized
  681.         mag = settings.magZoomFactor
  682.  
  683.     if enabled:
  684.         scale = 1 * mag
  685.     else:
  686.         scale = 0
  687.     if not enabled and customEnabled:
  688.         size = 0
  689.     
  690.     bonobo.pbclient_set_float(_magnifierPBag, 'cursor-scale-factor', scale)
  691.     bonobo.pbclient_set_long(_magnifierPBag, 'cursor-size', size)
  692.     if updateScreen:
  693.         _zoomer.markDirty(_roi)
  694.     
  695.  
  696.  
  697. def setMagnifierCrossHair(enabled, updateScreen = True):
  698.     '''Sets the cross-hair.
  699.  
  700.     Arguments:
  701.     - enabled: Whether or not the cross-hair should be enabled
  702.     - updateScreen:  Whether or not to update the screen
  703.     '''
  704.     if not _initialized:
  705.         return None
  706.     size = 0
  707.     if enabled:
  708.         size = settings.magCrossHairSize
  709.     
  710.     bonobo.pbclient_set_long(_magnifierPBag, 'crosswire-size', size)
  711.     if updateScreen:
  712.         _zoomer.markDirty(_roi)
  713.     
  714.  
  715.  
  716. def setMagnifierCrossHairClip(enabled, updateScreen = True):
  717.     '''Sets the cross-hair clip.
  718.  
  719.     Arguments:
  720.     - enabled: Whether or not the cross-hair clip should be enabled
  721.     - updateScreen:   Whether or not to update the screen
  722.     '''
  723.     if not _initialized:
  724.         return None
  725.     bonobo.pbclient_set_boolean(_magnifierPBag, 'crosswire-clip', enabled)
  726.     if updateScreen:
  727.         _zoomer.markDirty(_roi)
  728.     
  729.  
  730.  
  731. def setZoomerColorInversion(enabled, updateScreen = True):
  732.     '''Sets the color inversion.
  733.  
  734.     Arguments:
  735.     - enabled: Whether or not color inversion should be enabled
  736.     - updateScreen:   Whether or not to update the screen
  737.     '''
  738.     if not _initialized:
  739.         return None
  740.     bonobo.pbclient_set_boolean(_zoomerPBag, 'inverse-video', enabled)
  741.     if updateScreen:
  742.         _zoomer.markDirty(_roi)
  743.     
  744.  
  745.  
  746. def setZoomerBrightness(red = 0, green = 0, blue = 0, updateScreen = True):
  747.     '''Increases/Decreases the brightness level by the specified
  748.     increments.  Increments are floats ranging from -1 (black/no
  749.     brightenss) to 1 (white/100% brightness).  0 means no change.
  750.  
  751.     Arguments:
  752.     - red:    The amount to alter the red brightness level
  753.     - green:  The amount to alter the green brightness level
  754.     - blue:   The amount to alter the blue brightness level
  755.     - updateScreen:   Whether or not to update the screen
  756.     '''
  757.     if not _initialized:
  758.         return None
  759.     _zoomer.setBrightness(red, green, blue)
  760.     if updateScreen:
  761.         _zoomer.markDirty(_roi)
  762.     
  763.  
  764.  
  765. def setZoomerContrast(red = 0, green = 0, blue = 0, updateScreen = True):
  766.     '''Increases/Decreases the contrast level by the specified
  767.     increments.  Increments are floats ranging from -1 (grey/no
  768.     contrast) to 1 (white/back/100% contrast).  0 means no change.
  769.  
  770.     Arguments:
  771.     - red:    The amount to alter the red contrast level
  772.     - green:  The amount to alter the green contrast level
  773.     - blue:   The amount to alter the blue contrast level
  774.     - updateScreen:  Whether or not to update the screen
  775.     '''
  776.     if not _initialized:
  777.         return None
  778.     _zoomer.setContrast(red, green, blue)
  779.     if updateScreen:
  780.         _zoomer.markDirty(_roi)
  781.     
  782.  
  783.  
  784. def setMagnifierObjectSize(magProperty, size, updateScreen = True):
  785.     '''Sets the specified magnifier property to the specified size.
  786.  
  787.     Arguments:
  788.     - magProperty:   The property to set (as a string)
  789.     - size:          The size to apply
  790.     - updateScreen:  Whether or not to update the screen
  791.     '''
  792.     if not _initialized:
  793.         return None
  794.     bonobo.pbclient_set_long(_magnifierPBag, magProperty, size)
  795.     if updateScreen:
  796.         _zoomer.markDirty(_roi)
  797.     
  798.  
  799.  
  800. def setZoomerObjectSize(magProperty, size, updateScreen = True):
  801.     '''Sets the specified zoomer property to the specified size.
  802.  
  803.     Arguments:
  804.     - magProperty:   The property to set (as a string)
  805.     - size:          The size to apply
  806.     - updateScreen:  Whether or not to update the screen
  807.     '''
  808.     if not _initialized:
  809.         return None
  810.     if updateScreen:
  811.         _zoomer.markDirty(_roi)
  812.     
  813.  
  814.  
  815. def setZoomerObjectColor(magProperty, colorSetting, updateScreen = True):
  816.     '''Sets the specified zoomer property to the specified color.
  817.  
  818.     Arguments:
  819.     - magProperty:  The property to set (as a string)
  820.     - colorSetting: The Orca color setting to apply
  821.     - updateScreen:  Whether or not to update the screen
  822.     '''
  823.     if not _initialized:
  824.         return None
  825.     colorPreference = gtk.gdk.color_parse(colorSetting)
  826.     colorPreference.red = colorPreference.red >> 8
  827.     colorPreference.blue = colorPreference.blue >> 8
  828.     colorPreference.green = colorPreference.green >> 8
  829.     colorString = '0x%02X%02X%02X' % (colorPreference.red, colorPreference.green, colorPreference.blue)
  830.     toChange = _zoomerPBag.getValue(magProperty)
  831.     _zoomerPBag.setValue(magProperty, ORBit.CORBA.Any(toChange.typecode(), long(colorString, 0)))
  832.     if updateScreen:
  833.         _zoomer.markDirty(_roi)
  834.     
  835.  
  836.  
  837. def setMagnifierObjectColor(magProperty, colorSetting, updateScreen = True):
  838.     '''Sets the specified magnifier property to the specified color.
  839.  
  840.     Arguments:
  841.     - magProperty:  The property to set (as a string)
  842.     - colorSetting: The Orca color setting to apply
  843.     - updateScreen:  Whether or not to update the screen
  844.     '''
  845.     if not _initialized:
  846.         return None
  847.     colorPreference = gtk.gdk.color_parse(colorSetting)
  848.     colorPreference.red = colorPreference.red >> 8
  849.     colorPreference.blue = colorPreference.blue >> 8
  850.     colorPreference.green = colorPreference.green >> 8
  851.     colorString = '0x%02X%02X%02X' % (colorPreference.red, colorPreference.green, colorPreference.blue)
  852.     toChange = _magnifierPBag.getValue(magProperty)
  853.     _magnifierPBag.setValue(magProperty, ORBit.CORBA.Any(toChange.typecode(), long(colorString, 0)))
  854.     if updateScreen:
  855.         _zoomer.markDirty(_roi)
  856.     
  857.  
  858.  
  859. def setZoomerMagFactor(x, y, updateScreen = True):
  860.     '''Sets the magnification level.
  861.  
  862.     Arguments:
  863.     - x: The horizontal magnification level
  864.     - y: The vertical magnification level
  865.     - updateScreen:  Whether or not to update the screen
  866.     '''
  867.     global _minROIX, _minROIY
  868.     if not _initialized:
  869.         return None
  870.     (oldX, oldY) = _zoomer.getMagFactor()
  871.     _zoomer.setMagFactor(x, y)
  872.     if updateScreen:
  873.         __updateROIDimensions()
  874.         if oldX > x and x < 1.5:
  875.             _minROIX = _sourceDisplayBounds.x1
  876.             _minROIY = _sourceDisplayBounds.y1
  877.             __setROI(GNOME.Magnifier.RectBounds(_minROIX, _minROIY, _minROIX + _roiWidth, _minROIY + _roiHeight))
  878.         else:
  879.             extents = orca_state.locusOfFocus.queryComponent().getExtents(0)
  880.             __setROICenter(extents.x, extents.y)
  881.     
  882.  
  883.  
  884. def setZoomerSmoothingType(smoothingType, updateScreen = True):
  885.     """Sets the zoomer's smoothing type.
  886.  
  887.     Arguments:
  888.     - smoothingType: The type of smoothing to use
  889.     - updateScreen:  Whether or not to update the screen
  890.     """
  891.     if not _initialized:
  892.         return None
  893.     if smoothingType == settings.MAG_SMOOTHING_MODE_BILINEAR:
  894.         string = 'bilinear'
  895.     else:
  896.         string = 'None'
  897.     
  898.     try:
  899.         bonobo.pbclient_set_string(_zoomerPBag, 'smoothing-type', string)
  900.     except:
  901.         pass
  902.  
  903.     if updateScreen:
  904.         _zoomer.markDirty(_roi)
  905.     
  906.  
  907.  
  908. def setZoomerColorFilter(colorFilter, updateScreen = True):
  909.     """Sets the zoomer's color filter.
  910.  
  911.     Arguments:
  912.     - colorFilter: The color filter to apply
  913.     - updateScreen:  Whether or not to update the screen
  914.     """
  915.     if not _initialized or not isFilteringCapable():
  916.         return None
  917.     if colorFilter == settings.MAG_COLOR_FILTERING_MODE_SATURATE_RED:
  918.         toApply = _zoomer.COLORBLIND_FILTER_T_SELECTIVE_SATURATE_RED
  919.     elif colorFilter == settings.MAG_COLOR_FILTERING_MODE_SATURATE_GREEN:
  920.         toApply = _zoomer.COLORBLIND_FILTER_T_SELECTIVE_SATURATE_GREEN
  921.     elif colorFilter == settings.MAG_COLOR_FILTERING_MODE_SATURATE_BLUE:
  922.         toApply = _zoomer.COLORBLIND_FILTER_T_SELECTIVE_SATURATE_BLUE
  923.     elif colorFilter == settings.MAG_COLOR_FILTERING_MODE_DESATURATE_RED:
  924.         toApply = _zoomer.COLORBLIND_FILTER_T_SELECTIVE_DESSATURATE_RED
  925.     elif colorFilter == settings.MAG_COLOR_FILTERING_MODE_DESATURATE_GREEN:
  926.         toApply = _zoomer.COLORBLIND_FILTER_T_SELECTIVE_DESSATURATE_GREEN
  927.     elif colorFilter == settings.MAG_COLOR_FILTERING_MODE_DESATURATE_BLUE:
  928.         toApply = _zoomer.COLORBLIND_FILTER_T_SELECTIVE_DESSATURATE_BLUE
  929.     elif colorFilter == settings.MAG_COLOR_FILTERING_MODE_NEGATIVE_HUE_SHIFT:
  930.         toApply = _zoomer.COLORBLIND_FILTER_T_HUE_SHIFT_NEGATIVE
  931.     elif colorFilter == settings.MAG_COLOR_FILTERING_MODE_POSITIVE_HUE_SHIFT:
  932.         toApply = _zoomer.COLORBLIND_FILTER_T_HUE_SHIFT_POSITIVE
  933.     else:
  934.         toApply = _zoomer.COLORBLIND_FILTER_T_NO_FILTER
  935.     colorFilter = _zoomerPBag.getValue('color-blind-filter')
  936.     _zoomerPBag.setValue('color-blind-filter', ORBit.CORBA.Any(colorFilter.typecode(), toApply))
  937.     if updateScreen:
  938.         _zoomer.markDirty(_roi)
  939.     
  940.  
  941.  
  942. def hideSystemPointer(hidePointer):
  943.     '''Hide or show the system pointer.
  944.  
  945.     Arguments:
  946.     -hidePointer: If True, hide the system pointer, otherwise show it.
  947.     '''
  948.     
  949.     try:
  950.         if hidePointer:
  951.             _magnifier.hideCursor()
  952.         else:
  953.             _magnifier.showCursor()
  954.     except:
  955.         debug.printException(debug.LEVEL_FINEST)
  956.  
  957.  
  958.  
  959. def isFullScreenCapable():
  960.     '''Returns True if we are capable of doing full screen (i.e. whether
  961.     composite is being used.
  962.     '''
  963.     
  964.     try:
  965.         capable = _magnifier.fullScreenCapable()
  966.     except:
  967.         capable = False
  968.  
  969.     return capable
  970.  
  971.  
  972. def isFilteringCapable():
  973.     """Returns True if we're able to take advantage of libcolorblind's color
  974.     filtering.
  975.     """
  976.     
  977.     try:
  978.         capable = _magnifier.supportColorblindFilters()
  979.     except:
  980.         capable = False
  981.  
  982.     return capable
  983.  
  984.  
  985. def updateMouseTracking(newMode):
  986.     '''Updates the mouse tracking mode.
  987.  
  988.     Arguments:
  989.     -newMode: The new mode to use.
  990.     '''
  991.     global _mouseTracking
  992.     _mouseTracking = newMode
  993.  
  994.  
  995. def updateControlTracking(newMode):
  996.     '''Updates the control tracking mode.
  997.  
  998.     Arguments:
  999.     -newMode: The new mode to use.
  1000.     '''
  1001.     global _controlTracking
  1002.     _controlTracking = newMode
  1003.  
  1004.  
  1005. def updateTextTracking(newMode):
  1006.     '''Updates the text tracking mode.
  1007.  
  1008.     Arguments:
  1009.     -newMode: The new mode to use.
  1010.     '''
  1011.     global _textTracking
  1012.     _textTracking = newMode
  1013.  
  1014.  
  1015. def updateEdgeMargin(amount):
  1016.     '''Updates the edge margin
  1017.  
  1018.     Arguments:
  1019.     -amount: The new margin to use, in pixels.
  1020.     '''
  1021.     global _edgeMargin
  1022.     _edgeMargin = amount
  1023.  
  1024.  
  1025. def updatePointerFollowsFocus(enabled):
  1026.     '''Updates the pointer follows focus setting.
  1027.  
  1028.     Arguments:
  1029.     -enabled: whether or not pointer follows focus should be enabled.
  1030.     '''
  1031.     global _pointerFollowsFocus
  1032.     _pointerFollowsFocus = enabled
  1033.  
  1034.  
  1035. def updatePointerFollowsZoomer(enabled):
  1036.     '''Updates the pointer follows zoomer setting.
  1037.  
  1038.     Arguments:
  1039.     -enabled: whether or not pointer follows zoomer should be enabled.
  1040.     '''
  1041.     global _pointerFollowsZoomer
  1042.     _pointerFollowsZoomer = enabled
  1043.  
  1044.  
  1045. def finishLiveUpdating():
  1046.     '''Restores things that were altered via a live update.'''
  1047.     global _liveUpdatingMagnifier, _mouseTracking, _controlTracking, _textTracking, _edgeMargin, _pointerFollowsFocus, _pointerFollowsZoomer
  1048.     _liveUpdatingMagnifier = False
  1049.     _mouseTracking = settings.magMouseTrackingMode
  1050.     _controlTracking = settings.magControlTrackingMode
  1051.     _textTracking = settings.magTextTrackingMode
  1052.     _edgeMargin = settings.magEdgeMargin
  1053.     _pointerFollowsFocus = settings.magPointerFollowsFocus
  1054.     _pointerFollowsZoomer = settings.magPointerFollowsZoomer
  1055.     if settings.enableMagnifier:
  1056.         setupMagnifier(settings.magZoomerType)
  1057.         init()
  1058.     else:
  1059.         shutdown()
  1060.  
  1061.  
  1062. def toggleColorEnhancements(script = None, inputEvent = None):
  1063.     '''Toggles the color enhancements on/off.'''
  1064.     if not _initialized:
  1065.         return None
  1066.     (levelX, levelY) = _zoomer.getMagFactor()
  1067.     normal = {
  1068.         'enableMagZoomerColorInversion': False,
  1069.         'magBrightnessLevelRed': 0,
  1070.         'magBrightnessLevelGreen': 0,
  1071.         'magBrightnessLevelBlue': 0,
  1072.         'magContrastLevelRed': 0,
  1073.         'magContrastLevelGreen': 0,
  1074.         'magContrastLevelBlue': 0,
  1075.         'magColorFilteringMode': settings.MAG_COLOR_FILTERING_MODE_NONE,
  1076.         'magSmoothingMode': settings.MAG_SMOOTHING_MODE_BILINEAR,
  1077.         'magZoomerBorderColor': '#000000',
  1078.         'magZoomFactor': levelX }
  1079.     if orca_state.colorEnhancementsEnabled:
  1080.         __setupZoomer(restore = normal)
  1081.         speech.speak(_('Color enhancements disabled.'))
  1082.     else:
  1083.         toRestore = {
  1084.             'magZoomFactor': levelX }
  1085.         __setupZoomer(restore = toRestore)
  1086.         speech.speak(_('Color enhancements enabled.'))
  1087.     orca_state.colorEnhancementsEnabled = not (orca_state.colorEnhancementsEnabled)
  1088.     return True
  1089.  
  1090.  
  1091. def toggleMouseEnhancements(script = None, inputEvent = None):
  1092.     '''Toggles the mouse enhancements on/off.'''
  1093.     if not _initialized:
  1094.         return None
  1095.     if orca_state.mouseEnhancementsEnabled:
  1096.         setMagnifierCrossHair(False, False)
  1097.         setMagnifierObjectColor('cursor-color', '#000000', False)
  1098.         setMagnifierCursor(True, False, 0)
  1099.         speech.speak(_('Mouse enhancements disabled.'))
  1100.     else:
  1101.         cursorEnable = settings.enableMagCursor
  1102.         crossHairEnable = settings.enableMagCrossHair
  1103.         if not cursorEnable or crossHairEnable:
  1104.             cursorEnable = True
  1105.             crossHairEnable = True
  1106.         
  1107.         setMagnifierCursor(cursorEnable, settings.enableMagCursorExplicitSize, settings.magCursorSize, False)
  1108.         setMagnifierObjectColor('cursor-color', settings.magCursorColor, False)
  1109.         setMagnifierObjectColor('crosswire-color', settings.magCrossHairColor, False)
  1110.         setMagnifierCrossHairClip(settings.enableMagCrossHairClip, False)
  1111.         setMagnifierCrossHair(crossHairEnable)
  1112.         speech.speak(_('Mouse enhancements enabled.'))
  1113.     orca_state.mouseEnhancementsEnabled = not (orca_state.mouseEnhancementsEnabled)
  1114.     return True
  1115.  
  1116.  
  1117. def increaseMagnification(script = None, inputEvent = None):
  1118.     '''Increases the magnification level.'''
  1119.     if not _initialized:
  1120.         return None
  1121.     (levelX, levelY) = _zoomer.getMagFactor()
  1122.     if levelX <= levelX:
  1123.         pass
  1124.     elif levelX < 4:
  1125.         increment = 0.25
  1126.     elif levelX <= levelX:
  1127.         pass
  1128.     elif levelX < 7:
  1129.         increment = 0.5
  1130.     else:
  1131.         increment = 1
  1132.     newLevel = levelX + increment
  1133.     if newLevel <= 16:
  1134.         setZoomerMagFactor(newLevel, newLevel)
  1135.         speech.speak(str(newLevel))
  1136.     
  1137.     return True
  1138.  
  1139.  
  1140. def decreaseMagnification(script = None, inputEvent = None):
  1141.     '''Decreases the magnification level.'''
  1142.     if not _initialized:
  1143.         return None
  1144.     (levelX, levelY) = _zoomer.getMagFactor()
  1145.     if levelX <= levelX:
  1146.         pass
  1147.     elif levelX < 4:
  1148.         increment = 0.25
  1149.     elif levelX <= levelX:
  1150.         pass
  1151.     elif levelX < 7:
  1152.         increment = 0.5
  1153.     else:
  1154.         increment = 1
  1155.     newLevel = levelX - increment
  1156.     if newLevel >= 1:
  1157.         setZoomerMagFactor(newLevel, newLevel)
  1158.         speech.speak(str(newLevel))
  1159.     
  1160.     return True
  1161.  
  1162.  
  1163. def toggleMagnifier(script = None, inputEvent = None):
  1164.     '''Toggles the magnifier.'''
  1165.     if not _initialized:
  1166.         init()
  1167.         speech.speak(_('Magnifier enabled.'))
  1168.     else:
  1169.         shutdown()
  1170.         speech.speak(_('Magnifier disabled.'))
  1171.     return True
  1172.  
  1173.  
  1174. def cycleZoomerType(script = None, inputEvent = None):
  1175.     '''Allows the user to cycle through the available zoomer types.'''
  1176.     if not _initialized:
  1177.         return None
  1178.     orca_state.zoomerType += 1
  1179.     toRestore = { }
  1180.     (levelX, levelY) = _zoomer.getMagFactor()
  1181.     if levelX != settings.magZoomFactor:
  1182.         toRestore['magZoomFactor'] = levelX
  1183.     
  1184.     if not orca_state.colorEnhancementsEnabled:
  1185.         toRestore.update({
  1186.             'enableMagZoomerColorInversion': False,
  1187.             'magBrightnessLevelRed': 0,
  1188.             'magBrightnessLevelGreen': 0,
  1189.             'magBrightnessLevelBlue': 0,
  1190.             'magContrastLevelRed': 0,
  1191.             'magContrastLevelGreen': 0,
  1192.             'magContrastLevelBlue': 0,
  1193.             'magColorFilteringMode': settings.MAG_COLOR_FILTERING_MODE_NONE,
  1194.             'magSmoothingMode': settings.MAG_SMOOTHING_MODE_BILINEAR,
  1195.             'magZoomerBorderColor': '#000000' })
  1196.     
  1197.     setupMagnifier(orca_state.zoomerType, restore = toRestore)
  1198.     if not orca_state.mouseEnhancementsEnabled:
  1199.         setMagnifierCrossHair(False)
  1200.         setMagnifierObjectColor('cursor-color', settings.magCursorColor, False)
  1201.         setMagnifierCursor(False, False, 0)
  1202.     
  1203.     if orca_state.zoomerType == settings.MAG_ZOOMER_TYPE_FULL_SCREEN:
  1204.         if _fullScreenCapable:
  1205.             zoomerType = _('Full Screen')
  1206.         else:
  1207.             zoomerType = _('Full Screen mode unavailable')
  1208.     elif orca_state.zoomerType == settings.MAG_ZOOMER_TYPE_TOP_HALF:
  1209.         zoomerType = _('Top Half')
  1210.     elif orca_state.zoomerType == settings.MAG_ZOOMER_TYPE_BOTTOM_HALF:
  1211.         zoomerType = _('Bottom Half')
  1212.     elif orca_state.zoomerType == settings.MAG_ZOOMER_TYPE_LEFT_HALF:
  1213.         zoomerType = _('Left Half')
  1214.     elif orca_state.zoomerType == settings.MAG_ZOOMER_TYPE_RIGHT_HALF:
  1215.         zoomerType = _('Right Half')
  1216.     elif orca_state.zoomerType == settings.MAG_ZOOMER_TYPE_CUSTOM:
  1217.         zoomerType = _('Custom')
  1218.     else:
  1219.         zoomerType = ''
  1220.     speech.speak(zoomerType)
  1221.     return True
  1222.  
  1223.