win_gui 0.2.14 → 0.2.15
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY +4 -0
- data/VERSION +1 -1
- data/lib/win_gui/application.rb +2 -0
- data/lib/win_gui/window.rb +39 -35
- data/spec/win_gui/window_spec.rb +5 -0
- metadata +4 -4
data/HISTORY
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.15
|
data/lib/win_gui/application.rb
CHANGED
data/lib/win_gui/window.rb
CHANGED
@@ -9,36 +9,40 @@ module WinGui
|
|
9
9
|
|
10
10
|
attr_reader :handle
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
12
|
+
class << self
|
13
|
+
# Looks up window handle using code specified in attached block (either with or without :timeout).
|
14
|
+
# Returns either Window instance (for a found handle) or nil if nothing found.
|
15
|
+
# Private method to dry up other window lookup methods
|
16
|
+
#
|
17
|
+
def lookup_window(opts) # :yields: index, position
|
18
|
+
# Need this to avoid handle considered local in begin..end block
|
19
|
+
handle = yield
|
20
|
+
if opts[:timeout]
|
21
|
+
begin
|
22
|
+
timeout(opts[:timeout]) do
|
23
|
+
sleep SLEEP_DELAY until handle = yield
|
24
|
+
end
|
25
|
+
rescue TimeoutError
|
26
|
+
nil
|
23
27
|
end
|
24
|
-
rescue TimeoutError
|
25
|
-
nil
|
26
28
|
end
|
29
|
+
raise opts[:raise] if opts[:raise] && !handle
|
30
|
+
Window.new(handle) if handle
|
27
31
|
end
|
28
|
-
raise opts[:raise] if opts[:raise] && !handle
|
29
|
-
Window.new(handle) if handle
|
30
|
-
end
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
33
|
+
# Finds top level window by title/class, returns wrapped Window object or nil (raises exception if asked to).
|
34
|
+
# If timeout option given, waits for window to appear within timeout, returns nil if it didn't.
|
35
|
+
# Options:
|
36
|
+
# :title:: window title
|
37
|
+
# :class:: window class
|
38
|
+
# :timeout:: timeout (seconds)
|
39
|
+
# :raise:: raise this exception instead of returning nil if nothing found
|
40
|
+
#
|
41
|
+
def top_level(opts={})
|
42
|
+
lookup_window(opts) { WinGui.find_window opts[:class], opts[:title] }
|
43
|
+
end
|
44
|
+
|
45
|
+
alias_method :find, :top_level
|
42
46
|
end
|
43
47
|
|
44
48
|
# Finds child window (control) by either control ID or window class/title.
|
@@ -72,7 +76,7 @@ module WinGui
|
|
72
76
|
# Returns array of Windows that are descendants (not only DIRECT children) of a given Window
|
73
77
|
#
|
74
78
|
def children
|
75
|
-
enum_child_windows.map{|child_handle| Window.new child_handle}
|
79
|
+
enum_child_windows.map { |child_handle| Window.new child_handle }
|
76
80
|
end
|
77
81
|
|
78
82
|
# Emulates click of the control identified by opts (:id, :title, :class).
|
@@ -92,13 +96,13 @@ module WinGui
|
|
92
96
|
|
93
97
|
where = opts[:point] || opts[:where] || opts[:position]
|
94
98
|
point = case where
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
99
|
+
when Array
|
100
|
+
where # Explicit screen coords
|
101
|
+
when :random
|
102
|
+
[left + rand(right - left), top + rand(bottom - top)] # Random point within control window
|
103
|
+
else
|
104
|
+
[(left + right) / 2, (top + bottom) / 2] # Center of a control window
|
105
|
+
end
|
102
106
|
|
103
107
|
WinGui.set_cursor_pos *point
|
104
108
|
|
@@ -117,7 +121,7 @@ module WinGui
|
|
117
121
|
|
118
122
|
# Waits for this window to close with timeout (default CLOSE_TIMEOUT).
|
119
123
|
#
|
120
|
-
def wait_for_close(timeout=CLOSE_TIMEOUT
|
124
|
+
def wait_for_close(timeout=CLOSE_TIMEOUT)
|
121
125
|
timeout(timeout) do
|
122
126
|
sleep SLEEP_DELAY while window_visible?
|
123
127
|
end
|
data/spec/win_gui/window_spec.rb
CHANGED
@@ -103,6 +103,11 @@ module WinGuiTest
|
|
103
103
|
it 'raises exception if asked to' do
|
104
104
|
expect{ Window.top_level( title: IMPOSSIBLE, raise: "Horror!")}.to raise_error "Horror!"
|
105
105
|
end
|
106
|
+
|
107
|
+
it 'uses .find as alias for .top_level' do
|
108
|
+
use { @window = Window.find() }
|
109
|
+
@window.should be_a Window
|
110
|
+
end
|
106
111
|
end # describe .top_level
|
107
112
|
|
108
113
|
describe '#child' do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: win_gui
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 9
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 15
|
10
|
+
version: 0.2.15
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- arvicco
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-10-
|
18
|
+
date: 2010-10-05 00:00:00 +04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|