sikulix 1.1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/sikulix.rb +4 -0
- data/lib/sikulix/platform.rb +20 -0
- data/lib/sikulix/sikulix.rb +249 -0
- metadata +47 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a7c4359e746a37ba626adf4cb83f74d09d30732c
|
4
|
+
data.tar.gz: 14ce0e756ad42ee1ed80322c79a5e65b61d810e4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 51f964e357683a1f5f770571760ee2c7ba76b7beea5dfb9eba2878d6d8319a2fac683361e1173b3346afee1bd18f886d6d547dca546ee392ccb141699f38a9cf
|
7
|
+
data.tar.gz: dc9500381e9abc84b251f3f695bc9606005d169358368d3cd3ca7654c4849cef027453905f979b34f30d6bf98e79bcf5c207f824cedff43d343d2fe833fdcb37
|
data/lib/sikulix.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'java'
|
2
|
+
|
3
|
+
module Sikulix
|
4
|
+
class Platform
|
5
|
+
def self.check_and_require
|
6
|
+
begin
|
7
|
+
# check running from IDE
|
8
|
+
java_import org.sikuli.basics.Sikulix
|
9
|
+
rescue
|
10
|
+
# check external jar
|
11
|
+
sikulix_path = (ENV['SIKULIXAPI_JAR'] || ENV['SIKULIX_HOME'] || "").chomp(' ')
|
12
|
+
unless File.exist? sikulix_path
|
13
|
+
raise LoadError, "Failed to load #{sikulix_path}\nMake sure SIKULIXAPI_JAR is set!"
|
14
|
+
end
|
15
|
+
require sikulix_path
|
16
|
+
end
|
17
|
+
return true
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,249 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# SikuliX for Ruby
|
3
|
+
|
4
|
+
require 'java'
|
5
|
+
|
6
|
+
# Classes and methods for using SikuliX
|
7
|
+
module Sikulix
|
8
|
+
private
|
9
|
+
|
10
|
+
# 'private' for avoiding of unexpected effects when
|
11
|
+
# 'include Sikulix' is used.
|
12
|
+
|
13
|
+
java_import org.sikuli.basics.Sikulix
|
14
|
+
java_import org.sikuli.script.Screen
|
15
|
+
java_import org.sikuli.script.Region
|
16
|
+
java_import org.sikuli.script.ScreenUnion
|
17
|
+
|
18
|
+
java_import org.sikuli.script.Observing
|
19
|
+
java_import org.sikuli.script.ObserverCallBack
|
20
|
+
|
21
|
+
java_import org.sikuli.script.Constants
|
22
|
+
java_import org.sikuli.script.Finder
|
23
|
+
java_import org.sikuli.script.ImageFinder
|
24
|
+
java_import org.sikuli.script.ImageFind
|
25
|
+
|
26
|
+
java_import org.sikuli.script.Button
|
27
|
+
java_import org.sikuli.basics.OS
|
28
|
+
|
29
|
+
java_import org.sikuli.script.Match
|
30
|
+
java_import org.sikuli.script.Pattern
|
31
|
+
java_import org.sikuli.script.Location
|
32
|
+
|
33
|
+
java_import org.sikuli.script.ImagePath
|
34
|
+
java_import org.sikuli.script.Image
|
35
|
+
java_import org.sikuli.script.ImageGroup
|
36
|
+
|
37
|
+
java_import org.sikuli.script.App
|
38
|
+
java_import org.sikuli.script.Key
|
39
|
+
java_import org.sikuli.script.KeyModifier
|
40
|
+
java_import org.sikuli.script.Mouse
|
41
|
+
java_import org.sikuli.script.Keys
|
42
|
+
|
43
|
+
java_import org.sikuli.basics.Settings
|
44
|
+
java_import org.sikuli.basics.ExtensionManager
|
45
|
+
|
46
|
+
java_import org.sikuli.script.compare.DistanceComparator
|
47
|
+
java_import org.sikuli.script.compare.VerticalComparator
|
48
|
+
java_import org.sikuli.script.compare.HorizontalComparator
|
49
|
+
|
50
|
+
java_import org.sikuli.basics.SikuliScript
|
51
|
+
|
52
|
+
java_import org.sikuli.basics.Debug
|
53
|
+
|
54
|
+
#
|
55
|
+
# This method generates a wrapper for Java Native exception processing
|
56
|
+
# in native java methods. It allows to detect a line number in script
|
57
|
+
# that opened in IDE where the exception was appearing.
|
58
|
+
#
|
59
|
+
# obj - class for the wrapping
|
60
|
+
# methods_array - array of method names as Symbols
|
61
|
+
def self.native_exception_protect(obj, methods_array)
|
62
|
+
methods_array.each do |name|
|
63
|
+
m = obj.instance_method name
|
64
|
+
obj.class_exec do
|
65
|
+
alias_method(('java_' + name.to_s).to_sym, name)
|
66
|
+
define_method(name) do |*args|
|
67
|
+
begin
|
68
|
+
# java specific call for unbound methods
|
69
|
+
m.bind(self).call(*args)
|
70
|
+
rescue NativeException => e
|
71
|
+
raise StandardError, e.message
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# Dynamic method definition for several cases of invocation
|
79
|
+
def self.dynamic_def(name, &block)
|
80
|
+
# using as:
|
81
|
+
# include Sikulix
|
82
|
+
# some_method(...)
|
83
|
+
define_method(name, &block)
|
84
|
+
# using as:
|
85
|
+
# Sikulix::some_method(...)
|
86
|
+
define_singleton_method(name, &block)
|
87
|
+
|
88
|
+
# private method to avoid of attachment to all subclasses
|
89
|
+
private name
|
90
|
+
end
|
91
|
+
|
92
|
+
# Redefinition of native org.sikuli.script.Region class
|
93
|
+
class Region
|
94
|
+
# Service class for all callbacks processing
|
95
|
+
class RObserverCallBack < ObserverCallBack # :nodoc: all
|
96
|
+
def initialize(block)
|
97
|
+
super()
|
98
|
+
@block = block
|
99
|
+
end
|
100
|
+
%w(appeared vanished changed).each do |name|
|
101
|
+
define_method(name) do |*args|
|
102
|
+
@block.call(*(args.first @block.arity))
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
alias_method :java_onAppear, :onAppear
|
107
|
+
alias_method :java_onVanish, :onVanish
|
108
|
+
alias_method :java_onChange, :onChange
|
109
|
+
|
110
|
+
# Redefinition of the java method for Ruby specific
|
111
|
+
def onAppear(target, &block)
|
112
|
+
java_onAppear target, RObserverCallBack.new(block)
|
113
|
+
end
|
114
|
+
|
115
|
+
# Redefinition of the java method for Ruby specific
|
116
|
+
def onVanish(target, &block)
|
117
|
+
java_onVanish target, RObserverCallBack.new(block)
|
118
|
+
end
|
119
|
+
|
120
|
+
# Redefinition of the java method for Ruby specific
|
121
|
+
def onChange(&block)
|
122
|
+
java_onChange RObserverCallBack.new(block)
|
123
|
+
end
|
124
|
+
|
125
|
+
# alias_method :java_findAll, :findAll
|
126
|
+
# def findAll(*args)
|
127
|
+
# begin
|
128
|
+
# java_findAll(*args)
|
129
|
+
# rescue NativeException => e; raise e.message; end
|
130
|
+
# end
|
131
|
+
end
|
132
|
+
|
133
|
+
# Wrap following java-methods by an exception processor
|
134
|
+
native_exception_protect(
|
135
|
+
Region,
|
136
|
+
[:find, :findAll, :wait, :waitVanish, :exists,
|
137
|
+
:click, :doubleClick, :rightClick, :hover, :dragDrop,
|
138
|
+
:type, :paste, :observe]
|
139
|
+
)
|
140
|
+
|
141
|
+
# Default screen object for "undotted" methods.
|
142
|
+
$SIKULI_SCREEN = Screen.new
|
143
|
+
|
144
|
+
# This is an alternative for method generation using define_method
|
145
|
+
# # Generate hash of ('method name'=>method)
|
146
|
+
# # for all possible "undotted" methods.
|
147
|
+
# UNDOTTED_METHODS =
|
148
|
+
# [$SIKULI_SCREEN, Sikulix].reduce({}) do |h, obj|
|
149
|
+
# h.merge!(
|
150
|
+
# obj.methods.reduce({}) do |h2, name|
|
151
|
+
# h2.merge!(name => obj.method(name))
|
152
|
+
# end
|
153
|
+
# )
|
154
|
+
# end
|
155
|
+
|
156
|
+
# It makes possible to use java-constants as a methods
|
157
|
+
# Example: Key.CTRL instead of Key::CTRL
|
158
|
+
[Key, KeyModifier].each do |obj|
|
159
|
+
obj.class_exec do
|
160
|
+
def self.method_missing(name)
|
161
|
+
if (val = const_get(name))
|
162
|
+
return val
|
163
|
+
end
|
164
|
+
fails "method missing #{name}"
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
# Generate static methods in Sikulix context
|
170
|
+
# for possible "undotted" methods.
|
171
|
+
[$SIKULI_SCREEN, Sikulix].each do |obj|
|
172
|
+
mtype = (obj.class == Class ? :java_class_methods : :java_instance_methods)
|
173
|
+
obj.java_class.method(mtype).call.map(&:name).uniq.each do |name|
|
174
|
+
obj_meth = obj.method(name)
|
175
|
+
dynamic_def(name) { |*args, &block| obj_meth.call(*args, &block) }
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
# Display some help in interactive mode.
|
180
|
+
def shelp
|
181
|
+
SikuliScript.shelp
|
182
|
+
end
|
183
|
+
|
184
|
+
# TODO: check it after Env Java-class refactoring
|
185
|
+
java_import org.sikuli.script.Env
|
186
|
+
java_import org.sikuli.basics.HotkeyListener
|
187
|
+
|
188
|
+
class Env # :nodoc: all
|
189
|
+
class RHotkeyListener < HotkeyListener
|
190
|
+
def initialize(block)
|
191
|
+
super()
|
192
|
+
@block = block
|
193
|
+
end
|
194
|
+
|
195
|
+
def hotkeyPressed(event)
|
196
|
+
@block.call event
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
##
|
202
|
+
# Register hotkeys
|
203
|
+
#
|
204
|
+
# Example:
|
205
|
+
# addHotkey( Key::F1, KeyModifier::ALT + KeyModifier::CTRL ) do
|
206
|
+
# popup 'hallo', 'Title'
|
207
|
+
# end
|
208
|
+
#
|
209
|
+
def addHotkey(key, modifiers, &block)
|
210
|
+
Env.addHotkey key, modifiers, Env::RHotkeyListener.new(block)
|
211
|
+
end
|
212
|
+
|
213
|
+
##
|
214
|
+
# Unregister hotkeys
|
215
|
+
#
|
216
|
+
# Example:
|
217
|
+
# removeHotkey( Key::F1, KeyModifier::ALT + KeyModifier::CTRL )
|
218
|
+
def removeHotkey(key, modifiers)
|
219
|
+
Env.removeHotkey key, modifiers
|
220
|
+
end
|
221
|
+
|
222
|
+
# Generate methods like constructors.
|
223
|
+
# Example: Pattern("123.png").similar(0.5)
|
224
|
+
[Pattern, Region, Screen, App, Location].each do |cl|
|
225
|
+
name = cl.java_class.simple_name
|
226
|
+
dynamic_def(name) { |*args| cl.new(*args) }
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
# This is an alternative for method generation using define_method
|
231
|
+
## This method allow to call "undotted" methods that belong to
|
232
|
+
## Region/Screen or SikuliX classes.
|
233
|
+
# def self.method_missing(name, *args, &block)
|
234
|
+
#
|
235
|
+
# if (method = Sikulix::UNDOTTED_METHODS[name])
|
236
|
+
# begin
|
237
|
+
# ret = method.call(*args, &block)
|
238
|
+
# # Dynamic methods that throw a native Java-exception,
|
239
|
+
# # hide a line number in the scriptfile!
|
240
|
+
# # Object.send(:define_method, name){ |*args| method.call(*args) }
|
241
|
+
# return ret
|
242
|
+
# rescue NativeException => e
|
243
|
+
# raise StandardError, "Sikulix: Problem (#{e})\n" \
|
244
|
+
# "with undotted method: #{name} (#{args})"
|
245
|
+
# end
|
246
|
+
# else
|
247
|
+
# fail "undotted method '#{name}' missing"
|
248
|
+
# end
|
249
|
+
# end
|
metadata
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sikulix
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Roman S Samarev
|
8
|
+
- Raimund Hocke
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-07-03 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: A wrapper over SikuliX java lib (sikulixapi.jar)
|
15
|
+
email: rssdev10@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/sikulix.rb
|
21
|
+
- lib/sikulix/platform.rb
|
22
|
+
- lib/sikulix/sikulix.rb
|
23
|
+
homepage: http://sikulix.com
|
24
|
+
licenses:
|
25
|
+
- MIT
|
26
|
+
metadata: {}
|
27
|
+
post_install_message:
|
28
|
+
rdoc_options: []
|
29
|
+
require_paths:
|
30
|
+
- lib
|
31
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - '>='
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
requirements: []
|
42
|
+
rubyforge_project:
|
43
|
+
rubygems_version: 2.1.9
|
44
|
+
signing_key:
|
45
|
+
specification_version: 4
|
46
|
+
summary: Sikulix gem
|
47
|
+
test_files: []
|