Skip to content

Dynamically change the interactive_ratio on VtkRemoteView python-side #73

@banesullivan-kobold

Description

@banesullivan-kobold

Is it possible to directly change the interactive_ratio from the VtkRemoteView instance itself in Python code? Take the following example with PyVista where I get access to the underlying VtkRemoteView instance and attempt to change the interactive_ratio. However, this change does not take affect (the dirty() call was my attempt at pushing this change):

import pyvista as pv

pl = pv.Plotter()
pl.add_mesh(pv.Wavelet())
w = pl.show(return_viewer=True)

for view in w._viewer.views:
    view.interactive_ratio = 4
    view.state.dirty('interactiveRatio')
    view.update()

w  # <-- repr in Jupyter noteook

I'm able to link the interactive_ratio to a variable, so I know it can be dynamically changed, but how can I do this directly from the VtkRemoteView instance python-side?

from trame.app import get_server
from trame.ui.vuetify3 import SinglePageLayout
from trame.widgets import vuetify3 as vuetify
from trame.widgets.vtk import VtkRemoteView

import pyvista as pv

server = get_server()
state, ctrl = server.state, server.controller

state.trame__title = "PyVista Remote View Ratios"

# -----------------------------------------------------------------------------

mesh = pv.Wavelet()

plotter = pv.Plotter(off_screen=True)
actor = plotter.add_mesh(mesh)
plotter.set_background("lightgrey")
plotter.view_isometric()


# -----------------------------------------------------------------------------
# GUI
# -----------------------------------------------------------------------------

with SinglePageLayout(server) as layout:
    layout.icon.click = ctrl.view_reset_camera
    layout.title.set_text(state.trame__title)

    with layout.toolbar:
        vuetify.VSpacer()
        vuetify.VSlider(
            label='Interactive ratio',
            v_model=('interactive_ratio', 2),
            min=0.05,
            max=4,
            step=0.05,
            hide_details=True,
            density='compact',
            style='max-width: 300px',
            # change=ctrl.view_update,
        )

    with layout.content:
        with vuetify.VContainer(
            fluid=True,
            classes="pa-0 fill-height",
        ):
            view = VtkRemoteView(plotter.ren_win, interactive_ratio=('interactive_ratio', 2), still_ratio=2)
            ctrl.view_update = view.update
            ctrl.view_reset_camera = view.reset_camera

# -----------------------------------------------------------------------------
# Main
# -----------------------------------------------------------------------------

if __name__ == "__main__":
    server.start()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions