2012-10-04 19:33:47 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
***************************************************************************
|
|
|
|
DeleteScriptAction.py
|
|
|
|
---------------------
|
|
|
|
Date : August 2012
|
|
|
|
Copyright : (C) 2012 by Victor Olaya
|
|
|
|
Email : volayaf 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__ = 'Victor Olaya'
|
|
|
|
__date__ = 'August 2012'
|
|
|
|
__copyright__ = '(C) 2012, Victor Olaya'
|
2013-10-01 20:52:22 +03:00
|
|
|
|
2012-09-15 18:25:25 +03:00
|
|
|
import os
|
2012-12-08 19:42:43 +02:00
|
|
|
|
2018-02-22 00:36:30 +01:00
|
|
|
from qgis.PyQt.QtCore import QCoreApplication
|
2016-04-22 10:38:48 +02:00
|
|
|
from qgis.PyQt.QtWidgets import QMessageBox
|
2012-12-08 19:42:43 +02:00
|
|
|
|
2018-01-29 18:54:26 +02:00
|
|
|
from qgis.core import QgsApplication, QgsProcessingAlgorithm
|
2017-04-04 11:28:28 +10:00
|
|
|
|
2012-12-08 19:42:43 +02:00
|
|
|
from processing.gui.ContextAction import ContextAction
|
|
|
|
|
2018-01-29 18:54:26 +02:00
|
|
|
from processing.script import ScriptUtils
|
2013-10-01 20:52:22 +03:00
|
|
|
|
2016-05-27 19:04:25 +03:00
|
|
|
|
2012-09-15 18:25:25 +03:00
|
|
|
class DeleteScriptAction(ContextAction):
|
2018-01-29 18:54:26 +02:00
|
|
|
|
2018-01-29 15:50:16 +02:00
|
|
|
def __init__(self):
|
2019-02-01 12:22:23 +10:00
|
|
|
super().__init__()
|
2018-02-22 00:36:30 +01:00
|
|
|
self.name = QCoreApplication.translate("DeleteScriptAction", "Delete Script…")
|
2012-09-15 18:25:25 +03:00
|
|
|
|
|
|
|
def isEnabled(self):
|
2018-01-29 18:54:26 +02:00
|
|
|
return isinstance(self.itemData, QgsProcessingAlgorithm) and self.itemData.provider().id() == "script"
|
2012-09-15 18:25:25 +03:00
|
|
|
|
2016-04-06 10:50:54 +02:00
|
|
|
def execute(self):
|
2014-10-03 14:44:01 +03:00
|
|
|
reply = QMessageBox.question(None,
|
2018-02-21 18:24:29 +10:00
|
|
|
self.tr("Delete Script"),
|
2018-01-29 18:54:26 +02:00
|
|
|
self.tr("Are you sure you want to delete this script?"),
|
2015-08-22 14:29:41 +02:00
|
|
|
QMessageBox.Yes | QMessageBox.No,
|
|
|
|
QMessageBox.No)
|
2012-12-08 19:42:43 +02:00
|
|
|
if reply == QMessageBox.Yes:
|
2018-12-10 16:35:52 +10:00
|
|
|
filePath = ScriptUtils.findAlgorithmSource(self.itemData.name())
|
2018-02-01 12:50:04 +02:00
|
|
|
if filePath is not None:
|
|
|
|
os.remove(filePath)
|
|
|
|
QgsApplication.processingRegistry().providerById("script").refreshAlgorithms()
|
|
|
|
else:
|
2018-02-21 18:24:29 +10:00
|
|
|
QMessageBox.warning(None,
|
|
|
|
self.tr("Delete Script"),
|
|
|
|
self.tr("Can not find corresponding script file.")
|
|
|
|
)
|