win_gui 0.1.6 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (169) hide show
  1. data/.gitignore +21 -21
  2. data/HISTORY +7 -0
  3. data/LICENSE +20 -20
  4. data/README.rdoc +77 -114
  5. data/Rakefile +24 -58
  6. data/VERSION +1 -1
  7. data/features/support/env.rb +7 -4
  8. data/features/win_gui.feature +9 -9
  9. data/lib/version.rb +8 -0
  10. data/lib/win_gui/window.rb +78 -69
  11. data/lib/win_gui.rb +25 -3
  12. data/spec/spec.opts +1 -1
  13. data/spec/spec_helper.rb +90 -118
  14. data/spec/win_gui/window_spec.rb +120 -123
  15. data/tasks/common.rake +14 -0
  16. data/tasks/doc.rake +14 -0
  17. data/tasks/gem.rake +39 -0
  18. data/tasks/git.rake +34 -0
  19. data/tasks/spec.rake +19 -0
  20. data/tasks/version.rake +71 -0
  21. metadata +68 -188
  22. data/.document +0 -5
  23. data/book_code/early_success/bundle.rb +0 -34
  24. data/book_code/early_success/english.txt +0 -1
  25. data/book_code/early_success/jruby_basics.rb +0 -47
  26. data/book_code/early_success/windows_basics.rb +0 -97
  27. data/book_code/guessing/locknote.rb +0 -379
  28. data/book_code/guessing/monkeyshines.rb +0 -14
  29. data/book_code/guessing/note.rb +0 -120
  30. data/book_code/guessing/note_spec.rb +0 -175
  31. data/book_code/guessing/replay.rb +0 -21
  32. data/book_code/guessing/seed.rb +0 -9
  33. data/book_code/guessing/spec_helper.rb +0 -69
  34. data/book_code/guessing/windows_gui.rb +0 -247
  35. data/book_code/home_stretch/junquenote.rb +0 -151
  36. data/book_code/home_stretch/locknote.rb +0 -180
  37. data/book_code/home_stretch/note.rb +0 -144
  38. data/book_code/home_stretch/note_spec.rb +0 -191
  39. data/book_code/home_stretch/spec_helper.rb +0 -55
  40. data/book_code/home_stretch/swing_gui.rb +0 -50
  41. data/book_code/home_stretch/windows_gui.rb +0 -232
  42. data/book_code/junquenote/exports.sh +0 -10
  43. data/book_code/junquenote/jruby_mac.sh +0 -10
  44. data/book_code/junquenote/junquenote_app.rb +0 -262
  45. data/book_code/novite/Rakefile +0 -10
  46. data/book_code/novite/app/controllers/application.rb +0 -18
  47. data/book_code/novite/app/controllers/guests_controller.rb +0 -28
  48. data/book_code/novite/app/controllers/parties_controller.rb +0 -77
  49. data/book_code/novite/app/helpers/application_helper.rb +0 -11
  50. data/book_code/novite/app/helpers/guests_helper.rb +0 -10
  51. data/book_code/novite/app/helpers/parties_helper.rb +0 -10
  52. data/book_code/novite/app/models/guest.rb +0 -11
  53. data/book_code/novite/app/models/party.rb +0 -32
  54. data/book_code/novite/app/models/party_mailer.rb +0 -19
  55. data/book_code/novite/app/views/layouts/application.rhtml +0 -44
  56. data/book_code/novite/app/views/parties/new.html.erb +0 -42
  57. data/book_code/novite/app/views/parties/show.html.erb +0 -43
  58. data/book_code/novite/app/views/party_mailer/invite.erb +0 -17
  59. data/book_code/novite/config/boot.rb +0 -117
  60. data/book_code/novite/config/database.yml +0 -19
  61. data/book_code/novite/config/environment.rb +0 -67
  62. data/book_code/novite/config/environments/development.rb +0 -29
  63. data/book_code/novite/config/environments/production.rb +0 -27
  64. data/book_code/novite/config/environments/test.rb +0 -30
  65. data/book_code/novite/config/initializers/inflections.rb +0 -18
  66. data/book_code/novite/config/initializers/mime_types.rb +0 -13
  67. data/book_code/novite/config/routes.rb +0 -47
  68. data/book_code/novite/db/migrate/001_create_parties.rb +0 -26
  69. data/book_code/novite/db/migrate/002_create_guests.rb +0 -23
  70. data/book_code/novite/db/schema.rb +0 -41
  71. data/book_code/novite/log/empty.txt +0 -0
  72. data/book_code/novite/public/.htaccess +0 -40
  73. data/book_code/novite/public/404.html +0 -38
  74. data/book_code/novite/public/422.html +0 -38
  75. data/book_code/novite/public/500.html +0 -38
  76. data/book_code/novite/public/dispatch.cgi +0 -10
  77. data/book_code/novite/public/dispatch.fcgi +0 -24
  78. data/book_code/novite/public/dispatch.rb +0 -18
  79. data/book_code/novite/public/favicon.ico +0 -0
  80. data/book_code/novite/public/images/rails.png +0 -0
  81. data/book_code/novite/public/index.html +0 -285
  82. data/book_code/novite/public/javascripts/application.js +0 -10
  83. data/book_code/novite/public/javascripts/controls.js +0 -971
  84. data/book_code/novite/public/javascripts/dragdrop.js +0 -980
  85. data/book_code/novite/public/javascripts/effects.js +0 -1128
  86. data/book_code/novite/public/javascripts/prototype.js +0 -4233
  87. data/book_code/novite/public/robots.txt +0 -5
  88. data/book_code/novite/script/about +0 -3
  89. data/book_code/novite/script/console +0 -3
  90. data/book_code/novite/script/destroy +0 -3
  91. data/book_code/novite/script/generate +0 -3
  92. data/book_code/novite/script/performance/benchmarker +0 -3
  93. data/book_code/novite/script/performance/profiler +0 -3
  94. data/book_code/novite/script/performance/request +0 -3
  95. data/book_code/novite/script/plugin +0 -3
  96. data/book_code/novite/script/process/inspector +0 -3
  97. data/book_code/novite/script/process/reaper +0 -3
  98. data/book_code/novite/script/process/spawner +0 -3
  99. data/book_code/novite/script/runner +0 -3
  100. data/book_code/novite/script/server +0 -3
  101. data/book_code/novite/test/test_helper.rb +0 -46
  102. data/book_code/one_more_thing/applescript.rb +0 -68
  103. data/book_code/one_more_thing/note_spec.rb +0 -50
  104. data/book_code/one_more_thing/spec_helper.rb +0 -17
  105. data/book_code/one_more_thing/textedit-pure.rb +0 -28
  106. data/book_code/one_more_thing/textedit.applescript +0 -26
  107. data/book_code/one_more_thing/textedit.rb +0 -32
  108. data/book_code/one_more_thing/textnote.rb +0 -87
  109. data/book_code/simplify/junquenote.rb +0 -48
  110. data/book_code/simplify/locknote.rb +0 -46
  111. data/book_code/simplify/note.rb +0 -35
  112. data/book_code/simplify/note_spec.rb +0 -28
  113. data/book_code/simplify/swing_gui.rb +0 -45
  114. data/book_code/simplify/windows_gui.rb +0 -232
  115. data/book_code/simplify/windows_gui_spec.rb +0 -35
  116. data/book_code/story/invite.story +0 -19
  117. data/book_code/story/journal.txt +0 -29
  118. data/book_code/story/novite_stories.rb +0 -156
  119. data/book_code/story/party.rb +0 -149
  120. data/book_code/story/password.rb +0 -61
  121. data/book_code/story/password.story +0 -26
  122. data/book_code/story/rsvp.story +0 -29
  123. data/book_code/tables/TestTime.html +0 -93
  124. data/book_code/tables/TestTimeSample.html +0 -63
  125. data/book_code/tables/calculate_time.rb +0 -39
  126. data/book_code/tables/calculator.rb +0 -108
  127. data/book_code/tables/calculator_actions.rb +0 -27
  128. data/book_code/tables/calculator_spec.rb +0 -47
  129. data/book_code/tables/fit.rb +0 -32
  130. data/book_code/tables/matrix.rb +0 -109
  131. data/book_code/tables/pseudocode.rb +0 -17
  132. data/book_code/tubes/book_selenium.rb +0 -67
  133. data/book_code/tubes/book_watir.rb +0 -60
  134. data/book_code/tubes/dragdrop.html +0 -81
  135. data/book_code/tubes/html_capture.rb +0 -33
  136. data/book_code/tubes/joke_list.rb +0 -67
  137. data/book_code/tubes/list_spec.rb +0 -41
  138. data/book_code/tubes/search_spec.rb +0 -32
  139. data/book_code/tubes/selenium_example.rb +0 -66
  140. data/book_code/tubes/selenium_link.rb +0 -23
  141. data/book_code/tubes/web_server.rb +0 -14
  142. data/book_code/windows/wgui.rb +0 -29
  143. data/book_code/windows/wobj.rb +0 -25
  144. data/book_code/windows/wsh.rb +0 -25
  145. data/book_code/with_rspec/empty_spec.rb +0 -13
  146. data/book_code/with_rspec/junquenote.rb +0 -60
  147. data/book_code/with_rspec/locknote.rb +0 -129
  148. data/book_code/with_rspec/note_spec.rb +0 -32
  149. data/book_code/with_rspec/should_examples.rb +0 -18
  150. data/lib/note/java/jemmy.jar +0 -0
  151. data/lib/note/java/jnote.rb +0 -48
  152. data/lib/note/java/jruby_basics.rb +0 -37
  153. data/lib/note/java/junquenote_app.rb +0 -262
  154. data/lib/note/java/note_spec.rb +0 -20
  155. data/lib/note/win/locknote.rb +0 -19
  156. data/lib/note.rb +0 -15
  157. data/lib/win_gui/constants.rb +0 -82
  158. data/lib/win_gui/def_api.rb +0 -160
  159. data/lib/win_gui/string_extensions.rb +0 -36
  160. data/lib/win_gui/win_gui.rb +0 -437
  161. data/old/windows_basics.rb +0 -80
  162. data/old/wnote.rb +0 -80
  163. data/old/wnote_spec.rb +0 -20
  164. data/spec/note/win/locknote_spec.rb +0 -7
  165. data/spec/test_apps/locknote/LockNote.exe +0 -0
  166. data/spec/win_gui/def_api_spec.rb +0 -339
  167. data/spec/win_gui/string_extensions_spec.rb +0 -61
  168. data/spec/win_gui/win_gui_spec.rb +0 -537
  169. data/win_gui.gemspec +0 -215
data/.gitignore CHANGED
@@ -1,21 +1,21 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
-
21
- ## PROJECT::SPECIFIC
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/HISTORY ADDED
@@ -0,0 +1,7 @@
1
+ == 0.0.0 / 2010-01-08
2
+
3
+ * Birthday! Initial concept: Following "Scripted Gui testing with Ruby" by Ian Dees
4
+
5
+ == 0.2.0 / 2010-05-15
6
+
7
+ * Window class extracted into a separate lib
data/LICENSE CHANGED
@@ -1,20 +1,20 @@
1
- Copyright (c) 2009 arvicco
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ Copyright (c) 2010 Arvicco
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc CHANGED
@@ -1,114 +1,77 @@
1
- = win_gui
2
- by: Arvicco
3
- url: http://github.com/arvicco/win_gui
4
-
5
- == DESCRIPTION:
6
-
7
- WinGui is a module that provides convenient wrapper methods for multiple Win32 API
8
- functions (mostly from user32.dll) dealing with Windows GUI manipulation/automation.
9
- In addition to straightforward API wrappers, it also defines more Ruby-like
10
- abstractions and convenience methods for manipulating windows and other GUI
11
- elements (such as WinGui::Window class and its methods).
12
-
13
- !!! This project has been discontinued due to problems with Win32::API Callbacks and
14
- need to support non-MRI Ruby implementations. So, new project is now based on FFI and
15
- can be found here:http://github.com/arvicco/win (it is now available as a gem 'win').
16
-
17
- == SUMMARY
18
-
19
- So you want to write a simple program that makes some Win32 API function calls.
20
- You searched MSDN high and low and you now know exactly what functions you need.
21
- All you want is just putting those function calls into your Ruby code without too
22
- much pain. You'd love this to be more or less natural extension of your Ruby code,
23
- preferably not turning your code base into an ugly C++ like spaghetty
24
- of CamelCase calls, String/Array pack/unpack gymnastics, buffer allocations,
25
- extracting return values from [in/out] parameters and checking return codes for 0.
26
-
27
- You can definitely use excellent 'win32-api' gem by Daniel J. Berger and Park Heesob
28
- that allows you to define Win32 API objects for any function you can find on MSDN,
29
- execute calls on them and even define callback objects that some of those API functions expect.
30
-
31
- However, that gem will only take you so far. You'll still have to handle (somewhat)
32
- gory details of argument preparation, mimicking pointers with Strings and stuff.
33
- For example, consider the amount of code needed to complete a task as simple as
34
- getting unicode title text for the window that you already have handle for:
35
-
36
- api = Win32::API.new( 'GetWindowTextW', ['L', 'P', 'I'], 'L', 'user32' )
37
- buffer = "\x00" * 1024 # I just hope it will be enough...
38
- num_chars = api.call( window_handle, buffer, buffer.size)
39
- title = if num_chars == 0
40
- nil
41
- else
42
- buffer.force_encoding('utf-16LE').encode('utf-8').rstrip
43
- end
44
-
45
- Ew, ugly. What about getting information about process id for a known window?
46
-
47
- api = Win32::API.new( 'GetWindowThreadProcessId', ['L', 'P'], 'L' , 'user32' )
48
- process_packed = [1].pack('L')
49
- thread = api.call(window_handle, process_packed)
50
- process = process_packed.unpack('L').first
51
-
52
- Wow, packing and unpacking arrays into String to get hold of a simple integer id.
53
- Just great. Now, wouldn't it be MUCH better if you can just say something like this:
54
-
55
- title = window_text( window_handle)
56
- thread, process = window_thread_process_id( window_handle)
57
-
58
- What about API functions expecting callbacks? Well, something like this may be nice:
59
-
60
- enum_child_windows( parent_handle, message ){|child_handle, message| puts child_handle }
61
-
62
- If you think about it, callbacks are not much more than code blocks, so let's not be afraid
63
- to treat them as such. It would be also good if test functions return true/false instead of
64
- zero/nonzero, find functions return nil if nothing was found etc...
65
-
66
- So this is an idea behind WinGui library - make Win32 API functions more fun to use
67
- and feel more natural inside Ruby code. Following the principle of least surprise, we
68
- define methods with Rubyesque names (minimized? instead of IsMinimized, etc), minimum
69
- arguments with sensible defaults, explicit return values and generous use of attached blocks.
70
-
71
- Well, we even keep a backup solution for those diehard Win32 API longtimers who would rather
72
- allocate their buffer strings by hand and mess with obscure return codes. If you use original
73
- CamelCase method name instead of Rubyesque snake_case one, it will expect those standard
74
- parameters you know and love from MSDN, return your zeroes instead of nils and support no
75
- other enhancements.
76
-
77
- And if you do not see your favorite Windows API function amoung those already defined, it is
78
- quite easy to define new one with def_api class method that does a lot of heavy lifting for
79
- you and can be customized with options and code blocks to give you reusable API wrapper method
80
- with the exact behavior you need.
81
-
82
- == DOCUMENTATION:
83
-
84
- See WinGui and WinGui::Window for documentation
85
-
86
- == REQUIREMENTS:
87
-
88
- Only works with Ruby 1.9.1+ since it uses some of the most recent features (block
89
- arguments given to block, etc...)
90
-
91
- == FEATURES/PROBLEMS:
92
-
93
- This project is quite new, so it may be not suitable for production-quality systems yet.
94
- Contributors always welcome!
95
-
96
- == INSTALL:
97
-
98
- $ sudo gem install win_gui
99
-
100
- == SYNOPSIS:
101
-
102
- require 'win_gui'
103
- include WinGui
104
-
105
- More examples will follow when the code is closer to production quality...
106
-
107
- == CREDITS:
108
-
109
- This library started as an extension of ideas and code described in excellent book
110
- "Scripted GUI Testing with Ruby" by Ian Dees.
111
-
112
- == LICENSE:
113
-
114
- Copyright (c) 2009 Arvicco. See LICENSE for details
1
+ = win_gui
2
+ by:: Arvicco
3
+ url:: http://github.com/arvicco/win_gui
4
+
5
+ == DESCRIPTION:
6
+
7
+ WinGui is a module that provides higher-level abstractions/wrappers around GUI-related
8
+ Win32 API functions. It uses Win gem as a basis, which in turn uses FFI.
9
+ So (in theory) it should work for any Ruby implementation supporting FFI. In practice,
10
+ it's only been tested under mingw and cygwin flavors of Ruby 1.9.1.
11
+
12
+ == SUMMARY:
13
+
14
+ Win gem provides Rubyesque wrappers around Win32 API functions, but it is not enough to
15
+ to make Win32 API calls feel like more or less natural extension of Ruby code.
16
+ The reason for this, straightforward API wrappers are not object-oriented enough.
17
+
18
+ For example, here is how you deal with typical GUI-related tasks using Win:
19
+
20
+ require 'win/gui'
21
+ include Win::Gui::Window
22
+
23
+ window_handle = find_window('WinClass', nil)
24
+ title = window_text(window_handle )
25
+ thread, process = window_thread_process_id(window_handle)
26
+ puts window_handle, title, thread, process
27
+
28
+ enum_child_windows(window_handle, message) do |child_handle, message|
29
+ title = window_text(child_handle )
30
+ thread, process = window_thread_process_id(child_handle)
31
+ puts child_handle, title, thread, process
32
+ end
33
+ close_window(window_handle)
34
+
35
+ Ideally, there should be a thin wrapper class around window handle, and the code above should be more like this:
36
+ require 'win_gui'
37
+ include WinGui
38
+
39
+ window = Window.find(:first, :class => 'WinClass')
40
+ puts window.handle, window.title, window.thread, window.process
41
+ window.each_child {|child| puts child.handle, child.title, child.thread, child.process }
42
+ window.close
43
+
44
+ This library will try to provide such wrappers and convenience methods that will make working with
45
+ Windows GUI-related code much more fun than it is right now.
46
+
47
+ == REQUIREMENTS:
48
+
49
+ Only works with Ruby 1.9.1+ compatible implementations since Win gem uses some of latest Ruby features.
50
+
51
+ == FEATURES/PROBLEMS:
52
+
53
+ This project is quite new, so it may be not suitable for production-quality systems yet.
54
+ Contributors always welcome!
55
+
56
+ == INSTALL:
57
+
58
+ $ sudo gem install win_gui
59
+
60
+ == SYNOPSIS:
61
+
62
+ require 'win_gui'
63
+ include WinGui
64
+
65
+ More examples will follow when the code is closer to production quality...
66
+
67
+ == CREDITS/PRIOR ART:
68
+
69
+ This library started as an extension of ideas and code described in excellent book
70
+ "Scripted GUI Testing with Ruby" by Ian Dees.
71
+
72
+ Win32::GuiTest by MoonWolf is a port of eponimous Perl library to Ruby
73
+ (http://raa.ruby-lang.org/project/win32-guitest). I do not like its Perlisms though.
74
+
75
+ == LICENSE:
76
+
77
+ Copyright (c) 2010 Arvicco. See LICENSE for details
data/Rakefile CHANGED
@@ -1,58 +1,24 @@
1
- require 'rubygems'
2
- require 'rake'
3
-
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "win_gui"
8
- gem.summary = %Q{Rubyesque interfaces and wrappers for Win32 API GUI functions}
9
- gem.description = %Q{Rubyesque interfaces and wrappers for Win32 API GUI functions}
10
- gem.email = "arvitallian@gmail.com"
11
- gem.homepage = "http://github.com/arvicco/win_gui"
12
- gem.authors = ["arvicco"]
13
- gem.add_dependency "win32-api", ">= 1.4.5"
14
- gem.add_development_dependency "rspec", ">= 1.2.9"
15
- gem.add_development_dependency "cucumber", ">= 0"
16
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
- end
18
- Jeweler::GemcutterTasks.new
19
- rescue LoadError
20
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
21
- end
22
-
23
- require 'spec/rake/spectask'
24
- Spec::Rake::SpecTask.new(:spec) do |spec|
25
- spec.libs << 'lib' << 'spec'
26
- spec.spec_files = FileList['spec/**/*_spec.rb']
27
- end
28
-
29
- Spec::Rake::SpecTask.new(:rcov) do |spec|
30
- spec.libs << 'lib' << 'spec'
31
- spec.pattern = 'spec/**/*_spec.rb'
32
- spec.rcov = true
33
- end
34
-
35
- task :spec => :check_dependencies
36
-
37
- begin
38
- require 'cucumber/rake/task'
39
- Cucumber::Rake::Task.new(:features)
40
-
41
- task :features => :check_dependencies
42
- rescue LoadError
43
- task :features do
44
- abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
45
- end
46
- end
47
-
48
- task :default => :spec
49
-
50
- require 'rake/rdoctask'
51
- Rake::RDocTask.new do |rdoc|
52
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
53
-
54
- rdoc.rdoc_dir = 'rdoc'
55
- rdoc.title = "win_gui #{version}"
56
- rdoc.rdoc_files.include('README*')
57
- rdoc.rdoc_files.include('lib/**/*.rb')
58
- end
1
+ require 'pathname'
2
+ NAME = 'win_gui'
3
+ BASE_PATH = Pathname.new(__FILE__).dirname
4
+ LIB_PATH = BASE_PATH + 'lib'
5
+ PKG_PATH = BASE_PATH + 'pkg'
6
+ DOC_PATH = BASE_PATH + 'rdoc'
7
+
8
+ $LOAD_PATH.unshift LIB_PATH.to_s
9
+ require 'version'
10
+
11
+ CLASS_NAME = WinGui
12
+ VERSION = CLASS_NAME::VERSION
13
+
14
+ begin
15
+ require 'rake'
16
+ rescue LoadError
17
+ require 'rubygems'
18
+ gem 'rake', '~> 0.8.3.1'
19
+ require 'rake'
20
+ end
21
+
22
+ # Load rakefile tasks
23
+ Dir['tasks/*.rake'].sort.each { |file| load file }
24
+
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.6
1
+ 0.2.0
@@ -1,4 +1,7 @@
1
- $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
2
- require 'win_gui'
3
-
4
- require 'spec/expectations'
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
2
+ require 'win_gui'
3
+ require 'spec/expectations'
4
+ require 'spec/stubs/cucumber'
5
+
6
+ require 'pathname'
7
+ BASE_PATH = Pathname.new(__FILE__).dirname + '../..'
@@ -1,9 +1,9 @@
1
- Feature: something something
2
- In order to something something
3
- A user something something
4
- something something something
5
-
6
- Scenario: something something
7
- Given inspiration
8
- When I create a sweet new gem
9
- Then everyone should see how awesome I am
1
+ Feature: something something
2
+ In order to something something
3
+ A user something something
4
+ something something something
5
+
6
+ Scenario: something something
7
+ Given inspiration
8
+ When I create a sweet new gem
9
+ Then everyone should see how awesome I am
data/lib/version.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'pathname'
2
+
3
+ module WinGui
4
+
5
+ VERSION_FILE = Pathname.new(__FILE__).dirname + '../VERSION' # :nodoc:
6
+ VERSION = VERSION_FILE.exist? ? VERSION_FILE.read.strip : nil
7
+
8
+ end
@@ -1,70 +1,79 @@
1
- module WinGui
2
- class Window
3
- include WinGui
4
- extend WinGui
5
-
6
- attr_reader :handle
7
-
8
- # find top level window by title, return wrapped Window object
9
- def self.top_level(title, seconds=3)
10
- @handle = timeout(seconds) do
11
- sleep WG_SLEEP_DELAY while (h = find_window nil, title) == nil; h
12
- end
13
- Window.new @handle
14
- end
15
-
16
- def initialize(handle)
17
- @handle = handle
18
- end
19
-
20
- # find child window (control) by title, window class, or control ID:
21
- def child(id)
22
- result = case id
23
- when String
24
- by_title = find_window_ex @handle, 0, nil, id.gsub('_' , '&' )
25
- by_class = find_window_ex @handle, 0, id, nil
26
- by_title ? by_title : by_class
27
- when Fixnum
28
- get_dlg_item @handle, id
29
- when nil
30
- find_window_ex @handle, 0, nil, nil
31
- else
32
- nil
33
- end
34
- raise "Control '#{id}' not found" unless result
35
- Window.new result
36
- end
37
-
38
- def children
39
- enum_child_windows(@handle,'Msg').map{|child_handle| Window.new child_handle}
40
- end
41
-
42
- # emulate click of the control identified by id
43
- def click(id)
44
- h = child(id).handle
45
- rectangle = [0, 0, 0, 0].pack 'LLLL'
46
- get_window_rect h, rectangle
47
- left, top, right, bottom = rectangle.unpack 'LLLL'
48
- center = [(left + right) / 2, (top + bottom) / 2]
49
- set_cursor_pos *center
50
- mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
51
- mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
52
- end
53
-
54
- def close
55
- post_message @handle, WM_SYSCOMMAND, SC_CLOSE, 0
56
- end
57
-
58
- def wait_for_close
59
- timeout(WG_CLOSE_TIMEOUT) do
60
- sleep WG_SLEEP_DELAY while window_visible?(@handle)
61
- end
62
- end
63
-
64
- def text
65
- buffer = "\x0" * 2048
66
- length = send_message @handle, WM_GETTEXT, buffer.length, buffer
67
- length == 0 ? '' : buffer[0..length - 1]
68
- end
69
- end
1
+ require 'win/gui'
2
+
3
+ module WinGui
4
+ # Delay between key commands (events)
5
+ WG_KEY_DELAY = 0.00001
6
+ # Wait delay quant
7
+ WG_SLEEP_DELAY = 0.001
8
+ # Timeout waiting for Window to be closed
9
+ WG_CLOSE_TIMEOUT = 1
10
+
11
+ class Window
12
+ include Win::Gui
13
+ extend Win::Gui
14
+
15
+ def initialize(handle)
16
+ @handle = handle
17
+ end
18
+
19
+ attr_reader :handle
20
+
21
+ # find top level window by title, return wrapped Window object
22
+ def self.top_level(title, seconds=3)
23
+ @handle = timeout(seconds) do
24
+ sleep WG_SLEEP_DELAY while (h = find_window nil, title) == nil; h
25
+ end
26
+ Window.new @handle
27
+ end
28
+
29
+ # find child window (control) by title, window class, or control ID:
30
+ def child(id)
31
+ result = case id
32
+ when String
33
+ by_title = find_window_ex @handle, 0, nil, id.gsub('_' , '&' )
34
+ by_class = find_window_ex @handle, 0, id, nil
35
+ by_title ? by_title : by_class
36
+ when Fixnum
37
+ get_dlg_item @handle, id
38
+ when nil
39
+ find_window_ex @handle, 0, nil, nil
40
+ else
41
+ nil
42
+ end
43
+ raise "Control '#{id}' not found" unless result
44
+ Window.new result
45
+ end
46
+
47
+ def children
48
+ enum_child_windows(@handle).map{|child_handle| Window.new child_handle}
49
+ end
50
+
51
+ # emulate click of the control identified by id
52
+ def click(id)
53
+ h = child(id).handle
54
+ rectangle = [0, 0, 0, 0].pack 'LLLL'
55
+ get_window_rect h, rectangle
56
+ left, top, right, bottom = rectangle.unpack 'LLLL'
57
+ center = [(left + right) / 2, (top + bottom) / 2]
58
+ set_cursor_pos *center
59
+ mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
60
+ mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
61
+ end
62
+
63
+ def close
64
+ post_message @handle, WM_SYSCOMMAND, SC_CLOSE, nil
65
+ end
66
+
67
+ def wait_for_close
68
+ timeout(WG_CLOSE_TIMEOUT) do
69
+ sleep WG_SLEEP_DELAY while window_visible?(@handle)
70
+ end
71
+ end
72
+
73
+ def text
74
+ buffer = "\x0" * 2048
75
+ length = send_message @handle, WM_GETTEXT, buffer.length, buffer
76
+ length == 0 ? '' : buffer[0..length - 1]
77
+ end
78
+ end
70
79
  end
data/lib/win_gui.rb CHANGED
@@ -1,3 +1,25 @@
1
- win_gui_dir = File.join(File.dirname(__FILE__),"win_gui" )
2
- $LOAD_PATH.unshift win_gui_dir unless $LOAD_PATH.include?(win_gui_dir)
3
- require 'win_gui'
1
+ require 'version'
2
+
3
+ module WinGui
4
+
5
+ # require "bundler"
6
+ # Bundler.setup
7
+
8
+ # Requires ruby source file(s). Accepts either single filename/glob or Array of filenames/globs.
9
+ # Accepts following options:
10
+ # :*file*:: Lib(s) required relative to this file - defaults to __FILE__
11
+ # :*dir*:: Required lib(s) located under this dir name - defaults to gem name
12
+ #
13
+ def self.require_libs( libs, opts={} )
14
+ file = Pathname.new(opts[:file] || __FILE__)
15
+ [libs].flatten.each do |lib|
16
+ name = file.dirname + (opts[:dir] || file.basename('.*')) + lib.gsub(/(?<!.rb)$/, '.rb')
17
+ Pathname.glob(name.to_s).sort.each {|rb| require rb}
18
+ end
19
+ end
20
+ end # module WinGui
21
+
22
+ # Require all ruby source files located under directory lib/win_gui
23
+ # If you need files in specific order, you should specify it here before the glob
24
+ WinGui.require_libs %W[**/*]
25
+
data/spec/spec.opts CHANGED
@@ -1,2 +1,2 @@
1
- --color
1
+ --color
2
2
  --format nested