Package Pmv :: Module colorPalette
[hide private]
[frames] | no frames]

Source Code for Module Pmv.colorPalette

  1  ######################################################################## 
  2  # 
  3  # Date: April 2006 Authors: Guillaume Vareille, Michel Sanner 
  4  # 
  5  #    vareille@scripps.edu 
  6  #    sanner@scripps.edu 
  7  # 
  8  #       The Scripps Research Institute (TSRI) 
  9  #       Molecular Graphics Lab 
 10  #       La Jolla, CA 92037, USA 
 11  # 
 12  # Copyright: Guillaume Vareille, Michel Sanner and TSRI 
 13  # 
 14  ######################################################################### 
 15  # 
 16  # $Header$ 
 17  # 
 18  # $Id$ 
 19  # 
 20   
 21   
 22  from DejaVu.colorMap import ColorMap 
 23  from DejaVu.ColormapGui import ColorMapGUI 
24 -class ColorPalette(ColorMapGUI):
25 26 FLOAT = 0 27 INT = 1 28
29 - def __init__(self, name, colorDict={}, readonly=0, colortype=None, 30 info='', sortedkeys=None, lookupMember=None):
31 32 if len(colorDict) > 0: 33 if sortedkeys is None: 34 labels = colorDict.keys() 35 values = colorDict.values() 36 else: 37 labels = sortedkeys 38 values = [] 39 for label in labels: 40 values.append(colorDict[label]) 41 else: 42 labels = None 43 values = None 44 45 46 ColorMapGUI.__init__(self, name=name, ramp=values, labels=labels, show=False, 47 numOfBlockedLabels = len(labels) ) 48 49 self.readonly = readonly 50 self.info = info 51 #self.viewer = None 52 self.sortedkeys = sortedkeys 53 if colortype is None: 54 self.colortype = self.FLOAT 55 self.lookupMember = lookupMember
56 57
58 - def _lookup(self, name):
59 #print "_lookup", name, type(name) 60 try: 61 col = ColorMap._lookup(self, name) 62 if len(col) == 4: 63 return col[:3] 64 else: 65 return col 66 except: 67 return (0., 1., 0.)
68 69
70 - def lookup(self, objects):
71 # Maybe should try that first in case all the objects don't have the 72 # lookup member 73 names = objects.getAll(self.lookupMember) 74 return map( self._lookup, names)
75 76
77 - def display(self,*args, **kw):
78 """ Will create an instance of PaletteChooser later on""" 79 pass
80 81
82 - def undisplay(self, *args, **kw):
83 pass
84 85
86 - def copy(self):
87 """make a deep copy of a palette""" 88 import copy 89 c = copy.copy(self) 90 c.readonly = 0 91 c.ramp = copy.deepcopy(self.ramp) 92 c.labels = copy.deepcopy(self.labels) 93 return c
94 95
96 -class ColorPaletteFunction(ColorPalette):
97
98 - def __init__(self, name, colorDict={}, readonly=0, colortype=None, 99 info='', sortedkeys=None, lookupFunction = None):
100 """ lookupFunction : needs to be function or a lambda function""" 101 ColorPalette.__init__(self, name, colorDict, readonly,colortype, 102 info, sortedkeys) 103 from types import FunctionType 104 if not type(lookupFunction) is FunctionType: 105 self.lookupFunction = None 106 107 self.lookupFunction = lookupFunction
108 109
110 - def lookup(self, objects):
111 # maybe should do that in a try to catch the exception in case it 112 # doesnt work 113 names = map(self.lookupFunction, objects) 114 return map(self._lookup, names)
115