Skip to content

Commit

Permalink
[processing] implement alternative display names for algorithms
Browse files Browse the repository at this point in the history
  • Loading branch information
volaya committed May 21, 2015
1 parent 7a35d62 commit 87f2370
Show file tree
Hide file tree
Showing 6 changed files with 488 additions and 443 deletions.
6 changes: 3 additions & 3 deletions python/plugins/processing/core/Processing.py
Expand Up @@ -17,7 +17,6 @@
***************************************************************************
"""


__author__ = 'Victor Olaya'
__date__ = 'August 2012'
__copyright__ = '(C) 2012, Victor Olaya'
Expand All @@ -34,11 +33,11 @@
from qgis.utils import iface

import processing
from processing.gui import AlgorithmClassification
from processing.modeler.ModelerUtils import ModelerUtils
from processing.core.ProcessingConfig import ProcessingConfig
from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.ProcessingLog import ProcessingLog
from processing.gui.AlgorithmClassification import AlgorithmDecorator
from processing.gui.MessageBarProgress import MessageBarProgress
from processing.gui.RenderingStyles import RenderingStyles
from processing.gui.Postprocessing import handleAlgorithmResults
Expand Down Expand Up @@ -142,7 +141,8 @@ def initialize():
Processing.modeler.initializeSettings()

# And initialize
AlgorithmDecorator.loadClassification()
AlgorithmClassification.loadClassification()
AlgorithmClassification.loadDisplayNames()
ProcessingLog.startLogging()
ProcessingConfig.initialize()
ProcessingConfig.readSettings()
Expand Down
77 changes: 45 additions & 32 deletions python/plugins/processing/gui/AlgorithmClassification.py
Expand Up @@ -27,39 +27,52 @@

import os

displayNames = {}
classification = {}

class AlgorithmDecorator:

classification = {}

@staticmethod
def loadClassification():
if not os.path.isfile(AlgorithmDecorator.classificationFile()):
return
lines = open(AlgorithmDecorator.classificationFile())
def loadClassification():
global classification
if not os.path.isfile(classificationFile()):
return
lines = open(classificationFile())
line = lines.readline().strip('\n')
while line != '':
tokens = line.split(',')
subtokens = tokens[1].split('/')
try:
classification[tokens[0]] = subtokens
except:
raise Exception(line)
line = lines.readline().strip('\n')
while line != '':
tokens = line.split(',')
subtokens = tokens[2].split('/')
try:
AlgorithmDecorator.classification[tokens[0]] = (subtokens[0],
subtokens[1], tokens[1])
except:
raise Exception(line)
line = lines.readline().strip('\n')
lines.close()
lines.close()

def loadDisplayNames():
global displayNames
if not os.path.isfile(displayNamesFile()):
return
lines = open(displayNamesFile())
line = lines.readline().strip('\n')
while line != '':
tokens = line.split(',')
try:
displayNames[tokens[0]] = tokens[1]
except:
raise Exception(line)
line = lines.readline().strip('\n')
lines.close()

def classificationFile():
return os.path.join(os.path.dirname(__file__), 'algclasssification.txt')

@staticmethod
def classificationFile():
return os.path.join(os.path.dirname(__file__), 'algclasssification.txt')
def displayNamesFile():
return os.path.join(os.path.dirname(__file__), 'algnames.txt')

@staticmethod
def getGroupsAndName(alg):
if alg.commandLineName().lower() in AlgorithmDecorator.classification:
(group, subgroup, name) = \
AlgorithmDecorator.classification[alg.commandLineName()]
if name == 'USE_ORIGINAL_NAME':
name = alg.name
return (group, subgroup, name)
else:
return (None, None, alg.name)
def getClassification(alg):
if alg.commandLineName().lower() in classification:
group, subgroup = classification[alg.commandLineName()]
return group, subgroup
else:
return None, None

def getDisplayName(alg):
return displayNames.get(alg.commandLineName().lower(), alg.name)
12 changes: 5 additions & 7 deletions python/plugins/processing/gui/ProcessingToolbox.py
Expand Up @@ -17,7 +17,6 @@
***************************************************************************
"""


__author__ = 'Victor Olaya'
__date__ = 'August 2012'
__copyright__ = '(C) 2012, Victor Olaya'
Expand All @@ -39,7 +38,7 @@
from processing.core.ProcessingConfig import ProcessingConfig
from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.gui.MessageDialog import MessageDialog
from processing.gui.AlgorithmClassification import AlgorithmDecorator
from processing.gui import AlgorithmClassification
from processing.gui.AlgorithmDialog import AlgorithmDialog
from processing.gui.BatchAlgorithmDialog import BatchAlgorithmDialog
from processing.gui.EditRenderingStylesDialog import EditRenderingStylesDialog
Expand Down Expand Up @@ -280,11 +279,11 @@ def fillTreeUsingCategories(self):
for alg in algs:
if not alg.showInToolbox:
continue
(altgroup, altsubgroup, altname) = \
AlgorithmDecorator.getGroupsAndName(alg)
altgroup, altsubgroup = AlgorithmClassification.getClassification(alg)
if altgroup is None:
continue
if text == '' or text.lower() in altname.lower():
algName = AlgorithmClassification.getDisplayName(alg)
if text == '' or text.lower() in algName.lower():
if altgroup not in groups:
groups[altgroup] = {}
group = groups[altgroup]
Expand Down Expand Up @@ -346,10 +345,9 @@ def __init__(self, alg):
QTreeWidgetItem.__init__(self)
self.alg = alg
icon = alg.getIcon()
name = alg.name
if useCategories:
icon = GeoAlgorithm.getDefaultIcon()
(group, subgroup, name) = AlgorithmDecorator.getGroupsAndName(alg)
name = AlgorithmClassification.getDisplayName(alg)
self.setIcon(0, icon)
self.setToolTip(0, name)
self.setText(0, name)
Expand Down

0 comments on commit 87f2370

Please sign in to comment.