question about handler attribute

Asked by Ankur on 2018-08-13

there is any way to add other attribute to the handler other to event.
let me explain my real problemis is that when a obser has find a pattern i want to stop also others observer so i have to send regions of others observer to the handler in order to call stopObserver on them. i have one observes with a waiting time and the others observes in background but when one of them find a pattern it must stops all observers

Question information

Language:
English Edit question
Status:
Solved
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
2018-08-13
Last query:
2018-08-13
Last reply:
2018-08-13
Best RaiMan (raimund-hocke) said : #1

supposing we are talking about scripting:
easiest way: using global

- collect the regions, whose observers should be stopped ins list:
toBeStopped = (region2, region2, region3, ...)

- in the handler use global to access the list:
def handler(event):
    global toBeStopped
    for reg in toBeStopped:
        # do something

Ankur (aknm) said : #2

It works!! Great idea! You make me save time ( i have started reading about multithreading with python in order to run my function in a new thread). But what do you think to add a way to send also other attribute ? In this way it could be used also with attribute of classes.

RaiMan (raimund-hocke) said : #3

--- in order to run my function in a new thread
not sure, what that might help

--- In this way it could be used also with attribute of classes.
A class is only a more general container for attributes and functions.
Through instantiation you get an object, that can be used for storing and retrieving attributes.
So you could use such a class/object in the same way as the suggested list above.
In between you have the dictionary as a key-value store.