On Fri, Jan 13, 2017 at 4:12 PM fruity <[email protected]> wrote:
> Thanks for the answer Justin ! > I didn't really understand the event loop thing. > Its just basically meaning that the function you have asked to run as a slot, when a signal fires, is a request for Qt to run it for you at a later date in time. So when Qt wants to fire the signal and then goes to all the registered slots to run them, it does not know about Maya. It just catches the exception itself and prints it. Thats why you would have to put your own wrapper around it and handle it the way you want, for Maya. > The decorator thing is handy, however it'll raise a warning, not an error. > If I change it to make it raise an error, same problem. > Yea I saw that difference as well, but I didn't really track down the reason. I just switched to using a warning to get the example working. > I'm actually really surprised that no one (including me) never has to > raise errors in methods^^ > Well more specifically you are talking about errors from Qt slots, and not just any method that runs and raises an error :-) > > > Le jeudi 12 janvier 2017 13:00:10 UTC-8, Justin Israel a écrit : > > 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/2bb80ce0-41b9-4c3b-ac88-169dcb43795c%40googlegroups.com > <https://groups.google.com/d/msgid/python_inside_maya/2bb80ce0-41b9-4c3b-ac88-169dcb43795c%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/CAPGFgA0czQbAGasAHVF%2BZan5nmzfkHtNVoT77s70GKqKZaiMKA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
