from ..properties.initializer import strong_property_initializer
from ..properties.descriptor import property_descriptor, restricted_property
from ..properties.processors import processor_typecast
from ..properties.restrictions import restrict_type
from ..properties.predefined import RESTRICT_FRACTION, bool_property

__all__ = ["color_property",
           "display_style",
           "display_style_property"]

color_property = property_descriptor

class display_style(strong_property_initializer):
    color = color_property(default = "black")
    transparancy = restricted_property(restriction = RESTRICT_FRACTION, default = 0.0)
    visible = bool_property(default = False)
    
class processor_display_style(processor_typecast):
    def __init__(self):
        processor_typecast.__init__(self, display_style)
    
    def process(self, value, obj= None):
        if value == None:
            return display_style()
        else:
            return processor_typecast.process(self, value, obj)
       

def display_style_property(internal_member_name = None, restriction = None, preprocess = None,**kwargs):
    if kwargs.has_key("default"): default = kwargs["default"]
    else: default = None
    R = restrict_type(display_style) & restriction
    P = processor_display_style() + preprocess
    return restricted_property(internal_member_name, default = default, restriction = R, preprocess = P)


