Skip to content

Commit c3ed390

Browse files
committedNov 24, 2016
[processing] improve script editor dialog
Use QMainWindow instead of QDialog, add normal toolbar instead of QToolButtons. Also fix some issues caused by Qt5 switch.
1 parent 7e0cd9a commit c3ed390

File tree

7 files changed

+1342
-331
lines changed

7 files changed

+1342
-331
lines changed
 

‎images/images.qrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@
115115
<file>themes/default/mActionAddBasicCircle.svg</file>
116116
<file>themes/default/mActionEditNodesItem.svg</file>
117117
<file>themes/default/mActionEditHelpContent.svg</file>
118+
<file>themes/default/mActionIncreaseFont.svg</file>
119+
<file>themes/default/mActionDecreaseFont.svg</file>
118120
<file>themes/default/mActionAddNodesItem.svg</file>
119121
<file>themes/default/mActionAddPolygon.svg</file>
120122
<file>themes/default/mActionAddPolyline.svg</file>

‎images/themes/default/mActionDecreaseFont.svg

Lines changed: 555 additions & 0 deletions
Loading

‎images/themes/default/mActionIncreaseFont.svg

Lines changed: 555 additions & 0 deletions
Loading

‎python/plugins/processing/gui/CreateNewScriptAction.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ def execute(self):
6060
if self.scriptType == self.SCRIPT_R:
6161
dlg = ScriptEditorDialog(ScriptEditorDialog.SCRIPT_R, None)
6262
dlg.show()
63-
dlg.exec_()
6463
if dlg.update:
6564
if self.scriptType == self.SCRIPT_PYTHON:
6665
algList.reloadProvider('script')

‎python/plugins/processing/gui/ScriptEditorDialog.py

Lines changed: 64 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,14 @@
3131
import os
3232

3333
from qgis.PyQt import uic
34-
from qgis.PyQt.QtCore import Qt
34+
from qgis.PyQt.QtCore import Qt, QSize, QByteArray, QSettings
3535
from qgis.PyQt.QtGui import QIcon, QCursor
36-
from qgis.PyQt.QtWidgets import QMenu, QAction, QMessageBox, QFileDialog, QApplication
36+
from qgis.PyQt.QtWidgets import (QMenu,
37+
QAction,
38+
QToolButton,
39+
QMessageBox,
40+
QFileDialog,
41+
QApplication)
3742

3843
from qgis.core import QgsApplication
3944
from qgis.utils import iface
@@ -65,40 +70,52 @@ def __init__(self, algType, alg):
6570
self.setWindowFlags(Qt.WindowMinimizeButtonHint |
6671
Qt.WindowMaximizeButtonHint |
6772
Qt.WindowCloseButtonHint)
68-
# Set icons
69-
self.btnOpen.setIcon(
73+
74+
settings = QSettings()
75+
self.restoreState(settings.value("/Processing/stateScriptEditor", QByteArray()))
76+
self.restoreGeometry(settings.value("/Processing/geometryScriptEditor", QByteArray()))
77+
78+
iconSize = settings.value("iconsize", 24)
79+
self.toolBar.setIconSize(QSize(iconSize, iconSize))
80+
81+
self.actionOpenScript.setIcon(
7082
QgsApplication.getThemeIcon('/mActionFileOpen.svg'))
71-
self.btnSave.setIcon(
83+
self.actionSaveScript.setIcon(
7284
QgsApplication.getThemeIcon('/mActionFileSave.svg'))
73-
self.btnSaveAs.setIcon(
85+
self.actionSaveScriptAs.setIcon(
7486
QgsApplication.getThemeIcon('/mActionFileSaveAs.svg'))
75-
self.btnEditHelp.setIcon(
76-
QIcon(os.path.join(pluginPath, 'images', 'edithelp.png')))
77-
self.btnRun.setIcon(
78-
QIcon(os.path.join(pluginPath, 'images', 'runalgorithm.png')))
79-
self.btnCut.setIcon(QgsApplication.getThemeIcon('/mActionEditCut.svg'))
80-
self.btnCopy.setIcon(
87+
self.actionEditScriptHelp.setIcon(
88+
QgsApplication.getThemeIcon('/mActionEditHelpContent.svg'))
89+
self.actionRunScript.setIcon(
90+
QgsApplication.getThemeIcon('/mActionStart.svg'))
91+
self.actionCut.setIcon(
92+
QgsApplication.getThemeIcon('/mActionEditCut.svg'))
93+
self.actionCopy.setIcon(
8194
QgsApplication.getThemeIcon('/mActionEditCopy.svg'))
82-
self.btnPaste.setIcon(
95+
self.actionPaste.setIcon(
8396
QgsApplication.getThemeIcon('/mActionEditPaste.svg'))
84-
self.btnUndo.setIcon(QgsApplication.getThemeIcon('/mActionUndo.svg'))
85-
self.btnRedo.setIcon(QgsApplication.getThemeIcon('/mActionRedo.svg'))
86-
self.btnSnippets.setIcon(QgsApplication.getThemeIcon('/mActionHelpAPI.png'))
97+
self.actionUndo.setIcon(
98+
QgsApplication.getThemeIcon('/mActionUndo.svg'))
99+
self.actionRedo.setIcon(
100+
QgsApplication.getThemeIcon('/mActionRedo.svg'))
101+
self.actionIncreaseFontSize.setIcon(
102+
QgsApplication.getThemeIcon('/mActionIncreaseFont.svg'))
103+
self.actionDecreaseFontSize.setIcon(
104+
QgsApplication.getThemeIcon('/mActionDecreaseFont.svg'))
87105

88106
# Connect signals and slots
89-
self.btnOpen.clicked.connect(self.openScript)
90-
self.btnSave.clicked.connect(self.save)
91-
self.btnSaveAs.clicked.connect(self.saveAs)
92-
self.btnEditHelp.clicked.connect(self.editHelp)
93-
self.btnRun.clicked.connect(self.runAlgorithm)
94-
self.btnSnippets.clicked.connect(self.showSnippets)
95-
self.btnCut.clicked.connect(self.editor.cut)
96-
self.btnCopy.clicked.connect(self.editor.copy)
97-
self.btnPaste.clicked.connect(self.editor.paste)
98-
self.btnUndo.clicked.connect(self.editor.undo)
99-
self.btnRedo.clicked.connect(self.editor.redo)
100-
self.btnIncreaseFont.clicked.connect(self.editor.zoomIn)
101-
self.btnDecreaseFont.clicked.connect(self.editor.zoomOut)
107+
self.actionOpenScript.triggered.connect(self.openScript)
108+
self.actionSaveScript.triggered.connect(self.save)
109+
self.actionSaveScriptAs.triggered.connect(self.saveAs)
110+
self.actionEditScriptHelp.triggered.connect(self.editHelp)
111+
self.actionRunScript.triggered.connect(self.runAlgorithm)
112+
self.actionCut.triggered.connect(self.editor.cut)
113+
self.actionCopy.triggered.connect(self.editor.copy)
114+
self.actionPaste.triggered.connect(self.editor.paste)
115+
self.actionUndo.triggered.connect(self.editor.undo)
116+
self.actionRedo.triggered.connect(self.editor.redo)
117+
self.actionIncreaseFontSize.triggered.connect(self.editor.zoomIn)
118+
self.actionDecreaseFontSize.triggered.connect(self.editor.zoomOut)
102119
self.editor.textChanged.connect(lambda: self.setHasChanged(True))
103120

104121
self.alg = alg
@@ -107,7 +124,7 @@ def __init__(self, algType, alg):
107124
self.snippets = {}
108125
if self.algType == self.SCRIPT_PYTHON:
109126
path = os.path.join(os.path.dirname(os.path.dirname(__file__)), "script", "snippets.py")
110-
with open(path) as f:
127+
with codecs.open(path, 'r', encoding='utf-8') as f:
111128
lines = f.readlines()
112129
snippetlines = []
113130
name = None
@@ -122,8 +139,8 @@ def __init__(self, algType, alg):
122139
if snippetlines:
123140
self.snippets[name] = "".join(snippetlines)
124141

125-
if not self.snippets:
126-
self.btnSnippets.setVisible(False)
142+
#if self.snippets:
143+
# self.btnSnippets.setVisible(False)
127144

128145
if self.alg is not None:
129146
self.filename = self.alg.descriptionFile
@@ -138,13 +155,13 @@ def __init__(self, algType, alg):
138155

139156
self.editor.setLexerType(self.algType)
140157

141-
def showSnippets(self, evt):
142-
popupmenu = QMenu()
143-
for name, snippet in list(self.snippets.items()):
144-
action = QAction(self.tr(name), self.btnSnippets)
145-
action.triggered[()].connect(lambda snippet=snippet: self.editor.insert(snippet))
146-
popupmenu.addAction(action)
147-
popupmenu.exec_(QCursor.pos())
158+
#def showSnippets(self, evt):
159+
# popupmenu = QMenu()
160+
# for name, snippet in list(self.snippets.items()):
161+
# action = QAction(self.tr(name), self.btnSnippets)
162+
# action.triggered[()].connect(lambda snippet=snippet: self.editor.insert(snippet))
163+
# popupmenu.addAction(action)
164+
# popupmenu.exec_(QCursor.pos())
148165

149166
def closeEvent(self, evt):
150167
if self.hasChanged:
@@ -189,7 +206,7 @@ def openScript(self):
189206
scriptDir = RUtils.RScriptsFolders()[0]
190207
filterName = self.tr('Processing R script (*.rsx)')
191208

192-
self.filename = QFileDialog.getOpenFileName(
209+
self.filename, fileFilter = QFileDialog.getOpenFileName(
193210
self, self.tr('Open script'), scriptDir, filterName)
194211

195212
if self.filename == '':
@@ -220,9 +237,8 @@ def saveScript(self, saveAs):
220237
scriptDir = RUtils.RScriptsFolders()[0]
221238
filterName = self.tr('Processing R script (*.rsx)')
222239

223-
self.filename = str(QFileDialog.getSaveFileName(self,
224-
self.tr('Save script'), scriptDir,
225-
filterName))
240+
self.filename, fileFilter = QFileDialog.getSaveFileName(
241+
self, self.tr('Save script'), scriptDir, filterName)
226242

227243
if self.filename:
228244
if self.algType == self.SCRIPT_PYTHON and \
@@ -239,17 +255,17 @@ def saveScript(self, saveAs):
239255
with codecs.open(self.filename, 'w', encoding='utf-8') as fout:
240256
fout.write(text)
241257
except IOError:
242-
QMessageBox.warning(self, self.tr('I/O error'),
243-
self.tr('Unable to save edits. Reason:\n %s')
244-
% str(sys.exc_info()[1])
258+
QMessageBox.warning(self,
259+
self.tr('I/O error'),
260+
self.tr('Unable to save edits. Reason:\n{}').format(sys.exc_info()[1])
245261
)
246262
return
247263
self.update = True
248264

249265
# If help strings were defined before saving the script for
250266
# the first time, we do it here
251267
if self.help:
252-
with open(self.filename + '.help', 'w') as f:
268+
with codecs.open(self.filename + '.help', 'w', encoding='utf-8') as f:
253269
json.dump(self.help, f)
254270
self.help = None
255271
self.setHasChanged(False)
@@ -258,7 +274,7 @@ def saveScript(self, saveAs):
258274

259275
def setHasChanged(self, hasChanged):
260276
self.hasChanged = hasChanged
261-
self.btnSave.setEnabled(hasChanged)
277+
self.actionSaveScript.setEnabled(hasChanged)
262278

263279
def runAlgorithm(self):
264280
if self.algType == self.SCRIPT_PYTHON:

‎python/plugins/processing/modeler/ModelerDialog.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,9 @@ def saveAs(self):
279279
self.saveModel(True)
280280

281281
def exportAsImage(self):
282-
filename, filter = QFileDialog.getSaveFileName(self,
283-
self.tr('Save Model As Image'), '',
284-
self.tr('PNG files (*.png *.PNG)'))
282+
filename, fileFilter = QFileDialog.getSaveFileName(self,
283+
self.tr('Save Model As Image'), '',
284+
self.tr('PNG files (*.png *.PNG)'))
285285
if not filename:
286286
return
287287

‎python/plugins/processing/ui/DlgScriptEditor.ui

Lines changed: 163 additions & 279 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.