Skip to content

Commit

Permalink
[processing] filter items in toolbox using translated and original na…
Browse files Browse the repository at this point in the history
…mes (fix #13764)
  • Loading branch information
alexbruy committed Apr 11, 2016
1 parent 16d8da3 commit abda90f
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 21 deletions.
Expand Up @@ -36,8 +36,8 @@
class OpenViewerAction(ToolboxAction):

def __init__(self):
self.name = self.tr('Open Fusion LAS viewer')
self.group = self.tr('Visualization')
self.name, self.i18n_name = self.trAction('Open Fusion LAS viewer')
self.group, self.i18n_group = self.trAction('Visualization')

def getIcon(self):
return QIcon(os.path.dirname(__file__) + '/../../../images/tool.png')
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/r/RAlgorithmProvider.py
Expand Up @@ -52,7 +52,7 @@ def __init__(self):
AlgorithmProvider.__init__(self)
self.activate = False
self.actions.append(CreateNewScriptAction(
self.tr('Create new R script'), CreateNewScriptAction.SCRIPT_R))
'Create new R script', CreateNewScriptAction.SCRIPT_R))
self.actions.append(GetRScriptsAction())
self.contextMenuActions = \
[EditScriptAction(EditScriptAction.SCRIPT_R),
Expand Down
4 changes: 4 additions & 0 deletions python/plugins/processing/gui/AlgorithmClassification.py
Expand Up @@ -74,3 +74,7 @@ def getDisplayNameEn(alg):

def getDisplayName(alg):
return alg.i18n_name or alg.name


def getDisplayNames(alg):
return alg.name, alg.i18n_name
5 changes: 3 additions & 2 deletions python/plugins/processing/gui/CreateNewScriptAction.py
Expand Up @@ -41,8 +41,9 @@ class CreateNewScriptAction(ToolboxAction):
SCRIPT_R = 1

def __init__(self, actionName, scriptType):
self.name = actionName
self.group = self.tr('Tools', 'CreateNewScriptAction')
self.name, self.i18n_name = self.trAction(actionName)
self.group, self.i18n_group = self.trAction('Tools')

self.scriptType = scriptType

def getIcon(self):
Expand Down
12 changes: 6 additions & 6 deletions python/plugins/processing/gui/GetScriptsAndModels.py
Expand Up @@ -55,8 +55,8 @@
class GetScriptsAction(ToolboxAction):

def __init__(self):
self.name = self.tr('Get scripts from on-line scripts collection', 'GetScriptsAction')
self.group = self.tr('Tools', 'GetScriptsAction')
self.name, self.i18n_name = self.trAction('Get scripts from on-line scripts collection')
self.group, self.i18n_group = self.trAction('Tools')

def getIcon(self):
return QIcon(os.path.join(pluginPath, 'images', 'script.png'))
Expand All @@ -71,8 +71,8 @@ def execute(self):
class GetRScriptsAction(ToolboxAction):

def __init__(self):
self.name = self.tr('Get R scripts from on-line scripts collection', 'GetRScriptsAction')
self.group = self.tr('Tools', 'GetRScriptsAction')
self.name, self.i18n_name = self.trAction('Get R scripts from on-line scripts collection')
self.group, self.i18n_group = self.trAction('Tools')

def getIcon(self):
return QIcon(os.path.join(pluginPath, 'images', 'r.svg'))
Expand All @@ -87,8 +87,8 @@ def execute(self):
class GetModelsAction(ToolboxAction):

def __init__(self):
self.name = self.tr('Get models from on-line scripts collection', 'GetModelsAction')
self.group = self.tr('Tools', 'GetModelsAction')
self.name, self.i18n_name = self.trAction('Get models from on-line scripts collection')
self.group, self.i18n_group = self.trAction('Tools')

def getIcon(self):
return QIcon(os.path.join(pluginPath, 'images', 'model.png'))
Expand Down
9 changes: 6 additions & 3 deletions python/plugins/processing/gui/ProcessingToolbox.py
Expand Up @@ -133,7 +133,8 @@ def _filterItem(self, item, text):
item.setHidden(not show)
return show
elif isinstance(item, (TreeAlgorithmItem, TreeActionItem)):
hide = bool(text) and (text not in item.text(0).lower())
#hide = bool(text) and (text not in item.text(0).lower())
hide = bool(text) and not any(text in t for t in [item.text(0).lower(), item.data(0, Qt.UserRole).lower()])
if isinstance(item, TreeAlgorithmItem):
hide = hide and (text not in item.alg.commandLineName())
item.setHidden(hide)
Expand Down Expand Up @@ -327,19 +328,21 @@ def __init__(self, alg):
QTreeWidgetItem.__init__(self)
self.alg = alg
icon = alg.getIcon()
name = AlgorithmClassification.getDisplayName(alg)
nameEn, name = AlgorithmClassification.getDisplayNames(alg)
self.setIcon(0, icon)
self.setToolTip(0, name)
self.setText(0, name)
self.setData(0, Qt.UserRole, nameEn)


class TreeActionItem(QTreeWidgetItem):

def __init__(self, action):
QTreeWidgetItem.__init__(self)
self.action = action
self.setText(0, action.name)
self.setText(0, action.i18n_name)
self.setIcon(0, action.getIcon())
self.setData(0, Qt.UserRole, action.name)


class TreeProviderItem(QTreeWidgetItem):
Expand Down
5 changes: 5 additions & 0 deletions python/plugins/processing/gui/ToolboxAction.py
Expand Up @@ -42,3 +42,8 @@ def tr(self, string, context=''):
if context == '':
context = self.__class__.__name__
return QCoreApplication.translate(context, string)

def trAction(self, string, context=''):
if context == '':
context = self.__class__.__name__
return string, QCoreApplication.translate(context, string)
4 changes: 2 additions & 2 deletions python/plugins/processing/modeler/AddModelFromFileAction.py
Expand Up @@ -41,8 +41,8 @@
class AddModelFromFileAction(ToolboxAction):

def __init__(self):
self.name = self.tr('Add model from file', 'AddModelFromFileAction')
self.group = self.tr('Tools', 'AddModelFromFileAction')
self.name, self.i18n_name = self.trAction('Add model from file')
self.group, self.i18n_group = self.trAction('Tools')

def getIcon(self):
return QIcon(os.path.join(pluginPath, 'images', 'model.png'))
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/processing/modeler/CreateNewModelAction.py
Expand Up @@ -36,8 +36,8 @@
class CreateNewModelAction(ToolboxAction):

def __init__(self):
self.name = self.tr('Create new model', 'CreateNewModelAction')
self.group = self.tr('Tools', 'CreateNewModelAction')
self.name, self.i18n_name = self.trAction('Create new model')
self.group, self.i18n_group = self.trAction('Tools')

def getIcon(self):
return QIcon(os.path.join(pluginPath, 'images', 'model.png'))
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/processing/script/AddScriptFromFileAction.py
Expand Up @@ -42,8 +42,8 @@
class AddScriptFromFileAction(ToolboxAction):

def __init__(self):
self.name = self.tr('Add script from file', 'AddScriptFromFileAction')
self.group = self.tr('Tools', 'AddScriptFromFileAction')
self.name, self.i18n_name = self.trAction('Add script from file')
self.group, self.i18n_group = self.trAction('Tools')

def getIcon(self):
return QIcon(os.path.join(pluginPath, 'images', 'script.png'))
Expand Down
Expand Up @@ -45,7 +45,7 @@ class ScriptAlgorithmProvider(AlgorithmProvider):

def __init__(self):
AlgorithmProvider.__init__(self)
self.actions.extend([CreateNewScriptAction(self.tr('Create new script', 'ScriptAlgorithmProvider'),
self.actions.extend([CreateNewScriptAction('Create new script',
CreateNewScriptAction.SCRIPT_PYTHON),
AddScriptFromFileAction(),
GetScriptsAction()])
Expand Down

0 comments on commit abda90f

Please sign in to comment.