1
# Copyright (c) 2007, Enthought, Inc.
5
A demonstration of how the TabularEditor can be used to display (large) NumPy
6
arrays, in this case 100,000 random 3D points from a unit cube.
8
In addition to showing the coordinates of each point, it also displays the
9
index of each point in the array, as well as a red flag if the point lies within
10
0.25 of the center of the cube.
13
#-- Imports --------------------------------------------------------------------
22
import HasTraits, Property, Array, Font
25
import View, Item, TabularEditor
27
from traitsui.tabular_adapter \
30
#-- Tabular Adapter Definition -------------------------------------------------
32
class ArrayAdapter ( TabularAdapter ):
34
columns = [ ( 'i', 'index' ), ( 'x', 0 ), ( 'y', 1 ), ( 'z', 2 ) ]
36
font = Font('Courier 10')
40
index_image = Property
42
def _get_index_text ( self ):
43
return str( self.row )
45
def _get_index_image ( self ):
47
if sqrt( (x - 0.5) ** 2 + (y - 0.5) ** 2 + (z - 0.5) ** 2 ) <= 0.25:
48
return '@icons:red_ball'
52
#-- ShowArray Class Definition -------------------------------------------------
54
class ShowArray ( HasTraits ):
62
editor = TabularEditor( adapter = ArrayAdapter() )
64
title = 'Array Viewer',
71
demo = ShowArray( data = random( ( 100000, 3 ) ) )
73
# Run the demo (if invoked from the command line):
74
if __name__ == '__main__':
75
demo.configure_traits()