[QGIS-Developer] Add algorithm to an existing provider?

Raymond Nijssen r.nijssen at terglobo.nl
Fri May 13 02:48:06 PDT 2022


Hi Benjamin, thanks for your reply.

I'm not sure how the provider should "save a reference on my algorithm". 
What do you mean?

Some things I tried:


self.provider = TestProvider()
QgsApplication.processingRegistry().addProvider(self.provider)

alg2 = TestAlgorithm2()
alg2.setProvider(self.provider) # Maybe this is "setting a reference??

self.provider.addAlgorithm(alg2)

# Now the provider shows the extra algorithms (but not in the GUI)
print(self.provider.algorithms())

# Attempts to get it in the GUI:
self.provider.refreshAlgorithms()
self.provider.loadAlgorithms()
self.provider.load()


Still no luck!

Regards,
Raymond


On 13-05-2022 09:07, Benjamin Jakimow wrote:
> Hi Raymond,
> 
> you need to ensure that your provider saves a python reference on your 
> TestAlgorithm2() (which you probably already do).
> After its set of algorithms has changed (i.e. refresh, addAlgorithm(s) 
> etc.) it needs to emit the algorithmsLoaded signal.
> 
> Greetings,
> Benjamin
> 
> On 2022-05-13 08:15, Raymond Nijssen via QGIS-Developer wrote:
>> Is there a way to add a processing algorithm to an existing provider
>> using pyqgis?
>>
>> I have 2 plugins and don't know if they are both installed (or which
>> one will load first). The both contain processing algorithms and I
>> want those to end up in the same group.
>>
>> Documentation is a bit brief on this:
>>
>> QgsProcessingProvider
>>
>> Examples show to put the addAlgorithm() function(s) in the
>> loadAlgorithms() function. Then calling
>>
>> QgsApplication.processingRegistry().addProvider(provider)
>>
>> adds the group (=provider?) and the algorithms are in it.
>>
>>
>>
>> What I want to do is finding the provider if it exists already:
>>
>> self.provider = QgsApplication.processingRegistry().providerById('test')
>> if self.provider is None:
>>     self.provider = RayProvider()
>>
>> and then:
>>
>> self.provider.addAlgorithm(TestAlgorithm2())
>>
>> This doesn't work, neither when doing:
>>
>> provider.refreshAlgorithms()
>> provider.load()
>> provider.loadAlgorithms()
>> ...
>>
>>
>> I'm currently trial-and-errorring my way through this, but I hope
>> someone has a hint. Even someone pointing at 2 plugins working like
>> this would be very welcome!
>>
>> Kind regards,
>> Raymond
>> _______________________________________________
>> QGIS-Developer mailing list
>> QGIS-Developer at lists.osgeo.org
>> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
>> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> 


More information about the QGIS-Developer mailing list