1# -------------------------------------------------------------------------
2#
3#  Copyright (c) 2007-19, Enthought, Inc.
4#  All rights reserved.
5#
6#  This software is provided without warranty under the terms of the BSD
7#  license included in LICENSE.txt and may be redistributed only
8#  under the conditions described in the aforementioned license.  The license
9#  is also available online at http://www.enthought.com/licenses/BSD.txt
10#
11#  Thanks for using Enthought open source!
12#
13#  Author: David C. Morrill
14#  Date:   07/13/2007
15#
16# -------------------------------------------------------------------------
17
18""" Defines 'theme' related classes.
19"""
20
21from traits.api import HasPrivateTraits, Property, cached_property
22from traits.etsconfig.api import ETSConfig
23
24from .ui_traits import Image, HasBorder, HasMargin, Alignment
25
26
27class Theme(HasPrivateTraits):
28
29    # -- Public Traits --------------------------------------------------------
30
31    #: The background image to use for the theme:
32    image = Image
33
34    #: The border inset:
35    border = HasBorder
36
37    #: The margin to use around the content:
38    content = HasMargin
39
40    #: The margin to use around the label:
41    label = HasMargin
42
43    #: The alignment to use for positioning the label:
44    alignment = Alignment(cols=4)
45
46    #: The color to use for content text (Wx only)
47    content_color = Property()
48
49    #: The color to use for label text (Wx only)
50    label_color = Property()
51
52    #: The image slice used to draw the theme (Wx only)
53    image_slice = Property(depends_on="image")
54
55    # -- Constructor ----------------------------------------------------------
56
57    def __init__(self, image=None, **traits):
58        """ Initializes the object.
59        """
60        if image is not None:
61            self.image = image
62
63        super(Theme, self).__init__(**traits)
64
65    # -- Property Implementations ---------------------------------------------
66
67    def _get_content_color(self):
68        if ETSConfig.toolkit == "wx":
69            import wx
70
71            if self._content_color is None:
72                color = wx.BLACK
73                islice = self.image_slice
74                if islice is not None:
75                    color = islice.content_color
76
77                self._content_color = color
78
79        return self._content_color
80
81    def _set_content_color(self, color):
82        self._content_color = color
83
84    def _get_label_color(self):
85        if ETSConfig.toolkit == "wx":
86            import wx
87
88            if self._label_color is None:
89                color = wx.BLACK
90                islice = self.image_slice
91                if islice is not None:
92                    color = islice.label_color
93
94                self._label_color = color
95
96        return self._label_color
97
98    def _set_label_color(self, color):
99        self._label_color = color
100
101    @cached_property
102    def _get_image_slice(self):
103        if self.image is None:
104            return None
105
106        if ETSConfig.toolkit == "wx":
107            from traitsui.wx.image_slice import image_slice_for
108
109            return image_slice_for(self.image)
110
111
112#: The default theme:
113default_theme = Theme()
114