EditScriptAction.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. """
  2. ***************************************************************************
  3. EditScriptAction.py
  4. ---------------------
  5. Date : August 2012
  6. Copyright : (C) 2012 by Victor Olaya
  7. Email : volayaf at gmail dot com
  8. ***************************************************************************
  9. * *
  10. * This program is free software; you can redistribute it and/or modify *
  11. * it under the terms of the GNU General Public License as published by *
  12. * the Free Software Foundation; either version 2 of the License, or *
  13. * (at your option) any later version. *
  14. * *
  15. ***************************************************************************
  16. """
  17. __author__ = 'Victor Olaya'
  18. __date__ = 'August 2012'
  19. __copyright__ = '(C) 2012, Victor Olaya'
  20. import inspect
  21. from qgis.core import QgsProcessingAlgorithm, QgsMessageLog
  22. from qgis.utils import iface
  23. from qgis.PyQt.QtCore import QCoreApplication
  24. from qgis.PyQt.QtWidgets import QMessageBox
  25. from processing.gui.ContextAction import ContextAction
  26. from processing.script.ScriptEditorDialog import ScriptEditorDialog
  27. from processing.script import ScriptUtils
  28. class EditScriptAction(ContextAction):
  29. def __init__(self):
  30. super().__init__()
  31. self.name = QCoreApplication.translate("EditScriptAction", "Edit Script…")
  32. def isEnabled(self):
  33. return isinstance(self.itemData, QgsProcessingAlgorithm) and self.itemData.provider().id() == "script"
  34. def execute(self):
  35. filePath = ScriptUtils.findAlgorithmSource(self.itemData.name())
  36. if filePath is not None:
  37. dlg = ScriptEditorDialog(filePath, parent=iface.mainWindow())
  38. dlg.show()
  39. else:
  40. QMessageBox.warning(None,
  41. self.tr("Edit Script"),
  42. self.tr("Can not find corresponding script file.")
  43. )