diff --git a/lib/galaxy/tools/__init__.py b/lib/galaxy/tools/__init__.py index 1968113b86c..e427cc05167 100755 --- a/lib/galaxy/tools/__init__.py +++ b/lib/galaxy/tools/__init__.py @@ -53,6 +53,8 @@ from galaxy.tools.test import parse_tests from galaxy.tools.parser import get_tool_source from galaxy.tools.parser.xml import XmlPageSource from galaxy.tools.toolbox import ToolPanelElements +from galaxy.tools.toolbox import ToolSection +from galaxy.tools.toolbox import ToolSectionLabel from galaxy.tools.toolbox import tool_tag_manager from galaxy.tools.toolbox.lineages import LineageMap from galaxy.util import listify, parse_xml, rst_to_html, string_as_bool, string_to_object @@ -1293,67 +1295,6 @@ def _filter_for_panel( item, filters, context ): return None -class ToolSection( object, Dictifiable ): - """ - A group of tools with similar type/purpose that will be displayed as a - group in the user interface. - """ - - dict_collection_visible_keys = ( 'id', 'name', 'version' ) - - def __init__( self, elem=None ): - """ Build a ToolSection from an ElementTree element or a dictionary. - """ - f = lambda elem, val: elem is not None and elem.get( val ) or '' - self.name = f( elem, 'name' ) - self.id = f( elem, 'id' ) - self.version = f( elem, 'version' ) - self.elems = ToolPanelElements() - - def copy( self ): - copy = ToolSection() - copy.name = self.name - copy.id = self.id - copy.version = self.version - copy.elems = self.elems.copy() - return copy - - def to_dict( self, trans, link_details=False ): - """ Return a dict that includes section's attributes. """ - - section_dict = super( ToolSection, self ).to_dict() - section_elts = [] - kwargs = dict( - trans=trans, - link_details=link_details - ) - for elt in self.elems.values(): - section_elts.append( elt.to_dict( **kwargs ) ) - section_dict[ 'elems' ] = section_elts - - return section_dict - - -class ToolSectionLabel( object, Dictifiable ): - """ - A label for a set of tools that can be displayed above groups of tools - and sections in the user interface - """ - - dict_collection_visible_keys = ( 'id', 'text', 'version' ) - - def __init__( self, elem ): - """ Build a ToolSectionLabel from an ElementTree element or a - dictionary. - """ - self.text = elem.get( "text" ) - self.id = elem.get( "id" ) - self.version = elem.get( "version" ) or '' - - def to_dict( self, **kwds ): - return super( ToolSectionLabel, self ).to_dict() - - class DefaultToolState( object ): """ Keeps track of the state of a users interaction with a tool between diff --git a/lib/galaxy/tools/toolbox/__init__.py b/lib/galaxy/tools/toolbox/__init__.py index e6161bac174..398e0dd4cf2 100644 --- a/lib/galaxy/tools/toolbox/__init__.py +++ b/lib/galaxy/tools/toolbox/__init__.py @@ -3,6 +3,8 @@ from .tags import tool_tag_manager from .panel import ToolPanelElements +from .panel import ToolSection +from .panel import ToolSectionLabel -__all__ = ["ToolPanelElements", "tool_tag_manager"] +__all__ = ["ToolPanelElements", "tool_tag_manager", "ToolSection", "ToolSectionLabel"] diff --git a/lib/galaxy/tools/toolbox/panel.py b/lib/galaxy/tools/toolbox/panel.py index c4ae1b1e522..3c186e1b68a 100644 --- a/lib/galaxy/tools/toolbox/panel.py +++ b/lib/galaxy/tools/toolbox/panel.py @@ -1,4 +1,66 @@ from galaxy.util.odict import odict +from galaxy.model.item_attrs import Dictifiable + + +class ToolSection( object, Dictifiable ): + """ + A group of tools with similar type/purpose that will be displayed as a + group in the user interface. + """ + + dict_collection_visible_keys = ( 'id', 'name', 'version' ) + + def __init__( self, elem=None ): + """ Build a ToolSection from an ElementTree element or a dictionary. + """ + f = lambda elem, val: elem is not None and elem.get( val ) or '' + self.name = f( elem, 'name' ) + self.id = f( elem, 'id' ) + self.version = f( elem, 'version' ) + self.elems = ToolPanelElements() + + def copy( self ): + copy = ToolSection() + copy.name = self.name + copy.id = self.id + copy.version = self.version + copy.elems = self.elems.copy() + return copy + + def to_dict( self, trans, link_details=False ): + """ Return a dict that includes section's attributes. """ + + section_dict = super( ToolSection, self ).to_dict() + section_elts = [] + kwargs = dict( + trans=trans, + link_details=link_details + ) + for elt in self.elems.values(): + section_elts.append( elt.to_dict( **kwargs ) ) + section_dict[ 'elems' ] = section_elts + + return section_dict + + +class ToolSectionLabel( object, Dictifiable ): + """ + A label for a set of tools that can be displayed above groups of tools + and sections in the user interface + """ + + dict_collection_visible_keys = ( 'id', 'text', 'version' ) + + def __init__( self, elem ): + """ Build a ToolSectionLabel from an ElementTree element or a + dictionary. + """ + self.text = elem.get( "text" ) + self.id = elem.get( "id" ) + self.version = elem.get( "version" ) or '' + + def to_dict( self, **kwds ): + return super( ToolSectionLabel, self ).to_dict() class ToolPanelElements( odict ): diff --git a/lib/tool_shed/galaxy_install/tool_migration_manager.py b/lib/tool_shed/galaxy_install/tool_migration_manager.py index cb4e20a497a..f8469fe96f8 100644 --- a/lib/tool_shed/galaxy_install/tool_migration_manager.py +++ b/lib/tool_shed/galaxy_install/tool_migration_manager.py @@ -10,7 +10,7 @@ import threading import logging from galaxy import util -from galaxy.tools import ToolSection +from galaxy.tools.toolbox import ToolSection from galaxy.util.odict import odict from tool_shed.galaxy_install import install_manager diff --git a/templates/admin/package_tool.mako b/templates/admin/package_tool.mako index 1557a5a8273..6d4818ee6a7 100644 --- a/templates/admin/package_tool.mako +++ b/templates/admin/package_tool.mako @@ -1,6 +1,9 @@ <%inherit file="/base.mako"/> <%namespace file="/message.mako" import="render_msg" /> -<% from galaxy.tools import Tool, ToolSection %> +<% + from galaxy.tools import Tool + from galaxy.tools.toolbox import ToolSection +%>