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-10-04 19:33:47 +02:00
|
|
|
# This will get replaced with a git SHA1 when you do a git archive
|
2013-10-01 20:52:22 +03:00
|
|
|
|
2012-10-04 19:33:47 +02:00
|
|
|
__revision__ = '$Format:%H$'
|
|
|
|
|
2012-09-15 18:25:25 +03:00
|
|
|
import os
|
2012-12-08 19:42:43 +02:00
|
|
|
|
|
|
|
from PyQt4.QtGui import *
|
|
|
|
|
|
|
|
from processing.gui.ContextAction import ContextAction
|
|
|
|
|
2014-04-17 01:41:25 +02:00
|
|
|
from processing.algs.r.RAlgorithm import RAlgorithm
|
2012-12-08 19:42:43 +02:00
|
|
|
from processing.script.ScriptAlgorithm import ScriptAlgorithm
|
2012-09-15 18:25:25 +03:00
|
|
|
|
2013-10-01 20:52:22 +03:00
|
|
|
|
2012-09-15 18:25:25 +03:00
|
|
|
class DeleteScriptAction(ContextAction):
|
|
|
|
|
2012-12-08 19:42:43 +02:00
|
|
|
SCRIPT_PYTHON = 0
|
|
|
|
SCRIPT_R = 1
|
|
|
|
|
|
|
|
def __init__(self, scriptType):
|
2014-10-03 14:44:01 +03:00
|
|
|
self.name = self.tr('Delete script', 'DeleteScriptAction')
|
2012-12-08 19:42:43 +02:00
|
|
|
self.scriptType = scriptType
|
2012-09-15 18:25:25 +03:00
|
|
|
|
|
|
|
def isEnabled(self):
|
2012-12-08 19:42:43 +02:00
|
|
|
if self.scriptType == self.SCRIPT_PYTHON:
|
2014-07-10 17:24:07 +02:00
|
|
|
return isinstance(self.alg, ScriptAlgorithm) and self.alg.allowEdit
|
2012-12-08 19:42:43 +02:00
|
|
|
elif self.scriptType == self.SCRIPT_R:
|
|
|
|
return isinstance(self.alg, RAlgorithm)
|
2012-09-15 18:25:25 +03:00
|
|
|
|
|
|
|
def execute(self, alg):
|
2014-10-03 14:44:01 +03:00
|
|
|
reply = QMessageBox.question(None,
|
|
|
|
self.tr('Confirmation', 'DeleteScriptAction'),
|
2014-10-03 21:56:24 +03:00
|
|
|
self.tr('Are you sure you want to delete this script?',
|
|
|
|
'DeleteScriptAction'),
|
2014-10-03 14:44:01 +03:00
|
|
|
QMessageBox.Yes | QMessageBox.No,
|
|
|
|
QMessageBox.No)
|
2012-12-08 19:42:43 +02:00
|
|
|
if reply == QMessageBox.Yes:
|
2012-09-15 18:25:25 +03:00
|
|
|
os.remove(self.alg.descriptionFile)
|
2014-04-19 16:42:14 +02:00
|
|
|
if self.scriptType == self.SCRIPT_PYTHON:
|
|
|
|
self.toolbox.updateProvider('script')
|
|
|
|
elif self.scriptType == self.SCRIPT_R:
|
|
|
|
self.toolbox.updateProvider('r')
|