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 CHANGED
@@ -61,3 +61,7 @@
61
61
  == 0.2.14 / 2010-10-04
62
62
 
63
63
  * Reimplemented App#close with timeout
64
+
65
+ == 0.2.15 / 2010-10-05
66
+
67
+ * Window.find added as alias to Window.top_level
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.14
1
+ 0.2.15
@@ -81,7 +81,9 @@ module WinGui
81
81
  end
82
82
 
83
83
  # Launch App in a separate window
84
+ p command
84
85
  system command # TODO: make sure only valid commands are fed into system
86
+ p "Returned from system"
85
87
  end
86
88
 
87
89
  end
@@ -9,36 +9,40 @@ module WinGui
9
9
 
10
10
  attr_reader :handle
11
11
 
12
- # Looks up window handle using code specified in attached block (either with or without :timeout).
13
- # Returns either Window instance (for a found handle) or nil if nothing found.
14
- # Private method to dry up other window lookup methods
15
- #
16
- def self.lookup_window(opts) # :yields: index, position
17
- # Need this to avoid handle considered local in begin..end block
18
- handle = yield
19
- if opts[:timeout]
20
- begin
21
- timeout(opts[:timeout]) do
22
- sleep SLEEP_DELAY until handle = yield
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
- # Finds top level window by title/class, returns wrapped Window object or nil (raises exception if asked to).
33
- # If timeout option given, waits for window to appear within timeout, returns nil if it didn't.
34
- # Options:
35
- # :title:: window title
36
- # :class:: window class
37
- # :timeout:: timeout (seconds)
38
- # :raise:: raise this exception instead of returning nil if nothing found
39
- #
40
- def self.top_level(opts={})
41
- lookup_window(opts) { WinGui.find_window opts[:class], opts[:title] }
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
- when Array
96
- where # Explicit screen coords
97
- when :random
98
- [left + rand(right - left), top + rand(bottom - top)] # Random point within control window
99
- else
100
- [(left + right) / 2, (top + bottom) / 2] # Center of a control window
101
- end
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
@@ -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: 11
4
+ hash: 9
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 14
10
- version: 0.2.14
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-04 00:00:00 +04:00
18
+ date: 2010-10-05 00:00:00 +04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency