You need to embed your vispy canvas into your pyqt5 gui. Creating an instance of the simulation inside the gui file won't work without subsequently adding the canvas wrapper to the main layout/frame/widget. Running the gui from the simulation file won't work. You need to specify pyqt5 as the backend: app = use_app("pyqt5")
Here is a bare-bones example:
from PyQt5 import QtWidgets
from vispy.scene import SceneCanvas, visuals
from vispy.app import use_app
class MainWindow(QtWidgets.QMainWindow):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
central_widget = QtWidgets.QWidget()
main_layout = QtWidgets.QHBoxLayout()
# initialize control class & add to widget
self._controls = Controls()
main_layout.addWidget(self._controls)
# initialize vispy canvas & add to widget
self._canvas_wrapper = CanvasWrapper()
main_layout.addWidget(self._canvas_wrapper.canvas.native)
central_widget.setLayout(main_layout)
self.setCentralWidget(central_widget)
class Controls(QtWidgets.QWidget):
def __init__(self, parent=None):
super().__init__(parent)
layout = QtWidgets.QVBoxLayout()
self.test_label = QtWidgets.QLabel("Label:")
layout.addWidget(self.test_label)
self.test_options = QtWidgets.QComboBox()
self.test_options.addItems(["option1", "option2", "option3"])
layout.addWidget(self.test_options)
layout.addStretch(1)
self.setLayout(layout)
class CanvasWrapper:
def __init__(self):
self.canvas = SceneCanvas(size=(800, 600))
self.grid = self.canvas.central_widget.add_grid()
self.grid.add_view(0, 0, bgcolor='cyan')
if __name__ == "__main__":
app = use_app("pyqt5")
app.create()
win = MainWindow()
win.show()
which will run:
