On 5/2/22 9:36 PM, Stephen Sacks via Qgis-user wrote:
I would like to terminate a Python script gracefully. Both quit() and
exit() not only abort the script but end the entire QGIS app.
Assuming the script runs as a QGIS plugin, a better alternative is to
raise an exception, which will be reported in the QGIS messages tab.
class MyPluginException:
pass
if not filePath.is_file():
# This line should cause the exception message and
# a stack trace be reported in the QGIS messages window.
raise MyPluginException("Unable to find file %s" % fName)
I remember using QgsMessageBar [1] once to provide better cues in the
QGIS UI. It generates a message bar with background color set according
to the severity of the message (info, warning, error).
Hope that helps.
Asim
[1]
https://qgis.org/pyqgis/master/gui/QgsMessageBar.html?highlight=qgsmessagebar#qgis.gui.QgsMessageBar.pushMessage
_______________________________________________
Qgis-user mailing list
[email protected]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user