Skip to content

Commit

Permalink
[processing][feature] load default script from template
Browse files Browse the repository at this point in the history
  • 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.
93 changes: 93 additions & 0 deletions images/themes/default/mActionOpenFromTemplate.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions python/plugins/processing/script/ScriptEditorDialog.py
Expand Up @@ -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(
Expand All @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
12 changes: 12 additions & 0 deletions python/plugins/processing/ui/DlgScriptEditor.ui
Expand Up @@ -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"/>
Expand Down Expand Up @@ -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>
Expand Down

0 comments on commit 46d59b7

Please sign in to comment.