Tset-Noitamotua / Sikuli-and-Robot-Framework-Integration

Windows 7 / 8.1 + Sikuli 1.1.0 compatible version of source for the great tuturial from Mike´s blog
http://blog.mykhailo.com/2011/02/how-to-sikuli-and-robot-framework.html
10 stars 5 forks source link

Unresolved references in IntelliJ IDEA #7

Closed Tset-Noitamotua closed 9 years ago

Tset-Noitamotua commented 9 years ago

In IntelliJ IDEA 14.02 I do this import in my SikuliX script:

from sikuli import *

But as you can see in below screenshot quite a few references are marked unresolved by the IDE. The script works fine though. Is there another way than making some extra import to solve that?

unresolved references

Tset-Noitamotua commented 9 years ago

Raiman's answer from Sikuli-launchpad:

this is by intention/design or however you name it and cannot be solved, when you are using the undotted Region and Screen ,methods outside the Sikuli IDE in other IDE's having auto-complete and continous compile/syntax check.

a method use like click(some_image)

is dynamically at runtime interpreted as SCREEN.click(some_image)

where SCREEN is a constant object created as Screen() internally.

So any compile time engine MUST produce these errors.

Your solution is the worst possible though, since it leads to a mix of Python level and Java level Region objects, which still might lead to strange situations.

If you want to be strict, you have to set aside the usage of undated methods completely and script "normally"

for all actions not bound to a specific region:

SCREEN.click()

or once at the beginning s = Screen()

and later: s.click() s.wait()

...

Everything needed is already imported by from sikuli import *

... never import anything from the Java level from the classes Region or Screen, because these classes are overwritten/wrapped on the Python level.

I hope, I find a better solution for version 2. But any solution will not allow to use undotted methods in other IDE's than the Sikuli IDE. So start today, to live without it, if you want to use IntelliJ.

Tset-Noitamotua commented 9 years ago

Thanks for the quick reply, Raiman.

I followed your recommendation and removed all java level imports und used "normal" method calls (e.g. s.click()). This almost solved the problem but there is still one unresolved reference left: SCREEN

An example of usage can be seen in this code

(Line 52) - What can I do in this case?

Tset-Noitamotua commented 9 years ago

Rainman's answer from Sikuli-launchpad:

from the referenced snippet I cannot judge, wether SCREEN.getLastMatch() makes sense at all.

the Region method getLastMatch() returns the match of the last search op done in this region as e.g.

someRegion.click(someImage) # indirect search someRegion.find(someImage) # direct search

and then match = someRegion.getLastMatch()

so if you are saying, that you are only using "normal" method calls, then you must reference here the region, that was used for searching (e.g. s, when you used s.click(img) )

using the convenience scripting with undated Region methods SCREEN.getLastMatch() is the same as getLastMatch()

The reason, that the undotted methods work, is the internal runtime trick: SCREEN = Screen(0) and then dynamically register all Region methods with this object SCREEN as global.

... and this is why IntelliJ does not see theses undotted methods at edit time (SCREEN and the methods simply do not exist yet)

hope it helps.