<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 12 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
pre
        {mso-style-priority:99;
        mso-style-link:"Pré-formatação HTML Char";
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";}
span.EstiloDeEmail17
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.Pr-formataoHTMLChar
        {mso-style-name:"Pré-formatação HTML Char";
        mso-style-priority:99;
        mso-style-link:"Pré-formatação HTML";
        font-family:"Courier New";}
span.k
        {mso-style-name:k;}
span.nc
        {mso-style-name:nc;}
span.p
        {mso-style-name:p;}
span.n
        {mso-style-name:n;}
span.fm
        {mso-style-name:fm;}
span.bp
        {mso-style-name:bp;}
span.o
        {mso-style-name:o;}
span.mi
        {mso-style-name:mi;}
span.nf
        {mso-style-name:nf;}
span.s2
        {mso-style-name:s2;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:70.85pt 3.0cm 70.85pt 3.0cm;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=PT-BR link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Hi,<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>I think in this case, as you do not want to close your gui, you should put the message bar in your gui, I suppose it's a dialog.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>you have a code sample in <a href="https://docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/communicating.html">Qgis cookbook</a>, may it can help you:<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:10.0pt;font-family:"Courier New"'>class MyDialog(QDialog):<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:10.0pt;font-family:"Courier New"'>    def __init__(self):<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:10.0pt;font-family:"Courier New"'>        QDialog.__init__(self)<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:10.0pt;font-family:"Courier New"'>        self.bar = QgsMessageBar()<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:10.0pt;font-family:"Courier New"'>        self.bar.setSizePolicy( QSizePolicy.Minimum, QSizePolicy.Fixed )<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:10.0pt;font-family:"Courier New"'>        self.setLayout(QGridLayout())<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:10.0pt;font-family:"Courier New"'>        self.layout().setContentsMargins(0, 0, 0, 0)<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:10.0pt;font-family:"Courier New"'>        self.buttonbox = QDialogButtonBox(QDialogButtonBox.Ok)<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:10.0pt;font-family:"Courier New"'>        self.buttonbox.accepted.connect(self.run)<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:10.0pt;font-family:"Courier New"'>        self.layout().addWidget(self.buttonbox, 0, 0, 2, 1)<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:10.0pt;font-family:"Courier New"'>        self.layout().addWidget(self.bar, 0, 0, 1, 1)<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:10.0pt;font-family:"Courier New"'>    def run(self):<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:10.0pt;font-family:"Courier New"'>        self.bar.pushMessage("Hello", "World", level=Qgis.Info)<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm'><p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>De:</span></b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> QGIS-Developer [mailto:qgis-developer-bounces@lists.osgeo.org] <b>Em nome de </b>Roberta Fagandini<br><b>Enviada em:</b> sexta-feira, 3 de maio de 2019 10:45<br><b>Para:</b> qgis-developer@lists.osgeo.org<br><b>Assunto:</b> [QGIS-Developer] show error message without exiting the plugin<o:p></o:p></span></p></div><p class=MsoNormal><o:p> </o:p></p><div><div><p class=MsoNormal>Hi all,<o:p></o:p></p><div><p class=MsoNormal>I'm developing a plugin and I need to check if some features of the input vector layer are selected or not. If not I'd like to show an error message without closing the plugin gui:<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>This is the code at the moment:<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><div><p class=MsoNormal>            if self.dlg.checkBox.isChecked():<o:p></o:p></p></div><div><p class=MsoNormal>                check_sel = selectedLayer2.selectedFeatureCount()<o:p></o:p></p></div><div><p class=MsoNormal>                if check_sel > 0:<o:p></o:p></p></div><div><p class=MsoNormal>                    intersec_layer = QgsProcessingFeatureSourceDefinition(selectedLayer2.id(), True)<o:p></o:p></p></div><div><p class=MsoNormal>                else:<o:p></o:p></p></div><div><p class=MsoNormal>                    self.iface.messageBar().pushCritical("Error", "No features selected in layer {}.".format(selectedLayer2.name()))<o:p></o:p></p></div><div><p class=MsoNormal>                    return <o:p></o:p></p></div></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>Any idea?<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>Thanks<o:p></o:p></p></div><div><p class=MsoNormal>Roberta<o:p></o:p></p></div></div></div></div></body></html>