win_gui 0.2.9 → 0.2.10

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY CHANGED
@@ -41,3 +41,7 @@
41
41
  == 0.2.9 / 2010-06-04
42
42
 
43
43
  * Window: Full feature parity with Book code
44
+
45
+ == 0.2.10 / 2010-06-04
46
+
47
+ * Window#child now searches all descendant windows with :indirect option
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.9
1
+ 0.2.10
@@ -5,8 +5,6 @@ module WinGui
5
5
 
6
6
  def initialize(handle)
7
7
  @handle = handle
8
- # puts "Window #{handle} created "
9
- # p self.class.ancestors
10
8
  end
11
9
 
12
10
  attr_reader :handle
@@ -48,12 +46,25 @@ module WinGui
48
46
  # :id:: integer control id (such as IDOK, IDCANCEL, etc)
49
47
  # :title:: window title
50
48
  # :class:: window class
49
+ # :indirect:: search all descendants, not only direct children
51
50
  # :timeout:: timeout (seconds)
52
51
  # :raise:: raise this exception instead of returning nil if nothing found
52
+ # TODO: add the ability to nail indirect children as well
53
53
  #
54
54
  def child(opts={})
55
- self.class.lookup_window(opts) do
56
- opts[:id] ? get_dlg_item(opts[:id]) : find_window_ex(0, opts[:class], opts[:title])
55
+ if opts[:indirect]
56
+ self.class.lookup_window opts do
57
+ found = children.find do |child|
58
+ (opts[:id] ? child.id == opts[:id] : true) &&
59
+ (opts[:class] ? child.class_name == opts[:class] : true) &&
60
+ (opts[:title] ? child.title == opts[:title] : true)
61
+ end
62
+ found.handle if found
63
+ end
64
+ else
65
+ self.class.lookup_window opts do
66
+ opts[:id] ? get_dlg_item(opts[:id]) : find_window_ex(0, opts[:class], opts[:title])
67
+ end
57
68
  end
58
69
  end
59
70
 
@@ -121,6 +132,25 @@ module WinGui
121
132
  shut_window
122
133
  end
123
134
 
135
+ # Alias for [get_]window_text
136
+ #
137
+ def title
138
+ get_window_text
139
+ end
140
+
141
+ def thread
142
+ get_window_thread_process_id.first
143
+ end
144
+
145
+ def process
146
+ get_window_thread_process_id.last
147
+ end
148
+
149
+ # Control ID associated with the window (only makes sense for controls)
150
+ def id
151
+ get_dlg_ctrl_id
152
+ end
153
+
124
154
  # Since Window instances wrap actual window handles, they should directly support Win32 API functions
125
155
  # manipulating these handles. Therefore, when unsupported instance method is invoked, we check if
126
156
  # WinGui responds to such method, and if yes, call it with our window handle as a first argument.
@@ -14,11 +14,6 @@ module WinGuiTest
14
14
  end
15
15
 
16
16
  context 'manipulating' do
17
- it 'has handle property equal to underlying window handle' do
18
- any = Window.new any_handle
19
- any.handle.should == any_handle
20
- end
21
-
22
17
  it 'closes when asked nicely' do
23
18
  @app.close
24
19
  sleep SLEEP_DELAY # needed to ensure window had enough time to close down
@@ -48,13 +43,32 @@ module WinGuiTest
48
43
  @app.window_thread_process_id.should be_an Array
49
44
  @app.enum_child_windows.should be_an Array
50
45
  end
46
+ end
51
47
 
52
- it 'has class_name and text properties (derived from WinGui function calls)' do
48
+ context 'derived properties' do
49
+ it 'has handle property equal to underlying window handle' do
50
+ any = Window.new any_handle
51
+ any.handle.should == any_handle
52
+ end
53
+
54
+ it 'has class_name and text/title properties (derived from WinGui function calls)' do
53
55
  @app.class_name.should == WIN_CLASS
54
- # window_text propery accessed via GetWindowText
55
- @app.window_text.should == WIN_TITLE
56
56
  # text propery accessed by sending WM_GETTEXT directly to window (convenience method in WinGui)
57
57
  @app.text.should == WIN_TITLE
58
+ # window_text propery accessed via GetWindowText
59
+ @app.window_text.should == WIN_TITLE
60
+ # title property is just an alias for window_text
61
+ @app.title.should == WIN_TITLE
62
+ end
63
+
64
+ it 'has thread and process properties derived from get_window_thread_process_id' do
65
+ thread = @app.thread
66
+ process = @app.process
67
+ [thread, process].should == get_window_thread_process_id(@app.handle)
68
+ end
69
+
70
+ it 'has id property that only makes sense for controls' do
71
+ use{ @app.id }
58
72
  end
59
73
  end
60
74
 
@@ -132,7 +146,6 @@ module WinGuiTest
132
146
 
133
147
  it 'finds child with specific text and returns it as a Window object' do
134
148
  with_dialog(:save) do |dialog|
135
- # @dialog.children.each{|child| puts "#{child.handle}, #{child.class_name}, #{child.window_text}"}
136
149
  child = dialog.child( title: "Cancel")
137
150
  child.should_not == nil
138
151
  dialog.child?(child.handle).should == true
@@ -153,6 +166,47 @@ module WinGuiTest
153
166
  child.text.should == "Cancel"
154
167
  end
155
168
  end
169
+
170
+ context 'indirect child' do
171
+ it 'returns nil if specified child not found' do
172
+ @app.child( title: IMPOSSIBLE, indirect: true).should == nil
173
+ end
174
+
175
+ it 'finds ANY child window without other args' do
176
+ use { @child = @app.child(indirect: true) }
177
+ @child.should_not == nil
178
+ @app.child?(@child.handle).should == true
179
+ end
180
+
181
+ it 'finds child window by class' do
182
+ child = @app.child( class: TEXTAREA_CLASS, indirect: true)
183
+ child.should_not == nil
184
+ @app.child?(child.handle).should == true
185
+ end
186
+
187
+ it 'finds child with specific text' do
188
+ with_dialog(:save) do |dialog|
189
+ child = dialog.child( title: "Cancel", indirect: true)
190
+ child.should_not == nil
191
+ dialog.child?(child.handle).should == true
192
+ child.id.should == IDCANCEL
193
+
194
+ child = dialog.child( title: "&Save", indirect: true)
195
+ child.should_not == nil
196
+ dialog.child?(child.handle).should == true
197
+ child.id.should == IDOK
198
+ end
199
+ end
200
+
201
+ it 'finds child control with a given ID ' do
202
+ with_dialog(:save) do |dialog|
203
+ child = dialog.child( id: IDCANCEL, indirect: true)
204
+ child.should_not == nil
205
+ dialog.child?(child.handle).should == true
206
+ child.text.should == "Cancel"
207
+ end
208
+ end
209
+ end # context indirect
156
210
  end # describe child
157
211
 
158
212
  describe '#children' do
@@ -169,6 +223,13 @@ module WinGuiTest
169
223
  end # describe #children
170
224
 
171
225
  describe '#click' do
226
+ # it 'tests' do
227
+ # with_dialog(:save) do |dialog|
228
+ # dialog.children.each{|child| puts "#{child.handle}, #{child.class_name}, #{child.window_text}, #{dialog.child?(child.handle)}"}
229
+ # true.should == false
230
+ # end
231
+ # end
232
+
172
233
  it 'emulates left click of the control identified by id, returns click coords' do
173
234
  with_dialog(:save) do |dialog|
174
235
  point = dialog.click(id: IDCANCEL)
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 9
9
- version: 0.2.9
8
+ - 10
9
+ version: 0.2.10
10
10
  platform: ruby
11
11
  authors:
12
12
  - arvicco