I believe it is caused by the fact that Qt slot exceptions can't be caught by the user, since they can happen async in the event loop, so there is a top level sys exception hook that will catch them and print them. But being Maya, this has no integration with the Script Editor, since it doesn't really know an exception happened. This is all a guess.
But, here is a possible solution you could use: https://gist.github.com/justinfx/91cc21a79a182a6d028ab9943381a781 It is a decorator, which you can add to your slots, in order to report exceptions to the Script Editor Justin On Fri, Jan 13, 2017 at 8:26 AM fruity <[email protected]> wrote: > Hi there, > > I'm facing a problem that I never noticed before in python / qt : when I > try to raise an error from a function triggered by a signal, I can't get > the red message in maya. The error is raised in the script editor, but if > the SE is closed, no way to know that an error occured. > To see what I mean, you can run the piece of code at the end of my post. > From what I understood, it comes from the mechanism of signals / slots > itself, like if the function triggered by a signal was 'local' only. If I > call the same method manually (i.e. NOT with the signal), it works. > I tried with both pyqt4 and pyside, same result. > I have a couple of workarounds (I can use the api to raise my error > instead, or I can use logging), but the truth is that I really like the > built-in errors in python, and I'd love to be able to stick to this > workflow if possible. > If anyone has a solution for that, I'd be really happy to know it ! > Many thanks > > from PySide.QtGui import * > from PySide.QtCore import * > class Xxx(QWidget): > def __init__(self, parent=None): > super(Xxx, self).__init__(parent) > self.ui() > def ui(self): > btn = QPushButton('Raise error') > btn.clicked.connect(self.raiseError) > mainLayout = QHBoxLayout() > mainLayout.addWidget(btn) > self.setLayout(mainLayout) > def raiseError(self): > raise NameError > a = Xxx() > a.show() > > -- > You received this message because you are subscribed to the Google Groups > "Python Programming for Autodesk Maya" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/python_inside_maya/76b853ec-2ba8-4d79-85e4-fcf78be74cf2%40googlegroups.com > <https://groups.google.com/d/msgid/python_inside_maya/76b853ec-2ba8-4d79-85e4-fcf78be74cf2%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA3eNtUa5anqd1An-6z2GsJ1zjh-4zZeaXdKLP_qFFrmew%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
