Skip to content

Commit 05beaa7

Browse files
committedMay 21, 2018
[needs-docs][processing] open existing script toolbar action
1 parent 35b3e9b commit 05beaa7

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed
 
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
***************************************************************************
5+
OpenScriptFromFileAction.py
6+
---------------------
7+
Date : May 2018
8+
Copyright : (C) 2018 by Mathieu Pellerin
9+
Email : nirvn dot asia at gmail dot com
10+
***************************************************************************
11+
* *
12+
* This program is free software; you can redistribute it and/or modify *
13+
* it under the terms of the GNU General Public License as published by *
14+
* the Free Software Foundation; either version 2 of the License, or *
15+
* (at your option) any later version. *
16+
* *
17+
***************************************************************************
18+
"""
19+
20+
__author__ = 'Nyall Dawson'
21+
__date__ = 'February 2018'
22+
__copyright__ = '(C) 2018, Nyall Dawson'
23+
24+
# This will get replaced with a git SHA1 when you do a git archive
25+
26+
__revision__ = '$Format:%H$'
27+
28+
import os
29+
from qgis.PyQt.QtWidgets import QFileDialog
30+
from qgis.PyQt.QtCore import QFileInfo, QCoreApplication
31+
32+
from qgis.core import QgsApplication, QgsSettings
33+
34+
from processing.gui.ToolboxAction import ToolboxAction
35+
from processing.script.ScriptEditorDialog import ScriptEditorDialog
36+
37+
pluginPath = os.path.split(os.path.dirname(__file__))[0]
38+
39+
40+
class OpenScriptFromFileAction(ToolboxAction):
41+
42+
def __init__(self):
43+
self.name = QCoreApplication.translate('OpenScriptFromFileAction', 'Open Existing Script…')
44+
self.group = self.tr('Tools')
45+
46+
def getIcon(self):
47+
return QgsApplication.getThemeIcon("/processingScript.svg")
48+
49+
def execute(self):
50+
settings = QgsSettings()
51+
lastDir = settings.value('Processing/lastScriptsDir', '')
52+
filename, selected_filter = QFileDialog.getOpenFileName(self.toolbox,
53+
self.tr('Open Script', 'AddScriptFromFileAction'), lastDir,
54+
self.tr('Script files (*.py)', 'AddScriptFromFileAction'))
55+
if filename:
56+
settings.setValue('Processing/lastScriptsDir',
57+
QFileInfo(filename).absoluteDir().absolutePath())
58+
59+
dlg = ScriptEditorDialog(filePath=filename)
60+
dlg.show()

‎python/plugins/processing/script/ScriptAlgorithmProvider.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
from processing.script.AddScriptFromTemplateAction import AddScriptFromTemplateAction
4141
from processing.script.DeleteScriptAction import DeleteScriptAction
4242
from processing.script.EditScriptAction import EditScriptAction
43+
from processing.script.OpenScriptFromFileAction import OpenScriptFromFileAction
4344
from processing.script import ScriptUtils
4445

4546

@@ -51,6 +52,7 @@ def __init__(self):
5152
self.folder_algorithms = []
5253
self.actions = [CreateNewScriptAction(),
5354
AddScriptFromTemplateAction(),
55+
OpenScriptFromFileAction(),
5456
AddScriptFromFileAction()
5557
]
5658
self.contextMenuActions = [EditScriptAction(),

0 commit comments

Comments
 (0)
Please sign in to comment.