[QGIS-Developer] show error message without exiting the plugin

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[QGIS-Developer] show error message without exiting the plugin

Roberta Fagandini-2
Hi all,
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:

This is the code at the moment:

            if self.dlg.checkBox.isChecked():
                check_sel = selectedLayer2.selectedFeatureCount()
                if check_sel > 0:
                    intersec_layer = QgsProcessingFeatureSourceDefinition(selectedLayer2.id(), True)
                else:
                    self.iface.messageBar().pushCritical("Error", "No features selected in layer {}.".format(selectedLayer2.name()))
                    return 

Any idea?

Thanks
Roberta

_______________________________________________
QGIS-Developer mailing list
[hidden email]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Reply | Threaded
Open this post in threaded view
|

[QGIS-Developer] RES: show error message without exiting the plugin

Jorge Almerio

Hi,

 

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.

you have a code sample in Qgis cookbook, may it can help you:

 

class MyDialog(QDialog):

    def __init__(self):

        QDialog.__init__(self)

        self.bar = QgsMessageBar()

        self.bar.setSizePolicy( QSizePolicy.Minimum, QSizePolicy.Fixed )

        self.setLayout(QGridLayout())

        self.layout().setContentsMargins(0, 0, 0, 0)

        self.buttonbox = QDialogButtonBox(QDialogButtonBox.Ok)

        self.buttonbox.accepted.connect(self.run)

        self.layout().addWidget(self.buttonbox, 0, 0, 2, 1)

        self.layout().addWidget(self.bar, 0, 0, 1, 1)

    def run(self):

        self.bar.pushMessage("Hello", "World", level=Qgis.Info)

 

 

 

 

 

De: QGIS-Developer [mailto:[hidden email]] Em nome de Roberta Fagandini
Enviada em: sexta-feira, 3 de maio de 2019 10:45
Para: [hidden email]
Assunto: [QGIS-Developer] show error message without exiting the plugin

 

Hi all,

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:

 

This is the code at the moment:

 

            if self.dlg.checkBox.isChecked():

                check_sel = selectedLayer2.selectedFeatureCount()

                if check_sel > 0:

                    intersec_layer = QgsProcessingFeatureSourceDefinition(selectedLayer2.id(), True)

                else:

                    self.iface.messageBar().pushCritical("Error", "No features selected in layer {}.".format(selectedLayer2.name()))

                    return 

 

Any idea?

 

Thanks

Roberta


_______________________________________________
QGIS-Developer mailing list
[hidden email]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer