hanjinliu / magic-class

Generate multifunctional and macro recordable GUIs from Python classes
https://hanjinliu.github.io/magic-class/
BSD 3-Clause "New" or "Revised" License
40 stars 5 forks source link

Warning when launching GUI #25

Open GiuseppeCiccone96 opened 2 years ago

GiuseppeCiccone96 commented 2 years ago

Hi,

I get this warning whenever I use my magic-class built GUI - do you know where it comes from?

qt.qpa.window: <QNSWindow: 0x137414bf0; contentView=<QNSView: 0x1374147e0; QCocoaWindow(0x60000382cd10, window=QWidgetWindow(0x600002b05260, name="magicgui.QPushButtonWindow"))>> has active key-value observers (KVO)! These will stop working now that the window is recreated, and will result in exceptions when the observers are removed. Break in QCocoaWindow::recreateWindowIfNeeded to debug. qt.qpa.window: <QNSWindow: 0x13740fac0; contentView=<QNSView: 0x13740f6b0; QCocoaWindow(0x60000382ca50, window=QWidgetWindow(0x600002b3fc00, name="Prepare ExperimentWindow"))>> has active key-value observers (KVO)! These will stop working now that the window is recreated, and will result in exceptions when the observers are removed. Break in QCocoaWindow::recreateWindowIfNeeded to debug. qt.qpa.window: <QNSWindow: 0x13744cd50; contentView=<QNSView: 0x13744c860; QCocoaWindow(0x60000382cd10, window=QWidgetWindow(0x600002b07600, name="magicgui.QPushButtonWindow"))>> has active key-value observers (KVO)! These will stop working now that the window is recreated, and will result in exceptions when the observers are removed. Break in QCocoaWindow::recreateWindowIfNeeded to debug. qt.qpa.window: <QNSWindow: 0x114f067a0; contentView=<QNSView: 0x114f06390; QCocoaWindow(0x600003830000, window=QWidgetWindow(0x600002b2e100, name="VisualizationWindow"))>> has active key-value observers (KVO)! These will stop working now that the window is recreated, and will result in exceptions when the observers are removed. Break in QCocoaWindow::recreateWindowIfNeeded to debug. qt.qpa.window: <QNSWindow: 0x137457e70; contentView=<QNSView: 0x137457a60; QCocoaWindow(0x60000382cfd0, window=QWidgetWindow(0x600002b1b960, name="Further OptionsWindow"))>> has active key-value observers (KVO)! These will stop working now that the window is recreated, and will result in exceptions when the observers are removed. Break in QCocoaWindow::recreateWindowIfNeeded to debug.

thanks a lot,

Giuseppe

hanjinliu commented 2 years ago

Hi @GiuseppeCiccone96 I've never seen that kind of errors... Can you tell me the OS, qtpy version, pyqt/pyside version you are using?

GiuseppeCiccone96 commented 2 years ago

Maybe it's the way the GUI is set up... macOS Monterey Version 12.1 qtpy 2.0.1 pyqt 5.15.2

GiuseppeCiccone96 commented 2 years ago

this is the code:

https://github.com/GiuseppeCiccone96/bulkrheogui

hanjinliu commented 2 years ago

Strangely I could not reproduce the warning (on Windows). The Qt versions are following:

qtpy                      2.0.1
pyqt5                     5.15.6
pyqt5-qt5                 5.15.2
pyqt5-sip                 12.10.1

The only change I applied to your code is deleting the line mpl.use('qtagg') because I did not work from IPython but I don't think this would be the reason. I'll check it later with MacBook.

hanjinliu commented 2 years ago

Hi @GiuseppeCiccone96, Finally I found why it happens. It seems that in MacOS, recreation of Qt window is not allowed. Even in following example I got the similar warning.

from magicgui.widgets import Container, PushButton

button = PushButton()
button.show()

c = Container()
c.show()

c.append(button)  # warning here!

This might be a bug in Qt, but I think I can somehow solve this problem on my side by avoiding unnecessary window creation. Thanks for the report!

GiuseppeCiccone96 commented 2 years ago

Thanks a lot for the clarification :)!