Skip to content

Commit

Permalink
[needs-docs][processing] open existing script toolbar action
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed May 21, 2018
1 parent 35b3e9b commit 05beaa7
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
60 changes: 60 additions & 0 deletions python/plugins/processing/script/OpenScriptFromFileAction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# -*- coding: utf-8 -*-

"""
***************************************************************************
OpenScriptFromFileAction.py
---------------------
Date : May 2018
Copyright : (C) 2018 by Mathieu Pellerin
Email : nirvn dot asia at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************
"""

__author__ = 'Nyall Dawson'
__date__ = 'February 2018'
__copyright__ = '(C) 2018, Nyall Dawson'

# This will get replaced with a git SHA1 when you do a git archive

__revision__ = '$Format:%H$'

import os
from qgis.PyQt.QtWidgets import QFileDialog
from qgis.PyQt.QtCore import QFileInfo, QCoreApplication

from qgis.core import QgsApplication, QgsSettings

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

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


class OpenScriptFromFileAction(ToolboxAction):

def __init__(self):
self.name = QCoreApplication.translate('OpenScriptFromFileAction', 'Open Existing Script…')
self.group = self.tr('Tools')

def getIcon(self):
return QgsApplication.getThemeIcon("/processingScript.svg")

def execute(self):
settings = QgsSettings()
lastDir = settings.value('Processing/lastScriptsDir', '')
filename, selected_filter = QFileDialog.getOpenFileName(self.toolbox,
self.tr('Open Script', 'AddScriptFromFileAction'), lastDir,
self.tr('Script files (*.py)', 'AddScriptFromFileAction'))
if filename:
settings.setValue('Processing/lastScriptsDir',
QFileInfo(filename).absoluteDir().absolutePath())

dlg = ScriptEditorDialog(filePath=filename)
dlg.show()
2 changes: 2 additions & 0 deletions python/plugins/processing/script/ScriptAlgorithmProvider.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
from processing.script.AddScriptFromTemplateAction import AddScriptFromTemplateAction
from processing.script.DeleteScriptAction import DeleteScriptAction
from processing.script.EditScriptAction import EditScriptAction
from processing.script.OpenScriptFromFileAction import OpenScriptFromFileAction
from processing.script import ScriptUtils


Expand All @@ -51,6 +52,7 @@ def __init__(self):
self.folder_algorithms = []
self.actions = [CreateNewScriptAction(),
AddScriptFromTemplateAction(),
OpenScriptFromFileAction(),
AddScriptFromFileAction()
]
self.contextMenuActions = [EditScriptAction(),
Expand Down

0 comments on commit 05beaa7

Please sign in to comment.