GNOME Bugzilla – Bug 395548
Refactor calls to util.py as calls from delegates in default.py
Last modified: 2007-07-30 09:26:37 UTC
util.py contains a number of methods that are used by default.py. We sometimes run into occasions where we'd like to extend/override the behavior of these methods in subscripts. A possible way to support the extend/override desire is to provide "one line" delegate methods in default.py:Script that call their associated methods in util.py. Alternatively, we may just consider sucking some util.py methods into the default.py:Script class, removing them from util.py altogether.
Will and I just talked about this. The new plan (once the Orca code is branched on Monday), is to move all the methods in util.py directly over to default.py, fixup where they are being called and (eventually) remove util.py. I plan to do this one method at a time (to reduce the possibility of change conflicts) and to apply numerous patches to this bug report, so you can easily see exactly what I've changed. Routines are: def isSameObject(obj1, obj2): def appendString(text, newText, delimiter=" "): def __hasLabelForRelation(label): def __isLabeling(label, object): def getUnicodeCurrencySymbols(): def getDisplayedLabel(object): def __getDisplayedTextInComboBox(combo): def getDisplayedText(obj): def getRealActiveDescendant(obj): def findFocusedObject(root): def getClickCount(lastInputEvent, inputEvent): def isDesiredFocusedItem(obj, rolesList): def speakMisspeltWord(allTokens, badWord): def textLines(obj): def _addRepeatSegment(segment, line, respectPunctuation=True): def adjustForRepeats(line): def adjustForPronunciation(line): def getLinkIndex(obj, characterIndex): def isWordDelimiter(character): def getFrame(obj): def getTopLevel(obj): def getTopLevelName(obj): def getTextLineAtCaret(obj): def getNodeLevel(obj): def getAcceleratorAndShortcut(obj): def getKnownApplications(): def getObjects(root, onlyShowing=True): def findByRole(root, role, onlyShowing=True): def findUnrelatedLabels(root): def phoneticSpellCurrentItem(string): def printAncestry(child): def printHierarchy(root, ooi, indent="", onlyShowing=True, omitManaged=True): def printApps(): def printActiveApp(): def isInActiveApp(obj): def findActiveWindow(): def saveOldAppSettings(): def restoreOldAppSettings(prefsDict): def drawOutline(x, y, width, height, erasePrevious=True): def outlineAccessible(accessible, erasePrevious=True): def isTextSelected(obj, startOffset, endOffset): def speakTextSelectionState(obj, startOffset, endOffset): def traceit(frame, event, arg): More next week.
Created attachment 83978 [details] [review] Patch for "def traceit(frame, event, arg):" Moved: def traceit(frame, event, arg): (in this case into debug.py).
Created attachment 84012 [details] [review] Patch for moving "def speakTextSelectionState(obj, startOffset, endOffset):"
Created attachment 84014 [details] [review] Patch for moving "def isTextSelected(obj, startOffset, endOffset):"
Created attachment 84018 [details] [review] Moving two more routines over. def drawOutline(x, y, width, height, erasePrevious=True): def outlineAccessible(accessible, erasePrevious=True):
Created attachment 84025 [details] [review] Moving saveOldAppSettings() and restoreOldAppSettings(prefsDict)
Created attachment 84027 [details] [review] Moving findActiveWindow()
Created attachment 84030 [details] [review] Moving isInActiveApp(obj)
Created attachment 84079 [details] [review] Moving four more routines over def printAncestry(child): def printHierarchy(root, ooi, indent="", onlyShowing=True, omitManaged=True): def printApps(): def printActiveApp():
Created attachment 84080 [details] [review] Moving phoneticSpellCurrentItem(string)
Created attachment 84081 [details] [review] Moving findUnrelatedLabels(root)
Created attachment 84083 [details] [review] Moving findByRole(root, role, onlyShowing=True)
Created attachment 84090 [details] [review] Moving getKnownApplications()
Created attachment 84095 [details] [review] Moving getAcceleratorAndShortcut(obj)
Created attachment 84097 [details] [review] Moving getNodeLevel(obj)
Created attachment 84106 [details] [review] Moving three more routines over. def __getDisplayedTextInComboBox(combo): def getDisplayedText(obj): def getTextLineAtCaret(obj):
Created attachment 84107 [details] [review] Moving three more routines over. def getFrame(obj): def getTopLevel(obj): def getTopLevelName(obj):
Created attachment 84111 [details] [review] Moving three more routines over. def adjustForPronunciation(line): def getLinkIndex(obj, characterIndex): def isWordDelimiter(character):
Created attachment 84112 [details] [review] Moving three more routines over. def textLines(obj): def _addRepeatSegment(segment, line, respectPunctuation=True): def adjustForRepeats(line):
Created attachment 84116 [details] [review] Moving five more routines over. def __hasLabelForRelation(label): def __isLabeling(label, object): def getDisplayedLabel(object): def isDesiredFocusedItem(obj, rolesList): def speakMisspeltWord(allTokens, badWord):
Created attachment 84117 [details] [review] Moving two more routines over. def findFocusedObject(root): def getClickCount(lastInputEvent, inputEvent):
Created attachment 84119 [details] [review] Moving three more routine over. def isSameObject(obj1, obj2): def appendString(text, newText, delimiter=" "): def getUnicodeCurrencySymbols():
Created attachment 84123 [details] [review] Patch to remove all occurances of "import util" and the util.py file. Plus a few cleanups. I think the refactoring is now complete. The slightly worrying part is that there are now a lot of occurances of orca_state.activeScript.<whatever> in files like orca.py, flat_review.py and where_am_I.py. This suggests that we possibly need a bit more refactoring. I've been testing this on Ubuntu Edgy. I'm getting a few COMM_FAILURES, but it still seems to braille/speak okay. I'm looking for others to checkout this version, take it for a spin and provide feedback. I'll put this bug report into the "[pending]" state, but I suspect there will still need to be a few final touchups. It was a large set of changes.
Mike and Joanie gave me a heads-up on a few tracebacks from running latest Orca. I'll work on a patch after lunch and check it in.
Created attachment 84196 [details] [review] Various fixups All changes were adjustments from "self.<whatever>" to "self._script.<whatever>" in various files because I didn't initially notice that those were changes inside subclasses of BrailleGenerator and SpeechGenerator rather than Script. Mike, Joanie, could you give it another try please?
Seems to solve the problem Rich. Thanks!!!
Thanks Rich, this seems much better. I'm still testing other apps now though to see if I can find anything else for you.
Created attachment 84325 [details] debug.out from OOo 2.2 open dialog, files table I may have found another issue. Take a look at the attached beginning with line 1498.
+ Trace 117293
if self.isDesiredFocusedItem(obj, rolesList):
Created attachment 84329 [details] [review] Patch to fixup the problems in StarOffice.py Thanks Joanie. I've just committed the attached patch which should fix that problem (and a similar one in the locateInputLine() routine).
Yup, much better. Thanks!! Just discovered something interesting as a result of this which may prove useful -- or not. :-) Regardless, as soon as I track down the relevant bug, I'll share the info. :-)
Created attachment 84405 [details] debug.out from OOo 2.2 Calc Rich, this is from navigating within a Calc document. Thanks!!!
Created attachment 84407 [details] [review] Patch to StarOffice.py script. Thanks Joanie. I've just had a nap so I'm a little more awake then I was on Friday. Hopefully this is the correct fix.
> Hopefully this is the correct fix. Seems to be. Thanks much!!
Created attachment 84511 [details] [review] Patch to fixup problems in self_voicing.py reported by hermann.
Created attachment 84712 [details] acroread debug.out [...]
+ Trace 119111
if self.isDesiredFocusedItem(obj, rolesList): NameError: global name 'self' is not defined
Looks like there are several global methods that need to be moved into the acroread.Script class.
Was wondering about that myself, actually....
Created attachment 84717 [details] [review] patch to solve the immediate problem This patch makes the errors go away so that Orca provides access to PDFs in acroread. Will, what about checking this in and then having a conversation about what needs to be moved where?
Yeah, that patch should work. Joanie, could you commit it please (I need to go into the office for a meeting) and announce it on the orca-list. Thanks!
Hi Rich. Will and I discussed this via IM and he called my patch "ugly". <grins at Will> As you (and he) pointed out, we need to move the global methods into the acroread.Script class. I'm nearly finished with the moving. After I do some testing, I'm going to open a new bug for the acroread refactoring, post a patch, and -- assuming *it's* not ugly <grins> -- check that in instead. Then I'll announce it on the list.
Just opened bug #419006 for the acroread.py refactoring and posted a patch.
Closing as FIXED. If any problems are found, please reopen.