Skip to content
Permalink
Browse files
[processing][feature] load default script from template
  • Loading branch information
ghtmtt authored and nyalldawson committed Mar 31, 2018
1 parent 1a74b0a commit 46d59b7
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 0 deletions.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -72,6 +72,8 @@ def __init__(self, filePath=None, parent=None):
QgsApplication.getThemeIcon('/mActionFileSave.svg'))
self.actionSaveScriptAs.setIcon(
QgsApplication.getThemeIcon('/mActionFileSaveAs.svg'))
self.actionLoadFromTemplate.setIcon(
QgsApplication.getThemeIcon('/mActionOpenFromTemplate.svg'))
self.actionRunScript.setIcon(
QgsApplication.getThemeIcon('/mActionStart.svg'))
self.actionCut.setIcon(
@@ -95,6 +97,7 @@ def __init__(self, filePath=None, parent=None):
self.actionOpenScript.triggered.connect(self.openScript)
self.actionSaveScript.triggered.connect(self.save)
self.actionSaveScriptAs.triggered.connect(self.saveAs)
self.actionLoadFromTemplate.triggered.connect(self.loadFrom)
self.actionRunScript.triggered.connect(self.runAlgorithm)
self.actionCut.triggered.connect(self.editor.cut)
self.actionCopy.triggered.connect(self.editor.copy)
@@ -166,6 +169,22 @@ def save(self):
def saveAs(self):
self.saveScript(True)

def loadFrom(self):
if self.hasChanged:
ret = QMessageBox.warning(self,
self.tr("Unsaved changes"),
self.tr("There are unsaved changes in the script. Continue?"),
QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
if ret == QMessageBox.No:
return

templatePath = os.path.join(
pluginPath, 'script', 'script_template.py')

with codecs.open(templatePath, 'r', encoding='utf-8') as f:
templateTxt = f.read()
self.editor.setText(templateTxt)

def saveScript(self, saveAs):
newPath = None
if self.filePath is None or saveAs:
@@ -106,6 +106,7 @@
<addaction name="actionOpenScript"/>
<addaction name="actionSaveScript"/>
<addaction name="actionSaveScriptAs"/>
<addaction name="actionLoadFromTemplate"/>
<addaction name="separator"/>
<addaction name="separator"/>
<addaction name="actionRunScript"/>
@@ -155,6 +156,17 @@
<string>Ctrl+Shift+S</string>
</property>
</action>
<action name="actionLoadFromTemplate">
<property name="text">
<string>Load script from template...</string>
</property>
<property name="toolTip">
<string>oad script from template...</string>
</property>
<property name="shortcut">
<string>Ctrl+Shift+M</string>
</property>
</action>
<action name="actionRunScript">
<property name="text">
<string>Run script</string>

0 comments on commit 46d59b7

Please sign in to comment.