Skip to content

Commit

Permalink
[processing] Fix running script algorithm from editor dialog
Browse files Browse the repository at this point in the history
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 92ebf7b
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions python/plugins/processing/script/ScriptEditorDialog.py
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 92ebf7b

Please sign in to comment.