Skip to content
Permalink
Browse files
Report Python errors with QgsMessageOutput instead of QMessageBox.
(User can copy & paste message from it, with message box he can't)


git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@6761 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Mar 4, 2007
1 parent 70146f3 commit 19f18f091c68761b3bca2297b6b9746277e62b8d
Showing with 9 additions and 4 deletions.
  1. +9 −4 src/app/qgspythonutils.cpp
@@ -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(

0 comments on commit 19f18f0

Please sign in to comment.