@@ -72,6 +72,8 @@ def __init__(self, filePath=None, parent=None):
72
72
QgsApplication .getThemeIcon ('/mActionFileSave.svg' ))
73
73
self .actionSaveScriptAs .setIcon (
74
74
QgsApplication .getThemeIcon ('/mActionFileSaveAs.svg' ))
75
+ self .actionLoadFromTemplate .setIcon (
76
+ QgsApplication .getThemeIcon ('/mActionOpenFromTemplate.svg' ))
75
77
self .actionRunScript .setIcon (
76
78
QgsApplication .getThemeIcon ('/mActionStart.svg' ))
77
79
self .actionCut .setIcon (
@@ -95,6 +97,7 @@ def __init__(self, filePath=None, parent=None):
95
97
self .actionOpenScript .triggered .connect (self .openScript )
96
98
self .actionSaveScript .triggered .connect (self .save )
97
99
self .actionSaveScriptAs .triggered .connect (self .saveAs )
100
+ self .actionLoadFromTemplate .triggered .connect (self .loadFrom )
98
101
self .actionRunScript .triggered .connect (self .runAlgorithm )
99
102
self .actionCut .triggered .connect (self .editor .cut )
100
103
self .actionCopy .triggered .connect (self .editor .copy )
@@ -166,6 +169,22 @@ def save(self):
166
169
def saveAs (self ):
167
170
self .saveScript (True )
168
171
172
+ def loadFrom (self ):
173
+ if self .hasChanged :
174
+ ret = QMessageBox .warning (self ,
175
+ self .tr ("Unsaved changes" ),
176
+ self .tr ("There are unsaved changes in the script. Continue?" ),
177
+ QMessageBox .Yes | QMessageBox .No , QMessageBox .No )
178
+ if ret == QMessageBox .No :
179
+ return
180
+
181
+ templatePath = os .path .join (
182
+ pluginPath , 'script' , 'script_template.py' )
183
+
184
+ with codecs .open (templatePath , 'r' , encoding = 'utf-8' ) as f :
185
+ templateTxt = f .read ()
186
+ self .editor .setText (templateTxt )
187
+
169
188
def saveScript (self , saveAs ):
170
189
newPath = None
171
190
if self .filePath is None or saveAs :
0 commit comments