Skip to content

Commit

Permalink
Merge pull request #4206 from volaya/fix_processing_provider_update
Browse files Browse the repository at this point in the history
[processing] fixed update of toolbox after editing script providers
  • Loading branch information
volaya committed Mar 3, 2017
2 parents fb409b5 + 51da47d commit e5ebcd1
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 17 deletions.
5 changes: 3 additions & 2 deletions python/plugins/processing/core/Processing.py
Expand Up @@ -172,11 +172,12 @@ def removeScripts(folder):
def updateAlgsList():
"""Call this method when there has been any change that
requires the list of algorithms to be created again from
algorithm providers.
algorithm providers. Use reloadProvider() for a more fine-grained
update.
"""
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
for p in Processing.providers:
Processing.reloadProvider(p)
Processing.reloadProvider(p.id())
QApplication.restoreOverrideCursor()

@staticmethod
Expand Down
4 changes: 1 addition & 3 deletions python/plugins/processing/core/alglist.py
Expand Up @@ -38,16 +38,14 @@ class AlgorithmList(QObject):
# and values are list with all algorithms from that provider
algs = {}

providers = []

def removeProvider(self, provider_id):
if provider_id in self.algs:
del self.algs[provider_id]

QgsApplication.processingRegistry().removeProvider(provider_id)

def reloadProvider(self, provider_id):
for p in self.providers:
for p in QgsApplication.processingRegistry().providers():
if p.id() == provider_id:
p.loadAlgorithms()
self.algs[p.id()] = {a.commandLineName(): a for a in p.algs}
Expand Down
5 changes: 0 additions & 5 deletions python/plugins/processing/gui/CreateNewScriptAction.py
Expand Up @@ -62,8 +62,3 @@ def execute(self):
if self.scriptType == self.SCRIPT_R:
dlg = ScriptEditorDialog(ScriptEditorDialog.SCRIPT_R, None)
dlg.show()
if dlg.update:
if self.scriptType == self.SCRIPT_PYTHON:
algList.reloadProvider('script')
elif self.scriptType == self.SCRIPT_R:
algList.reloadProvider('r')
6 changes: 0 additions & 6 deletions python/plugins/processing/gui/EditScriptAction.py
Expand Up @@ -50,9 +50,3 @@ def isEnabled(self):
def execute(self):
dlg = ScriptEditorDialog(self.scriptType, self.itemData)
dlg.show()
dlg.exec_()
if dlg.update:
if self.scriptType == ScriptEditorDialog.SCRIPT_PYTHON:
algList.reloadProvider('script')
elif self.scriptType == ScriptEditorDialog.SCRIPT_R:
algList.reloadProvider('r')
2 changes: 1 addition & 1 deletion python/plugins/processing/gui/ProcessingToolbox.py
Expand Up @@ -385,7 +385,7 @@ def __init__(self, provider_id, tree, toolbox):

def refresh(self):
self.takeChildren()
Processing.updateAlgsList()
#Processing.updateAlgsList()
self.populate()

def populate(self):
Expand Down
10 changes: 10 additions & 0 deletions python/plugins/processing/gui/ScriptEditorDialog.py
Expand Up @@ -49,6 +49,7 @@
from processing.algs.r.RUtils import RUtils
from processing.script.ScriptAlgorithm import ScriptAlgorithm
from processing.script.ScriptUtils import ScriptUtils
from processing.core.alglist import algList

pluginPath = os.path.split(os.path.dirname(__file__))[0]
WIDGET, BASE = uic.loadUiType(
Expand Down Expand Up @@ -169,12 +170,21 @@ def closeEvent(self, evt):
QMessageBox.Yes | QMessageBox.No, QMessageBox.No
)
if ret == QMessageBox.Yes:
self.updateProviders()
evt.accept()
else:
evt.ignore()
else:
self.updateProviders()
evt.accept()

def updateProviders(self):
if self.update:
if self.algType == self.SCRIPT_PYTHON:
algList.reloadProvider('script')
elif self.algType == self.SCRIPT_R:
algList.reloadProvider('r')

def editHelp(self):
if self.alg is None:
if self.algType == self.SCRIPT_PYTHON:
Expand Down

0 comments on commit e5ebcd1

Please sign in to comment.