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 46d59b7177edaef90dcd56a65c3438993a85fa94
@@ -0,0 +1,93 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="24"
height="24"
id="svg6601"
version="1.1"
inkscape:version="0.91 r13725"
sodipodi:docname="iconOpenConsole.svg">
<metadata
id="metadata6619">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<defs
id="defs6617" />
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1280"
inkscape:window-height="998"
id="namedview6615"
showgrid="false"
inkscape:zoom="11.770382"
inkscape:cx="0.50932908"
inkscape:cy="4.5211089"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:window-maximized="1"
inkscape:current-layer="svg6601" />
<rect
x="3.9137633"
y="1.6883943"
width="16.126532"
height="20.668375"
id="rect6605"
style="fill:#ffffff;stroke:#999999;stroke-width:1.5267067" />
<g
transform="matrix(1.1104467,0,0,1.1104467,3.0934388,-4.5934549)"
id="g6607">
<path
d="M 8,7 C 5.44,7 5.6,8.11 5.6,8.11 l 0.00383,0.892 2.44,0 0,0.501 -3.4,0 c 0,0 -1.64,-0.0869 -1.64,2.49 0,2.58 1.43,2.48 1.43,2.48 l 0.853,0 0,-1.19 c 0,0 -0.0457,-1.43 1.41,-1.43 l 2.42,0 c 0,0 1.36,0.0227 1.36,-1.31 l 0,-2.21 c -2.2e-5,0 0.207,-1.33 -2.47,-1.33 z M 6.65,7.769 c 0.244,0 0.438,0.197 0.438,0.438 a 0.44,0.437 0 1 1 -0.875,0 c 0,-0.242 0.196,-0.438 0.438,-0.438 z"
overflow="visible"
id="path6609"
inkscape:connector-curvature="0"
style="overflow:visible;fill:#366c99" />
<path
d="m 8,17 c 2.56,0 2.4,-1.11 2.4,-1.11 l -0.0038,-1.15 -2.44,0 0,-0.346 3.4,0 c 0,0 1.64,0.185 1.64,-2.39 0,-2.58 -1.43,-2.48 -1.43,-2.48 l -0.853,0 0,1.19 c 0,0 0.0457,1.43 -1.41,1.43 l -2.42,0 c 0,0 -1.36,-0.0208 -1.36,1.31 l 0,2.21 c 0,0 -0.207,1.33 2.47,1.33 z m 1.35,-0.769 a 0.44,0.437 0 0 1 -0.438,-0.438 0.44,0.437 0 1 1 0.875,0 0.44,0.437 0 0 1 -0.438,0.438 z"
overflow="visible"
id="path6611"
inkscape:connector-curvature="0"
style="overflow:visible;fill:#ffcb3a;stroke-width:3.77999997" />
</g>
<path
style="fill:#fe6b6b;fill-opacity:1;fill-rule:evenodd;stroke:#2d2d2d;stroke-width:0.5;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 6.3697345,16.309517 11.2145895,0"
id="path6623"
inkscape:connector-curvature="0" />
<path
style="fill:#fe6b6b;fill-opacity:1;fill-rule:evenodd;stroke:#2d2d2d;stroke-width:0.42468894;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 9.4936395,17.752192 8.0906845,0"
id="path6623-7"
inkscape:connector-curvature="0" />
<path
style="fill:#fe6b6b;fill-opacity:1;fill-rule:evenodd;stroke:#2d2d2d;stroke-width:0.42468894;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 9.4936395,18.923655 8.0906845,0"
id="path6623-7-5"
inkscape:connector-curvature="0" />
<path
style="fill:#fe6b6b;fill-opacity:1;fill-rule:evenodd;stroke:#2d2d2d;stroke-width:0.42468894;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 9.4936395,20.095119 8.0906845,0"
id="path6623-7-5-3"
inkscape:connector-curvature="0" />
</svg>
@@ -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.
You can’t perform that action at this time.