|
| 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() |
0 commit comments