Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A QgsProcessingParameter with custom WidgetWrapper can't be connected correctly in the Model Designer #48816

Closed
1 of 2 tasks
janzandr opened this issue Jun 1, 2022 · 4 comments
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Modeller Processing Relating to QGIS Processing framework or individual Processing algorithms Widgets

Comments

@janzandr
Copy link

janzandr commented Jun 1, 2022

What is the bug or the crash?

I want to implement a QgsProcessingAlgorithm with a QgsProcessingParameterFile that has a custom WidgetWrapper.

Here is a minimal example:

from processing.gui.wrappers import WidgetWrapper
from qgis._core import QgsProcessingParameterFile, QgsProcessingAlgorithm
from qgis._gui import QgsFileWidget


class MyAlgorithm(QgsProcessingAlgorithm):

    def displayName(self):
        return 'My Algorithm'

    def name(self):
        return 'MyAlgorithm'

    def shortDescription(self):
        return 'dummy'

    def group(self):
        return 'Debugging'

    def createInstance(self):
        return type(self)()

    def initAlgorithm(self, configuration):

        # add a normal parameter
        self.addParameter(QgsProcessingParameterFile('file1', 'Normal File'))

        # add a parameter with custom widget
        param = QgsProcessingParameterFile('file2', 'Custom File')
        param.setMetadata({'widget_wrapper': {'class': MyWidgetWrapper}})
        self.addParameter(param)

    def processAlgorithm(self, parameters, context, feedback):
        return {}


class MyWidgetWrapper(WidgetWrapper):
    widget: QgsFileWidget

    def createWidget(self):
        return QgsFileWidget()

    def setValue(self, value):
        self.widget.setFilePath(value)

    def value(self):
        return self.widget.filePath()

Executing the algorithm in the Processing Toolbox works fine.

image

Using the algorithm in the Model Designer is not working as expected:

image

The menu-button for correctly connecting previous outputs is missing:
image

This makes it impossible to actually use the algorithm inside a model.

Steps to reproduce the issue

  1. Add the algorithm from above to a processing provider of your choice.
  2. Use the algorithm in the Model Designer.
  3. See the bug: the "123" menu-button is not shown.

Versions

QGIS version
3.24.2-Tisler
QGIS code revision
13c1a02
Qt version
5.15.3
Python version
3.9.5
GDAL/OGR version
3.4.3
PROJ version
9.0.0
EPSG Registry database version
v10.054 (2022-02-13)
GEOS version
3.10.2-CAPI-1.16.0
SQLite version
3.38.1
PDAL version
2.3.0
PostgreSQL client version
unknown
SpatiaLite version
5.0.1
QWT version
6.1.6
QScintilla2 version
2.13.1
OS version
Windows 10 Version 2009

Active Python plugins
ee_plugin
0.0.4
enmapboxplugin
3.10.0.20220524T082114.TEST
geetimeseriesexplorer
2.0
qgis-maptiler-plugin
3.0.3
timeseriesviewerplugin
1.17.20210312T143004.master
vrtbuilderplugin
0.9.20210222T174536.master
db_manager
0.1.20
grassprovider
2.12.99
MetaSearch
0.3.6
processing
2.12.99
sagaprovider
2.12.99

Supported QGIS version

  • I'm running a supported QGIS version according to the roadmap.

New profile

  • I tried with a new QGIS profile

Additional context

No response

@janzandr janzandr added the Bug Either a bug report, or a bug fix. Let's hope for the latter! label Jun 1, 2022
@nyalldawson
Copy link
Collaborator

The WidgetWrapper class is deprecated -- this is a wontfix

@janzandr
Copy link
Author

janzandr commented Jun 1, 2022

Ah ok, thanks.
@nyalldawson can you point me to an alternative, that I suppose to use instead (e.g. an algorithm or documentation).

@Pedro-Murteira Pedro-Murteira added Processing Relating to QGIS Processing framework or individual Processing algorithms Modeller Widgets labels Jun 1, 2022
@janzandr
Copy link
Author

janzandr commented Jun 3, 2022

Can anybody point me to an example or documentation?
I understand that WidgetWrapper class is deprecated, but how would I implement a custom widget correctly?

@janzandr
Copy link
Author

Hi @alexbruy, I understand, that the WidgetWrapper class is deprecated.
But what would be the correct API to use? Any PyQGIS examples available?
Regards, Andreas.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Modeller Processing Relating to QGIS Processing framework or individual Processing algorithms Widgets
Projects
None yet
Development

No branches or pull requests

4 participants