Module: Accessibility::Console

Defined in:
lib/project/motion-accessibility-console/tree.rb,
lib/project/motion-accessibility-console/touch.rb,
lib/project/motion-accessibility-console/browser.rb

Defined Under Namespace

Classes: Tree

Constant Summary collapse

Update_Delay =
1.0

Class Method Summary collapse

Class Method Details

.browse(request = nil) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/project/motion-accessibility-console/browser.rb', line 48

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||request==:refresh
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==: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 found.view.inspect_a11y
end
A11y::Console.init unless A11y::Data[:refresh]
$browser_current=found
$browser_path<<found
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

.display_viewsObject



30
31
32
33
34
35
36
37
38
# File 'lib/project/motion-accessibility-console/browser.rb', line 30

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) ⇒ Object



23
24
25
26
27
28
# File 'lib/project/motion-accessibility-console/browser.rb', line 23

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

.refreshObject



90
91
92
93
94
95
96
97
98
99
# File 'lib/project/motion-accessibility-console/browser.rb', line 90

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) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
19
20
21
# File 'lib/project/motion-accessibility-console/browser.rb', line 15

def self.scrollable_view?(view)
control=view.class
until control==UIScrollView||control.nil?
control=control.superclass
end
control==UIScrollView
end

.start_refreshingObject



40
41
42
43
44
45
46
# File 'lib/project/motion-accessibility-console/browser.rb', line 40

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(view, arg = nil, options = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/project/motion-accessibility-console/touch.rb', line 4

def self.touch(view, arg=nil, options={})
self.start_refreshing
$browser_current=$browser_tree unless $browser_current
unless RUBYMOTION_ENV=='test'
found=$browser_current.find(view)
raise "Could not find the view" unless found
      view=found.view
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 "Could not get the UITableView" unless sv.kind_of?(UITableView)
index=options[:index]||sv.indexPathForCell(view)
raise "Could not get the index" unless index
sv.delegate.tableView(self, 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) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/project/motion-accessibility-console/touch.rb', line 54

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) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/project/motion-accessibility-console/touch.rb', line 79

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) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/project/motion-accessibility-console/browser.rb', line 7

def self.touchable_type(view)
control=view.class
until A11y::Touchable_Types.member?(control.to_s)||control.nil?
control=control.superclass
end
control
end

.view(request = nil) ⇒ Object



101
102
103
104
105
106
107
108
109
110
# File 'lib/project/motion-accessibility-console/browser.rb', line 101

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
return $browser_cursor.view unless request
result=$browser_current.find(request)
raise "Unknown view" unless result
$browser_cursor=result
result.view
end