Skip to content
Permalink
Browse files

[processing] Fix running script algorithm from editor dialog

We have to keep a local reference to the dialog, otherwise sip suddenly
"forgets" about the python subclass and treats the dialog as just
the parent c++ class. Really weird, thanks sip.

Fixes #36436
  • Loading branch information
nyalldawson committed May 20, 2020
1 parent b48c70f commit 92ebf7bc8d2910db0fc5cf01d78581a90030980e
Showing with 10 additions and 5 deletions.
  1. +10 −5 python/plugins/processing/script/ScriptEditorDialog.py
@@ -27,7 +27,7 @@
import traceback
import warnings

from qgis.PyQt import uic
from qgis.PyQt import uic, sip
from qgis.PyQt.QtCore import Qt
from qgis.PyQt.QtGui import QCursor
from qgis.PyQt.QtWidgets import (QMessageBox,
@@ -113,6 +113,7 @@ def __init__(self, filePath=None, parent=None):
self.btnFind.clicked.connect(self.find)
self.btnReplace.clicked.connect(self.replace)
self.lastSearch = None
self.run_dialog = None

self.filePath = None
if filePath is not None:
@@ -219,6 +220,10 @@ def setHasChanged(self, hasChanged):
self.update_dialog_title()

def runAlgorithm(self):
if self.run_dialog and not sip.isdeleted(self.run_dialog):
self.run_dialog.close()
self.run_dialog = None

_locals = {}
try:
exec(self.editor.text(), _locals)
@@ -248,14 +253,14 @@ def runAlgorithm(self):
alg.setProvider(QgsApplication.processingRegistry().providerById("script"))
alg.initAlgorithm()

dlg = alg.createCustomParametersWidget(iface.mainWindow())
if not dlg:
dlg = AlgorithmDialog(alg, parent=iface.mainWindow())
self.run_dialog = alg.createCustomParametersWidget(self)
if not self.run_dialog:
self.run_dialog = AlgorithmDialog(alg, parent=self)

canvas = iface.mapCanvas()
prevMapTool = canvas.mapTool()

dlg.show()
self.run_dialog.show()

if canvas.mapTool() != prevMapTool:
try:

0 comments on commit 92ebf7b

Please sign in to comment.
You can’t perform that action at this time.