File: color.py

package info (click to toggle)
esys-particle 2.3.5%2Bdfsg2-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 13,132 kB
  • sloc: cpp: 81,480; python: 5,872; makefile: 1,259; sh: 313; perl: 225
file content (45 lines) | stat: -rw-r--r-- 1,781 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#############################################################
##                                                         ##
## Copyright (c) 2003-2017 by The University of Queensland ##
## Centre for Geoscience Computing                         ##
## http://earth.uq.edu.au/centre-geoscience-computing      ##
##                                                         ##
## Primary Business: Brisbane, Queensland, Australia       ##
## Licensed under the Open Software License version 3.0    ##
## http://www.apache.org/licenses/LICENSE-2.0              ##
##                                                         ##
#############################################################

from esys.lsm.vis.core.exception import raiseNotImplemented
from esys.lsm.vis                import core
from .modifier                    import Modifier

class RgbColor(core.RgbColor, Modifier):
    """
    Extends L{core.RgbColor} by implementing the L{applyTo} method.
    """
    def applyTo(self, actor):
        actor.GetProperty().SetColor(self.getRgb())

class Colors:
    def __init__(self):
        raiseNotImplemented(
          "This class is not designed for instantiation."
        )

_nameRgbColorDict = dict()

for attribute in dir(core.Colors):
    attr = getattr(core.Colors, attribute)
    if (isinstance(attr, core.RgbColor)):
        setattr(Colors, attribute, RgbColor(attr[0], attr[1], attr[2]))
        _nameRgbColorDict[str.upper(attr.getName())] = getattr(Colors, attribute)

def findColor(colorName):
    """
    Performs a case-insensitive search for a color with name colorName.
    Returns None if no color matching colorName is found.
    """
    if (str.upper(colorName) in _nameRgbColorDict):
        return _nameRgbColorDict[str.upper(colorName)]
    return None