Module: Accessibility::Debug

Defined in:
lib/accessibility/debug.rb

Overview

Collection of utility methods helpful when trying to debug issues.

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.onBoolean Also known as: on?

Whether or not to turn on DEBUG features in AXElements. The value is initially inherited from $DEBUG but can be overridden by an environment variable named AXDEBUG or changed dynamically at runtime.

Returns:

  • (Boolean)


21
22
23
# File 'lib/accessibility/debug.rb', line 21

def on
  @on
end

Class Method Details

.graph_subtree(root) ⇒ String

Note:

This is an unfinished feature

Make a dot format graph of the tree, meant for graphing with GraphViz.

Returns:



49
50
51
52
53
54
# File 'lib/accessibility/debug.rb', line 49

def graph_subtree root
  require 'accessibility/graph'
  dot = Accessibility::Graph.new(root)
  dot.build!
  dot.to_s
end

.highlight(element, opts = {}) ⇒ NSWindow

Highlight an element on screen. You can optionally specify the highlight colour or pass a timeout to automatically have the highlighter disappear.

The highlighter is actually a window, so if you do not set a timeout, you will need to call #stop or #close on the NSWindow object that this method returns in order to get rid of the highlighter.

You could use this method to highlight an arbitrary number of elements on screen, with a rainbow of colours for debugging.

Examples:


highlighter = highlight window.outline
highlight window.outline.row, colour: NSColor.greenColor, timeout: 5
highlighter.stop

Parameters:

Options Hash (opts):

  • :timeout (Number)
  • :colour (NSColor)

Returns:

  • (NSWindow)


99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/accessibility/debug.rb', line 99

def highlight element, opts = {}
  app    = NSApplication.sharedApplication
  colour = opts[:colour] || opts[:color] || NSColor.magentaColor
  window = highlight_window_for element.bounds, colour

  if opts.has_key? :timeout
    Dispatch::Queue.new('window_killer').after opts[:timeout] do
      window.close
    end
  end

  window
end

.path(*elements) ⇒ Array<AX::Element>

Get a list of elements, starting with an element you give, and riding the hierarchy up to the top level object (i.e. the AX::Application).

Examples:


element = AX::DOCK.list.application_dock_item
path_for element
  # => [AX::ApplicationDockItem, AX::List, AX::Application]

Parameters:

Returns:



36
37
38
39
40
# File 'lib/accessibility/debug.rb', line 36

def path *elements
  element = elements.last
  return path(elements << element.parent) if element.respond_to? :parent
  return elements
end

.text_subtree(element) ⇒ String

Dump a tree to the console, indenting for each level down the tree that we go, and inspecting each element.

Examples:


puts subtree_for app

Returns:



65
66
67
68
69
70
71
72
73
# File 'lib/accessibility/debug.rb', line 65

def text_subtree element
  output = element.inspect + "\n"
  # @todo should use each_child_with_level instead
  enum   = Accessibility::Enumerators::DepthFirst.new element
  enum.each_with_level do |element, depth|
    output << "\t"*depth + element.inspect + "\n"
  end
  output
end