You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
the following error message is generated (similar errors occur with PyQt5, PySide2, and PySide6):
Traceback (most recent call last):
File "/Users/joeyo/src/bmi/analysis/joeyo/fpl/qt_minimal.py", line 3, in <module>
plot = fpl.Plot(canvas="qt")
File "/opt/homebrew/lib/python3.10/site-packages/fastplotlib/layouts/_plot.py", line 54, in __init__
super(Plot, self).__init__(
File "/opt/homebrew/lib/python3.10/site-packages/fastplotlib/layouts/_subplot.py", line 77, in __init__
canvas, renderer = make_canvas_and_renderer(canvas, renderer)
File "/opt/homebrew/lib/python3.10/site-packages/fastplotlib/layouts/_utils.py", line 50, in make_canvas_and_renderer
raise ImportError(
ImportError: The qt framework is not installed for using this canvas
Which suggests that fastplotlib/layouts/_utils.py:17 is raising an ImportError:
"""Use a simple Plot to display a video frame that can be updated using a QSlider"""fromPyQt6importQtWidgets, QtCoreimportfastplotlibasfplimportimageio.v3asiio# Qt app MUST be instantiated before creating any fpl objects, or any other Qt objectsapp=QtWidgets.QApplication([])
video=iio.imread("imageio:cockatoo.mp4")
# force qt canvas, wgpu will sometimes pick glfw by default even if Qt is presentplot=fpl.Plot(canvas="qt")
plot.add_image(video[0], name="video")
plot.camera.local.scale*=-1defupdate_frame(ix):
plot["video"].data=video[ix]
# you can also do plot.graphics[0].data = video[ix]# create a QMainWindow, set the plot canvas as the main widget# The canvas does not have to be in a QMainWindow and it does# not have to be the central widget, it will work like any QWidgetmain_window=QtWidgets.QMainWindow()
main_window.setCentralWidget(plot.canvas)
# Create a QSlider for updating framesslider=QtWidgets.QSlider(QtCore.Qt.Orientation.Horizontal)
slider.setMaximum(video.shape[0] -1)
slider.setMinimum(0)
slider.valueChanged.connect(update_frame)
# put slider in a dockdock=QtWidgets.QDockWidget()
dock.setWidget(slider)
# put the dock in the main windowmain_window.addDockWidget(
QtCore.Qt.DockWidgetArea.BottomDockWidgetArea,
dock
)
# calling plot.show() is required to start the rendering loopplot.show()
# set window size from width and height of videomain_window.resize(video.shape[2], video.shape[1])
# show the main windowmain_window.show()
# execute Qt appapp.exec()
@joeyo I just merged #313 which implements output contexts, so now plots, gridplots, and even image widgets work the same between Qt and jupyter including the toobars 😄
You can use the Qt context in standalone Qt applications, or in notebooks by just using %gui qt
Note that the ImageWidget is currently limited to grayscale images/image sequences, it does not handle RBGA. If you want RGBA you will have to add the image graphic yourself and use a gridplot/plot with your own sliders etc.
Activity
kushalkolar commentedon Oct 26, 2023
You'll need to encapsulate it within a Qt app, I'll make an example later today.
kushalkolar commentedon Oct 26, 2023
By the way, @EricThomson says hi 😄
kushalkolar commentedon Oct 26, 2023
@joeyo
Here's an example with video and a slider. Qt is quite tedious which is why I mostly use ipywidgets these days 😄
#341
joeyo commentedon Oct 26, 2023
@kushalkolar Awesome, works out of the box!
(Hi @EricThomson!)
[-]Interoperability with PyQt[/-][+]Embedding in PyQt[/+]EricThomson commentedon Oct 26, 2023
Hey @joeyo if you are going to SFN there is going to be a fastplotlib code sprint 😄
https://twitter.com/kushalkolar/status/1706725236719354241
Maybe a good time to add Qt demo @kushalkolar
kushalkolar commentedon Oct 26, 2023
@joeyo I just added a minimal Qt example: https://github.com/fastplotlib/fastplotlib/blob/main/examples/qt/minimal.py
I'm thinking we might make a Qt toolbar as well, so that plots can be QWidgets that come pre-loaded with the toolbar that you get in notebooks.
EricThomson commentedon Oct 26, 2023
nevermind Kushal is fast as usual 😆
kushalkolar commentedon Oct 31, 2023
@joeyo I just merged #313 which implements output contexts, so now plots, gridplots, and even image widgets work the same between Qt and jupyter including the toobars 😄
You can use the Qt context in standalone Qt applications, or in notebooks by just using
%gui qtAdded qt image widget example here: https://github.com/fastplotlib/fastplotlib/blob/main/examples/qt/imagewidget.py
Note that the
ImageWidgetis currently limited to grayscale images/image sequences, it does not handle RBGA. If you want RGBA you will have to add the image graphic yourself and use a gridplot/plot with your own sliders etc.