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