File: dock_item_alerts.enaml

package info (click to toggle)
python-enaml 0.19.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,284 kB
  • sloc: python: 31,443; cpp: 4,499; makefile: 140; javascript: 68; lisp: 53; sh: 20
file content (176 lines) | stat: -rw-r--r-- 5,359 bytes parent folder | download
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#------------------------------------------------------------------------------
#  Copyright (c) 2013-2025, Nucleic Development Team
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file LICENSE, distributed with this software.
#------------------------------------------------------------------------------
""" This example demonstrates the use of alerts on the DockItem widget.

The DockItem widget and related bits in the DockArea support a style
sheet pseudo-class named 'alert'. This pseudo-class is very powerful in
that it allows the developer to provide their own arbitrary token to the
pseudo-class as an argument, and then apply that token to a dock item at
runtime. This gives the developer complete freedom over the how they style
their alerts, and does not force them in to a pre-defined hierarchy of
alert levels.

<< autodoc-me >>
"""
from enaml.layout.api import (
    HSplitLayout, VSplitLayout, TabLayout, hbox, vbox, spacer
)
from enaml.styling import StyleSheet
from enaml.stdlib.dock_area_styles import (
    VS2010Style, TitleBarStyle, DockBarButtonStyle, ContainerStyle,
    ItemStyle, TabBarTabStyle, TitleBarLabelStyle
)
from enaml.widgets.api import (
    Window, Container, DockArea, DockItem, Html, Field, PushButton
)


HTML = """
<h3><center>
Drag the dock items to different locations to and then trigger an alert.
</center></h3>
"""

MELTDOWN_HTML = """
<h1><center>Everything is NOT okay!</center></h1>
"""

enamldef MyAlertStyleSheet(StyleSheet):

    # Include the base VS 2010 styling rules
    VS2010Style():
        pass

    # Add alert styles for an "important" alert.
    TitleBarStyle:
        pseudo_class = 'alert(important)'
        background = 'orange'

    TitleBarLabelStyle:
        pseudo_class = 'alert(important)'
        color = 'black'

    DockBarButtonStyle:
        pseudo_class = 'alert(important)'
        background = 'orange'

    TabBarTabStyle:
        pseudo_class = 'alert(important)'
        background = 'orange'


    # Add alert styles for an "information" alert.
    TitleBarStyle:
        pseudo_class = 'alert(information)'
        background = 'olivedrab'

    DockBarButtonStyle:
        pseudo_class = 'alert(information)'
        background = 'olivedrab'

    TabBarTabStyle:
        pseudo_class = 'alert(information)'
        background = 'olivedrab'


    # Add alert styles for a "meltdown" alert.
    TitleBarStyle:
        pseudo_class = 'alert(meltdown)'
        background = 'red'

    DockBarButtonStyle:
        pseudo_class = 'alert(meltdown)'
        background = 'red'

    TabBarTabStyle:
        pseudo_class = 'alert(meltdown)'
        background = 'red'

    ContainerStyle:
        pseudo_class = 'alert(meltdown)'
        background = 'yellow'

    ItemStyle:
        pseudo_class = 'alert(meltdown)'
        background = 'red'


enamldef DummyItem(DockItem):
    title = ' '.join(s.capitalize() for s in name.split('_'))
    Container:
        Field: pass
        Field: pass
        Field: pass
        Field: pass


enamldef Main(Window):
    title = 'Dock Item Alerts'
    MyAlertStyleSheet:
        pass
    Container:
        padding = 0
        DockArea:
            # A custom style sheet is being used, so the default style
            # sheet must be disabled - IMPORTANT!
            style = ''
            layout = HSplitLayout(
                VSplitLayout('controls', 'information'),
                VSplitLayout('important', 'meltdown'),
                TabLayout('dummy_1', 'dummy_2', 'dummy_3', 'dummy_4'),
            )
            DockItem:
                title = 'Controls'
                name = 'controls'
                stretch = 0
                Container:
                    PushButton:
                        text = 'Information'
                        clicked ::
                            info_item.alert('information')
                    PushButton:
                        text = 'Important'
                        clicked ::
                            important_item.alert('important', persist=True)
                    PushButton:
                        text = 'Meltdown'
                        clicked ::
                            meltdown_item.alert(
                                'meltdown', on=60, off=60, repeat=100
                            )
            DockItem: info_item:
                title = 'Information'
                name = 'information'
                stretch = 0
                Container:
                    Field:
                        placeholder = 'just'
                    Field:
                        placeholder = 'some'
                    Field:
                        placeholder = 'information'
            DockItem: important_item:
                title = 'Important Data'
                name = 'important'
                Container:
                    Html:
                        source = HTML
            DockItem: meltdown_item:
                title = 'Meltdown'
                name = 'meltdown'
                Container:
                    Html:
                        source = MELTDOWN_HTML
            DummyItem:
                name = 'dummy_1'
            DummyItem:
                name = 'dummy_2'
            DummyItem:
                name = 'dummy_3'
            DummyItem:
                name = 'dummy_4'