# Orca # # Copyright 2006-2008 Sun Microsystems Inc. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the # Free Software Foundation, Inc., Franklin Street, Fifth Floor, # Boston MA 02110-1301 USA. """Provides support for a flat review find.""" __id__ = "$Id$" __version__ = "$Revision$" __date__ = "$Date$" __copyright__ = "Copyright (c) 2005-2008 Sun Microsystems Inc." __license__ = "LGPL" import copy import re from . import debug from . import flat_review from . import messages from . import orca_state class SearchQuery: """Represents a search that the user wants to perform.""" def __init__(self): """Creates a new SearchQuery. A searchQuery has the following properties: searchString - the string to find searchBackwards - if true, search upward for matches caseSensitive - if true, case counts matchEntireWord - if true, only match on the entire string startAtTop - if true, begin the search from the top of the window, rather than at the current location windowWrap - if true, when the top/bottom edge of the window is reached wrap to the bottom/top and continue searching """ self.searchString = "" self.searchBackwards = False self.caseSensitive = False self.matchEntireWord = False self.windowWrap = False self.startAtTop = False self.debugLevel = debug.LEVEL_FINEST def debugContext(self, context, string): """Prints out the context and the string to find to debug.out""" debug.println(self.debugLevel, \ "------------------------------------------------------------") debug.println(self.debugLevel, \ "findQuery: %s line=%d zone=%d word=%d char=%d" \ % (string, context.lineIndex, context.zoneIndex, \ context.wordIndex, context.charIndex)) debug.println(self.debugLevel, \ "Number of lines: %d" % len(context.lines)) debug.println(self.debugLevel, \ "Number of zones in current line: %d" % \ len(context.lines[context.lineIndex].zones)) debug.println(self.debugLevel, \ "Number of words in current zone: %d" % \ len(context.lines[context.lineIndex].zones[context.zoneIndex].words)) debug.println(self.debugLevel, \ "==========================================================\n\n") def dumpContext(self, context): """Debug utility which prints out the context.""" print("DUMP") for i in range(0, len(context.lines)): print(" Line %d" % i) for j in range(0, len(context.lines[i].zones)): print(" Zone: %d" % j) for k in range(0, len(context.lines[i].zones[j].words)): print(" Word %d = `%s` len(word): %d" % \ (k, context.lines[i].zones[j].words[k].string, \ len(context.lines[i].zones[j].words[k].string))) def findQuery(self, context, justEnteredFlatReview): """Performs a search on the string specified in searchQuery. Arguments: - context: The context from active script - justEnteredFlatReview: If true, we began the search in focus tracking mode. Returns: - The context of the match, if found """ # Get the starting context so that we can restore it at the end. # originalLineIndex = context.lineIndex originalZoneIndex = context.zoneIndex originalWordIndex = context.wordIndex originalCharIndex = context.charIndex debug.println(self.debugLevel, \ "findQuery: original context line=%d zone=%d word=%d char=%d" \ % (originalLineIndex, originalZoneIndex, \ originalWordIndex, originalCharIndex)) # self.dumpContext(context) flags = re.LOCALE if not self.caseSensitive: flags = flags | re.IGNORECASE if self.matchEntireWord: regexp = "\\b" + self.searchString + "\\b" else: regexp = self.searchString pattern = re.compile(regexp, flags) debug.println(self.debugLevel, \ "findQuery: startAtTop: %d regexp: `%s`" \ % (self.startAtTop, regexp)) if self.startAtTop: context.goBegin(flat_review.Context.WINDOW) self.debugContext(context, "go begin") location = None found = False wrappedYet = False doneWithLine = False while not found: # Check the current line for the string. # [currentLine, x, y, width, height] = \ context.getCurrent(flat_review.Context.LINE) debug.println(self.debugLevel, \ "findQuery: current line=`%s` x=%d y=%d width=%d height=%d" \ % (currentLine, x, y, width, height)) if re.search(pattern, currentLine) and not doneWithLine: # It's on this line. Check the current zone for the string. # while not found: [currentZone, x, y, width, height] = \ context.getCurrent(flat_review.Context.ZONE) debug.println(self.debugLevel, \ "findQuery: current zone=`%s` x=%d y=%d " % \ (currentZone, x, y)) debug.println(self.debugLevel, \ "width=%d height=%d" % (width, height)) if re.search(pattern, currentZone): # It's in this zone at least once. # theZone = context.lines[context.lineIndex] \ .zones[context.zoneIndex] startedInThisZone = \ (originalLineIndex == context.lineIndex) and \ (originalZoneIndex == context.zoneIndex) try: theZone.accessible.queryText() except: pass else: # Make a list of the character offsets for the # matches in this zone. # allMatches = re.finditer(pattern, currentZone) offsets = [] for m in allMatches: offsets.append(m.start(0)) if self.searchBackwards: offsets.reverse() i = 0 while not found and (i < len(offsets)): [nextInstance, offset] = \ theZone.getWordAtOffset(offsets[i]) if nextInstance: offsetDiff = \ nextInstance.index - context.wordIndex if self.searchBackwards \ and (offsetDiff < 0) \ or (not self.searchBackwards \ and offsetDiff > 0): context.wordIndex = nextInstance.index context.charIndex = 0 found = True elif not offsetDiff and \ (not startedInThisZone or \ justEnteredFlatReview): # We landed on a match by happenstance. # This can occur when the nextInstance # is the first thing we come across. # found = True else: i += 1 else: break if not found: # Locate the next zone to try again. # if self.searchBackwards: moved = context.goPrevious( \ flat_review.Context.ZONE, \ flat_review.Context.WRAP_LINE) self.debugContext(context, "[1] go previous") context.goEnd(flat_review.Context.ZONE) self.debugContext(context, "[1] go end") else: moved = context.goNext( \ flat_review.Context.ZONE, \ flat_review.Context.WRAP_LINE) self.debugContext(context, "[1] go next") if not moved: doneWithLine = True break else: # Locate the next line to try again. # if self.searchBackwards: moved = context.goPrevious(flat_review.Context.LINE, \ flat_review.Context.WRAP_LINE) self.debugContext(context, "[2] go previous") else: moved = context.goNext(flat_review.Context.LINE, \ flat_review.Context.WRAP_LINE) self.debugContext(context, "[2] go next") if moved: if self.searchBackwards: moved = context.goEnd(flat_review.Context.LINE) self.debugContext(context, "[2] go end") else: # Then we're at the screen's edge. # if self.windowWrap and not wrappedYet: script = orca_state.activeScript doneWithLine = False wrappedYet = True if self.searchBackwards: script.presentMessage(messages.WRAPPING_TO_BOTTOM) moved = context.goPrevious( \ flat_review.Context.LINE, \ flat_review.Context.WRAP_ALL) self.debugContext(context, "[3] go previous") else: script.presentMessage(messages.WRAPPING_TO_TOP) moved = context.goNext( \ flat_review.Context.LINE, \ flat_review.Context.WRAP_ALL) self.debugContext(context, "[3] go next") if not moved: debug.println(self.debugLevel, \ "findQuery: cannot wrap") break else: break if found: location = copy.copy(context) self.debugContext(context, "before setting original") context.setCurrent(originalLineIndex, originalZoneIndex, \ originalWordIndex, originalCharIndex) self.debugContext(context, "after setting original") if location: debug.println(self.debugLevel, \ "findQuery: returning line=%d zone=%d word=%d char=%d" \ % (location.lineIndex, location.zoneIndex, \ location.wordIndex, location.charIndex)) return location def getLastQuery(): """Grabs the last search query performed from orca_state. Returns: - A copy of the last search query, if it exists """ lastQuery = copy.copy(orca_state.searchQuery) return lastQuery
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
__pycache__ | Folder | 0755 |
|
|
backends | Folder | 0755 |
|
|
scripts | Folder | 0755 |
|
|
__init__.py | File | 115 B | 0644 |
|
acss.py | File | 3.49 KB | 0644 |
|
bookmarks.py | File | 8.37 KB | 0644 |
|
braille.py | File | 59.87 KB | 0644 |
|
braille_generator.py | File | 20.5 KB | 0644 |
|
braille_rolenames.py | File | 10.33 KB | 0644 |
|
brlmon.py | File | 6.45 KB | 0644 |
|
brltablenames.py | File | 7.15 KB | 0644 |
|
caret_navigation.py | File | 13.67 KB | 0644 |
|
chat.py | File | 33.63 KB | 0644 |
|
chnames.py | File | 23.03 KB | 0644 |
|
cmdnames.py | File | 55.65 KB | 0644 |
|
colornames.py | File | 38.13 KB | 0644 |
|
common_keyboardmap.py | File | 6.64 KB | 0644 |
|
debug.py | File | 17.16 KB | 0644 |
|
desktop_keyboardmap.py | File | 4.62 KB | 0644 |
|
event_manager.py | File | 31.81 KB | 0644 |
|
eventsynthesizer.py | File | 17.82 KB | 0644 |
|
find.py | File | 12.77 KB | 0644 |
|
flat_review.py | File | 51.84 KB | 0644 |
|
formatting.py | File | 53.94 KB | 0644 |
|
generator.py | File | 59.09 KB | 0644 |
|
guilabels.py | File | 45.78 KB | 0644 |
|
input_event.py | File | 36.41 KB | 0644 |
|
keybindings.py | File | 16.39 KB | 0644 |
|
keynames.py | File | 9.71 KB | 0644 |
|
label_inference.py | File | 19.38 KB | 0644 |
|
laptop_keyboardmap.py | File | 4.61 KB | 0644 |
|
liveregions.py | File | 21.55 KB | 0644 |
|
logger.py | File | 1.97 KB | 0644 |
|
mathsymbols.py | File | 88.14 KB | 0644 |
|
messages.py | File | 140.32 KB | 0644 |
|
mouse_review.py | File | 18.91 KB | 0644 |
|
notification_messages.py | File | 6.18 KB | 0644 |
|
object_properties.py | File | 32.74 KB | 0644 |
|
orca.py | File | 25 KB | 0644 |
|
orca_gtkbuilder.py | File | 5.35 KB | 0644 |
|
orca_gui_commandlist.py | File | 4.19 KB | 0644 |
|
orca_gui_find.py | File | 8.12 KB | 0644 |
|
orca_gui_navlist.py | File | 6.66 KB | 0644 |
|
orca_gui_prefs.py | File | 139.07 KB | 0644 |
|
orca_gui_profile.py | File | 4.06 KB | 0644 |
|
orca_i18n.py | File | 3.18 KB | 0644 |
|
orca_platform.py | File | 1.41 KB | 0644 |
|
orca_state.py | File | 2.1 KB | 0644 |
|
phonnames.py | File | 2.76 KB | 0644 |
|
pronunciation_dict.py | File | 2.61 KB | 0644 |
|
punctuation_settings.py | File | 13.64 KB | 0644 |
|
script.py | File | 19.04 KB | 0644 |
|
script_manager.py | File | 13.31 KB | 0644 |
|
script_utilities.py | File | 183.59 KB | 0644 |
|
settings.py | File | 12.82 KB | 0644 |
|
settings_manager.py | File | 20.73 KB | 0644 |
|
sound.py | File | 5.17 KB | 0644 |
|
sound_generator.py | File | 11.99 KB | 0644 |
|
speech.py | File | 11.4 KB | 0644 |
|
speech_generator.py | File | 108.24 KB | 0644 |
|
speechdispatcherfactory.py | File | 24.54 KB | 0644 |
|
speechserver.py | File | 7.41 KB | 0644 |
|
spellcheck.py | File | 10.07 KB | 0644 |
|
structural_navigation.py | File | 122.53 KB | 0644 |
|
text_attribute_names.py | File | 28.62 KB | 0644 |
|
tutorialgenerator.py | File | 30.41 KB | 0644 |
|