source: cows/trunk/cows/service/imps/data_reader_geoplot_backend/slab_options_parser.py @ 5692

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/cows/trunk/cows/service/imps/data_reader_geoplot_backend/slab_options_parser.py@5692
Revision 5692, 1.5 KB checked in by pnorton, 11 years ago (diff)

Made some modifications to the data renderer backend. The display options are now attached to each of the slabs rather than being stored in the shared option parser and the controller.

I've also added some code to generate the display options JSON string.

RevLine 
[5692]1import logging
2import mock
3
4from matplotlib import cm
5from cows.service.imps.csmlbackend.config import config
6
7log = logging.getLogger(__name__)
8
9class SlabOptionsParser(object):
10   
11    def __init__(self, slabOptions, renderOptions):
12       
13        self._slabOptionsLookup = {}
14        for option in slabOptions:
15            self._slabOptionsLookup[option.name] = option
16       
17        self._renderOptions = renderOptions
18       
19    def getOption(self, optionName):
20        return self._getOption(optionName)
21   
22    def _getOption(self, optionName):
23       
24       
25        if optionName not in self._slabOptionsLookup:
26            log.warning("Unknown option %s received, returning None")
27            return None
28       
29        value = None;
30        if optionName in self._renderOptions:
31            value = self._getOptionFromDict(optionName)
32       
33        if value == None:
34            value = self._getDefaultForOption(optionName)
35       
36        return value
37   
38    def _getOptionFromDict(self, optionName):
39       
40        value = None
41       
42        try:
43            stringValue = self._renderOptions[optionName]
44            type = self._slabOptionsLookup[optionName].type
45           
46            value = type(stringValue)
47        except:
48            log.exception("Error getting option %s from renderOptions=%s" % (optionName, self._renderOptions))
49            value = None
50           
51        return value
52
53    def _getDefaultForOption(self, optionName):
54        return self._slabOptionsLookup[optionName].default
55       
Note: See TracBrowser for help on using the repository browser.