<div dir="ltr">Hi all,<div><br></div><div>I'm a newbie with PyQt. I'm writing an App and want to retrieve the layers' names available in QGis's layer tree using the INPUT parameter as the one available in the Processing Algorithm with the layer dropdown widget and the widget options [iterate over this layer, advanced options, select input].</div><div>I wonder if it's possible to inherit the widget from the QgsProcessingAlgorithm class as shown below or whether I should write a new dropdown widget from scratch to retrieve all the layers available in the layer tree.</div><div><br></div><div>import sys<br>from PyQt5.QtCore import (QSize,Qt)<br>import sys<br>from PyQt5.QtWidgets import (QApplication, <br>                                QWidget, <br>                                QPushButton, <br>                                QMainWindow,<br>                                QVBoxLayout)<br>                                <br>from qgis.PyQt.QtCore import QCoreApplication<br>from qgis.core import (QgsProcessing,<br>                       QgsFeatureSink,<br>                       QgsProcessingException,<br>                       QgsProcessingAlgorithm,<br>                       QgsProcessingParameterFeatureSource,<br>                       QgsProcessingParameterFeatureSink)<br>from qgis import processing<br><br><br>class MainWindow(QMainWindow,QgsProcessingAlgorithm):<br>    def __init__(self):<br>        super().__init__()<br>        self.setWindowTitle("My App")<br>        self.setGeometry(100,100,400,200)<br>        <br>               <br>        layout = QVBoxLayout()<br>        self.button = QPushButton("Calculate Area")<br>        layout.addWidget(self.button)<br>        self.result_label = QLabel("QGIS3")<br>        layout.addWidget(self.result_label)<br>        self.button.clicked.connect(self.calculate_area)<br>        central_widget = QWidget()<br>        central_widget.setLayout(layout)<br>        <br>       <br>        self.setCentralWidget(central_widget)<br>        self.button.clicked.connect(self.calculate_area)<br>        #self.setFixedSize(QSize(400,300))<br>        <br>    def initAlgorithm(self, config=None):<br>        """<br>        Here we define the inputs and output of the algorithm, along<br>        with some other properties.<br>        """<br><br>        # We add the input vector features source. It can have any kind of<br>        # geometry.<br>        self.addParameter(<br>            QgsProcessingParameterFeatureSource(<br>                self.INPUT,<br>                <a href="http://self.tr">self.tr</a>('Input layer'),<br>                [QgsProcessing.TypeVectorAnyGeometry]<br>            )<br>        )<br>    <br>    def calculate_area(self):<br>        print('568,00 km2')<br>        # Prepare polygon geometry (replace with your own geometry)<br>        # wkt = "POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))"<br>        # polygon = QgsGeometry.fromWkt(wkt)<br><br>        # # Use the Processing algorithm to calculate the area<br>        <br>        <br>        # params = {<br>        #     "INPUT": self.INPUT,<br>        #     "OUTPUT": "memory:",<br>        # }<br>        # result = processing.run("qgis:exportaddgeometrycolumns", params)<br>        # area = result["OUTPUT"].getFeatures().__next__().attribute("area")<br><br>        # self.result_label.setText(f"Calculated Area: {area:.2f} square units")<br><br>window = MainWindow()<br>window.show()<br></div><div><br></div><div><br clear="all"><div><br></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><font face="verdana, sans-serif">##########################################</font></div><font size="4" face="verdana, sans-serif"><b><font color="#20124d">Julierme G Pinheiro</font></b><br><b><font color="#660000">SDI Expert & Geoprocessing Specialist</font></b></font><div><font size="4" face="verdana, sans-serif"><font color="#351c75">Phone:</font> <font color="#444444">+55 61 99994-3569</font></font></div><div><font size="4" face="verdana, sans-serif"><font color="#351c75">Website:</font> <a href="https://www.udemy.com/course/qgis-server-para-iniciantes-instalacao-e-configuracao/" target="_blank">GIS</a></font></div></div></div></div></div>