1. Robert Kern
  2. colormap-explorer

Commits

Robert Kern  committed ad5e06e

Convert to Envisage 3

  • Participants
  • Parent commits d00179e
  • Branches default

Comments (0)

Files changed (10)

File app/plugin_definitions.py

-# Enthought library imports.
-from enthought.envisage.api import join
-
-from enthought import envisage
-import colormap_explorer
-
-
-# The plugin definitions used in the application.
-PLUGIN_DEFINITIONS = [
-    # Envisage plugins.
-    join(envisage, 'core/core_plugin_definition.py'),
-    join(envisage, 'resource/resource_plugin_definition.py'),
-    join(envisage, 'workbench/workbench_plugin_definition.py'),
-    join(envisage, 'action/action_plugin_definition.py'),
-    join(envisage, 'workbench/action/action_plugin_definition.py'),
-    join(envisage, 'workbench/preference/preference_plugin_definition.py'),
-
-    # Application plugins.
-    join(colormap_explorer, 'plugin/model_plugin_definition.py'),
-    join(colormap_explorer, 'plugin/ui_plugin_definition.py'),
-]
-
-#### EOF ######################################################################

File app/run.py

View file
-""" The entry point for an Envisage application. """
-
+#!/usr/bin/env python
+# -*- coding: UTF-8 -*-
+""" The main script for the Colormap Explorer application.
+"""
 
 # Standard library imports.
+import logging
+import os
 import sys
 
 # Enthought library imports.
-from enthought.envisage.workbench.api import WorkbenchApplication
-from enthought.pyface.api import GUI
+from enthought.envisage.ui.workbench.api import WorkbenchApplication
 
-# Local imports.
-from plugin_definitions import PLUGIN_DEFINITIONS
 
+def get_plugins():
+    from enthought.envisage.core_plugin import CorePlugin
+    from enthought.envisage.ui.workbench.workbench_plugin import WorkbenchPlugin
+    from enthought.logger.plugin.logger_plugin import LoggerPlugin
+    from enthought.plugins.python_shell.python_shell_plugin import PythonShellPlugin
+    from colormap_explorer.plugins.model_plugin import ColormapExplorerModelPlugin
+    from colormap_explorer.plugins.ui_plugin import ColormapExplorerUIPlugin
+
+    plugins = [
+        CorePlugin(),
+        WorkbenchPlugin(),
+        LoggerPlugin(),
+        PythonShellPlugin(),
+        ColormapExplorerModelPlugin(),
+        ColormapExplorerUIPlugin(),
+    ]
+    return plugins
 
 def run(argv=sys.argv):
     """ Runs the application. """
 
-    # Create a GUI and put up the splash screen.
-    gui = GUI()
+    from enthought.etsconfig.api import ETSConfig
+    ETSConfig.application_home = os.path.expanduser('~/.colormap_explorer')
+    logger = logging.getLogger()
+    logger.basicConfig(filename=os.path.join(ETSConfig.application_home,
+        'explorer.log'))
 
     # Create the application.
     application = WorkbenchApplication(
-        argv               = argv,
-        gui                = gui,
-        id                 = 'colormap_explorer',
-        plugin_definitions = PLUGIN_DEFINITIONS
+        id = 'colormap_explorer',
+        name = 'Colormap Explorer',
+        plugins = get_plugins(),
     )
 
     # Run the application.

File colormap_explorer/plugin/model_plugin.py

View file
+""" The implementation of the Colormap Explorer plugin.
+"""
+
+# Standard library imports
+import logging
+
+# Enthought library imports
+from enthought.envisage.api import ExtensionPoint, Plugin
+from enthought.traits.api import Any, Array, Callable, List, Str
+
+# Local imports.
+from colormap_explorer.colorspace import sRGB, Lab, Luv, XYZ
+from colormap_explorer.vision_model import VisionModel
+from model_service import ModelService
+
+
+# Setup a logger for this module.
+logger = logging.getLogger(__name__)
+
+
+# The plugin's globally unique identifier (also used as the prefix for all
+# identifiers defined in this module).
+ID = "colormap_explorer.plugin.model"
+ICMAP_EXPLORER_MODEL = ID + '.ModelService'
+
+class ColormapExplorerModelPlugin(Plugin):
+    """ The implementation of the Colormap Explorer plugin.
+    """
+
+    id = ID
+    name = 'Colormap Explorer Model'
+
+    #### Extension points for this plugin ######################################
+
+    COLORMAPS = ID + '.colormaps'
+    colormaps = ExtensionPoint(
+        List(Callable), id=COLORMAPS, desc="""
+        Generators yielding colormaps.
+        """,
+    )
+
+    VISION_MODELS = ID + '.vision_models'
+    vision_models = ExtensionPoint(
+        List(Any), id=VISION_MODELS, desc="""
+        VisionModels describing normal and colorblind vision.
+        """,
+    )
+
+    IMAGE_DATA = ID + '.image_data'
+    image_data = ExtensionPoint(
+        List(Str, Array), id=IMAGE_DATA, desc="""
+        Pairs of titles and image data to plot with the colormaps.
+        """,
+    )
+
+
+    #### Public 'Plugin' interface #############################################
+
+    def start(self):
+        """ Starts the plugin.
+        """
+        self._create_model_service()
+
+
+    #### Private 'PluginImplementation' interface ##############################
+
+    def _create_model_service(self):
+        """ Initialize the model service.
+        """
+
+        model = ModelService()
+
+        # Set up the standard choices for colorspaces.
+        if False:
+            # XXX: my profiles.
+            import lcms
+            from colormap_explorer.device_colorspace import DeviceColorspace, ProofingColorspace
+            my_monitor = lcms.FileProfile('/Users/rkern/hg/colormap_explorer/data/MyMonitor.icc')
+            my_printer = lcms.FileProfile('/Users/rkern/hg/colormap_explorer/data/MyPrinter.icc')
+            monitor_device = DeviceColorspace(device_profile=my_monitor)
+            printer_proof = ProofingColorspace(proofing_profile=my_printer)
+            monitor_proof = ProofingColorspace(proofing_profile=my_monitor)
+            extra_inputs = []
+            extra_outputs = [monitor_device]
+            extra_coordinates = [monitor_device]
+            extra_proofs = [monitor_proof, printer_proof]
+        else:
+            extra_inputs = []
+            extra_outputs = []
+            extra_coordinates = []
+            extra_proofs = []
+        model.pipeline_handler.input_colorspaces = [sRGB] + extra_inputs
+        model.pipeline.input_colorspace = sRGB
+        model.pipeline_handler.output_colorspaces = [sRGB] + extra_outputs
+        model.pipeline.output_colorspace = sRGB
+        model.pipeline_handler.coordinate_colorspaces = [Luv, Lab, XYZ, sRGB] + extra_coordinates
+        model.pipeline.coordinate_colorspace = Luv
+        model.pipeline.vision_model = VisionModel()
+        model.pipeline_handler.vision_models = [model.pipeline.vision_model]
+        model.pipeline_handler.proofing_colorspaces = extra_proofs
+        if extra_proofs:
+            model.pipeline.proofing_colorspace = extra_proofs[0]
+
+        # Get all of the contributed colormaps and add them to the database.
+        for cmaps in self.colormaps:
+            for cmap in cmaps:
+                model.colormaps.add_colormap(cmap)
+        model.colormaps_handler.on_trait_change(
+            lambda x: model.set(selected_colormap=x),
+            'selected_colormap')
+        model.colormaps_handler.selected_colormap = model.colormaps.colormap_list[0]
+
+        # Get all of the vision models and configure the pipeline handler.
+        model.pipeline_handler.vision_models.extend(self.vision_models)
+
+        # Get all of the image data to plot.
+        for name, image in self.image_data:
+            model.image_data[name] = image
+
+        self.application.register_service(ICMAP_EXPLORER_MODEL, model)
+
+
+### EOF ######################################################################
+

File colormap_explorer/plugin/model_plugin_definition.py

-""" The Colormap Explorer plugin.
-"""
-
-# Enthought library imports.
-from enthought.envisage.api import ExtensionPoint, PluginDefinition
-from enthought.traits.api import Str
-
-
-# The plugin's globally unique identifier (also used as the prefix for all
-# identifiers defined in this module).
-ID = "colormap_explorer.plugin.model"
-
-
-###############################################################################
-# Extension Points.
-###############################################################################
-
-class Colormaps(ExtensionPoint):
-    """ Provide UOLs to sequences of Colormaps to install.
-    """
-
-    uol = Str
-
-
-class VisionModels(ExtensionPoint):
-    """ Provide UOLs to sequences of VisionModels to install.
-    """
-
-    uol = Str
-
-
-class ImageData(ExtensionPoint):
-    """ Provide UOLs to sequences of (name, image) pairs to install.
-    """
-
-    uol = Str
-
-
-###############################################################################
-# The plugin definition!
-###############################################################################
-
-class ColormapExplorerPluginDefinition(PluginDefinition):
-    # The plugin's globally unique identifier.
-    id = ID
-
-    # The name of the class that implements the plugin.
-    class_name = "colormap_explorer.plugin.model_plugin_implementation.ColormapExplorerModelPlugin"
-
-    # General information about the plugin.
-    name          = "Colormap Explorer Model"
-    version       = "1.0.0"
-    provider_name = "Enthought Inc"
-    provider_url  = "www.enthought.com"
-    enabled       = True
-    autostart     = True
-    
-    # The Id's of the plugins that this plugin requires.
-    requires = []
-
-    # The extension points offered by this plugin.
-    extension_points = [Colormaps, VisionModels]
-    
-    # The contributions that this plugin makes to extension points offered by
-    # either itself or other plugins.
-    extensions = [
-        Colormaps(uol='factory://colormap_explorer.colormap_db.load_chaco_colormaps'),
-        Colormaps(uol='factory://colormap_explorer.colormap_db.load_matplotlib_colormaps'),
-        Colormaps(uol='factory://colormap_explorer.colormap_db.load_colorbrewer_colormaps'),
-        Colormaps(uol='factory://colormap_explorer.colormap_db.load_monochrome_colormaps'),
-        # XXX: colormaps I have locally.
-        #Colormaps(uol='factory://xsd.load_xsd_colormaps'),
-        #Colormaps(uol='factory://ncvtk.load_ncvtk_colormaps'),
-        VisionModels(uol='import://colormap_explorer.vision_model.colorblind_models'),
-        ImageData(uol='factory://colormap_explorer.example_images.all_images'),
-    ]
-
-#### EOF #######################################################################

File colormap_explorer/plugin/model_plugin_implementation.py

-""" The implementation of the Colormap Explorer plugin.
-"""
-
-# Standard library imports
-import logging
-
-# Enthought library imports
-from enthought.envisage.core.plugin import Plugin
-
-# Local imports.
-from colormap_explorer.colorspace import sRGB, Lab, Luv, XYZ
-from colormap_explorer.vision_model import VisionModel
-from model_service import ModelService
-from model_plugin_definition import Colormaps, VisionModels, ImageData
-import services
-
-
-# Setup a logger for this module.
-logger = logging.getLogger(__name__)
-
-
-class ColormapExplorerModelPlugin(Plugin):
-    """ The implementation of the Colormap Explorer plugin.
-    """
-
-    #### Public 'Plugin' interface #############################################
-
-    def start(self, application):
-        """ Starts the plugin.
-        """
-
-        super(ColormapExplorerModelPlugin, self).start(application)
-        self.application = application
-
-        self._create_model_service()
-
-
-    #### Private 'PluginImplementation' interface ##############################
-
-    def _create_model_service(self):
-        """ Initialize the model service.
-        """
-
-        model = ModelService()
-
-        # Set up the standard choices for colorspaces.
-        if False:
-            # XXX: my profiles.
-            import lcms
-            from colormap_explorer.device_colorspace import DeviceColorspace, ProofingColorspace
-            my_monitor = lcms.FileProfile('/Users/rkern/hg/colormap_explorer/data/MyMonitor.icc')
-            my_printer = lcms.FileProfile('/Users/rkern/hg/colormap_explorer/data/MyPrinter.icc')
-            monitor_device = DeviceColorspace(device_profile=my_monitor)
-            printer_proof = ProofingColorspace(proofing_profile=my_printer)
-            monitor_proof = ProofingColorspace(proofing_profile=my_monitor)
-            extra_inputs = []
-            extra_outputs = [monitor_device]
-            extra_coordinates = [monitor_device]
-            extra_proofs = [monitor_proof, printer_proof]
-        else:
-            extra_inputs = []
-            extra_outputs = []
-            extra_coordinates = []
-            extra_proofs = []
-        model.pipeline_handler.input_colorspaces = [sRGB] + extra_inputs
-        model.pipeline.input_colorspace = sRGB
-        model.pipeline_handler.output_colorspaces = [sRGB] + extra_outputs
-        model.pipeline.output_colorspace = sRGB
-        model.pipeline_handler.coordinate_colorspaces = [Luv, Lab, XYZ, sRGB] + extra_coordinates
-        model.pipeline.coordinate_colorspace = Luv
-        model.pipeline.vision_model = VisionModel()
-        model.pipeline_handler.vision_models = [model.pipeline.vision_model]
-        model.pipeline_handler.proofing_colorspaces = extra_proofs
-        if extra_proofs:
-            model.pipeline.proofing_colorspace = extra_proofs[0]
-
-        # Get all of the contributed colormaps and add them to the database.
-        all_cmaps = self.application.get_extensions(Colormaps)
-        for cmaps in all_cmaps:
-            actual_colormaps = self.application.lookup_application_object(
-                cmaps.uol)
-            for cmap in actual_colormaps:
-                model.colormaps.add_colormap(cmap)
-        model.colormaps_handler.on_trait_change(
-            lambda x: model.set(selected_colormap=x),
-            'selected_colormap')
-        model.colormaps_handler.selected_colormap = model.colormaps.colormap_list[0]
-
-        # Get all of the vision models and configure the pipeline handler.
-        all_vision_models = self.application.get_extensions(VisionModels)
-        for vision_models in all_vision_models:
-            actual_vision_models = self.application.lookup_application_object(
-                vision_models.uol)
-            model.pipeline_handler.vision_models.extend(actual_vision_models)
-
-        # Get all of the image data to plot.
-        all_image_data = self.application.get_extensions(ImageData)
-        for image_data in all_image_data:
-            actual_image_data = self.application.lookup_application_object(
-                image_data.uol)
-            for name, image in actual_image_data:
-                model.image_data[name] = image
-
-        self.register_service(services.ICMAP_EXPLORER_MODEL, model)
-
-
-### EOF ######################################################################
-

File colormap_explorer/plugin/services.py

-""" Service identifiers.
-"""
-
-ICMAP_EXPLORER_MODEL = 'colormap_explorer.plugin.model'
-
-
-#### EOF #######################################################################

File colormap_explorer/plugin/ui_plugin.py

View file
+""" The Colormap Explorer UI plugin.
+"""
+
+
+# Enthought library imports.
+from enthought.envisage.api import Plugin
+from enthought.traits.api import List
+
+# Plugin definition imports.
+from enthought.pyface.workbench.api import Perspective, PerspectiveItem
+
+
+# The plugin's globally unique identifier (also used as the prefix for all
+# identifiers defined in this module).
+ID = "colormap_explorer.plugin.ui"
+
+
+class ScenePerspective(Perspective):
+    id = ID + '.scene_perspective'
+    name = '3D Colormap Viewer'
+    show_editor_area = False
+    contents = [
+        PerspectiveItem(
+            id=ID+".SceneView",
+            position="right",
+            width=0.8,
+            height=1.0,
+        ),
+        PerspectiveItem(
+            id=ID+".PipelineView",
+            position="bottom",
+            height=0.2,
+        ),
+        PerspectiveItem(
+            id=ID+".ColormapDBView",
+            position="left",
+            width=0.2,
+            height=0.8,
+        ),
+    ]
+
+
+class ImagePerspective(Perspective):
+    id = ID + '.image_perspective'
+    name = 'Colormapped Image'
+    show_editor_area = False
+    contents = [
+        PerspectiveItem(
+            id=ID+".CmapImage",
+            position="right",
+            width=0.8,
+            height=1.0,
+        ),
+        PerspectiveItem(
+            id=ID+".PipelineView",
+            position="bottom",
+            height=0.2,
+        ),
+        PerspectiveItem(
+            id=ID+".ColormapDBView",
+            position="left",
+            width=0.2,
+            height=0.8,
+        ),
+    ]
+
+
+class ColormapExplorerUIPlugin(Plugin):
+    """ Workbench UI for the Colormap Explorer.
+    """
+
+    id = ID
+    name = "Colormap Explorer UI"
+
+    #### Contributions to extension points made by this plugin #################
+
+    PERSPECTIVES = 'enthought.envisage.ui.workbench.perspectives'
+    VIEWS = 'enthought.envisage.ui.workbench.views'
+
+    perspectives = List(contributes_to=PERSPECTIVES)
+    views = List(contributes_to=VIEWS)
+
+
+    def _perspectives_default(self):
+        return [ScenePerspective, ImagePerspective]
+
+    def _views_default(self):
+        from colormap_explorer.plugin import views
+        theviews = [
+            views.ColormapDBView,
+            views.PipelineView,
+            views.SceneView,
+            views.CmapImage,
+        ]
+        return theviews
+
+
+#### EOF #######################################################################

File colormap_explorer/plugin/ui_plugin_definition.py

-""" The Colormap Explorer UI plugin.
-"""
-
-
-# Enthought library imports.
-from enthought.envisage.api import PluginDefinition
-
-# Plugin definition imports.
-from enthought.envisage.workbench.workbench_plugin_definition import \
-     Perspective, View, Workbench
-
-
-# The plugin's globally unique identifier (also used as the prefix for all
-# identifiers defined in this module).
-ID = "colormap_explorer.plugin.ui"
-
-
-###############################################################################
-# The plugin definition!
-###############################################################################
-
-class ColormapExplorerUIPluginDefinition(PluginDefinition):
-    # The plugin's globally unique identifier.
-    id = ID
-
-    # The name of the class that implements the plugin.
-    class_name = "colormap_explorer.plugin.ui_plugin_implementation.ColormapExplorerUIPlugin"
-
-    # General information about the plugin.
-    name          = "Colormap Explorer UI"
-    version       = "1.0.0"
-    provider_name = "Enthought Inc"
-    provider_url  = "www.enthought.com"
-    enabled       = True
-    autostart     = True
-    
-    # The Id's of the plugins that this plugin requires.
-    requires = [
-        "enthought.envisage.workbench",
-        "colormap_explorer.plugin.model",
-    ]
-
-    # The extension points offered by this plugin.
-    extension_points = []
-    
-    # The contributions that this plugin makes to extension points offered by
-    # either itself or other plugins.
-    extensions = [
-        Workbench(
-            views = [
-                View(
-                    id       = "colormap_explorer.plugin.views.SceneView",
-                    class_name = "colormap_explorer.plugin.views.SceneView",
-                    name     = "Colormap in 3D",
-                    image    = "images/python_view.png",
-                    position = "right",
-                ),
-                View(
-                    id       = "colormap_explorer.plugin.views.PipelineView",
-                    class_name = "colormap_explorer.plugin.views.PipelineView",
-                    name     = "Colorspaces",
-                    image    = "images/python_view.png",
-                    position = "bottom",
-                ),
-                View(
-                    id       = "colormap_explorer.plugin.views.CmapImage",
-                    class_name = "colormap_explorer.plugin.views.CmapImage",
-                    name     = "Image",
-                    image    = "images/python_view.png",
-                    position = "right",
-                ),
-                View(
-                    id       = "colormap_explorer.plugin.views.ColormapDBView",
-                    class_name = "colormap_explorer.plugin.views.ColormapDBView",
-                    name     = "Colormaps",
-                    image    = "images/python_view.png",
-                    position = "left",
-                ),
-            ],
-
-            perspectives = [
-                Perspective(
-                    id = 'colormap_explorer.scene_perspective',
-                    name = '3D Colormap Viewer',
-                    show_editor_area = False,
-                    contents = [
-                        Perspective.Item(
-                            id="colormap_explorer.plugin.views.SceneView",
-                            position="right",
-                            width=0.8,
-                            height=1.0,
-                        ),
-                        Perspective.Item(
-                            id="colormap_explorer.plugin.views.PipelineView",
-                            position="bottom",
-                            height=0.2,
-                        ),
-                        Perspective.Item(
-                            id="colormap_explorer.plugin.views.ColormapDBView",
-                            position="left",
-                            width=0.2,
-                            height=0.8,
-                        ),
-                    ],
-                ),
-                Perspective(
-                    id = 'colormap_explorer.image_perspective',
-                    name = 'Colormapped Image',
-                    show_editor_area = False,
-                    contents = [
-                        Perspective.Item(
-                            id="colormap_explorer.plugin.views.CmapImage",
-                            position="right",
-                            width=0.8,
-                            height=1.0,
-                        ),
-                        Perspective.Item(
-                            id="colormap_explorer.plugin.views.PipelineView",
-                            position="bottom",
-                            height=0.2,
-                        ),
-                        Perspective.Item(
-                            id="colormap_explorer.plugin.views.ColormapDBView",
-                            position="left",
-                            width=0.2,
-                            height=0.8,
-                        ),
-                    ],
-                ),
-            ],
-
-            default_perspective = 'colormap_explorer.scene_perspective',
-        ),
-    ]
-
-#### EOF #######################################################################

File colormap_explorer/plugin/ui_plugin_implementation.py

-""" The implementation of the Colormap Explorer UI plugin.
-"""
-
-# Enthought library imports
-from enthought.envisage.core.plugin import Plugin
-
-
-class ColormapExplorerUIPlugin(Plugin):
-    """ The implementation of the Colormap Explorer UI plugin.
-
-    Nothing to do here, really.
-    """
-
-    pass
-
-### EOF ######################################################################
-

File colormap_explorer/plugin/views.py

View file
 # Enthought library imports.
 from enthought.chaco2.chaco2_plot_container_editor import PlotContainerEditor
 from enthought.chaco2.api import ArrayPlotData, DataRange1D, Plot, gray
-from enthought.envisage.workbench.api import TraitsUIView
+from enthought.pyface.workbench.api import TraitsUIView
+from enthought.pyface.api import ImageResource
 from enthought.traits.api import Any, Bool, Instance, Property, Str
 from enthought.traits.ui import api as tui
 from enthought.traits.ui import menu
 
 # Local imports.
 from colormap_explorer.pipelined_color_mapper import PipelinedColorMapper
-from colormap_explorer.plugin.services import ICMAP_EXPLORER_MODEL
 
+UI_ID = "colormap_explorer.plugin.ui"
+ICMAP_EXPLORER_MODEL = 'colormap_explorer.plugin.model.ModelService'
 
 
 class CmapImage(TraitsUIView):
     """ Color-mapped image using the current pipeline and colormap.
     """
 
+    id = UI_ID + '.CmapImage'
+    name = 'Image'
+    image = ImageResource('images/python_view.png')
+    position = 'right'
+
     # The various images one could display. They should be (m, n) float arrays.
     data = Instance(ArrayPlotData, ())
 
     """ View for a colorspace pipeline.
     """
 
-    #### Public 'TraitsUIView' interface #######################################
+    id       = UI_ID + ".PipelineView"
+    name     = "Colorspaces"
+    image    = ImageResource("images/python_view.png")
+    position = "bottom"
+
 
     def create_ui(self, parent):
         """ Creates the traits UI that represents the view.
             kind='subpanel')
 
 
+
 class SceneView(TraitsUIView):
     """ A Workbench View for the colorspace scene.
     """
 
-    #### Public 'TraitsUIView' interface #######################################
+    id       = UI_ID + ".SceneView"
+    name     = "Colormap in 3D"
+    image    = ImageResource("images/python_view.png")
+    position = "right"
+
 
     def create_ui(self, parent):
         """ Creates the traits UI that represents the view.
     """ A Workbench View for the colormap database.
     """
 
-    #### Public 'TraitsUIView' interface #######################################
+    id       = UI_ID + ".ColormapDBView"
+    name     = "Colormaps"
+    image    = ImageResource("images/python_view.png")
+    position = "left"
+
 
     def create_ui(self, parent):
         """ Creates the traits UI that represents the view.