Exception display to the right of Command Line for PyQt/PySide callbacks/slots in Autodesk Maya
Question: **Updated: to make it much clearer.**

In the following code snippets, making use of Maya widgets through `pymel`,
there is an error highlight on the right of Command Line.

    
    
    import pymel.core as pm
    
    def raiseError():
        pm.select("ooxx") # ooxx doesn't exist
        print "Something after the exception."
    
    class pymelWindow(object):
        def __init__(self):
            self.mainWin = pm.window("test")
            with self.mainWin:
                mainForm = pm.formLayout()
                with mainForm:
                    btn = pm.button(label='show error',command=pm.Callback(raiseError))
                mainForm.redistribute()
    
        def show(self):
            self.mainWin.show()
    
    win = pymelWindow()
    win.show()
    

Here attached is an snapshot of Maya 2011 (the same issue in Maya2014) with an
error highlight (**in red**).

![Maya with error highlight to the right of Command
Line.](http://i.stack.imgur.com/FKV2g.jpg)

and here is the Stack Trace:

    
    
    # Error: Maya Node does not exist: u'ooxx'
    # Traceback (most recent call last):
    #   File "/usr/autodesk/maya2014-x64/lib/python2.7/site-packages/pymel/internal/factories.py", line 778, in callback
    #     res = origCallback( *newargs )
    #   File "/usr/autodesk/maya2014-x64/lib/python2.7/site-packages/pymel/internal/factories.py", line 701, in __call__
    #     return self.func(*self.args, **self.kwargs)
    #   File "/dept/rdworks/drake/Desktop/pyqt_issues/testPyQtSpitError.py", line 119, in raiseError
    #     pm.select("ooxx")
    #   File "/usr/autodesk/maya2014-x64/lib/python2.7/site-packages/pymel/core/general.py", line 151, in select
    #     raise TypeError, msg
    # MayaNodeError: Maya Node does not exist: u'ooxx' # 
    

However, when I switch to use PyQt/PySide for widgets with the following code
snippets, there is no any visible _error highlight to the right of Command
Line_! Does anyone know how to make PyQt/PySide version have the same GUI
behaviours?

    
    
    import pymel.core as pm
    from PyQt4 import QtGui
    
    def raiseError():
        pm.select("ooxx") # ooxx doesn't exist
        print "Something after the exception."
    
    class pyQtWindow(QtGui.QMainWindow):
        def __init__(self, parent = None):
            # init our ui using the MayaWindow as parent
            super(pyQtWindow, self).__init__(parent)
    
            self.centralWidget = QtGui.QWidget(self)
            self.setCentralWidget(self.centralWidget)
            self.centralLayout = QtGui.QVBoxLayout()
            self.centralWidget.setLayout(self.centralLayout)
    
            self.errorBtn = QtGui.QPushButton('show error')
            self.errorBtn.clicked.connect(raiseError)
            self.centralLayout.addWidget(self.errorBtn)
    
    win = pyQtWindow()
    win.show()
    

![Maya without error highlight to the right of Command
Line!](http://i.stack.imgur.com/1YNKl.jpg)

    
    
    # Traceback (most recent call last):
    #   File "/usr/autodesk/maya2014-x64/lib/python2.7/site-packages/pymel/internal/factories.py", line 701, in __call__
    #     return self.func(*self.args, **self.kwargs)
    #   File "/dept/rdworks/drake/Desktop/pyqt_issues/testPyQtSpitError.py", line 119, in raiseError
    #     pm.select("ooxx")
    #   File "/usr/autodesk/maya2014-x64/lib/python2.7/site-packages/pymel/core/general.py", line 151, in select
    #     raise TypeError, msg
    # pymel.core.general.MayaNodeError: Maya Node does not exist: u'ooxx'
    


Answer: If you are using PyQt/PySide then the default behavior upon getting an
exception wont display the error in red. I have no idea _why_ nor do I know of
any switch which does that.

In order the achieve that you'd have to change the `raiseError` function to
something like this:

    
    
    def raiseError():
        import maya.OpenMaya as om
        import traceback as tb
        import sys
        try:
            pm.select("ooxx") # ooxx doesn't exist
        except Exception as exc:
            msg = "".join(tb.format_exception(*sys.exc_info())) # or any custom msg
            om.MGlobal.displayError(msg)
        finally:
            print "Something after the exception."
    

This way you'll get the red error display.

