15

Is there a way that from running a custom plugin made for QGIS that a Python Shell can appear when the plugin is run, like a debug screen?

I'm asking this to know if there is a way to see print commands through a Python Script while programming a plugin for QGIS.

3
  • Other than a tag of pyqgis this question seems to have no connection to GIS. Would you be able to re-phrase it to say why you think it is a GIS question rather than one more suited to StackOverflow, please?
    – PolyGeo
    Commented Apr 18, 2013 at 0:34
  • I edited, how about now? Commented Apr 18, 2013 at 1:00
  • 1
    Looks much better but I also turned your title into a question and added some extra tags to help attract the right audience.
    – PolyGeo
    Commented Apr 18, 2013 at 2:18

1 Answer 1

14

You send log messages to the QGIS log window using:

QgsMessageLog.logMessage(message, tag, level)

Tag is the title of the tab that will be displayed in the QGIS log window. Level is the message level (defaults to 0).

For example:

QgsMessageLog.logMessage('My message', 'MyPlugin')

See the QGIS API documentation for QgsMessageLog for details.

The log window can be made visible from the View->Panel->Log Messages menu.

The other way is to create a class that captures stdout and directs it to a log window within your plugin (the Script Runner plugin does this). Output from all print statements will be displayed in your log window, although this method is much more involved if you just want to display a few messages during development. You have to be careful doing this, as all print statements from other plugins will be sent to your plugin unless you capture and restore stdout as needed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.