Debian Codegraph @

envisage/ui/action/tool_bar.py

raw
1 # (C) Copyright 2007-2025 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 """ The *definition* of a tool bar. """
11
12 # Enthought library imports.
13 from traits.api import Instance, List, Str
14
15 # Local imports.
16 from .group import Group
17 from .location import Location
18
19
20 # fixme: Remove duplication (in menu.py too!)
21 class CGroup(Instance):
22 """A trait type for a 'Group' or anything that can be cast to a 'Group'.
23
24 Currently, the only cast allowed is from string -> Group using the
25 string as the group's ID.
26
27 """
28
29 ###########################################################################
30 # 'object' interface.
31 ###########################################################################
32
33 def __init__(self, **kw):
34 """Constructor."""
35
36 super().__init__(klass=Group, **kw)
37
38 ###########################################################################
39 # 'TraitType' interface.
40 ###########################################################################
41
42 def validate(self, object, name, value):
43 """Validate a value."""
44
45 if isinstance(value, str):
46 value = Group(id=value)
47
48 return super().validate(object, name, value)
49
50
51 class ToolBar(Location):
52 """The *definition* of a menu in a menu bar or menu."""
53
54 # The tool bars's unique identifier (unique within the multi-toolbar
55 # that the tool bar is to be added to).
56 id = Str
57
58 # The tool bar name (appears when the tool bar is 'undocked').
59 name = Str
60
61 # The groups in the tool bar.
62 groups = List(CGroup)
63
64 # The optional name of a class that implements the tool bar. The class must
65 # support the **pyface.action.ToolBarManager** protocol.
66 class_name = Str
67
68 ###########################################################################
69 # 'object' interface
70 ###########################################################################
71
72 def __str__(self):
73 """Return the 'informal' string representation of the object."""
74
75 return "ToolBar(%s)" % self.name
76
77 __repr__ = __str__
78
79 ###########################################################################
80 # 'Location' interface
81 ###########################################################################
82
83 def _path_default(self):
84 """Trait initializer."""
85
86 return "ToolBar"
87
88 ###########################################################################
89 # 'ToolBar' interface
90 ###########################################################################
91
92 def _id_default(self):
93 """Trait initializer."""
94
95 return self.name