| 1 |
# (C) Copyright 2004-2023 Enthought, Inc., Austin, TX |
| 2 |
# All rights reserved. |
| 3 |
# |
| 4 |
# This software is provided without warranty under the terms of the BSD |
| 5 |
# license included in LICENSE.txt and may be redistributed only under |
| 6 |
# the conditions described in the aforementioned license. The license |
| 7 |
# is also available online at http://www.enthought.com/licenses/BSD.txt |
| 8 |
# |
| 9 |
# Thanks for using Enthought open source! |
| 10 |
|
| 11 |
# ------------------------------------------------------------------------- |
| 12 |
# Imports: |
| 13 |
# ------------------------------------------------------------------------- |
| 14 |
|
| 15 |
import wx |
| 16 |
|
| 17 |
from traits.api import Trait, HasTraits, Str, Int |
| 18 |
from traitsui.api import Color, View, Group |
| 19 |
|
| 20 |
# ------------------------------------------------------------------------- |
| 21 |
# Model classes: |
| 22 |
# ------------------------------------------------------------------------- |
| 23 |
|
| 24 |
|
| 25 |
class Employer(HasTraits): |
| 26 |
company = Str('Enthought, Inc.') |
| 27 |
boss = Str('eric') |
| 28 |
|
| 29 |
view = View('company', 'boss') |
| 30 |
|
| 31 |
|
| 32 |
class Person(HasTraits): |
| 33 |
name = Str('David Morrill') |
| 34 |
age = Int(39) |
| 35 |
|
| 36 |
|
| 37 |
class ExtraPerson(Person): |
| 38 |
sex = Trait('Male', 'Female') |
| 39 |
eye_color = Color |
| 40 |
|
| 41 |
|
| 42 |
class LocatedPerson(Person): |
| 43 |
street = Str() |
| 44 |
city = Str() |
| 45 |
state = Str() |
| 46 |
zip = Int(78663) |
| 47 |
|
| 48 |
|
| 49 |
class EmployedPerson(LocatedPerson): |
| 50 |
employer = Trait(Employer()) |
| 51 |
|
| 52 |
|
| 53 |
# ------------------------------------------------------------------------- |
| 54 |
# View classes: |
| 55 |
# ------------------------------------------------------------------------- |
| 56 |
|
| 57 |
|
| 58 |
class PersonView(HasTraits): |
| 59 |
view = View('name', '<extra>', 'age', kind='modal') |
| 60 |
|
| 61 |
|
| 62 |
class ExtraPersonView(PersonView): |
| 63 |
extra = Group('sex', 'eye_color') |
| 64 |
|
| 65 |
|
| 66 |
class LocatedPersonView(PersonView): |
| 67 |
extra = Group('street', 'city', 'state', 'zip') |
| 68 |
|
| 69 |
|
| 70 |
class EmployedPersonView(LocatedPersonView): |
| 71 |
extra = Group('employer', '<extra>') |
| 72 |
|
| 73 |
|
| 74 |
# ------------------------------------------------------------------------- |
| 75 |
# 'TraitSheetApp' class: |
| 76 |
# ------------------------------------------------------------------------- |
| 77 |
|
| 78 |
|
| 79 |
class TraitSheetApp(wx.App): |
| 80 |
|
| 81 |
# ------------------------------------------------------------------------- |
| 82 |
# Initialize the object: |
| 83 |
# ------------------------------------------------------------------------- |
| 84 |
|
| 85 |
def __init__(self): |
| 86 |
wx.InitAllImageHandlers() |
| 87 |
wx.App.__init__(self, 1, 'debug.log') |
| 88 |
self.MainLoop() |
| 89 |
|
| 90 |
# ------------------------------------------------------------------------- |
| 91 |
# Handle application initialization: |
| 92 |
# ------------------------------------------------------------------------- |
| 93 |
|
| 94 |
def OnInit(self): |
| 95 |
PersonView().edit_traits(context=Person()) |
| 96 |
ExtraPersonView().edit_traits(context=ExtraPerson()) |
| 97 |
LocatedPersonView().edit_traits(context=LocatedPerson()) |
| 98 |
EmployedPersonView().edit_traits(context=EmployedPerson()) |
| 99 |
return True |
| 100 |
|
| 101 |
|
| 102 |
# ------------------------------------------------------------------------- |
| 103 |
# Main program: |
| 104 |
# ------------------------------------------------------------------------- |
| 105 |
|
| 106 |
TraitSheetApp() |