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

Add GetObserverPriority as a workaround for VTK #414

Open
paskino opened this issue Jun 6, 2024 · 0 comments
Open

Add GetObserverPriority as a workaround for VTK #414

paskino opened this issue Jun 6, 2024 · 0 comments

Comments

@paskino
Copy link
Collaborator

paskino commented Jun 6, 2024

We should add this code in the utils for vtk. See https://discourse.vtk.org/t/consume-a-vtk-event-in-python/13052/3

def GetObserverPriority(vtk_object, event_name: str) -> int:
    '''Given a vtk object and an event name, return the priority of the observer
    
    In Python it is impossible to get an observer from the object programmatically, 
    but the string representation of the object contains the observers with priority.

    This code reads the string representation and returns the priority as integer.
    '''
    string = str(vtk_object)

    ss = string.split("vtkObserver")

    eventObservers = []
    for s in ss:
        lines = s.split("\n")
        eo = {}
        for line in lines:
            try:
                k,v = line.split(":")
                k = k.strip()
                v = v.strip()
                if k in ['Event', 'EventName', 'Command', 'Priority', 'Tag']:
                    eo[k] = v
                    eventObservers.append(eo)
            except:
                pass

    for el in eventObservers:
        if el['EventName'] == event_name:
            return int(el['Priority'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant