forked from enthought/mayavi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtvtk_base_handler.py
80 lines (61 loc) · 2.56 KB
/
tvtk_base_handler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
""" Handler and UI elements for tvtk objects.
"""
# Author: Vibha Srinivasan <[email protected]>
# Copyright (c) 2008-2020, Enthought, Inc.
# License: BSD Style.
from traits.api import HasTraits, Str, Instance, Property, Button, List, Enum
from traitsui.handler import Handler
from traitsui.ui_info import UIInfo
from traitsui.item import Item
from traitsui.view import View
from traits.trait_base import user_name_for, xgetattr
def TableEditor(*args, **kw):
from .value_column import ObjectColumn, ValueColumn
from traitsui.api import TableEditor as _E
return _E(columns=[ObjectColumn(name='name'), ValueColumn(name='value')])
class TraitsViewObject(HasTraits):
""" Wrapper for all items to be included in the full traits view of the TVTKBase
object.
"""
# Trait name (name of the trait that is to be included in the view).
name = Str
# The TVTKBase object for which we are building a view.
parent = Instance(HasTraits)
class TVTKBaseHandler(Handler):
""" A handler for the TVTKBase object.
"""
# A reference to the UIInfo object.
info = Instance(UIInfo)
# Type of view (of info.object) to display.
view_type = Enum(['Basic', 'Advanced'])
# The view for the object (that is, info.object)
view = Property(depends_on='view_type')
# List of TraitsViewObject items, where each item contains information
# about the trait to display as a row in a table editor.
_full_traits_list = Property(List, editor=TableEditor)
def init_info(self, info):
""" Informs the handler what the UIInfo object for a View will be.
Overridden here to save a reference to the info object.
"""
self.info = info
return
def _get__full_traits_list(self):
""" Returns a list of objects to be included in the table editor for
the full traits view.
"""
return [TraitsViewObject(name=name, parent = self.info.object)
for name in self.info.object._full_traitnames_list_]
def _get_view(self):
""" Returns the view (for info.object) to be displayed in the
InstanceEditor.
"""
if self.view_type == "Basic":
view = self.info.object.trait_view('view')
else:
view = self.info.object.trait_view('full_traits_view')
# This method is called when the default traits view for the object is
# displayed. The default traits view already has a title, so do not
# display a title for the contained view.
view.title = ''
return view
#### EOF ###################################################################