au3 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -83,7 +83,7 @@ module AutoItX3
83
83
  INTDEFAULT = -2147483647
84
84
 
85
85
  #The version of this au3 library.
86
- VERSION = "0.1.0"
86
+ VERSION = "0.1.1"
87
87
 
88
88
  #This is the buffer size used for AutoItX3's text "returning" functions.
89
89
  #It will be subtracted by 1 due to the trailing 0 of wchar_t * type strings.
@@ -112,10 +112,12 @@ module AutoItX3
112
112
  "WinWaitDelay" => 250
113
113
  }
114
114
 
115
+ #All yet assigned functions.
115
116
  def self.functions
116
117
  @functions
117
118
  end
118
119
 
120
+ #Reset all functions to the given hash.
119
121
  def self.functions=(val)
120
122
  @functions = val
121
123
  end
@@ -40,10 +40,12 @@ module AutoItX3
40
40
  #the window holding the control (or "" if you don't want to specify one of them)
41
41
  #and the ID of the control. Instead of the ID you may use the name of the
42
42
  #control in combination width the occurence number of it, like "Edit1" and "Edit2".
43
+ #Raises an Au3Error if the control doesn't exist.
43
44
  def initialize(title, text, control_id)
44
45
  @title = title
45
46
  @text = text
46
47
  @c_id = control_id.to_s
48
+ visible? #Raises an error if the control doesn't exist
47
49
  end
48
50
 
49
51
  #Clicks +self+ with the given mouse +button+ (<tt>"Primary"</tt> by default)
@@ -183,12 +185,12 @@ module AutoItX3
183
185
 
184
186
  #Returns wheather or not a control is visible.
185
187
  def visible?
186
- send_command_to_control("IsVisible") == 1
188
+ send_command_to_control("IsVisible").to_i == 1
187
189
  end
188
190
 
189
191
  #Returns true if a control can interact with the user (i.e. it's not "grayed out").
190
192
  def enabled?
191
- send_command_to_control("IsEnabled") == 1
193
+ send_command_to_control("IsEnabled").to_i == 1
192
194
  end
193
195
 
194
196
  private
@@ -161,6 +161,37 @@ module AutoItX3
161
161
  @functions[__method__].call(keys.wide, flag)
162
162
  end
163
163
 
164
+ #Allows you to do things like
165
+ # AutoItX3.ctrl_c
166
+ #.Every _ will be used to separate a key press from another, so
167
+ #you can't send _ with this function. Possible shortcuts are:
168
+ #* ctrl
169
+ #* shift
170
+ #* alt
171
+ #* win
172
+ #* enter (or return)
173
+ #* del
174
+ #This text sequences can't be sent, too.
175
+ def method_missing(sym, *args, &block)
176
+ super if !args.empty? or block
177
+ cmds = sym.to_s.split("_")
178
+ callsequence = ""
179
+ cmds.each do |cmd|
180
+ callsequence << case cmd.downcase
181
+ when "ctrl" then "^"
182
+ when "shift" then "+"
183
+ when "alt" then "!"
184
+ when "win" then "#"
185
+ when "enter" then "{ENTER}"
186
+ when "return" then "{ENTER}"
187
+ when "del" then "{DEL}"
188
+ else
189
+ cmd
190
+ end
191
+ end
192
+ send_keys(callsequence)
193
+ end
194
+
164
195
  end
165
196
 
166
197
  end
@@ -1,5 +1,15 @@
1
1
  =History of au3
2
- Important changes are marked <b>bold</b>.
2
+ Important changes are marked <b>bold</b>. Bugfixes are written <i>italic</i>.
3
+ ==0.1.1
4
+ * Corrected documentation main page set by the Rakefile
5
+ * <b>Added ##method_missing to the AutoItX3 module to allow shortcuts like <tt>AutoItX3.ctrl_c</tt>. </b>
6
+ * Renamed test_tray.rb to test_misc.rb
7
+ * Added sleep test
8
+ * <i>Control#enabled? and Control#visible? never returned true. This has been fixed. </i>
9
+ * Added a control test
10
+ * Added a test for the ::set_option method.
11
+ * Added a test for the ::method_missing shortcut trick
12
+
3
13
  ==0.1.0
4
14
  * <b>Changed the API to use win32-api now instead of a C extension</b>
5
15
  * <b>Added wide, wide!, normal and normal! to Ruby's String class</b>
@@ -21,7 +21,7 @@ bin directory. If you want to deploy your program, the final recipient need not
21
21
  to have AutoIt installed - it's enough if you just include the AutoItX3.dll in your
22
22
  application (and make sure you've read the AutoItX3 license - it's quite short).
23
23
  ==Usage
24
- The majority of +au3+'s methods is bundled the AutoItX3 module
24
+ The majority of +au3+'s methods is bundled in the AutoItX3 module
25
25
  and accessable via it's module methods. In order to get them,
26
26
  just require +au3+:
27
27
  require "au3"
@@ -0,0 +1,68 @@
1
+ #Encoding: Windows-1252
2
+ #This file is part of au3.
3
+ #Copyright (c) 2009 Marvin G�lker
4
+ begin
5
+ require_relative "../lib/au3"
6
+ rescue LoadError
7
+ #Aha, this is the gem, not the build environment
8
+ require "au3"
9
+ end
10
+ require "test/unit"
11
+
12
+ class ControlTest < Test::Unit::TestCase
13
+
14
+ def setup
15
+ AutoItX3::Window.new(AutoItX3::Window::DESKTOP_WINDOW).activate #Needed, because Win+R is "eaten" by a console window
16
+ AutoItX3.send_keys("#r")
17
+ sleep 1 #I can't ise Window.wait here, because the window has a different title in different languages
18
+ @run_window = AutoItX3::Window.new(AutoItX3::Window::ACTIVE_WINDOW)
19
+ @edit = AutoItX3::Edit.from_control(@run_window.focused_control)
20
+ end
21
+
22
+ def teardown
23
+ @run_window.close
24
+ end
25
+
26
+ def test_from_control
27
+ AutoItX3.send_keys("Test")
28
+ assert_equal("Test", @edit.text)
29
+ end
30
+
31
+ def test_new
32
+ AutoItX3.send_keys("Test")
33
+ edit = AutoItX3::Edit.new(@run_window.title, "", "Edit1")
34
+ assert_equal("Test", edit.text)
35
+ end
36
+
37
+ def test_disable
38
+ @edit.disable
39
+ sleep 0.2
40
+ assert(!@edit.enabled?)
41
+ sleep 1
42
+ @edit.enable
43
+ sleep 0.2
44
+ assert(@edit.enabled?)
45
+ end
46
+
47
+ def test_hide
48
+ @edit.hide
49
+ sleep 0.2
50
+ assert(!@edit.visible?)
51
+ sleep 1
52
+ @edit.show
53
+ sleep 0.2
54
+ assert(@edit.visible?)
55
+ end
56
+
57
+ def test_set_text
58
+ @edit.text = "Test"
59
+ AutoItX3.ctrl_a
60
+ AutoItX3.ctrl_c
61
+ assert_equal("Test", AutoItX3.cliptext)
62
+ end
63
+
64
+ def test_nonexistant
65
+ assert_raise(AutoItX3::Au3Error){AutoItX3::Control.new(@run_window.title, "", "Nonexistant")}
66
+ end
67
+
68
+ end
@@ -58,4 +58,13 @@ class KeyboardTest < Test::Unit::TestCase
58
58
  assert_equal(TEXT3, AutoItX3.cliptext)
59
59
  end
60
60
 
61
+ def test_shortcuts
62
+ AutoItX3.send_keys(TEXT1)
63
+ AutoItX3.ctrl_a
64
+ AutoItX3.msleep(200)
65
+ AutoItX3.ctrl_c
66
+ AutoItX3.msleep(200)
67
+ assert_equal(TEXT1, AutoItX3.cliptext)
68
+ end
69
+
61
70
  end
@@ -0,0 +1,48 @@
1
+ #Encoding: UTF-8
2
+ #This file is part of au3.
3
+ #Copyright (c) 2009 Marvin Gülker
4
+ begin
5
+ require_relative "../lib/au3"
6
+ rescue LoadError
7
+ #Aha, this is the gem, not the build environment
8
+ require "au3"
9
+ end
10
+ require "test/unit"
11
+
12
+ class MiscTest < Test::Unit::TestCase
13
+
14
+ TEST_TRAY = "E:"
15
+
16
+ def test_cd_open
17
+ assert(AutoItX3.open_cd_tray(TEST_TRAY))
18
+ end
19
+
20
+ def test_cd_close
21
+ AutoItX3.open_cd_tray(TEST_TRAY)
22
+ if !AutoItX3.close_cd_tray(TEST_TRAY)
23
+ notify "Could not close your CD tray. Are you running on a laptop?"
24
+ else
25
+ assert(true)
26
+ end
27
+ end
28
+
29
+ def test_sleep
30
+ than = Time.now
31
+ AutoItX3.msleep(1000)
32
+ now = Time.now
33
+ assert_in_delta(1.0, now - than, 0.01)
34
+ end
35
+
36
+ def test_opt
37
+ AutoItX3.run("mspaint.exe")
38
+ AutoItX3.opt("WinTitleMatchMode", 2) do
39
+ assert(AutoItX3::Window.wait("Paint", "", 3)) #Timeout means false
40
+ end
41
+ assert_equal(false, AutoItX3::Window.wait("Paint", "", 3))
42
+ AutoItX3.set_option("WinTitleMatchMode", 2)
43
+ assert(AutoItX3::Window.wait("Paint", "", 3))
44
+ AutoItX3.opt("WinTitleMatchMode", 1)
45
+ assert_equal(false, AutoItX3::Window.wait("Paint", "", 3))
46
+ end
47
+
48
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: au3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marvin Guelker
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-10 00:00:00 +02:00
12
+ date: 2009-12-27 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -24,7 +24,7 @@ dependencies:
24
24
  version:
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: test-unit
27
- type: :runtime
27
+ type: :development
28
28
  version_requirement:
29
29
  version_requirements: !ruby/object:Gem::Requirement
30
30
  requirements:
@@ -43,11 +43,12 @@ extra_rdoc_files: []
43
43
 
44
44
  files:
45
45
  - test/test_clipboard.rb
46
+ - test/test_control.rb
46
47
  - test/test_ini.rb
47
48
  - test/test_keyboard.rb
49
+ - test/test_misc.rb
48
50
  - test/test_mouse.rb
49
51
  - test/test_process.rb
50
- - test/test_tray.rb
51
52
  - test/test_window.rb
52
53
  - lib/HISTORY.rdoc
53
54
  - lib/README.rdoc
@@ -62,13 +63,15 @@ files:
62
63
  - lib/AutoItX3/process.rb
63
64
  - lib/AutoItX3/window.rb
64
65
  has_rdoc: true
65
- homepage:
66
+ homepage: http://wiki.github.com/Quintus/Automations
66
67
  licenses: []
67
68
 
68
69
  post_install_message:
69
70
  rdoc_options:
70
- - " -m 'lib/README.rdoc'"
71
- - -t 'au3 RDocs'
71
+ - --title
72
+ - au3 RDocs
73
+ - --main
74
+ - lib/README.rdoc
72
75
  require_paths:
73
76
  - lib
74
77
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -93,9 +96,10 @@ specification_version: 3
93
96
  summary: A binding to the AutoItX3 Windows automation tool.
94
97
  test_files:
95
98
  - test/test_clipboard.rb
99
+ - test/test_control.rb
96
100
  - test/test_ini.rb
97
101
  - test/test_keyboard.rb
102
+ - test/test_misc.rb
98
103
  - test/test_mouse.rb
99
104
  - test/test_process.rb
100
- - test/test_tray.rb
101
105
  - test/test_window.rb
@@ -1,29 +0,0 @@
1
- #Encoding: Windows-1252
2
- #This file is part of au3.
3
- #Copyright (c) 2009 Marvin G�lker
4
- begin
5
- require_relative "../lib/au3"
6
- rescue LoadError
7
- #Aha, this is the gem, not the build environment
8
- require "au3"
9
- end
10
- require "test/unit"
11
-
12
- class CDTrayTest < Test::Unit::TestCase
13
-
14
- TEST_TRAY = "E:"
15
-
16
- def test_open
17
- assert(AutoItX3.open_cd_tray(TEST_TRAY))
18
- end
19
-
20
- def test_close
21
- AutoItX3.open_cd_tray(TEST_TRAY)
22
- if !AutoItX3.close_cd_tray(TEST_TRAY)
23
- notify "Could not close your CD tray. Are you running on a laptop?"
24
- else
25
- assert(true)
26
- end
27
- end
28
-
29
- end