Skip to content

Commit 925d45d

Browse files
ghtmttnyalldawson
authored andcommitted
new LoadFromTemplate action in toolbar dropdown
1 parent deaeaa6 commit 925d45d

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
***************************************************************************
5+
AddScriptFromTemplateAction.py
6+
---------------------
7+
Date : August 2012
8+
Copyright : (C) 2018 by Matteo Ghetta
9+
Email : matteo dot ghetta 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__ = 'Matteo Ghetta'
21+
__date__ = 'March 2018'
22+
__copyright__ = '(C) 2018, Matteo Ghetta'
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+
import codecs
30+
31+
from qgis.PyQt.QtCore import QCoreApplication
32+
33+
from qgis.core import QgsApplication
34+
35+
from processing.gui.ToolboxAction import ToolboxAction
36+
37+
from processing.script.ScriptEditorDialog import ScriptEditorDialog
38+
39+
40+
class AddScriptFromTemplateAction(ToolboxAction):
41+
42+
def __init__(self):
43+
self.name = QCoreApplication.translate("AddScriptFromTemplate",
44+
"Load Script From Template...")
45+
self.group = self.tr("Tools")
46+
47+
def execute(self):
48+
dlg = ScriptEditorDialog(None)
49+
50+
pluginPath = os.path.split(os.path.dirname(__file__))[0]
51+
templatePath = os.path.join(
52+
pluginPath, 'script', 'ScriptTemplate.py')
53+
54+
with codecs.open(templatePath, 'r', encoding='utf-8') as f:
55+
templateTxt = f.read()
56+
dlg.editor.setText(templateTxt)
57+
58+
dlg.show()

python/plugins/processing/script/ScriptAlgorithmProvider.py

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
from processing.script.AddScriptFromFileAction import AddScriptFromFileAction
3939
from processing.script.CreateNewScriptAction import CreateNewScriptAction
40+
from processing.script.AddScriptFromTemplateAction import AddScriptFromTemplateAction
4041
from processing.script.DeleteScriptAction import DeleteScriptAction
4142
from processing.script.EditScriptAction import EditScriptAction
4243
from processing.script import ScriptUtils
@@ -50,6 +51,7 @@ def __init__(self):
5051
self.folder_algorithms = []
5152
self.actions = [CreateNewScriptAction(),
5253
AddScriptFromFileAction(),
54+
AddScriptFromTemplateAction(),
5355
]
5456
self.contextMenuActions = [EditScriptAction(),
5557
DeleteScriptAction()]

0 commit comments

Comments
 (0)