onAppear

Asked by Neja

Hi! My code doesn't work:
 def Check(event):
        exists(confirm.png)
        event.reg.stopObserver()
  with "QTTTQwww2nd1.png" as reg:
        onAppear(message.png, Check)
        reg.observe(15)

AttributeError: 'str' object has no attribute '__exit__'

When message appears, it should be checked that the appearing message is correct and the confirm button exists.

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

with "QTTTQwww2nd1.png" as reg:

must be a Region object:

# as a guessed example
m = find("QTTTQwww2nd1.png")
reg = Region(m.x, m.y, 200, 200)
with reg:
     onAppear(message.png, Check)
     observe(15)

# or even simply
m = find("QTTTQwww2nd1.png")
reg = Region(m.x, m.y, 200, 200)
reg.onAppear(message.png, Check)
reg.observe(15)

Revision history for this message
Neja (keja04) said :
#2

It still doesn' t work

def Check(self,event):
        if exists(Pattern(disabled.png.similar(0.96)):
            print "Confirm is disabled"
        else:
            print "Confirm isn't disabled"
        event.stopObserver()
    def ConfirmBets(self):
        m=find("QTTTQwww2nd1.png")
        reg=Region(m.x, m.y, 200, 200)
        with reg:
            onAppear(message.png.exact().targetOffset(1,20), self.Check)
            observe(15)

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

what does this mean: It still doesn' t work?

Since I do not know your screenshot/images/app, I guessed a possible approach, that you had to adopt to your situation:
m=find("QTTTQwww2nd1.png")
reg=Region(m.x, m.y, 200, 200)
with reg:

this looks strange:
            onAppear(message.png.exact().targetOffset(1,20), self.Check)

should be something like:
            onAppear(Pattern("message.png").similar(0.99).targetOffset(1,20), self.Check)

BTW: due to problems in the current version it is recommended to use similar(0.99) instead of exact()

Revision history for this message
Neja (keja04) said :
#4

Sorry, i copied incorrectly. But this script doesn't check whether
1365687108852.png exists or not. Confirm is disabled or Confirm isn't
disabled is not shown in logs.

def
Check(self,event):
        if
exists(Pattern("1365687108852.png").similar(0.96)):

print "Confirm is
disabled"

else:

print "Confirm isn't
disabled"

event.stopObserver()
def
ConfirmBets(self):

click("1366114550585.png")

m=find("QTTTQwww2nd1.png")

reg=Region(m.x, m.y, 200,
200)
        with
reg:

onAppear(Pattern("9_NFFMEQlVTT-1.png").similar(0.92).targetOffset(1,20),
self.Check)

observe(15)

> Your question #226788 on Sikuli
changed:
>
https://answers.launchpad.net/sikuli/+question/226788
>
>
  Status: Open => Answered
>
> RaiMan proposed the
following answer:
> what does this mean: It still doesn' t
work?
>
> Since I do not know your screenshot/images/app, I
guessed a possible approach, that you had to adopt to your
situation:
> m=find("QTTTQwww2nd1.png")
> reg=Region(m.x,
m.y, 200, 200)
> with reg:
>
> this looks
strange:
>
onAppear(message.png.exact().targetOffset(1,20), self.Check)
>

> should be something like:
>
onAppear(Pattern("message.png").similar(0.99).targetOffset(1,20),
self.Check)
>
> BTW: due to problems in the current version
it is recommended to use
> similar(0.99) instead of
exact()
>
> --
> If this answers your question,
please go to the following page to let us
> know that it is
solved:
>
https://answers.launchpad.net/sikuli/+question/226788/+confirm?answer_id=2
>

> If you still need help, you can reply to this email or go to
the
> following page to enter your feedback:
>
https://answers.launchpad.net/sikuli/+question/226788
>
>
You received this question notification because you asked the
question.
>

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

your stuff is not readable here.

I cannot help you, if I only get some code, that I cannot verify due to not having any images/screenshots.

You say:
But this script doesn't check whether
1365687108852.png exists or not. Confirm is disabled or Confirm isn't
disabled is not shown in logs.

this simply means, that the onAppear event is not fired during the 15 seconds observation time, which in turn means, that the Pattern("9_NFFMEQlVTT-1.png").similar(0.92) is not found or does not appear.

Revision history for this message
Neja (keja04) said :
#6

Hi,

i tried this way and that, but it still doesn't work.
Could you help me with this onAppear and stopObserver? zip file is
attached

Regards
Neja

> Your question #226788 on
Sikuli changed:
>
https://answers.launchpad.net/sikuli/+question/226788
>=20
> =20
  Status: Open =3D> Answered
>=20
> RaiMan proposed the
following answer:
> your stuff is not readable here.
>

> I cannot help you, if I only get some code, that I cannot
verify due to
> not having any images/screenshots.
>

> You say:
> But this script doesn't check whether
>
1365687108852.png exists or not. Confirm is disabled or Confirm
isn't
> disabled is not shown in logs.
>=20
> this
simply means, that the onAppear event is not fired during the 15
>
seconds observation time, which in turn means, that the
>
Pattern("9_NFFMEQlVTT-1.png").similar(0.92) is not found or does
not
> appear.
>=20
> --=20
> If this answers your
question, please go to the following page to let us
> know that it
is solved:
>
https://answers.launchpad.net/sikuli/+question/226788/+confirm?answer_id=3D4
>

> If you still need help, you can reply to this email or go to
the
> following page to enter your feedback:
>
https://answers.launchpad.net/sikuli/+question/226788
>=20
>
You received this question notification because you asked the
question.
>

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

in this Q&A board one cannot have attachments.

Either put a link to some cloud storage or send it silently to my mail at: https://launchpad.net/~raimund-hocke

Be aware: the zip should contain some relevant screenshots, so I can do some testing.

Can you help with this problem?

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

To post a message you must log in.