Skip to content

Commit

Permalink
Report Python errors with QgsMessageOutput instead of QMessageBox.
Browse files Browse the repository at this point in the history
(User can copy & paste message from it, with message box he can't)


git-svn-id: http://svn.osgeo.org/qgis/trunk@6761 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Mar 4, 2007
1 parent e863ecc commit f0c814f
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/app/qgspythonutils.cpp
Expand Up @@ -83,15 +83,20 @@ void QgsPythonUtils::initPython(QgisInterface* interface)
runString("import traceback"); // for formatting stack traces

// hook that will show information and traceback in message box
// TODO: maybe QgsMessageOutput / QgsMessageViewer should be used instead
runString(
"def qgis_except_hook(type, value, tb):\n"
" lst = traceback.format_exception(type, value, tb)\n"
" str = 'An error has occured while executing Python code:\\n'\n"
" str = '<font color=\"red\">An error has occured while executing Python code:</font><br><br>'\n"
" for s in lst:\n"
" str += s\n"
" QtGui.QMessageBox.warning(None, 'Python error', str)\n");

" str = str.replace('\\n', '<br>')\n"
" str = str.replace(' ', '&nbsp;')\n" // preserve whitespaces for nicer output
" \n"
" msg = QgsMessageOutput.createMessageOutput()\n"
" msg.setTitle('Error')\n"
" msg.setMessage(str, QgsMessageOutput.MessageHtml)\n"
" msg.showMessage()\n");

// hook for python console so all output will be redirected
// and then shown in console
runString(
Expand Down

0 comments on commit f0c814f

Please sign in to comment.