[sikuli] 216/385: integrate Roman's fixes from today

Gilles Filippini pini at moszumanska.debian.org
Sun Jun 29 19:26:15 UTC 2014


This is an automated email from the git hooks/post-receive script.

pini pushed a commit to tag upstream/1.1.0_beta1
in repository sikuli.

commit 3278198f285fbc940b8ae03a93ea47b831643150
Author: Raimund Hocke <rmhdevelop at me.com>
Date:   Sun Feb 16 15:48:22 2014 +0100

    integrate Roman's fixes from today
---
 API/pom.xml                                        |   2 +-
 IDE/src/main/java/org/sikuli/ide/SikuliIDE.java    |   6 +-
 .../org/sikuli/scriptrunner/JRubyScriptRunner.java |  50 ++----
 JRuby/src/main/resources/sikulix.rb                | 181 +++++++++++++--------
 4 files changed, 137 insertions(+), 102 deletions(-)

diff --git a/API/pom.xml b/API/pom.xml
index 9041505..dcee6ff 100755
--- a/API/pom.xml
+++ b/API/pom.xml
@@ -45,7 +45,7 @@
     </dependency>
     <dependency>
       <groupId>org.sikuli</groupId>
-      <artifactId>SikuliX-OpenCV</artifactId>
+      <artifactId>OpenCV4SikuliX</artifactId>
       <version>2.4.7</version>
     </dependency>
 	</dependencies>
diff --git a/IDE/src/main/java/org/sikuli/ide/SikuliIDE.java b/IDE/src/main/java/org/sikuli/ide/SikuliIDE.java
index 8412f62..6587494 100755
--- a/IDE/src/main/java/org/sikuli/ide/SikuliIDE.java
+++ b/IDE/src/main/java/org/sikuli/ide/SikuliIDE.java
@@ -280,9 +280,8 @@ public class SikuliIDE extends JFrame {
 	}
 
 	//<editor-fold defaultstate="collapsed" desc="IDE setup and general">
-	private SikuliIDE(String[] args) {
+	private SikuliIDE() {
 		super("Sikuli IDE");
-		initSikuliIDE(args);
 	}
 
 	private void initSikuliIDE(String[] args) {
@@ -381,7 +380,8 @@ public class SikuliIDE extends JFrame {
 
 	public static synchronized SikuliIDE getInstance(String args[]) {
 		if (_instance == null) {
-			_instance = new SikuliIDE(args);
+			_instance = new SikuliIDE();
+      _instance.initSikuliIDE(args);
 //TODO restore selected tab
 			_instance.restoreSession();
 			_instance.makeTabNull();
diff --git a/JRuby/src/main/java/org/sikuli/scriptrunner/JRubyScriptRunner.java b/JRuby/src/main/java/org/sikuli/scriptrunner/JRubyScriptRunner.java
old mode 100644
new mode 100755
index 4d13de1..3bf9633
--- a/JRuby/src/main/java/org/sikuli/scriptrunner/JRubyScriptRunner.java
+++ b/JRuby/src/main/java/org/sikuli/scriptrunner/JRubyScriptRunner.java
@@ -63,9 +63,7 @@ public class JRubyScriptRunner implements IScriptRunner {
 	private final static String SCRIPT_HEADER
 					= "# coding: utf-8\n"
 					+ "require 'sikulix'\n"
-					+ "include SikuliX4Ruby\n"
-					+ "SikuliX4Ruby::image_path = SIKULI_IMAGE_PATH + '/'\n"
-					+ "SikuliX4Ruby::logging = true\n";
+					+ "include SikuliX4Ruby\n";
 
 	private static ArrayList<String> codeBefore = null;
 	private static ArrayList<String> codeAfter = null;
@@ -93,20 +91,6 @@ public class JRubyScriptRunner implements IScriptRunner {
 	public void init(String[] args) {
 		//TODO classpath and other path handlings
 		sikuliLibPath = new File(SikuliX.getJarPath(), "Lib").getAbsolutePath();
-		if (!SikuliX.isRunningFromJar()
-						|| !sikuliLibPath.contains("sikuli-ide")
-						|| !sikuliLibPath.contains("sikuli-script")) {
-			if (System.getProperty("ruby.path") == null) {
-				System.setProperty("ruby.path", sikuliLibPath);
-				log(lvl, "init: python.path hack: \n" + System.getProperty("ruby.path"));
-			} else {
-				String currentPath = System.getProperty("ruby.path");
-				if (!FileManager.pathEquals(currentPath, sikuliLibPath)) {
-					log(-1, "init: Not running from jar and Ruby path not empty: Sikuli might not work!\n"
-									+ "Current python.path: " + currentPath);
-				}
-			}
-		}
 	}
 
 	@Override
@@ -453,22 +437,22 @@ public class JRubyScriptRunner implements IScriptRunner {
 		if (syspaths.length > 0 && syspaths[0].toUpperCase().equals(COMPILE_ONLY)) {
 			return;
 		}
-		List<String> jypath = interpreter.getLoadPaths();
-		if (!FileManager.pathEquals((String) jypath.get(0), sikuliLibPath)) {
+		List<String> path = interpreter.getLoadPaths();
+		if (!FileManager.pathEquals((String) path.get(0), sikuliLibPath)) {
 			log(lvl, "executeScriptHeader: adding SikuliX Lib path to sys.path\n" + sikuliLibPath);
-			int jypathLength = jypath.size();
-			String[] jypathNew = new String[jypathLength + 1];
-			jypathNew[0] = sikuliLibPath;
-			for (int i = 0; i < jypathLength; i++) {
-				log(lvl + 1, "executeScriptHeader: before: %d: %s", i, jypath.get(i));
-				jypathNew[i + 1] = (String) jypath.get(i);
+			int pathLength = path.size();
+			String[] pathNew = new String[pathLength + 1];
+			pathNew[0] = sikuliLibPath;
+			for (int i = 0; i < pathLength; i++) {
+				log(lvl + 1, "executeScriptHeader: before: %d: %s", i, path.get(i));
+				pathNew[i + 1] = (String) path.get(i);
 			}
-			for (int i = 0; i < jypathLength; i++) {
-				jypath.set(i, jypathNew[i]);
+			for (int i = 0; i < pathLength; i++) {
+				path.set(i, pathNew[i]);
 			}
-			jypath.add(jypathNew[jypathNew.length - 1]);
-			for (int i = 0; i < jypathNew.length; i++) {
-				log(lvl + 1, "executeScriptHeader: after: %d: %s", i, jypath.get(i));
+			path.add(pathNew[pathNew.length - 1]);
+			for (int i = 0; i < pathNew.length; i++) {
+				log(lvl + 1, "executeScriptHeader: after: %d: %s", i, path.get(i));
 			}
 		}
 		if (savedpathlen == 0) {
@@ -479,12 +463,12 @@ public class JRubyScriptRunner implements IScriptRunner {
 			interpreter.getLoadPaths().remove(savedpathlen);
 		}
 		log(lvl + 1, "executeScriptHeader: at entry: path:");
-		for (Object p : interpreter.getLoadPaths()) {
-			log(lvl + 1, p.toString());
+		for (String p : interpreter.getLoadPaths()) {
+			log(lvl + 1, p);
 		}
 		log(lvl + 1, "executeScriptHeader: at entry: --- end ---");
 		for (String syspath : syspaths) {
-			jypath.add(FileManager.slashify(syspath, false));
+			path.add(FileManager.slashify(syspath, false));
 		}
 
 		interpreter.runScriptlet(SCRIPT_HEADER);
diff --git a/JRuby/src/main/resources/sikulix.rb b/JRuby/src/main/resources/sikulix.rb
index 37fc033..65a618b 100755
--- a/JRuby/src/main/resources/sikulix.rb
+++ b/JRuby/src/main/resources/sikulix.rb
@@ -1,93 +1,144 @@
-# SikuliX
-
+# SikuliX for Ruby
 require 'java'
 
+# Classes and methods for using SikuliX
 module SikuliX4Ruby
 
   java_import org.sikuli.basics.SikuliX
   java_import org.sikuli.script.Screen
   java_import org.sikuli.script.Region
-  java_import org.sikuli.script.compare.DistanceComparator
+  java_import org.sikuli.script.ScreenUnion
+
   java_import org.sikuli.script.Observer
+  java_import org.sikuli.script.ObserverCallBack
 
-  $SIKULI_SCREEN = Screen.new
+  java_import org.sikuli.script.Constants
+  java_import org.sikuli.script.Finder
 
+  java_import org.sikuli.script.Button
+  java_import org.sikuli.basics.OS
 
-  UNDOTTED_METHODS =
-    [SikuliX, $SIKULI_SCREEN].inject({}) do |h, obj|
-      p obj
-      h.merge!(obj.methods.inject({}){|h, name| h.merge!(name => obj.method(name))})
-    end
+  java_import org.sikuli.script.Match
+  java_import org.sikuli.script.Pattern
+  java_import org.sikuli.script.Location
 
-  def method_missing name, *args
-    ret = nil
-    puts "method not exists: #{name} - trying SikuliX"
-    begin
-      puts "using: #{args}"
-      if method = UNDOTTED_METHODS[name] then
-        puts "SikuliX has: #{name}"
-        ret = method.call *args
-        Object.send(:define_method, name){ |*args| method.call *args }
-        return ret
-      else
-        raise "Problem (#{e}) with SikuliX.#{m} (#{args})"
-      end
-    rescue Exception => e
-      raise "Problem (#{e}) with SikuliX.#{m} (#{args})"
-    end
-  end
+  java_import org.sikuli.script.ImagePath
 
+  java_import org.sikuli.script.App
+  java_import org.sikuli.script.Key
+  java_import org.sikuli.script.KeyModifier
+  java_import org.sikuli.script.Mouse
 
-  class Region
-    def on_vanish target, &block
-      onVanish target, block
-    end
-  end
+  java_import org.sikuli.basics.Settings
+  java_import org.sikuli.basics.ExtensionManager
 
-  # Public: the setter for the absolute file path where Sikuli will search
-  # for images with given a filename as an image
-  #
-  # Examples
-  #
-  #  Rukuli::Config.image_path = "/Users/andreanastacio/rukuli/images/"
-  #
-  # Returns nothing
-  def image_path=(path)
-    java.lang.System.setProperty("SIKULI_IMAGE_PATH", path)
+  java_import org.sikuli.script.compare.DistanceComparator
+  java_import org.sikuli.script.compare.VerticalComparator
+  java_import org.sikuli.script.compare.HorizontalComparator
+
+  java_import org.sikuli.basics.SikuliScript
+
+  java_import org.sikuli.basics.Debug
+
+  # Debug print
+  def log str
+    puts str if (org.sikuli.basics::Settings.DebugLogs == true)
   end
 
-  # Public: turns stdout logging on and off for the Sikuli java classes.
-  # Defaults to true.
   #
-  # Examples
+  # This method generates a wrapper for Java Native exception processing
+  # in native java methods. It allows to detect a line number in script
+  # that opened in IDE where the exception was appearing.
   #
-  #  Rukuli::Config.logging = false
-  #
-  # Returns nothing
-  def logging=(boolean)
-    return unless [TrueClass, FalseClass].include? boolean.class
-    org.sikuli.basics::Settings.InfoLogs   = boolean
-    org.sikuli.basics::Settings.ActionLogs = boolean
-    org.sikuli.basics::Settings.DebugLogs  = boolean
+  # obj - class for the wrapping
+  # methods_array - array of method names as Symbols
+  def self.native_exception_protect( obj, methods_array )
+    methods_array.each do |name|
+      m = obj.instance_method (name)
+      obj.class_exec do
+        alias_method ('java_' + name.to_s).to_sym, name
+        define_method(name) do |*args|
+          begin
+            # java specific call for unbound methods
+            m.bind(self).call *args
+          rescue NativeException => e;
+            raise StandardError.new(e.message);
+          end
+        end
+      end
+    end
   end
-end
 
-=begin Rukuli variant
+  # Redefinition of native org.sikuli.script.Region class
+  class Region
+    # Service class for all callbacks processing
+    class RObserverCallBack < ObserverCallBack
+      def initialize(block); super(); @block=block; end;
+      %w(appeared vanished changed).each do |name|
+        define_method(name) do |e|
+          (@block.arity != 0) ? @block.call(e) : @block.call
+        end
+      end
+    end
+    alias_method :java_onAppear, :onAppear
+    alias_method :java_onVanish, :onVanish
+    alias_method :java_onChange, :onChange
+
+    # Redefinition of the java method for Ruby specific
+    def onAppear target, &block
+      java_onAppear(target, RObserverCallBack.new(block))
+    end
+
+    # Redefinition of the java method for Ruby specific
+    def onVanish target, &block
+      java_onVanish(target, RObserverCallBack.new(block))
+    end
 
-require_relative 'rukuli'
-include Rukuli
+    # Redefinition of the java method for Ruby specific
+    def onChange &block
+      java_onChange(RObserverCallBack.new(block))
+    end
 
-$screen = Screen.new
+    #alias_method :java_findAll,  :findAll
+    #def findAll *args
+    #  begin
+    #    java_findAll *args
+    #  rescue NativeException => e; raise e.message; end
+    #end
+  end
 
-clickable  = [:click, :double_click, :click_and_hold, :drag_drop,
-              :hover, :wheel_down, :wheel_up ]
+  # Wrap following java-methods by an exception processor
+  native_exception_protect Region,
+    [:find, :findAll, :wait, :waitVanish, :exists,
+     :click, :doubleClick, :rightClick, :hover, :dragDrop,
+     :type, :paste]
 
-typeable   = [:enter, :type]
+  # default screen object for "undotted" methods
+  $SIKULI_SCREEN = Screen.new
 
-searchable = [:find, :find!, :find_all, :wait]
+  # generate hash of (method name => method) for all possible "undotted" methods
+  UNDOTTED_METHODS =
+    [$SIKULI_SCREEN, SikuliX].inject({}) do |h, obj|
+      h.merge!(obj.methods.inject({}){|h, name| h.merge!(name => obj.method(name))})
+    end
+end
 
-(clickable + typeable + searchable).each do |name|
-  method = $screen.method (name)
-  Object.send(:define_method, name){ |*args| method.call *args }
+# This method allow to call "undotted" methods that belong to
+# Region/Screen or SikuliX classes.
+def self.method_missing name, *args, &block
+  begin
+    log "method not exists: #{name} - trying SikuliX\n"
+    if method = SikuliX4Ruby::UNDOTTED_METHODS[name] then
+      log "SikuliX has: #{name}\n"
+      ret = method.call *args, &block
+      # Dynamic methods that throw a native Java-exception,
+      # hide a line number in the scriptfile!
+      #Object.send(:define_method, name){ |*args| method.call *args }
+      return ret
+    else
+      raise "Non SikuliX method: #{name} (#{args})"
+    end
+  rescue Exception => e
+    raise "Problem (#{e})\nwith SikuliX.#{name} (#{args})"
+  end
 end
-=end
\ No newline at end of file

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/sikuli.git



More information about the pkg-java-commits mailing list