Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

observe: Region::setInactive/setActive not working #270

Closed
RaiMan opened this issue Dec 21, 2019 · 0 comments
Closed

observe: Region::setInactive/setActive not working #270

RaiMan opened this issue Dec 21, 2019 · 0 comments
Assignees
Labels
bug Something isn't working fixed the problem has been fixed

Comments

@RaiMan
Copy link
Owner

RaiMan commented Dec 21, 2019

The test case:

  • img.png is either visible or not
  • using observeInBackground() with onAppear() and onVanish()
  • want to use Region.setInactive() and Region.setActive() to manage when what event should be observed

The problem: activation/deactivation of events did not work.

It is fixed now and additionally we have Event::setInactive() for use in a handler.

In the following workflow the image is not visible in the beginning and then appears and vanishes again and so on.

start = time.time()
def now():
  return 0.01 * int(100 * (time.time() - start))

def handler(evt):
  global stop
  cnt = evt.getCount()
  if evt.isAppear(): 
    name = "ona"
    evt.setInactive()  # deactivate onAppear
    evt.getRegion().setActive(onv)  # activate onVanish
  else : 
    name = "onv"
    evt.setInactive()  # deactivate onVanish    
    evt.getRegion().setActive(ona)  # deactivate onAppear
  print "in handler:", name, cnt, now() # activate onAppear
  if cnt > 2: stop = True
  
img = "img.png"
ona = onAppear(img, handler)
print "ona:", ona
onv = onVanish(img, handler)
print "onv:", onv
setInactive(onv) # to avoid triggering onVanish at start
stop = False
observeInBackground(FOREVER)

while not stop:  
  wait(1)

While the script is running I am making the image hidden/visible manually.
... and the printout:

ona: 1576919468469
onv: 1576919468495
in handler: ona 1 2.68
in handler: onv 1 5.15
in handler: ona 2 7.58
in handler: onv 2 9.87
in handler: ona 3 11.7
@RaiMan RaiMan self-assigned this Dec 21, 2019
@RaiMan RaiMan added bug Something isn't working fixed the problem has been fixed labels Dec 21, 2019
@RaiMan RaiMan added this to the 2.0.2 milestone Dec 21, 2019
@RaiMan RaiMan closed this as completed Dec 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed the problem has been fixed
Projects
None yet
Development

No branches or pull requests

1 participant