Jython scripting: Do not use the with statement with any SikuliX objects besides Regions.

Asked by Heiri

Hello,

I just don't get any further than the following problem:

   [error] AttributeError ( 'org.sikuli.script.Finder' object has no attribute '__exit__' )

The code is very easy:

   setAutoWaitTimeout(15)
   iTunes = App("iTunes")
   iTunes.focus()
   iTunesRegion = Region(iTunes.window()) # I read in one of the postings here, that casting it to a Region object could circumvent the problem.
   iTunesRegion.click("Devices.png")
   iTunesRegion.wait("Apps.png")
   iTunesRegion.click("Apps.png")
   iTunesRegion.wait("Entfernen.png") # Here the program stops with the above cited error.

The picture is there and it finds it. It even marks it red.

I use the latest nightly build.

Thanks for any help.

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

since the code lines are not left aligned, this cannot be all of the code.

there must be some surrounding code as well.

The error looks like some usage of with:

Revision history for this message
Heiri (phlomos) said :
#2

Sorry, I did the indentation myself for better readability here. There's none in the original source code.

Revision history for this message
RaiMan (raimund-hocke) said :
#3

is this on Windows?

Revision history for this message
RaiMan (raimund-hocke) said :
#4

are this all statements or are there some more?

Revision history for this message
Heiri (phlomos) said :
#5

No, this is on Mac.

Here's the whole source (I don't indent it this time):

Settings.ActionLogs = True
Settings.InfoLogs = True
Settings.DebugLogs = True
setShowActions(True)
Settings.MoveMouseDelay = 1
Settings.UserLogs = True
Settings.UserLogTime = True
Debug.on(3)
#Debug.setUserLogfile("/tmp/Sikuli.user.log")
#Debug.setLogfile("/tmp/Sikuli.log")
setAutoWaitTimeout(15)
iTunes = App("iTunes")
iTunes.focus()
#while not iTunes.window():
# wait(1)

iTunesRegion = Region(iTunes.window())
iTunesRegion.click("Devices.png")
iTunesRegion.wait("Apps.png") # Here it stops.
iTunesRegion.click("Apps.png")
iTunesRegion.wait("Entfernen.png")
#print(iTunes.window().find("Entfernen.png"))
with iTunes.window().findAll("Entfernen.png") as theButtons:
    Debug.user("Found: ", theButtons.next())

--------------------------------------------------------------------
Here's the debugging output:

[log] App.focus iTunes(0) #0
[debug] App.focus iTunes(0) #0

[debug] Region: find: waiting 3.0 secs for Devices.png to appear in R[4,23 1277x1177]@S(1)
[debug] Image: reused: Devices.png (file:/Users/moetteli/Developer/Source/Applications/AppsManager/AppsManager.sikuli/Devices.png)
[debug] RobotDesktop: captureScreen: on 1 using java.awt.Rectangle[x=4,y=23,width=1277,height=1177]

[log] highlight M[196,69 28x30]@S(S(1)[0,0 1920x1200]) S:1.00 C:210,84 [229/229 msec] for 2.0 secs
[debug] highlight M[196,69 28x30]@S(S(1)[0,0 1920x1200]) S:1.00 C:210,84 [229/229 msec] for 2.0 secs

[debug] Region: find: Devices.png has appeared
at M[196,69 28x30]@S(S(1)[0,0 1920x1200]) S:1.00 C:210,84 [229/229 msec]
[debug] showTarget 185 59 50 50

[debug] Device: Mouse: moved externally: now (-623,48) was (1576,534) (mouseMovedResponse 0)
[log] CLICK on L(210,84)@S(1)[0,0 1920x1200]
[debug] CLICK on L(210,84)@S(1)[0,0 1920x1200]

[debug] Region: find: waiting 3.0 secs for Apps.png to appear in R[4,23 1277x1177]@S(1)
[debug] Image: reused: Apps.png (file:/Users/moetteli/Developer/Source/Applications/AppsManager/AppsManager.sikuli/Apps.png)
[debug] RobotDesktop: captureScreen: on 1 using java.awt.Rectangle[x=4,y=23,width=1277,height=1177]

[debug] RobotDesktop: captureScreen: on 1 using java.awt.Rectangle[x=4,y=23,width=1277,height=1177]

[log] highlight M[8,215 105x27]@S(S(1)[0,0 1920x1200]) S:1.00 C:60,228 [166/22 msec] for 2.0 secs
[debug] highlight M[8,215 105x27]@S(S(1)[0,0 1920x1200]) S:1.00 C:60,228 [166/22 msec] for 2.0 secs

[debug] Region: find: Apps.png has appeared
at M[8,215 105x27]@S(S(1)[0,0 1920x1200]) S:1.00 C:60,228 [166/22 msec]
[debug] Region: find: waiting 3.0 secs for Apps.png to appear in R[4,23 1277x1177]@S(1)
[debug] Image: reused: Apps.png (file:/Users/moetteli/Developer/Source/Applications/AppsManager/AppsManager.sikuli/Apps.png)

[debug] RobotDesktop: captureScreen: on 1 using java.awt.Rectangle[x=4,y=23,width=1277,height=1177]
[debug] Region: checkLastSeen: still there
[log] highlight M[8,215 105x27]@S(S(1)[0,0 1920x1200]) S:1.00 C:60,228 [21/21 msec] for 2.0 secs
[debug] highlight M[8,215 105x27]@S(S(1)[0,0 1920x1200]) S:1.00 C:60,228 [21/21 msec] for 2.0 secs

[debug] Region: find: Apps.png has appeared
at M[8,215 105x27]@S(S(1)[0,0 1920x1200]) S:1.00 C:60,228 [21/21 msec]
[debug] showTarget 35 203 50 50

[log] CLICK on L(60,228)@S(1)[0,0 1920x1200]
[debug] CLICK on L(60,228)@S(1)[0,0 1920x1200]

[debug] Region: find: waiting 3.0 secs for Entfernen.png to appear in R[4,23 1277x1177]@S(1)
[debug] Image: reused: Entfernen.png (file:/Users/moetteli/Developer/Source/Applications/AppsManager/AppsManager.sikuli/Entfernen.png)
[debug] RobotDesktop: captureScreen: on 1 using java.awt.Rectangle[x=4,y=23,width=1277,height=1177]

[debug] RobotDesktop: captureScreen: on 1 using java.awt.Rectangle[x=4,y=23,width=1277,height=1177]

[log] highlight M[530,1097 121x19]@S(S(1)[0,0 1920x1200]) S:1.00 C:590,1106 [173/40 msec] for 2.0 secs
[debug] highlight M[530,1097 121x19]@S(S(1)[0,0 1920x1200]) S:1.00 C:590,1106 [173/40 msec] for 2.0 secs

[debug] Region: find: Entfernen.png has appeared
at M[530,1097 121x19]@S(S(1)[0,0 1920x1200]) S:1.00 C:590,1106 [173/40 msec]

[debug] RobotDesktop: captureScreen: on 1 using java.awt.Rectangle[x=4,y=23,width=1277,height=1177]

[debug] Image: reused: Entfernen.png (file:/Users/moetteli/Developer/Source/Applications/AppsManager/AppsManager.sikuli/Entfernen.png)

[error] script [ AppsManager ] stopped with error in line 21
[error] AttributeError ( 'org.sikuli.script.Finder' object has no attribute '__exit__' )

[debug] Sikulix: cleanUp: 0

Revision history for this message
RaiMan (raimund-hocke) said :
#6

The problem is the usage of the with: statement.

with iTunes.window().findAll("Entfernen.png") as theButtons:
    Debug.user("Found: ", theButtons.next())

this should work:

theButtons = iTunesRegion.findAll("Entfernen.png")
while theButtons.hasNext():
    Debug.user("Found: ", theButtons.next())

The usage of the with statement is only implemented for Region objects.
Since most SikuliX objects are not "real" Python/Jython objects, but Java objects, the with feature is not available for them and leads to weird errors.
I always recommend to not use it at all with any Sikuli objects.

Can you help with this problem?

Provide an answer of your own, or ask Heiri for more information if necessary.

To post a message you must log in.