Re: [Sikuli-driver] [Question #261426]: Region.observe(60, True) is throwing an exception

2015-02-03 Thread RaiMan
Question #261426 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/261426

RaiMan proposed the following answer:
for the error thrown:
the only thing I can see:

instead of:
menu_region = edit_menu.left(1).below().right().intersection(mw)

you might try:
menu_region = Region(edit_menu.left(1).below().right().intersection(mw))

to cast the evaluated Java level Region object to a Python level Region
object.

This cast will not be needed any more with the final version, since the
Jython Region does not have an extra observe() any more.

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.

___
Mailing list: https://launchpad.net/~sikuli-driver
Post to : sikuli-driver@lists.launchpad.net
Unsubscribe : https://launchpad.net/~sikuli-driver
More help   : https://help.launchpad.net/ListHelp


Re: [Sikuli-driver] [Question #261426]: Region.observe(60, True) is throwing an exception

2015-02-03 Thread RaiMan
Question #261426 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/261426

RaiMan proposed the following answer:
@comment #4
the setup looks principally ok, except that
C:\Users\pierreb\PycharmProjects\detect_region\sikuli\libs need not be

and 
C:\Users\pierreb\PycharmProjects\detect_region\sikuli\sikulix.jar should not 
be
on Python path (sys.path)

The latter, because it contains sikulixapi already and additionally a complete 
Jython, that might conflict with the external Jython
/C:/git/AlphaPack2/jython/2.7b3/jython.jar (on __classpath__)
C:\git\AlphaPack2\jython\2.7b3\Lib (on sys.path)

But in this case it does not matter, since the bundled Jython is the
same (2.7b3)

The exported Lib folder containing the SikuliX Python stuff comes from
sikulixapi.jar at setup time.

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.

___
Mailing list: https://launchpad.net/~sikuli-driver
Post to : sikuli-driver@lists.launchpad.net
Unsubscribe : https://launchpad.net/~sikuli-driver
More help   : https://help.launchpad.net/ListHelp


Re: [Sikuli-driver] [Question #261426]: Region.observe(60, True) is throwing an exception

2015-02-02 Thread Pierre Best
Question #261426 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/261426

Pierre Best posted a new comment:
import org.sikuli.basics.SikulixForJython
from sikuli import *


Settings.OcrTextSearch = True
Settings.OcrTextRead = True


_changes = []

def change_handler(event):
global _changes

for ec in event.changes:
_changes.append(Region(ec))
_changes.append(None)
event.region.stopObserver()

def detect_menu_appear():
_APP = 'notepad.exe'
_TITLE = 'Notepad'
_MENU_TITLE = 'Edit'


try:
np = App(_APP)

np.open()

for _ in range(10):
mw = np.window(0)
if mw:
break
time.sleep(0.1)
if not mw:
exit()

title = None
try:
title = mw.find(_TITLE)
except Sikuli.FindFailed:
exit()
if title is None:
exit()
if title.click(title) != 1:
exit()

edit_menu = None
try:
edit_menu = mw.find(_MENU_TITLE)
except Sikuli.FindFailed:
exit()
if edit_menu is None:
exit()

menu_region = edit_menu.left(1).below().right().intersection(mw)
menu_region.onChange(100, change_handler)

global _changes
_changes = []
menu_region.observe(60, True)

if edit_menu.click(edit_menu) != 1:
exit()

for _ in range(20):  # wait for the handler to terminate
if len(_changes) == 0:
time.sleep(1)
continue


for r in _changes[:-1]:
sys.__stdout__.write('%s' % r)

except:
sei0, sei1 = sys.exc_info()[:2]
sys.__stdout__.write('except-[%s, %s]\n' % (sei0, sei1))
pass
finally:
np.close()


detect_menu_appear()

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.

___
Mailing list: https://launchpad.net/~sikuli-driver
Post to : sikuli-driver@lists.launchpad.net
Unsubscribe : https://launchpad.net/~sikuli-driver
More help   : https://help.launchpad.net/ListHelp


Re: [Sikuli-driver] [Question #261426]: Region.observe(60, True) is throwing an exception

2015-02-02 Thread Pierre Best
Question #261426 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/261426

Pierre Best posted a new comment:
Configuration Information:
==

Adding

sys.__stdout__.write('[X] python version:   %s\n' % platform.python_version())
sys.__stdout__.write('[X] java version: %s\n' % list(platform.java_ver()))
sys.__stdout__.write('[X] python path:  %s\n' % sys.executable)
sys.__stdout__.write('[X] encoding: %s\n' % sys.stdout.encoding)
sys.__stdout__.write('[X] default encoding: %s\n' % sys.getdefaultencoding())
sys.__stdout__.write('[X] _classpath:  [\n\t%s\n]\n' % 
(\n\t.join([{0}.format(path_to_add) for path_to_add in map(lambda url: 
url.getFile(), ClassLoader.getSystemClassLoader().getURLs())])))
sys.__stdout__.write('[X] sys.path: [\n\t%s\n]\n' % 
(\n\t.join([{0}.format(path_to_add) for path_to_add in sys.path])))


to the start of the program gives the following output

[X] python version:   2.7.0
[X] java version: ['1.8.0_20', 'Oracle Corporation', ('Java HotSpot(TM) 
64-Bit Server VM', '25.20-b23', 'Oracle Corporation'), ('Windows 8.1', '6.3', 
'amd64')]
[X] python path:  C:\git\AlphaPack2\jython\2.7b3\jython.bat
[X] encoding: UTF-8
[X] default encoding: ascii
[X] _classpath:  [
/C:/git/AlphaPack2/jython/2.7b3/jython.jar
/C:/Users/pierreb/PycharmProjects/detect_region/sikuli/sikulixapi.jar
]
[X] sys.path: [
C:\Users\pierreb\PycharmProjects\detect_region\sikuli\libs
C:\Users\pierreb\PycharmProjects\detect_region\sikuli\Lib
C:\Program Files (x86)\JetBrains\PyCharm Community Edition 
4.0\helpers\pycharm
C:\Program Files (x86)\JetBrains\PyCharm Community Edition 
4.0\helpers\pydev
C:\Users\pierreb\PycharmProjects\detect_region\dr
C:\Users\pierreb\PycharmProjects\detect_region\sikuli\sikulix.jar
C:\git\AlphaPack2\jython\2.7b3\Lib
__classpath__
__pyclasspath__/
]

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.

___
Mailing list: https://launchpad.net/~sikuli-driver
Post to : sikuli-driver@lists.launchpad.net
Unsubscribe : https://launchpad.net/~sikuli-driver
More help   : https://help.launchpad.net/ListHelp


Re: [Sikuli-driver] [Question #261426]: Region.observe(60, True) is throwing an exception

2015-01-30 Thread RaiMan
Question #261426 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/261426

Description changed to:
Sikuli 1.1.0

I'm trying to track the sub-menu that appears when you click on a menu
name. I've set up the handler and assigned it with onChange() but when I
call r.observe(60, True) an exception is thrown. Printing the exception
type and message gives the following information:


   type 'exceptions.TypeError', observe(): expected 0-1 args; got 2


I need the observe() to run in the background as the script will also be 
generating the click so calling observe(60) won't work. 

running with Jython and PyCharm IDE

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.

___
Mailing list: https://launchpad.net/~sikuli-driver
Post to : sikuli-driver@lists.launchpad.net
Unsubscribe : https://launchpad.net/~sikuli-driver
More help   : https://help.launchpad.net/ListHelp


Re: [Sikuli-driver] [Question #261426]: Region.observe(60, True) is throwing an exception

2015-01-30 Thread RaiMan
Question #261426 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/261426

Status: Open = Answered

RaiMan proposed the following answer:
I removed the debug log, since this does not help.

More helpful would be to see the code you are using (just the relevant
snippet).

And since you are working with PyCharm and probably running with this
IDE, you setup would shed some light on your problem.

Might be that this already helps:

This works:

reg = Region(0, 20, 300, 200)
reg.highlight(2)

def handler(e):
  global shouldStop
  print changed
  e.stopObserver()
  shouldStop = True

reg.onChange(100, handler) # upper left where a menu will appear when I click 
there
switchApp(Safari) # get some app in foreground
wait(1)
shouldStop = False
reg.observe(background = True) # observing forever in background

while not shouldStop: # wait until I have clicked a menu, that opens into the 
reg and triggers the handler
  wait(1)

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.

___
Mailing list: https://launchpad.net/~sikuli-driver
Post to : sikuli-driver@lists.launchpad.net
Unsubscribe : https://launchpad.net/~sikuli-driver
More help   : https://help.launchpad.net/ListHelp


Re: [Sikuli-driver] [Question #261426]: Region.observe(60, True) is throwing an exception

2015-01-30 Thread RaiMan
Question #261426 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/261426

RaiMan proposed the following answer:
another problem might be, that you are importing Region stuff from the
Java level, which is strictly a no-go ;-)

Since auto-complete and auto-compile/syntax-check complain the use of
the undotted region methods (like click() instead of someRegion.click()
) people tend to solve that by importing stuff that gets intermixed with
the Jython scripting level.

from sikuli import *

is all you need, after having sikulixapi.jar on class path and
sikulixapi.jar/Lib on sys.path

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.

___
Mailing list: https://launchpad.net/~sikuli-driver
Post to : sikuli-driver@lists.launchpad.net
Unsubscribe : https://launchpad.net/~sikuli-driver
More help   : https://help.launchpad.net/ListHelp


[Sikuli-driver] [Question #261426]: Region.observe(60, True) is throwing an exception

2015-01-30 Thread Pierre Best
New question #261426 on Sikuli:
https://answers.launchpad.net/sikuli/+question/261426

Sikuli 1.1.0

I'm trying to track the sub-menu that appears when you click on a menu name. 
I've set up the handler and assigned it with onChange() but when I call 
r.observe(60, True) an exception is thrown. Printing the exception type and 
message gives the following information:


   type 'exceptions.TypeError', observe(): expected 0-1 args; got 2


I need the observe() to run in the background as the script will also be 
generating the click so calling observe(60) won't work. 

Here's the complete log
===
C:\git\AlphaPack2\jython\2.7b3\jython.bat -Dsikuli.Debug=3 
-Dpython.path=C:\Users\pierreb\PycharmProjects\detect_region\sikuli\libs;C:\Users\pierreb\PycharmProjects\detect_region\sikuli\sikulixapi.jar;C:\Users\pierreb\PycharmProjects\detect_region\sikuli\Lib;C:\Program
 Files (x86)\JetBrains\PyCharm Community Edition 4.0\helpers\pycharm;C:\Program 
Files (x86)\JetBrains\PyCharm Community Edition 
4.0\helpers\pydev;C:\Users\pierreb\PycharmProjects\detect_region\dr 
C:\Program Files (x86)\JetBrains\PyCharm Community Edition 
4.0\helpers\pydev\pydevd.py --multiproc --client 127.0.0.1 --port 51740 --file 
C:/Users/pierreb/PycharmProjects/detect_region/dr/main.py
Failed to get import name for name _codecs.class
pydev debugger: process 6544 is connecting

Failed to get import name for name thread.class
Failed to get import name for name _codecs.class
Connected to pydev debugger (build 139.1001)
Jan 30, 2015 11:45:39 AM java.util.prefs.WindowsPreferences init
WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs at root 
0x8002. Windows RegCreateKeyEx(...) returned error code 5.
[debug] SikuliXforJython: sys.path[0]: 
C:\Users\pierreb\PycharmProjects\detect_region\sikuli\libs
[debug] SikuliXforJython: sys.path[1]: 
C:\Users\pierreb\PycharmProjects\detect_region\sikuli\sikulixapi.jar
[debug] SikuliXforJython: sys.path[2]: 
C:\Users\pierreb\PycharmProjects\detect_region\sikuli\Lib
[error] Sikuli Jython API already on sys.path, but not at sikulixapi.jar/Lib
[error] Found here: C:/Users/pierreb/PycharmProjects/detect_region/sikuli/Lib/
[debug] Jython: sikuli: Sikuli: starting init
Failed to get import name for name FindFailedResponse.class
Failed to get import name for name FindFailedResponse.declaringClass
Failed to get import name for name Constants.class
Failed to get import name for name Constants.class
[debug] ResourceLoader: SikuliX Package Build: 1.1.0 2015-01-16_01:00nightly
[debug] ResourceLoader: check: we are running on arch: amd64
[debug] ResourceLoader: check: using Java at: C:/Program Files/Java/jre1.8.0_20/
[debug] ResourceLoader: check: Exists libs folder at location of jar? YES: 
C:/Users/pierreb/PycharmProjects/detect_region/sikuli/
[debug] ResourceLoader: checkLibsDir: trying: 
C:\Users\pierreb\PycharmProjects\detect_region\sikuli\libs
[debug] ResourceLoader: checkLibsDir: Running on Windows - checking system path!
[debug] ResourceLoader: checkLibsDir: Added libs dir to path: 
C:\Users\pierreb\PycharmProjects\detect_region\sikuli\libs
[debug] ResourceLoader: checkLibsDir: 
C:\Users\pierreb\PycharmProjects\detect_region\sikuli\libs;C:\ProgramData\Oracle\Java\javapath;C:\Apps\oracl...
[debug] ResourceLoader: checkLibsDir: checking ClassLoader.usrPaths having: 
C:\Users\pierreb\PycharmProjects\detect_region\sikuli\libs
[debug] ResourceLoader: checkLibsDir: added to ClassLoader.usrPaths
[debug] ResourceLoader: loadLib: Now loaded: VisionProxy from: 
C:\Users\pierreb\PycharmProjects\detect_region\sikuli\libs\VisionProxy.dll
[debug] ResourceLoader: checkLibsDir: Using libs at: 
C:\Users\pierreb\PycharmProjects\detect_region\sikuli\libs
[debug] Screen: initScreens: ScreenDevice 0 contains (0,0) --- will be used as 
primary
[debug] Screen: initScreens: basic initialization (1 Screen(s) found)
[debug] Screen: *** monitor configuration (primary: 0) ***
[debug] Screen: 0: S(0)[0,0 1920x1080]
[debug] Screen: *** end monitor configuration ***
[debug] Mouse: init
[debug] KeyBoard: init
[debug] ResourceLoader: loadLib: Now loaded: WinUtil from: 
C:\Users\pierreb\PycharmProjects\detect_region\sikuli\libs\WinUtil.dll
[debug] Jython: requested to use as default region: R[0,0 1920x1080]@S(0)
[debug] Jython: sikuli: Sikuli: ending init
[log] App.open notepad.exe(10836)
[debug] Region: find: waiting 3.0 secs for Edit to appear in R[189,95 
851x782]@S(0)
[error] ImagePath: setBundlePath: invalid BundlePath: null 
using working folder: C:\Users\pierreb\PycharmProjects\detect_region\dr
[debug] ImagePath: new BundlePath: 
C:/Users/pierreb/PycharmProjects/detect_region/dr
[error] Image: could not be loaded: 
file:C:\Users\pierreb\PycharmProjects\detect_region\dr\Edit.png
[debug] TextRecognizer: init OK: using as data folder:
C:\Users\pierreb\PycharmProjects\detect_region\sikuli\libs\tessdata
[debug] Region: doFind: Switching to TextSearch
[debug] Region: find: Edit has appeared 
at M[509,144