Sophie

Sophie

distrib > Fedora > 13 > i386 > by-pkgid > 0abf02bb2abda94c2db99ef2a28c8a2c > files > 789

python-AppTools-3.3.2-1.fc13.noarch.rpm

"""A simple example of an object model."""


# Enthought library imports.
from enthought.permissions.api import SecureHandler
from enthought.traits.api import HasTraits, Int, Unicode
from enthought.traits.ui.api import Item, View

# Local imports.
from permissions import UpdatePersonAgePerm, PersonSalaryPerm


class Person(HasTraits):
    """A simple example of an object model"""

    # Name.
    name = Unicode

    # Age in years.
    age = Int

    # Salary.
    salary = Int

    # Define the default view with permissions attached.
    age_perm = UpdatePersonAgePerm
    salary_perm = PersonSalaryPerm

    traits_view = View(
            Item(name='name'),
            Item(name='age', enabled_when='object.age_perm.granted'),
            Item(name='salary', visible_when='object.salary_perm.granted'),
            handler=SecureHandler)

    ###########################################################################
    # 'object' interface.
    ###########################################################################

    def __str__(self):
        """Return an informal string representation of the object."""

        return self.name

#### EOF ######################################################################