[Qgis-user] quit() and exit()
    Asim 
    asimrp at lavabit.com
       
    Mon May  2 11:35:32 PDT 2022
    
    
  
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20220503/bfc58685/attachment.htm>
    
    
More information about the Qgis-user
mailing list