-
Notifications
You must be signed in to change notification settings - Fork 4
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
how does BackgroundPlotter work? #139
Comments
That's a very interesting question @bistek ! And probably @akaszynski is way more knowledgeable than me on this matter but I can still try to redirect you to the part of the code which I believe manage to initialize https://github.com/pyvista/pyvista/blob/master/pyvista/plotting/qt_plotting.py#L647-L663 Notice that in the case of from IPython import get_ipython
ipython = get_ipython()
ipython.magic('gui qt')
from IPython.external.qt_for_kernel import QtGui
QtGui.QApplication.instance() So it's not your typical: from PyQt5.QtWidgets import *
app = QApplication([])
...
app.exec_() From what I know |
Thanks very much! |
@GuillaumeFavelier has it right. For applications outside of app = QApplication.instance()
if not app: # pragma: no cover
app = QApplication(['']) We then create a main window and a frame and populate it with our vtk widget: app_window = MainWindow()
frame = QFrame()
# add vtk widget to frame
frame.setLayout(vlayout)
app_window.setCentralWidget(self.frame) Finally, we show this window app_window.show() At no point do we run |
Hi,
If the axes are scaled the same: How can I ensure that the distance between the ticks of the axes is the same? |
Would it be possible for you to please post your data here so I can try to reproduce this on my end? |
@akaszynski so if I understand it correctly in order to show a Cannot be shown by itself as a standalone window as with and another question is it possible to keep the a |
Take a look at
The best way to do this is to use |
To be honest I did not really get the part of the code in the link, could you please elaborate a bit more. An example also I think would be quite insightful, if possible. |
Here's a basic example: """Basic example demonstrating QtInteractor usage"""
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow
from pyvista.plotting import QtInteractor
import pyvista
class PvWindow(QMainWindow):
""" Primary GUI object """
def __init__(self):
""" Generate window with a dock """
QMainWindow.__init__(self)
# initialize the plotter
self._plotter = QtInteractor(self)
self.setCentralWidget(self._plotter.interactor)
# add a mesh
self._plotter.add_mesh(pyvista.Sphere())
self._plotter.add_axes()
app = QApplication(sys.argv)
window = PvWindow()
window.show()
app.exec_() |
I am sorry but still I do not understand how this is connected with the
If I use run mode on PyCharm and I do not get any window and script terminates, if instead I use debug mode and put a checkpoint afterwards I am getting a window. If I use simple Ultimately, what I want to achieve is to have |
Sorry, I was confused about your question and I think I understand now.
If you run the above via a script (i.e. I recommend using PyCharm's console and creating an instance of import time
import pyvista
plotter = pyvista.BackgroundPlotter()
mesh = pyvista.Sphere()
plotter.add_mesh(mesh)
plotter.show()
# demonstrate non-blocking events
for i in range(100):
mesh.points *= 1.01
plotter.render()
plotter.app.processEvents()
plotter.add_text('sleeping...')
time.sleep(3) # demonstrate blocking event Let me know if this makes sense. |
Ok, that's better, but not exactly what I would like. Is it possible to keep the window open and be able to interact with with even if the script is done. For example take a Matlab development session with figure windows that come up with a responsive command prompt. Could that be possible to be done with And a second question does the |
You'll want to use the following at the end of the script. This effectively hands control over to the pyqt thread until the pyqt window is closed. plotter.app.exec_()
I'm afraid not at the moment. If you're running an interactive session (i.e. python in a console) this isn't an issue, but for your use case we'd have to add in additional hooks within |
@akaszynski thanks for the feedback. I was checking on
it will not continue to `print("hello!!!") until I terminate the window. As I said I would like to have the window available while the script continues or even terminates. |
At the moment, the only way you'll be able to pull up a background plotting window that updates and is interactive while your script runs is by adding: plotter.render()
plotter.app.processEvents() When you'd like the plot to update. It's not optimal, and we're going to have to add this feature in a future release. At the end of the script, if you want to keep the background plotter open and not have it just close, add |
@akaszynski thanks for the feedback. It will be nice to see that in a future release. |
For complement I've managed to have the plotting window in a different process with
|
Very interesting! Have you tried adding or removing actors to the renderer? E.g with Thanks! |
If you render anything within the On the other hand if you do it outside and once the main process is finished then I cannot see how to communicate to the Thus, I do not see how you could add multiple meshes on the same window like in a Matlab-wise development session. If anyone is aware of how possibly we could be doing that, I would appreciate any feedback. |
Dear All, I am trying to develop a Qt QTableView to show and edit interactively some data about the PyVista objects that we visualize, at the same time, in the BackgroundPlotter.
Basically we need another Qt window that is able to work in background exactly as the BackgroundPlotter.
The question is: how do you obtain the "active in background" behavior in the BackgroundPlotter? Can you please point us to the relevant lines of code or to some documentation that you have used to develop it?
Thanks very much!
The text was updated successfully, but these errors were encountered: