Skip to content

Commit 87f2370

Browse files
committed
[processing] implement alternative display names for algorithms
1 parent 7a35d62 commit 87f2370

File tree

6 files changed

+488
-443
lines changed

6 files changed

+488
-443
lines changed

python/plugins/processing/core/Processing.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
***************************************************************************
1818
"""
1919

20-
2120
__author__ = 'Victor Olaya'
2221
__date__ = 'August 2012'
2322
__copyright__ = '(C) 2012, Victor Olaya'
@@ -34,11 +33,11 @@
3433
from qgis.utils import iface
3534

3635
import processing
36+
from processing.gui import AlgorithmClassification
3737
from processing.modeler.ModelerUtils import ModelerUtils
3838
from processing.core.ProcessingConfig import ProcessingConfig
3939
from processing.core.GeoAlgorithm import GeoAlgorithm
4040
from processing.core.ProcessingLog import ProcessingLog
41-
from processing.gui.AlgorithmClassification import AlgorithmDecorator
4241
from processing.gui.MessageBarProgress import MessageBarProgress
4342
from processing.gui.RenderingStyles import RenderingStyles
4443
from processing.gui.Postprocessing import handleAlgorithmResults
@@ -142,7 +141,8 @@ def initialize():
142141
Processing.modeler.initializeSettings()
143142

144143
# And initialize
145-
AlgorithmDecorator.loadClassification()
144+
AlgorithmClassification.loadClassification()
145+
AlgorithmClassification.loadDisplayNames()
146146
ProcessingLog.startLogging()
147147
ProcessingConfig.initialize()
148148
ProcessingConfig.readSettings()

python/plugins/processing/gui/AlgorithmClassification.py

+45-32
Original file line numberDiff line numberDiff line change
@@ -27,39 +27,52 @@
2727

2828
import os
2929

30+
displayNames = {}
31+
classification = {}
3032

31-
class AlgorithmDecorator:
32-
33-
classification = {}
34-
35-
@staticmethod
36-
def loadClassification():
37-
if not os.path.isfile(AlgorithmDecorator.classificationFile()):
38-
return
39-
lines = open(AlgorithmDecorator.classificationFile())
33+
def loadClassification():
34+
global classification
35+
if not os.path.isfile(classificationFile()):
36+
return
37+
lines = open(classificationFile())
38+
line = lines.readline().strip('\n')
39+
while line != '':
40+
tokens = line.split(',')
41+
subtokens = tokens[1].split('/')
42+
try:
43+
classification[tokens[0]] = subtokens
44+
except:
45+
raise Exception(line)
4046
line = lines.readline().strip('\n')
41-
while line != '':
42-
tokens = line.split(',')
43-
subtokens = tokens[2].split('/')
44-
try:
45-
AlgorithmDecorator.classification[tokens[0]] = (subtokens[0],
46-
subtokens[1], tokens[1])
47-
except:
48-
raise Exception(line)
49-
line = lines.readline().strip('\n')
50-
lines.close()
47+
lines.close()
48+
49+
def loadDisplayNames():
50+
global displayNames
51+
if not os.path.isfile(displayNamesFile()):
52+
return
53+
lines = open(displayNamesFile())
54+
line = lines.readline().strip('\n')
55+
while line != '':
56+
tokens = line.split(',')
57+
try:
58+
displayNames[tokens[0]] = tokens[1]
59+
except:
60+
raise Exception(line)
61+
line = lines.readline().strip('\n')
62+
lines.close()
63+
64+
def classificationFile():
65+
return os.path.join(os.path.dirname(__file__), 'algclasssification.txt')
5166

52-
@staticmethod
53-
def classificationFile():
54-
return os.path.join(os.path.dirname(__file__), 'algclasssification.txt')
67+
def displayNamesFile():
68+
return os.path.join(os.path.dirname(__file__), 'algnames.txt')
5569

56-
@staticmethod
57-
def getGroupsAndName(alg):
58-
if alg.commandLineName().lower() in AlgorithmDecorator.classification:
59-
(group, subgroup, name) = \
60-
AlgorithmDecorator.classification[alg.commandLineName()]
61-
if name == 'USE_ORIGINAL_NAME':
62-
name = alg.name
63-
return (group, subgroup, name)
64-
else:
65-
return (None, None, alg.name)
70+
def getClassification(alg):
71+
if alg.commandLineName().lower() in classification:
72+
group, subgroup = classification[alg.commandLineName()]
73+
return group, subgroup
74+
else:
75+
return None, None
76+
77+
def getDisplayName(alg):
78+
return displayNames.get(alg.commandLineName().lower(), alg.name)

python/plugins/processing/gui/ProcessingToolbox.py

+5-7
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
***************************************************************************
1818
"""
1919

20-
2120
__author__ = 'Victor Olaya'
2221
__date__ = 'August 2012'
2322
__copyright__ = '(C) 2012, Victor Olaya'
@@ -39,7 +38,7 @@
3938
from processing.core.ProcessingConfig import ProcessingConfig
4039
from processing.core.GeoAlgorithm import GeoAlgorithm
4140
from processing.gui.MessageDialog import MessageDialog
42-
from processing.gui.AlgorithmClassification import AlgorithmDecorator
41+
from processing.gui import AlgorithmClassification
4342
from processing.gui.AlgorithmDialog import AlgorithmDialog
4443
from processing.gui.BatchAlgorithmDialog import BatchAlgorithmDialog
4544
from processing.gui.EditRenderingStylesDialog import EditRenderingStylesDialog
@@ -280,11 +279,11 @@ def fillTreeUsingCategories(self):
280279
for alg in algs:
281280
if not alg.showInToolbox:
282281
continue
283-
(altgroup, altsubgroup, altname) = \
284-
AlgorithmDecorator.getGroupsAndName(alg)
282+
altgroup, altsubgroup = AlgorithmClassification.getClassification(alg)
285283
if altgroup is None:
286284
continue
287-
if text == '' or text.lower() in altname.lower():
285+
algName = AlgorithmClassification.getDisplayName(alg)
286+
if text == '' or text.lower() in algName.lower():
288287
if altgroup not in groups:
289288
groups[altgroup] = {}
290289
group = groups[altgroup]
@@ -346,10 +345,9 @@ def __init__(self, alg):
346345
QTreeWidgetItem.__init__(self)
347346
self.alg = alg
348347
icon = alg.getIcon()
349-
name = alg.name
350348
if useCategories:
351349
icon = GeoAlgorithm.getDefaultIcon()
352-
(group, subgroup, name) = AlgorithmDecorator.getGroupsAndName(alg)
350+
name = AlgorithmClassification.getDisplayName(alg)
353351
self.setIcon(0, icon)
354352
self.setToolTip(0, name)
355353
self.setText(0, name)

0 commit comments

Comments
 (0)