| 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 |
# multi_object_view.py -- Sample code to show multi-object view with context |
| 12 |
|
| 13 |
from traits.api import Bool, HasTraits, Int, Str |
| 14 |
from traitsui.api import Group, Item, View |
| 15 |
|
| 16 |
|
| 17 |
class House(HasTraits): |
| 18 |
address = Str() |
| 19 |
bedrooms = Int() |
| 20 |
pool = Bool() |
| 21 |
price = Int() |
| 22 |
|
| 23 |
|
| 24 |
# View object designed to display two objects of class 'House' |
| 25 |
comp_view = View( |
| 26 |
Group( |
| 27 |
Group( |
| 28 |
Item('h1.address', resizable=True), |
| 29 |
Item('h1.bedrooms'), |
| 30 |
Item('h1.pool'), |
| 31 |
Item('h1.price'), |
| 32 |
show_border=True, |
| 33 |
), |
| 34 |
Group( |
| 35 |
Item('h2.address', resizable=True), |
| 36 |
Item('h2.bedrooms'), |
| 37 |
Item('h2.pool'), |
| 38 |
Item('h2.price'), |
| 39 |
show_border=True, |
| 40 |
), |
| 41 |
orientation='horizontal', |
| 42 |
), |
| 43 |
title='House Comparison', |
| 44 |
) |
| 45 |
|
| 46 |
# A pair of houses to demonstrate the View |
| 47 |
house1 = House( |
| 48 |
address='4743 Dudley Lane', |
| 49 |
bedrooms=3, |
| 50 |
pool=False, |
| 51 |
price=150000, |
| 52 |
) |
| 53 |
house2 = House( |
| 54 |
address='11604 Autumn Ridge', |
| 55 |
bedrooms=3, |
| 56 |
pool=True, |
| 57 |
price=200000, |
| 58 |
) |
| 59 |
|
| 60 |
# ...And the actual display command |
| 61 |
house1.configure_traits(view=comp_view, context={'h1': house1, 'h2': house2}) |