module Accessibility::Console

Constants

Update_Delay

Public Class Methods

browse(request=nil) click to toggle source
# File lib/project/motion-accessibility-console/browser.rb, line 52
def browse(request=nil)
A11y::Console.init unless $browser_current
A11y::Console.start_refreshing
request=0 if request==:back
if request.nil?
elsif request==:top
A11y::Console.init
$browser_current=$browser_tree
$browser_path.clear
elsif request==0
raise "You cannot go back any further" if $browser_path.length<2
$browser_path.pop
$browser_current=$browser_path.last
A11y::Console.init unless A11y::Data[:refresh]
elsif request==:refresh
        raise "This view cannot refresh." unless $browser_current.view.respond_to?(:reloadData)
        $browser_current.view.reloadData
elsif request==:scroll
raise "This view cannot scroll" unless A11y::Console.scrollable_view?($browser_current.view)
below=CGRect.new([0, $browser_current.view.size.height], $browser_current.view.size)
$browser_current.view.scrollRectToVisible(below, animated: false)
elsif request.kind_of?(Fixnum)||request.kind_of?(String)
A11y::Console.init unless $browser_tree
$browser_current=$browser_tree unless $browser_current
found=$browser_current.find(request)
if found
if found.subviews.empty?
$browser_cursor=found
return A11y.inspect found.view
end
A11y::Console.init unless A11y::Data[:refresh]
$browser_current=found
$browser_path<<found
$browser_last=request
end
elsif request.respond_to?(:view)&&request.respond_to?(:subviews)
        A11y::Console.init(request)
        $browser_current=$browser_tree
else
        puts "Unknown request: #{request.inspect}"
end
$browser_cursor=$browser_current
A11y::Console.display_views
nil
end
Also aliased as: b
display_views() click to toggle source
# File lib/project/motion-accessibility-console/browser.rb, line 34
def self.display_views
$browser_current=$browser_tree unless $browser_current
puts "Browsing "+$browser_current.display_view
$browser_current.browsable_nodes.each_with_index do |node, index|
next if node.nil?
output=node.display_view( index)
puts output unless output.nil?
end
end
init(view=nil) click to toggle source
# File lib/project/motion-accessibility-console/browser.rb, line 27
def self.init(view=nil)
view=UIApplication.sharedApplication.keyWindow if view.nil?
$browser_tree=A11y::Console::Tree.build(view)
$browser_path<<$browser_tree if $browser_path.empty?
nil
end
refresh() click to toggle source
# File lib/project/motion-accessibility-console/browser.rb, line 98
def self.refresh
A11y::Console.init
$before=$browser_tree.copy unless $before
unless $browser_tree==$before
puts "The screen has changed."
A11y::Console.browse :top
puts "(Main)> "
end
$before=$browser_tree.copy
end
scrollable_view?(view) click to toggle source
# File lib/project/motion-accessibility-console/browser.rb, line 19
def self.scrollable_view?(view)
control=view.class
until control==UIScrollView||control.nil?
control=control.superclass
end
control==UIScrollView
end
start_refreshing() click to toggle source
# File lib/project/motion-accessibility-console/browser.rb, line 44
def self.start_refreshing
if !A11y::Data[:refresh]&&RUBYMOTION_ENV!='test'
NSTimer.scheduledTimerWithTimeInterval(Update_Delay, target: self, selector: 'refresh', userInfo: nil, repeats: true)
A11y::Data[:refresh]=true
A11y::Console.init
end
end
touch(request, arg=nil, options={}) click to toggle source
# File lib/project/motion-accessibility-console/touch.rb, line 4
def self.touch(request, arg=nil, options={})
self.start_refreshing
$browser_current=$browser_tree unless $browser_current
view=nil
unless RUBYMOTION_ENV=='test'
found=$browser_current.find(request)
raise "Could not find the view" unless found
      view=found.view
else
        view=request
end
control=A11y::Console.touchable_type(view)
raise "I don't know how to touch a #{view.class}"  if control.nil?
if found
sv=options[:superview]||found.superview.view
else
sv=options[:superview]
end
case control.to_s
when "UIButton"
arg||=UIControlEventTouchUpInside
view.sendActionsForControlEvents(arg)
when "UITabBarButton"
arg||=UIControlEventTouchUpInside
view.sendActionsForControlEvents(arg)
when "UITextField"
view.text=arg
when "UIPickerView"
self.touch_pickerview(view, arg)
when "UIDatePicker"
view.date=arg
when "UISegmentedControl"
self.touch_segmented(view, arg)
when "UISlider"
view.value=arg
when "UIStepper"
view.value=arg
when "UISwitch"
arg||=!view.arg
view.on=arg
when "UITableViewCell"
        raise "You cannot touch cells in this table." unless sv.delegate.respond_to?("tableView:didSelectRowAtIndexPath")
raise "Could not get the UITableView" unless sv.kind_of?(UITableView)
if sv.respond_to?(:numberOfSections)
        sections=sv.numberOfSections
else
        sections=1
end
if sections>1
index=options[:index]||NSIndexPath.indexPathForRow(request-1, inSection: $browser_last-1)
else
index=options[:index]||NSIndexPath.indexPathForRow(request-1, inSection: 0)
end
raise "Could not get the index" unless index
sv.delegate.tableView(sv.delegate, didSelectRowAtIndexPath: index)
when "UITableViewCellAccessibilityElement" 
        raise "You cannot touch cells in this table." unless view.container.delegate.respond_to?("tableView:didSelectRowAtIndexPath")
if options[:index]
        index=options[:index]
else
raise "Invalid number" if request>view.container.delegate.accessibility_element_count
index=view.container.indexPathForCell(view.tableViewCell)
raise "Could not get the index" unless index
end
view.container.delegate.tableView(view.container, didSelectRowAtIndexPath: index)
when "UINavigationItemButtonView"
view.superview.delegate.popViewControllerAnimated(true)
else
raise "I don't know what to do with a #{control}"
end
self.browse unless RUBYMOTION_ENV=='test'
end
touch_pickerview(view, arg) click to toggle source
# File lib/project/motion-accessibility-console/touch.rb, line 77
def self.touch_pickerview(view, arg)
raise "You must pass a hash with the row and component keywords" unless arg.kind_of?(Hash)&&arg[:row]&&arg[:component]
arg[:animated]||=false
if arg[:row].kind_of?(String)
results=[]
view.numberOfRowsInComponent(arg[:component]).times do |row_index|
title=view.delegate.pickerView(view, titleForRow: row_index, forComponent: arg[:component])
if title.casecmp(arg[:row])==0
results=[row_index]
break
end
if title=~Regexp.new(arg[:row],true)
results<<row_index
end
end
raise "Unknown value" if results.empty?
raise "That could refer to more than one value." if results.length>1
view.selectRow(results.first, inComponent: arg[:component], animated: false)
elsif arg[:row].kind_of?(Fixnum)
view.selectRow(arg[:row], inComponent: arg[:component], animated: arg[:animated])
else
raise "Unknown row #{arg[:row]}"
end
end
touch_segmented(view, arg) click to toggle source
# File lib/project/motion-accessibility-console/touch.rb, line 102
def self.touch_segmented(view, arg)
if arg.kind_of?(Fixnum)
view.selectedSegmentIndex=arg
elsif arg.kind_of?(String)
results=[]
view.numberOfSegments.times do |index|
title=view.titleForSegmentAtIndex(index)
if title.casecmp(arg)==0
results=[index]
break
end
if title=~Regexp.new(arg,true)
results<<index
end
end
raise "Unknown segment" if results.empty?
raise "That could refer to more than one segment" if results.length>1
view.selectedSegmentIndex=results.first
else
raise "Invalid segment"
end
end
touchable_type(view) click to toggle source
# File lib/project/motion-accessibility-console/browser.rb, line 8
def self.touchable_type(view)
control=view.class
until A11y::Touchable_Types.member?(control.to_s)||control.nil?
control=control.superclass
end
if control.class==UITableViewCell
        control=nil unless controll.respond_to?("tableView:didSelectRowAtIndexPath")
end
control
end
view(request=nil) click to toggle source
# File lib/project/motion-accessibility-console/browser.rb, line 109
def view(request=nil)
A11y::Console.init unless A11y::Data[:refresh]
$browser_current=$browser_tree unless $browser_current
$browser_cursor=$browser_tree unless $browser_cursor
result=nil
if request
result=$browser_current.find(request)
raise "Unknown view" unless result
$browser_cursor=result
result=result.view
else
result=$browser_cursor.view 
result
end
if defined?(UITableViewCellAccessibilityElement)&&result.class==UITableViewCellAccessibilityElement
result=result.tableViewCell
end
result
end
Also aliased as: v

Public Instance Methods

b(request=nil)
Alias for: browse
v(request=nil)
Alias for: view

Private Instance Methods

browse(request=nil) click to toggle source
# File lib/project/motion-accessibility-console/browser.rb, line 52
def browse(request=nil)
A11y::Console.init unless $browser_current
A11y::Console.start_refreshing
request=0 if request==:back
if request.nil?
elsif request==:top
A11y::Console.init
$browser_current=$browser_tree
$browser_path.clear
elsif request==0
raise "You cannot go back any further" if $browser_path.length<2
$browser_path.pop
$browser_current=$browser_path.last
A11y::Console.init unless A11y::Data[:refresh]
elsif request==:refresh
        raise "This view cannot refresh." unless $browser_current.view.respond_to?(:reloadData)
        $browser_current.view.reloadData
elsif request==:scroll
raise "This view cannot scroll" unless A11y::Console.scrollable_view?($browser_current.view)
below=CGRect.new([0, $browser_current.view.size.height], $browser_current.view.size)
$browser_current.view.scrollRectToVisible(below, animated: false)
elsif request.kind_of?(Fixnum)||request.kind_of?(String)
A11y::Console.init unless $browser_tree
$browser_current=$browser_tree unless $browser_current
found=$browser_current.find(request)
if found
if found.subviews.empty?
$browser_cursor=found
return A11y.inspect found.view
end
A11y::Console.init unless A11y::Data[:refresh]
$browser_current=found
$browser_path<<found
$browser_last=request
end
elsif request.respond_to?(:view)&&request.respond_to?(:subviews)
        A11y::Console.init(request)
        $browser_current=$browser_tree
else
        puts "Unknown request: #{request.inspect}"
end
$browser_cursor=$browser_current
A11y::Console.display_views
nil
end
Also aliased as: b
view(request=nil) click to toggle source
# File lib/project/motion-accessibility-console/browser.rb, line 109
def view(request=nil)
A11y::Console.init unless A11y::Data[:refresh]
$browser_current=$browser_tree unless $browser_current
$browser_cursor=$browser_tree unless $browser_cursor
result=nil
if request
result=$browser_current.find(request)
raise "Unknown view" unless result
$browser_cursor=result
result=result.view
else
result=$browser_cursor.view 
result
end
if defined?(UITableViewCellAccessibilityElement)&&result.class==UITableViewCellAccessibilityElement
result=result.tableViewCell
end
result
end
Also aliased as: v