Skip to content
Permalink
Browse files
improved new algorithm classification mechanism
fixed #6834
  • Loading branch information
volaya committed Dec 8, 2012
1 parent eedd891 commit 7841975a830aae5f17a40ac5faabc982e5830760
@@ -37,8 +37,8 @@ def loadClassification():
lines = open(AlgorithmDecorator.classificationFile())
line = lines.readline().strip("\n")
while line != "":
tokens = line.split("\t")
AlgorithmDecorator.classification[tokens[0]] = (tokens[1], tokens[2]);
tokens = line.split("\t")
AlgorithmDecorator.classification[tokens[0]] = (tokens[1], tokens[2], tokens[3]);
line = lines.readline().strip("\n")
lines.close()

@@ -47,11 +47,14 @@ def classificationFile():
return os.path.join(SextanteUtils.userFolder(), "sextante_qgis_algclass.txt")

@staticmethod
def getGroupAndName(alg):
def getGroupsAndName(alg):
if alg.commandLineName() in AlgorithmDecorator.classification:
return AlgorithmDecorator.classification[alg.commandLineName]
group, subgroup, name = AlgorithmDecorator.classification[alg.commandLineName]
if name == "USE_ORIGINAL_NAME":
name = alg.name
return (group, subgroup, name)
else:
return (alg.group, alg.name)
return ("Uncategorized", alg.group, alg.name)



@@ -201,33 +201,41 @@ def fillTreeUsingCategories(self):
for alg in algs:
if not alg.showInToolbox:
continue
altgroup, altname = AlgorithmDecorator.getGroupAndName(alg)
if text =="" or text.lower() in altname.lower():
if altgroup in groups:
groupItem = groups[altgroup]
else:
groupItem = QTreeWidgetItem()
groupItem.setText(0, altgroup)
groupItem.setToolTip(0, altgroup)
groupItem.setIcon(0, GeoAlgorithm.getDefaultIcon())
groups[altgroup] = groupItem
algItem = TreeAlgorithmItem(alg)
groupItem.addChild(algItem)

altgroup, altsubgroup, altname = AlgorithmDecorator.getGroupsAndName(alg)
if text =="" or text.lower() in altname.lower():
if altgroup not in groups:
groups[altgroup] = {}
group = groups[altgroup]
if altsubgroup not in group:
groups[altgroup][altsubgroup] = []
subgroup = groups[altgroup][altsubgroup]
subgroup.append(alg)

if len(groups) > 0:
mainItem = QTreeWidgetItem()
mainItem.setText(0, "Geoalgorithms")
mainItem.setIcon(0, GeoAlgorithm.getDefaultIcon())
mainItem.setToolTip(0, mainItem.text(0))
for groupItem in groups.values():
mainItem.setToolTip(0, mainItem.text(0))
for groupname, group in groups.items():
groupItem = QTreeWidgetItem()
groupItem.setText(0, groupname)
groupItem.setIcon(0, GeoAlgorithm.getDefaultIcon())
groupItem.setToolTip(0, groupItem.text(0))
mainItem.addChild(groupItem)
for subgroupname, subgroup in group.items():
subgroupItem = QTreeWidgetItem()
subgroupItem.setText(0, subgroupname)
subgroupItem.setIcon(0, GeoAlgorithm.getDefaultIcon())
subgroupItem.setToolTip(0, subgroupItem.text(0))
groupItem.addChild(subgroupItem)
for alg in subgroup:
algItem = TreeAlgorithmItem(alg)
subgroupItem.addChild(algItem)
subgroupItem.setExpanded(text!="")
groupItem.setExpanded(text!="")
self.algorithmTree.addTopLevelItem(mainItem)
mainItem.setExpanded(text!="")
for groupItem in groups.values():
if text != "":
groupItem.setExpanded(True)



for providerName in Sextante.algs.keys():
groups = {}
provider = Sextante.algs[providerName]
@@ -341,7 +349,7 @@ def __init__(self, alg):
name = alg.name
if useCategories:
icon = GeoAlgorithm.getDefaultIcon()
group, name = AlgorithmDecorator.getGroupAndName(alg)
group, subgroup, name = AlgorithmDecorator.getGroupsAndName(alg)
self.setIcon(0, icon)
self.setToolTip(0, name)

@@ -16,6 +16,9 @@
* *
***************************************************************************
"""
from sextante.core.SextanteConfig import SextanteConfig
from sextante.core.GeoAlgorithm import GeoAlgorithm
from sextante.core.AlgorithmClassification import AlgorithmDecorator

__author__ = 'Victor Olaya'
__date__ = 'August 2012'
@@ -368,7 +371,107 @@ def addAlgorithm(self):
self.repaintModel()
self.view.ensureVisible(self.scene.getLastAlgorithmItem())

def fillAlgorithmTree(self):
def fillAlgorithmTree(self):
useCategories = SextanteConfig.getSetting(SextanteConfig.USE_CATEGORIES)
if useCategories:
self.fillAlgorithmTreeUsingCategories()
else:
self.fillAlgorithmTreeUsingProviders()

self.algorithmTree.sortItems(0, Qt.AscendingOrder)

def fillAlgorithmTreeUsingCategories(self):
providersToExclude = ["model", "script"]
self.algorithmTree.clear()
text = unicode(self.searchBox.text())
groups = {}
allAlgs = ModelerUtils.getAlgorithms()
for providerName in allAlgs.keys():
provider = allAlgs[providerName]
name = "ACTIVATE_" + providerName.upper().replace(" ", "_")
if not SextanteConfig.getSetting(name):
continue
if providerName in providersToExclude or len(Providers.providers[providerName].actions) != 0:
continue
algs = provider.values()
#add algorithms
for alg in algs:
if not alg.showInModeler:
continue
altgroup, altsubgroup, altname = AlgorithmDecorator.getGroupsAndName(alg)
if text =="" or text.lower() in altname.lower():
if altgroup not in groups:
groups[altgroup] = {}
group = groups[altgroup]
if altsubgroup not in group:
groups[altgroup][altsubgroup] = []
subgroup = groups[altgroup][altsubgroup]
subgroup.append(alg)

if len(groups) > 0:
mainItem = QTreeWidgetItem()
mainItem.setText(0, "Geoalgorithms")
mainItem.setIcon(0, GeoAlgorithm.getDefaultIcon())
mainItem.setToolTip(0, mainItem.text(0))
for groupname, group in groups.items():
groupItem = QTreeWidgetItem()
groupItem.setText(0, groupname)
groupItem.setIcon(0, GeoAlgorithm.getDefaultIcon())
groupItem.setToolTip(0, groupItem.text(0))
mainItem.addChild(groupItem)
for subgroupname, subgroup in group.items():
subgroupItem = QTreeWidgetItem()
subgroupItem.setText(0, subgroupname)
subgroupItem.setIcon(0, GeoAlgorithm.getDefaultIcon())
subgroupItem.setToolTip(0, subgroupItem.text(0))
groupItem.addChild(subgroupItem)
for alg in subgroup:
algItem = TreeAlgorithmItem(alg)
subgroupItem.addChild(algItem)
subgroupItem.setExpanded(text!="")
groupItem.setExpanded(text!="")
self.algorithmTree.addTopLevelItem(mainItem)
mainItem.setExpanded(text!="")

for providerName in allAlgs.keys():
groups = {}
provider = allAlgs[providerName]
name = "ACTIVATE_" + providerName.upper().replace(" ", "_")
if not SextanteConfig.getSetting(name):
continue
if providerName not in providersToExclude:
continue
algs = provider.values()
#add algorithms
for alg in algs:
if not alg.showInModeler:
continue
if text =="" or text.lower() in alg.name.lower():
if alg.group in groups:
groupItem = groups[alg.group]
else:
groupItem = QTreeWidgetItem()
groupItem.setText(0, alg.group)
groupItem.setToolTip(0, alg.group)
groups[alg.group] = groupItem
algItem = TreeAlgorithmItem(alg)
groupItem.addChild(algItem)

if len(groups) > 0:
providerItem = QTreeWidgetItem()
providerItem.setText(0, Providers.providers[providerName].getDescription())
providerItem.setIcon(0, Providers.providers[providerName].getIcon())
providerItem.setToolTip(0, providerItem.text(0))
for groupItem in groups.values():
providerItem.addChild(groupItem)
self.algorithmTree.addTopLevelItem(providerItem)
providerItem.setExpanded(text!="")
for groupItem in groups.values():
if text != "":
groupItem.setExpanded(True)


def fillAlgorithmTreeUsingProviders(self):
self.algorithmTree.clear()
text = str(self.searchBox.text())
allAlgs = ModelerUtils.getAlgorithms()
@@ -270,7 +270,8 @@ def getImportCommands(self):
value = value.replace("\\", "/")
filename = os.path.basename(value)
filename = filename[:-4]
commands.append(param.name + " = readOGR(\"" + value + "\",layer=\"" + filename + "\")")
folder = os.path.dirname(value)
commands.append(param.name + " = readOGR(\"" + folder + "\",layer=\"" + filename + "\")")
if isinstance(param, ParameterTable):
value = param.value
if not value.lower().endswith("csv"):

0 comments on commit 7841975

Please sign in to comment.