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

Exposing nv.saveScene on the python side #49

Open
kolibril13 opened this issue Feb 22, 2024 · 1 comment
Open

Exposing nv.saveScene on the python side #49

kolibril13 opened this issue Feb 22, 2024 · 1 comment

Comments

@kolibril13
Copy link
Collaborator

As @alexisthual suggested in today's meeting, it would be nice to expose nv.saveScene in order to generate static iamges.
Here's an example on how nv.saveScene is used in niivue:
https://github.com/niivue/ipyniivue-experimental/blob/main/original_gallery.md#color-maps-for-voxels

@kolibril13 kolibril13 transferred this issue from niivue/ipyniivue-experimental Mar 15, 2024
@kolibril13
Copy link
Collaborator Author

Just investigated this issue a bit:

Python

class AnyNiivue(OptionsMixin, anywidget.AnyWidget):
    _save_scene = t.Bool(False).tag(sync=True)

    def save_scene(self):
        """Saves the current scene to a file"""
        self._save_scene = True

In widget.js

model.on("change:_save_scene", () => {
  nv.saveScene();
});

in notebook:

nv.save_scene()

This does work, but only once, as _save_scene is not being reset to False.
After nv.saveScene(); is called, a pop-up window opens where one can define the filename.

Alternatively, there is also an option to directly pass a file name like this:
nv1.saveScene("ScreenShot.png"); which could be also be implemented on the python side.

I guess the best approach here is to have a JSON traitlet like this
_save_scene_as = t.Dict({"name": "screenshot.png", "counter": 1}).tag(sync=True)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo
Development

No branches or pull requests

1 participant