#
#   Python GUI - Controls - Generic
#

from Properties import overridable_property
from Components import Component

class Control(Component):
    """Abstract base class for components such as buttons, check
    boxes and text entry boxes."""

    title = overridable_property('title', "Title of the control.")
    enabled = overridable_property('enabled', "True if user can manipulate the control.")
    font = overridable_property('font')
    color = overridable_property('color')
    just = overridable_property('just', "Justification ('left', 'center' or 'right').")
    lines = overridable_property('lines',
        "Height of the control measured in lines of the current font.")
    
    _vertical_padding = 0 # Extra height to add when setting 'lines' property
    
    def __init__(self, font = None, lines = None, **kwds):
        Component.__init__(self, **kwds)
        #  If font and lines are both specified, must set font first.
        if font:
            self.font = font
        if lines is not None:
            self.lines = lines
    
    def get_lines(self):
        return (self.height - self._vertical_padding) / self.font.height
    
    def set_lines(self, v):
        self.height = v * self.font.height + self._vertical_padding
    
