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

BackgroundPlotter custom menus and buttons #122

Closed
andrea-bistacchi opened this issue Feb 9, 2020 · 7 comments
Closed

BackgroundPlotter custom menus and buttons #122

andrea-bistacchi opened this issue Feb 9, 2020 · 7 comments
Labels
PyQt5/PySide2 Topics on the use of PyVista in Qt/PySide apps

Comments

@andrea-bistacchi
Copy link

Hello, I was wondering if there is an already tested way to add custom menus and buttons to the BackgroundPlotter. I guess it should be possible since in the end it is a Qt window. I have not been able to find an example.

Thanks!

@banesullivan
Copy link
Member

Hi there, we've been working on expanding how users can customize the BackgroundPlotter with buttons/menus. You can currently do this, but the interface isn't all that clean. We are hoping to expand pyvista-gui into a fully customizable suite with tons of templates/easy to add features but we haven't had the time yet to make it functional.

In the meantime, here is an example of how to add custom menus and a toolbar to the BackgroundPlotter:

import pyvista as pv
from pyvista import examples

from PyQt5.QtWidgets import  QAction


st_helens = examples.download_st_helens().warp_by_scalar()


plotter = pv.BackgroundPlotter()

def add_st_helens():
    plotter.add_mesh(st_helens, name="st helens")

# Add a drop down menu
user_menu = plotter.main_menu.addMenu('My Features')
user_menu.addAction('Add St. Helens', add_st_helens)

# Add a toolbar
def add_action(toolbar, key, method, main_window):
    action = QAction(key, main_window)
    action.triggered.connect(method)
    toolbar.addAction(action)
    return

user_toolbar = plotter.app_window.addToolBar('User Toolbar')
add_action(user_toolbar, 'Line Widget', plotter.add_line_widget, plotter.app_window)

2020-02-09 12 37 49

@banesullivan banesullivan added the PyQt5/PySide2 Topics on the use of PyVista in Qt/PySide apps label Feb 9, 2020
@andrea-bistacchi
Copy link
Author

Good, thanks!

BTW, how do I access properties of the line widget? Particularly coordinates of the end points.

Thanks!

@banesullivan
Copy link
Member

You’d need to pass a callback method when activating the line widget. See https://docs.pyvista.org/plotting/widgets.html#line-widget

So in order to have a Qt button handle all that, you’d need a custom function to properly call the add_line_widget method with your callback

Something like

def line_callback(a, b):
    # do stuff with the two points
    pass

def add_line():
    plotter.add_line_widget(line_callback)

# put add_line on the Qt button

Sent with GitHawk

@andrea-bistacchi
Copy link
Author

Great thanks!

@banesullivan
Copy link
Member

banesullivan commented Feb 25, 2020

@bistek, would you please open a new issue about these picking issues? In the meantime, I'll try to find a solution

@andrea-bistacchi
Copy link
Author

Done #133, thanks!

@HametAl
Copy link

HametAl commented Mar 27, 2023

Hi there, we've been working on expanding how users can customize the BackgroundPlotter with buttons/menus. You can currently do this, but the interface isn't all that clean. We are hoping to expand pyvista-gui into a fully customizable suite with tons of templates/easy to add features but we haven't had the time yet to make it functional.

In the meantime, here is an example of how to add custom menus and a toolbar to the BackgroundPlotter:

import pyvista as pv
from pyvista import examples

from PyQt5.QtWidgets import  QAction


st_helens = examples.download_st_helens().warp_by_scalar()


plotter = pv.BackgroundPlotter()

def add_st_helens():
    plotter.add_mesh(st_helens, name="st helens")

# Add a drop down menu
user_menu = plotter.main_menu.addMenu('My Features')
user_menu.addAction('Add St. Helens', add_st_helens)

# Add a toolbar
def add_action(toolbar, key, method, main_window):
    action = QAction(key, main_window)
    action.triggered.connect(method)
    toolbar.addAction(action)
    return

user_toolbar = plotter.app_window.addToolBar('User Toolbar')
add_action(user_toolbar, 'Line Widget', plotter.add_line_widget, plotter.app_window)

2020-02-09 12 37 49 2020-02-09 12 37 49

Is there a way to remove default items from menu bar and toolbar, or we need to disable the default menu and tool bars and then define and add our own menu and tool bars?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PyQt5/PySide2 Topics on the use of PyVista in Qt/PySide apps
Projects
None yet
Development

No branches or pull requests

3 participants