Skip to content

Commit

Permalink
[processing] move script provider stuff into provider directory
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed Feb 5, 2018
1 parent 6841c52 commit 862b113
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 303 deletions.
2 changes: 1 addition & 1 deletion python/plugins/processing/gui/ContextAction.py
Expand Up @@ -37,5 +37,5 @@ def setData(self, itemData, toolbox):

def tr(self, string, context=''):
if context == '':
context = 'ContextAction'
context = self.__class__.__name__
return QCoreApplication.translate(context, string)
208 changes: 0 additions & 208 deletions python/plugins/processing/gui/ScriptEdit.py

This file was deleted.

14 changes: 8 additions & 6 deletions python/plugins/processing/script/AddScriptFromFileAction.py
Expand Up @@ -32,8 +32,9 @@

from qgis.core import QgsApplication, QgsSettings

from processing.script.ScriptAlgorithm import ScriptAlgorithm
from processing.gui.ToolboxAction import ToolboxAction

from processing.script.ScriptAlgorithm import ScriptAlgorithm
from processing.script.WrongScriptException import WrongScriptException
from processing.script.ScriptUtils import ScriptUtils

Expand All @@ -53,8 +54,9 @@ def execute(self):
settings = QgsSettings()
lastDir = settings.value('Processing/lastScriptsDir', '')
filenames, selected_filter = QFileDialog.getOpenFileNames(self.toolbox,
self.tr('Script files', 'AddScriptFromFileAction'), lastDir,
self.tr('Script files (*.py *.PY)', 'AddScriptFromFileAction'))
self.tr('Script files'),
lastDir,
self.tr('Script files (*.py *.PY)'))
if filenames:
validAlgs = 0
wrongAlgs = []
Expand All @@ -73,6 +75,6 @@ def execute(self):
QgsApplication.processingRegistry().providerById('script').refreshAlgorithms()
if wrongAlgs:
QMessageBox.warning(self.toolbox,
self.tr('Error reading scripts', 'AddScriptFromFileAction'),
self.tr('The following files do not contain a valid script:\n-', 'AddScriptFromFileAction') +
"\n-".join(wrongAlgs))
self.tr('Error reading scripts'),
self.tr('The following files do not contain a valid script:\n') +
"\n- ".join(wrongAlgs))
Expand Up @@ -30,27 +30,20 @@
from qgis.core import QgsApplication

from processing.gui.ToolboxAction import ToolboxAction
from processing.gui.ScriptEditorDialog import ScriptEditorDialog

from processing.script.ScriptEditorDialog import ScriptEditorDialog

pluginPath = os.path.split(os.path.dirname(__file__))[0]


class CreateNewScriptAction(ToolboxAction):

SCRIPT_PYTHON = 0

def __init__(self, actionName, scriptType):
def __init__(self, actionName):
self.name, self.i18n_name = self.trAction(actionName)
self.group, self.i18n_group = self.trAction('Tools')

self.scriptType = scriptType

def getIcon(self):
if self.scriptType == self.SCRIPT_PYTHON:
return QgsApplication.getThemeIcon("/processingScript.svg")
return QgsApplication.getThemeIcon("/processingScript.svg")

def execute(self):
dlg = None
if self.scriptType == self.SCRIPT_PYTHON:
dlg = ScriptEditorDialog(ScriptEditorDialog.SCRIPT_PYTHON, None)
dlg = ScriptEditorDialog(None)
dlg.show()
Expand Up @@ -37,25 +37,18 @@


class DeleteScriptAction(ContextAction):

SCRIPT_PYTHON = 0

def __init__(self, scriptType):
self.name = self.tr('Delete script', 'DeleteScriptAction')
self.scriptType = scriptType
def __init__(self):
self.name = self.tr('Delete script')

def isEnabled(self):
if self.scriptType == self.SCRIPT_PYTHON:
return isinstance(self.itemData, ScriptAlgorithm) and self.itemData.allowEdit
return isinstance(self.itemData, ScriptAlgorithm) and self.itemData.allowEdit

def execute(self):
reply = QMessageBox.question(None,
self.tr('Confirmation', 'DeleteScriptAction'),
self.tr('Are you sure you want to delete this script?',
'DeleteScriptAction'),
self.tr('Confirmation'),
self.tr('Are you sure you want to delete this script?'),
QMessageBox.Yes | QMessageBox.No,
QMessageBox.No)
if reply == QMessageBox.Yes:
os.remove(self.itemData.descriptionFile)
if self.scriptType == self.SCRIPT_PYTHON:
QgsApplication.processingRegistry().providerById('script').refreshAlgorithms()
QgsApplication.processingRegistry().providerById('script').refreshAlgorithms()
Expand Up @@ -26,22 +26,18 @@
__revision__ = '$Format:%H$'

from processing.gui.ContextAction import ContextAction
from processing.gui.ScriptEditorDialog import ScriptEditorDialog

from processing.script.ScriptEditorDialog import ScriptEditorDialog
from processing.script.ScriptAlgorithm import ScriptAlgorithm


class EditScriptAction(ContextAction):

SCRIPT_PYTHON = 0

def __init__(self, scriptType):
self.name = self.tr('Edit script', 'EditScriptAction')
self.scriptType = scriptType
def __init__(self):
self.name = self.tr('Edit script')

def isEnabled(self):
if self.scriptType == ScriptEditorDialog.SCRIPT_PYTHON:
return isinstance(self.itemData, ScriptAlgorithm) and self.itemData.allowEdit
return isinstance(self.itemData, ScriptAlgorithm) and self.itemData.allowEdit

def execute(self):
dlg = ScriptEditorDialog(self.scriptType, self.itemData)
dlg = ScriptEditorDialog(self.itemData)
dlg.show()
19 changes: 9 additions & 10 deletions python/plugins/processing/script/ScriptAlgorithmProvider.py
Expand Up @@ -31,14 +31,15 @@
QgsProcessingProvider)

from processing.core.ProcessingConfig import ProcessingConfig, Setting
from processing.gui.EditScriptAction import EditScriptAction
from processing.gui.DeleteScriptAction import DeleteScriptAction
from processing.gui.CreateNewScriptAction import CreateNewScriptAction
from processing.script.ScriptUtils import ScriptUtils
from processing.script.AddScriptFromFileAction import AddScriptFromFileAction
from processing.gui.ProviderActions import (ProviderActions,
ProviderContextMenuActions)

from processing.script.AddScriptFromFileAction import AddScriptFromFileAction
from processing.script.CreateNewScriptAction import CreateNewScriptAction
from processing.script.DeleteScriptAction import DeleteScriptAction
from processing.script.EditScriptAction import EditScriptAction
from processing.script.CreateScriptCollectionPluginAction import CreateScriptCollectionPluginAction
from processing.script.ScriptUtils import ScriptUtils

pluginPath = os.path.split(os.path.dirname(__file__))[0]

Expand All @@ -49,13 +50,11 @@ def __init__(self):
super().__init__()
self.algs = []
self.folder_algorithms = []
self.actions = [CreateNewScriptAction('Create new script',
CreateNewScriptAction.SCRIPT_PYTHON),
self.actions = [CreateNewScriptAction('Create new script'),
AddScriptFromFileAction(),
CreateScriptCollectionPluginAction()]
self.contextMenuActions = \
[EditScriptAction(EditScriptAction.SCRIPT_PYTHON),
DeleteScriptAction(DeleteScriptAction.SCRIPT_PYTHON)]
self.contextMenuActions = [EditScriptAction(),
DeleteScriptAction()]

def load(self):
ProcessingConfig.settingIcons[self.name()] = self.icon()
Expand Down

0 comments on commit 862b113

Please sign in to comment.