Commits

Robert Kern  committed 06b0596

Fixes and suchlike.

  • Participants
  • Parent commits ad5e06e

Comments (0)

Files changed (7)

 
 # Enthought library imports.
 from enthought.envisage.ui.workbench.api import WorkbenchApplication
+from enthought.envisage.api import Plugin
+from enthought.traits.api import List
+
+
+class AppPlugin(Plugin):
+    """ Make extension point contributions to configure the application.
+    """
+    id = 'colormap_explorer.app'
+
+    COLORMAPS = 'colormap_explorer.plugin.model_service.colormaps'
+    VISION_MODELS = 'colormap_explorer.plugin.model_service.vision_models'
+    IMAGE_DATA = 'colormap_explorer.plugin.model_service.image_data'
+
+    colormaps = List(contributes_to=COLORMAPS)
+    vision_models = List(contributes_to=VISION_MODELS)
+    image_data = List(contributes_to=IMAGE_DATA)
+
+    def _colormaps_default(self):
+        from colormap_explorer.colormap_db import (load_chaco_colormaps,
+            load_matplotlib_colormaps, load_colorbrewer_colormaps,
+            load_monochrome_colormaps)
+        colormaps = (list(load_chaco_colormaps()) +
+            list(load_colorbrewer_colormaps()) +
+            list(load_matplotlib_colormaps()) +
+            list(load_monochrome_colormaps()))
+        return colormaps
+
+    def _vision_models_default(self):
+        from colormap_explorer.vision_model import colorblind_models
+        return colorblind_models
+
+    def _image_data_default(self):
+        from colormap_explorer.example_images import all_images
+        return list(all_images())
 
 
 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
+    #from enthought.plugins.python_shell.python_shell_plugin import PythonShellPlugin
+    from colormap_explorer.plugin.model_plugin import ColormapExplorerModelPlugin
+    from colormap_explorer.plugin.ui_plugin import ColormapExplorerUIPlugin
 
     plugins = [
         CorePlugin(),
         WorkbenchPlugin(),
         LoggerPlugin(),
-        PythonShellPlugin(),
+        #PythonShellPlugin(),
         ColormapExplorerModelPlugin(),
         ColormapExplorerUIPlugin(),
+        AppPlugin(),
     ]
     return plugins
 
 
     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'))
+    ETSConfig.application_data = ETSConfig.application_home
+    if not os.path.exists(ETSConfig.application_home):
+        os.makedirs(ETSConfig.application_home)
+    logging.basicConfig(
+        stream=sys.stderr,
+        #filename=os.path.join(ETSConfig.application_home,'explorer.log'),
+        level=logging.INFO,
+    )
 
     # Create the application.
     application = WorkbenchApplication(

File colormap_explorer/colorspace_pipeline.py

         self.refresh_event = self
 
 
-class ColorspacePipelineHandler(tui.Handler):
+class ColorspacePipelineHandler(tui.Controller):
     """ Traits UI Handler for views of ColorspacePipelines.
 
     The selections for the EnumEditors are initialized in this object. In order
-    to use this handler for ColorspacePipeline objects, use its edit_traits()
-    method like so:
-
-        handler = ColorspacePipelineHandler(...)
-        handler.edit_traits(context=dict(object=pipeline))
+    to use this handler for ColorspacePipeline objects, assign the
+    ColorspacePipeline to the .model trait.
     """
 
     input_colorspaces = List(Instance(Colorspace))
     traits_view = tui.View(
         tui.VGroup(
             tui.Item('input_colorspace', 
-                editor=tui.EnumEditor(object='handler', name='input_colorspaces')),
+                editor=tui.EnumEditor(name='controller.input_colorspaces')),
             tui.Item('output_colorspace', 
-                editor=tui.EnumEditor(object='handler', name='output_colorspaces')),
+                editor=tui.EnumEditor(name='controller.output_colorspaces')),
             tui.HGroup(
                 tui.Item('do_soft_proof', label='Do soft proofing'),
                 tui.Item('proofing_colorspace', 
-                    editor=tui.EnumEditor(object='handler', name='proofing_colorspaces'), 
+                    editor=tui.EnumEditor(name='controller.proofing_colorspaces'), 
                     enabled_when='do_soft_proof', show_label=False),
             ),
             tui.Item('coordinate_colorspace', 
-                editor=tui.EnumEditor(object='handler', name='coordinate_colorspaces')),
+                editor=tui.EnumEditor(name='controller.coordinate_colorspaces')),
             tui.Item('vision_model', 
-                editor=tui.EnumEditor(object='handler', name='vision_models')),
+                editor=tui.EnumEditor(name='controller.vision_models')),
         ),
 
         buttons=['Undo', 'Revert', 'OK'],
     )
 
 
-    #### Public 'ColorspacePipelineHandler' interface ##########################
-
-    def __call__(self, pipeline, **kwds):
-        """ Return the UI for a ColorspacePipeline using this handler.
-
-        This just calls .edit_traits() conveniently.
-
-        Parameters
-        ----------
-        pipeline : ColorspacePipeline
-        **kwds
-            Any extra arguments to pass to .edit_traits().
-        """
-
-        return self.edit_traits(context=dict(object=pipeline), **kwds)
-
-
     #### Private 'ColorspacePipelineHandler' interface #########################
 
     def _get_output_colorspaces(self):

File colormap_explorer/pipelined_color_mapper.py

     #### Private 'ColorMapper' interface #######################################
 
     def __init__(self, **kwtraits):
-        # ColorMapper.__init__() since we don't want to use a segment map.
+        # Avoid ColorMapper.__init__() since we don't want to use a segment map.
         AbstractColormap.__init__(self, **kwtraits)
  
 
         self._red_lut = transformed_colors[:,0]
         self._green_lut = transformed_colors[:,1]
         self._blue_lut = transformed_colors[:,2]
+        self._alpha_lut = np.ones_like(self._red_lut)
 
         self._dirty = False
 

File colormap_explorer/plugin/model_plugin.py

 
 # Enthought library imports
 from enthought.envisage.api import ExtensionPoint, Plugin
-from enthought.traits.api import Any, Array, Callable, List, Str
+from enthought.traits.api import Any, Array, Callable, List, Str, Tuple
 
 # Local imports.
 from colormap_explorer.colorspace import sRGB, Lab, Luv, XYZ
 
 # The plugin's globally unique identifier (also used as the prefix for all
 # identifiers defined in this module).
-ID = "colormap_explorer.plugin.model"
+ID = "colormap_explorer.plugin.model_service"
 ICMAP_EXPLORER_MODEL = ID + '.ModelService'
 
 class ColormapExplorerModelPlugin(Plugin):
 
     COLORMAPS = ID + '.colormaps'
     colormaps = ExtensionPoint(
-        List(Callable), id=COLORMAPS, desc="""
-        Generators yielding colormaps.
+        List(Any), id=COLORMAPS, desc="""
+        Colormaps.
         """,
     )
 
 
     IMAGE_DATA = ID + '.image_data'
     image_data = ExtensionPoint(
-        List(Str, Array), id=IMAGE_DATA, desc="""
+        List(Tuple(Str, Array)), id=IMAGE_DATA, desc="""
         Pairs of titles and image data to plot with the colormaps.
         """,
     )
             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)
+        for cmap in self.colormaps:
+            model.colormaps.add_colormap(cmap)
         model.colormaps_handler.on_trait_change(
             lambda x: model.set(selected_colormap=x),
             'selected_colormap')

File colormap_explorer/plugin/model_service.py

 
     # The colorspace pipeline.
     pipeline = Instance(ColorspacePipeline, ())
-    pipeline_handler = Instance(ColorspacePipelineHandler, ())
+    pipeline_handler = Instance(ColorspacePipelineHandler)
 
     # Arrays for plotting image data.
     image_data = Dict(Str, Any)
     def _scene_default(self):
         return ColorspaceScene(colorspace_pipeline=self.pipeline)
 
+    def _pipeline_handler_default(self):
+        return ColorspacePipelineHandler(model=self.pipeline)
 
     def _selected_colormap_changed(self, old, new):
         """ Trigger any changes that are necessary for the new colormap.

File colormap_explorer/plugin/ui_plugin.py

 
 # The plugin's globally unique identifier (also used as the prefix for all
 # identifiers defined in this module).
-ID = "colormap_explorer.plugin.ui"
+ID = "colormap_explorer.plugin.ui_plugin"
+VIEW_ID = "colormap_explorer.plugin.views"
 
 
 class ScenePerspective(Perspective):
-    id = ID + '.scene_perspective'
+    id = ID + '.ScenePerspective'
     name = '3D Colormap Viewer'
     show_editor_area = False
     contents = [
         PerspectiveItem(
-            id=ID+".SceneView",
+            id=VIEW_ID+".SceneView",
             position="right",
             width=0.8,
             height=1.0,
         ),
         PerspectiveItem(
-            id=ID+".PipelineView",
+            id=VIEW_ID+".PipelineView",
             position="bottom",
             height=0.2,
         ),
         PerspectiveItem(
-            id=ID+".ColormapDBView",
+            id=VIEW_ID+".ColormapDBView",
             position="left",
             width=0.2,
             height=0.8,
 
 
 class ImagePerspective(Perspective):
-    id = ID + '.image_perspective'
+    id = ID + '.ImagePerspective'
     name = 'Colormapped Image'
     show_editor_area = False
     contents = [
         PerspectiveItem(
-            id=ID+".CmapImage",
+            id=VIEW_ID+".CmapImage",
             position="right",
             width=0.8,
             height=1.0,
         ),
         PerspectiveItem(
-            id=ID+".PipelineView",
+            id=VIEW_ID+".PipelineView",
             position="bottom",
             height=0.2,
         ),
         PerspectiveItem(
-            id=ID+".ColormapDBView",
+            id=VIEW_ID+".ColormapDBView",
             position="left",
             width=0.2,
             height=0.8,

File colormap_explorer/plugin/views.py

 # Local imports.
 from colormap_explorer.pipelined_color_mapper import PipelinedColorMapper
 
-UI_ID = "colormap_explorer.plugin.ui"
-ICMAP_EXPLORER_MODEL = 'colormap_explorer.plugin.model.ModelService'
+UI_ID = "colormap_explorer.plugin.views"
+ICMAP_EXPLORER_MODEL = 'colormap_explorer.plugin.model_service.ModelService'
 
 
 class CmapImage(TraitsUIView):
         # Listen to the model service for changes in the colormap selection and
         # to get the pipeline object.
         self._setup_notifications()
-        model = self.application.get_service(ICMAP_EXPLORER_MODEL)
+        model = self.window.application.get_service(ICMAP_EXPLORER_MODEL)
         self.pipeline = model.pipeline
     
         # Grab any configured data for plotting.
             biggest = max(abs(range.low), abs(range.high))
             range = DataRange1D(low=-biggest, high=biggest)
 
-        model = self.application.get_service(ICMAP_EXPLORER_MODEL)
+        model = self.window.application.get_service(ICMAP_EXPLORER_MODEL)
         underlying = model.selected_colormap
         if underlying is None:
             return gray(range)
 
         # Listen to the model service for changes in the colormap selection and
         # to get the pipeline object.
-        model = self.application.get_service(ICMAP_EXPLORER_MODEL)
+        model = self.window.application.get_service(ICMAP_EXPLORER_MODEL)
         model.on_trait_change(self.refresh_plot, 'selected_colormap',
             remove=remove)
         model.pipeline.on_trait_change(self.refresh_plot, 'refresh_event',
         """ Creates the traits UI that represents the view.
         """
 
-        model = self.application.get_service(ICMAP_EXPLORER_MODEL)
+        model = self.window.application.get_service(ICMAP_EXPLORER_MODEL)
  
-        return model.pipeline_handler(model.pipeline, parent=parent,
+        return model.pipeline_handler.edit_traits(parent=parent,
             kind='subpanel')
 
 
-
 class SceneView(TraitsUIView):
     """ A Workbench View for the colorspace scene.
     """
         """ Creates the traits UI that represents the view.
         """
 
-        model = self.application.get_service(ICMAP_EXPLORER_MODEL)
+        model = self.window.application.get_service(ICMAP_EXPLORER_MODEL)
  
         return model.scene.edit_traits(parent=parent, kind='subpanel')
 
         """ Creates the traits UI that represents the view.
         """
 
-        model = self.application.get_service(ICMAP_EXPLORER_MODEL)
+        model = self.window.application.get_service(ICMAP_EXPLORER_MODEL)
  
         return model.colormaps_handler(model.colormaps, parent=parent,
             kind='subpanel')