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

Interactor event OnKeyPress should be OnChar #412

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

Interactor event OnKeyPress should be OnChar #412

paskino opened this issue Jun 5, 2024 · 0 comments

Comments

@paskino
Copy link
Collaborator

paskino commented Jun 5, 2024

We defined lots of keyboard interaction in the viewer with OnKeyPress, but most of it should be OnChar. See https://discourse.vtk.org/t/consume-a-vtk-event-in-python/13052/3

self.AddObserver('KeyPressEvent', self.OnKeyPress, priority)

It would also be nice to add a function to get the observer priority, as I wrote in the discourse:

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant