Skip to content

Commit 1d62d10

Browse files
committedMay 31, 2018
[processing] Don't hold on to algorithm instances for menu items
Instead, only store references to the algorithm id string, and use this to retrieve algorithms when the actions are triggered. This avoids errors caused by the algorithm instances being removed, e.g. due to plugin removal or reload of providers (e.g. by opening options dialog). Fixes #19070
1 parent 59d425c commit 1d62d10

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed
 

‎python/plugins/processing/gui/menus.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,10 @@ def addAlgorithmEntry(alg, menuName, submenuName, actionText=None, icon=None, ad
189189
alg_title = QgsStringUtils.capitalize(alg.displayName(), QgsStringUtils.TitleCase)
190190
actionText = alg_title + QCoreApplication.translate('Processing', '…')
191191
action = QAction(icon or alg.icon(), actionText, iface.mainWindow())
192-
action.setData(alg.id())
193-
action.triggered.connect(lambda: _executeAlgorithm(alg))
194-
action.setObjectName("mProcessingUserMenu_%s" % alg.id())
192+
alg_id = alg.id()
193+
action.setData(alg_id)
194+
action.triggered.connect(lambda: _executeAlgorithm(alg_id))
195+
action.setObjectName("mProcessingUserMenu_%s" % alg_id)
195196

196197
if menuName:
197198
menu = getMenu(menuName, iface.mainWindow().menuBar())
@@ -225,11 +226,20 @@ def removeAlgorithmEntry(alg, menuName, submenuName, delButton=True):
225226
algorithmsToolbar.removeAction(action)
226227

227228

228-
def _executeAlgorithm(alg):
229+
def _executeAlgorithm(alg_id):
230+
alg = QgsApplication.processingRegistry().createAlgorithmById(alg_id)
231+
if alg is None:
232+
dlg = MessageDialog()
233+
dlg.setTitle(Processing.tr('Missing Algorithm'))
234+
dlg.setMessage(
235+
Processing.tr('The algorithm "{}" is no longer available. (Perhaps a plugin was uninstalled?)').format(alg_id))
236+
dlg.exec_()
237+
return
238+
229239
ok, message = alg.canExecute()
230240
if not ok:
231241
dlg = MessageDialog()
232-
dlg.setTitle(Processing.tr('Missing dependency'))
242+
dlg.setTitle(Processing.tr('Missing Dependency'))
233243
dlg.setMessage(
234244
Processing.tr('<h3>Missing dependency. This algorithm cannot '
235245
'be run :-( </h3>\n{0}').format(message))

0 commit comments

Comments
 (0)
Please sign in to comment.