Debian Codegraph @

docs/source/traitsui_user_manual/examples/handler_override.py

raw
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 # handler_override.py -- Example of a Handler that overrides setattr(), and
12 # that has a user interface notification method
13
14 from traits.api import Bool, HasTraits
15 from traitsui.api import Handler, View
16
17
18 class TC_Handler(Handler):
19 def setattr(self, info, object, name, value):
20 Handler.setattr(self, info, object, name, value)
21 info.object._updated = True
22
23 def object__updated_changed(self, info):
24 if info.initialized:
25 info.ui.title += "*"
26
27
28 class TestClass(HasTraits):
29 b1 = Bool()
30 b2 = Bool()
31 b3 = Bool()
32 _updated = Bool(False)
33
34
35 view1 = View(
36 'b1',
37 'b2',
38 'b3',
39 title="Alter Title",
40 handler=TC_Handler(),
41 buttons=['OK', 'Cancel'],
42 )
43
44 tc = TestClass()
45 tc.configure_traits(view=view1)