Skip to content

Commit

Permalink
Object's bootom/right edges and relative parent's bottom/right edtes
Browse files Browse the repository at this point in the history
DTK now allows users the ability to obtain the distance between an object's bottom edge and the bottom edge of the relative parent. Likewise, users can obtain the distance between the object's right edge and the relative parent's right edge.
Cleaned up some relative parent code and added a safety net that sets relative parent to the desktop object when the focused object and relative parent are the same, or when the relative parent is not a direct ancestor of the focused object.
  • Loading branch information
ajborka committed Aug 20, 2019
1 parent ca90fda commit f8cda20
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 18 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ The following gestures are available when DTK is enabled.
* Control+home - Move to top-most parent.
* A - In web content, speak HTML attributes. Press twice quickly to copy to the clipboard.
* B - Speak the position of the object’s bottom edge. Press twice quickly to copy to the clipboard.
* shift+b - Speak the distance between the object's bottom edge and the relative parent's bottom edge. Press twice quickly to copy to the clipboard.
* C - Speak the number of children contained inside the object. Press twice quickly to copy to the clipboard.
* Control+d - Enable or disable detailed messages.
* F - In web content, speaks the object’s font and formatting information. Press twice quickly to copy to the clipboard.
Expand All @@ -20,20 +21,22 @@ The following gestures are available when DTK is enabled.
* control+p - Set the relative parent for obtaining size/location of objects.
* p - Speak the relative parent's name. Press twice quickly to copy to the clipboard.
* R - Speak the position of the object’s right edge. Press twice quickly to copy to the clipboard.
* shift+r - Speaks the distance between the object's right edge and the relative parent's right edge. Press twice quickly to copy to the clipboard.
* S - Speak the number of siblings relative to the object. Press twice quickly to copy to the clipboard.
* T - Speak the position of the object’s top edge. Press twice quickly to copy to the clipboard.
* V - Speak Developer toolkit version. Press twice quickly to copy to the clipboard.
* W - Speak the object’s width. Press twice quickly to copy to the clipboard.

## Notes

* Edge has not been completely tested. Therefore, anything reported by the add-on should be considered with care.
* To avoid names of web elements appearing as "None", always give elements a title attribute.
* When using the relative parent feature, DTK will set the relative parent to the desktop under the following conditions.
* The focused object and the relative parent are the same.
* The relative parent is not a direct ancestor of the focused object.
* Edge is not supported.
* Font information is only available in web content. This should be fixed in a future version.

## Known issues

* DTK only honors configuration profiles. It will not automatically disable itself when switching windows.
* Users are not automatically notified of the enabled/disabled state of the add-on's features when switching between configuration profiles.
* The font information when pressing F is messy, and will get fixed in a future version.

Expand All @@ -42,6 +45,8 @@ The following gestures are available when DTK is enabled.

* Developers now have the ability to focus on smaller areas of their user interfaces by pressing control+p to set a relative parent. Use a relative parent as a reference point when obtaining size and location information. To use this feature, enable DTK features, navigate to the object to use as a relative parent, then press control+p. Then, return to your work as usual.
* Press the letter p while working in DTK to obtain the relative parent's name. Press twice quickly to copy to the clipboard.
* Use shift+b to obtain the distance between the focused object's bottom edge and the relative paren'ts bottom edge. DTK features must be enable to use this feature.
* Use shift+r to obtain the distance between the focused object's right edge and the relative paren'ts right edge. DTK features must be enable to use this feature.
* DTK now gracefully handles configuration profile switches.
* Removed '-preview' from the version number to avoid version number problems with add-on updater.

Expand Down
22 changes: 22 additions & 0 deletions addon/globalPlugins/developerToolkit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,26 @@ def script_SpeakObjectRightPosition(self, gesture):
elif getLastScriptRepeatCount() >= 1:
shared.copyToClipboard(message)

@script(description = _("Speaks the object's right edge location relative to the relative parent's right edge."))
def script_SpeakObjectRightPositionToRelativeParentRightPosition(self, gesture):
focus = api.getFocusObject()
message = shared.SpeakSizeAndLocationHelper("right-right", focus, self.relativeParent)
if getLastScriptRepeatCount() == 0:
ui.message(message)
elif getLastScriptRepeatCount() >= 1:
shared.copyToClipboard(message)

@script(description = _("Speaks the object's bottom edge relative to the relative parent's bottom edge."))
def script_SpeakObjectBottomPositionToRelativeParentBottomPosition(self, gesture):
focus = api.getFocusObject()
message = shared.SpeakSizeAndLocationHelper("bottom-bottom", focus, self.relativeParent)
if getLastScriptRepeatCount() == 0:
ui.message(message)
elif getLastScriptRepeatCount() >= 1:
shared.copyToClipboard(message)



@script(_("Speaks the position of the object's top edge. Press twice quickly to copy to clipboard."))
def script_SpeakObjectTopPosition(self, gesture):
focus = api.getFocusObject()
Expand Down Expand Up @@ -297,6 +317,7 @@ def script_SpeakRelativeParentName(self, gesture):
"kb:control+home": "MoveToTopParent",
"kb:a": "SpeakHtmlAttributes",
"kb:b": "SpeakObjectBottomPosition",
"kb:shift+b": "SpeakObjectBottomPositionToRelativeParentBottomPosition",
"kb:c": "SpeakChildCount",
"kb:control+d": "ToggleDetailedMessages",
"kb:f": "GetFontInfo",
Expand All @@ -306,6 +327,7 @@ def script_SpeakRelativeParentName(self, gesture):
"kb:control+p": "SetRelativeParent",
"kb:p": "SpeakRelativeParentName",
"kb:r": "SpeakObjectRightPosition",
"kb:shift+r": "SpeakObjectRightPositionToRelativeParentRightPosition",
"kb:s": "SpeakSiblingCount",
"kb:t": "SpeakObjectTopPosition",
"kb:v": "SpeakVersion",
Expand Down
37 changes: 22 additions & 15 deletions addon/globalPlugins/developerToolkit/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import config
from controlTypes import roleLabels
from controlTypes import stateLabels
import globalPluginHandler
import ui
from virtualBuffers import VirtualBuffer

Expand All @@ -18,21 +19,30 @@
isFocusAncestor = lambda a: a in api.getFocusAncestors()

def getSizeAndPosition(descendant, ancestor):
# if descendant and not isFocusAncestor(ancestor) and hasLocation(descendant):
# return {
# 'left':descendant.location.left,
# 'top':descendant.location.top,
# 'right':descendant.location.right,
# 'bottom':descendant.location.bottom,
# 'height':descendant.location.height,
# 'width':descendant.location.width,
# }
# The relative parent isn't an ancestor of the descendant.
if descendant and not isFocusAncestor(ancestor) and hasLocation(descendant):
dtk = list(filter(lambda p: isinstance(p, globalPluginHandler.globalPlugins.developerToolkit.GlobalPlugin), globalPluginHandler.runningPlugins))[0]
dtk.relativeParent = api.getDesktopObject()
return {
'left':descendant.location.left,
'top':descendant.location.top,
'right':descendant.location.right,
'bottom':descendant.location.bottom,
'bottom-bottom':ancestor.location.bottom - descendant.location.bottom,
'right-right':ancestor.location.right - descendant.location.right,

'height':descendant.location.height,
'width':descendant.location.width,
}
# The relative parent is an ancestor of the descendant.
if descendant and isFocusAncestor(ancestor) and hasLocation(descendant):
return {
'left':descendant.location.left - ancestor.location.left,
'top':descendant.location.top - ancestor.location.top,
'right':descendant.location.right - ancestor.location.left,
'bottom':descendant.location.bottom - ancestor.location.top,
'bottom-bottom':ancestor.location.bottom - descendant.location.bottom,
'right-right':ancestor.location.right - descendant.location.right,
'height':descendant.location.height,
'width':descendant.location.width,
}
Expand All @@ -52,13 +62,10 @@ def getRoleLabel(theObject):

def SpeakSizeAndLocationHelper(locationAttribute, descendant, ancestor):
attribute = getSizeAndPosition(descendant, ancestor)[locationAttribute]
if attribute > -1:
if isDetailedMessages():
return "{} pixels.".format(attribute)
else:
return "{}".format(attribute)
if isDetailedMessages():
return "{} pixels.".format(attribute)
else:
return "{} not available.".format(locationAttribute)
return "{}".format(attribute)

def NavigateTo(relationship, theObject):
if theObject:
Expand Down

0 comments on commit f8cda20

Please sign in to comment.