File: task_dialog.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 (209 lines) | stat: -rw-r--r-- 6,968 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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#------------------------------------------------------------------------------
# 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.
#------------------------------------------------------------------------------
from enaml.layout.layout_helpers import align, spacer, vbox, vertical
from enaml.styling import StyleSheet, Style, Setter
from enaml.widgets.container import Container
from enaml.widgets.separator import Separator


enamldef TaskDialogIconArea(Container):
    """ A custom container for use in a task dialog.

    User code can declare and instance of this element in the body of a
    TaskDialogBody in order to provide icon area content.

    """
    #: The default padding is set appropriate for common use cases.
    padding = (10, 0, 15, 10)

    #: The icon area resists clipping by default, since it is typically
    #: taller than the instruction and could otherwise lead to a system
    #: where the the instruction and icon compete to set the min height.
    resist_height = 'strong'

    #: Generate the layout constraints for the icon area. The icon area
    #: gets a default spacer so that it can expand to accomodate larger
    #: content areas.
    layout_constraints => ():
        if self.constraints:
            return self.constraints
        items = self.visible_widgets()
        items.append(spacer(0))
        return [vbox(*items)]


enamldef TaskDialogInstructionArea(Container):
    """ A custom container for use in a task dialog.

    User code can declare and instance of this element in the body of a
    TaskDialogBody in order to provide instruction area content.

    """
    #: The default padding is set appropriate for common use cases.
    padding = (10, 10, 15, 10)


enamldef TaskDialogContentArea(Container):
    """ A custom container for use in a task dialog.

    User code can declare and instance of this element in the body of a
    TaskDialogBody in order to provide content area content.

    """
    #: The default padding is set appropriate for common use cases.
    padding = (0, 10, 15, 10)


enamldef TaskDialogCommandArea(Container):
    """ A custom container for use in a task dialog.

    User code can declare and instance of this element in the body of a
    TaskDialogBody in order to provide command area content.

    """
    pass


enamldef TaskDialogDetailsArea(Container):
    """ A custom container for use in a task dialog.

    User code can declare and instance of this element in the body of a
    TaskDialogBody in order to provide details area content.

    """
    #: The default padding is set appropriate for common use cases.
    padding = (0, 10, 15, 10)

    # XXX ideally, this shouldn't be needed.
    visible :: parent.request_relayout()


enamldef TaskDialogFootnoteArea(Container):
    """ A custom container for use in a task dialog.

    User code can declare and instance of this element in the body of a
    TaskDialogBody in order to provide footnote area content.

    """
    pass


enamldef TaskDialogBody(Container):
    """ A custom container used to create a task dialog body.

    A TaskDialogBody element should be declared as the central widget
    of a Dialog widget. The element layout logic automatically arranges
    the dialog area containers declared as children.

    The dialog body supports the following area children, all of which
    are optional. User code should declare at most one of each type
    of child:

    - TaskDialogIconArea
    - TaskDialogInstructionArea
    - TaskDialogContentArea
    - TaskDialogDetailsArea
    - TaskDialogCommandArea
    - TaskDialogFootnoteArea

    No other widget types should be used as children of the dialog body.

    """
    #: The dialog body has no padding by default.
    padding = 0

    #: The dialog footnote separator. This is only made visible when
    #: using a dialog footnote area.
    Separator: separator:
        visible = False

    #: Generate the layout constraints for the dialog body. This method
    #: will setup a layout which is appropriate for the task dialog area
    #: children defined for the dialog body. The 'constraints' attribute
    #: is ignored entirely.
    layout_constraints => ():
        icon = inst = ctnt = dtls = cmnd = ftnt = None
        for item in self.visible_widgets():
            if isinstance(item, TaskDialogIconArea):
                icon = item
            elif isinstance(item, TaskDialogInstructionArea):
                inst = item
            elif isinstance(item, TaskDialogContentArea):
                ctnt = item
            elif isinstance(item, TaskDialogCommandArea):
                cmnd = item
            elif isinstance(item, TaskDialogDetailsArea):
                dtls = item
            elif isinstance(item, TaskDialogFootnoteArea):
                ftnt = item

        if ftnt is not None:
            separator.visible = True
            sepr = separator
        else:
            separator.visible = False
            sepr = None

        t = self.contents_top
        r = self.contents_right
        b = self.contents_bottom
        l = self.contents_left
        cns = [
            vertical(t, inst, ctnt, dtls, cmnd, sepr, ftnt, b, spacing=0),
            align('right', r, inst, ctnt, dtls, cmnd, sepr, ftnt),
            align('left', l, cmnd, sepr, ftnt),
            align('left', inst, ctnt, dtls),
        ]

        if icon is None:
            cns.append(align('left', l, inst or ctnt or dtls))
        else:
            cns.extend([
                vertical(t, icon, cmnd, spacing=0),
                align('left', l, icon),
                align('left', icon.right, inst or ctnt or dtls),
            ])

        return cns


enamldef TaskDialogStyleSheet(StyleSheet):
    """ A style sheet which provides basic styling for a task dialog.

    This stylesheet can be declared, and optionally extended, in the
    body of a Dialog which contains a TaskDialogBody as its central
    widget. It provides a styling theme which is consistent with the
    look and feel of Windows 7/8 task dialogs.

    """
    Style:
        element = ('TaskDialogIconArea, TaskDialogInstructionArea, '
                   'TaskDialogContentArea, TaskDialogDetailsArea')
        Setter:
            field = 'background'
            value = 'white'
    Style:
        element = 'TaskDialogCommandArea'
        Setter:
            field = 'border-top'
            value = '1px solid #D9D9D9'
    Style:
        element = 'Label'
        style_class = 'task-dialog-instructions'
        Setter:
            field = 'font'
            value = '12pt "Segoe UI"'
        Setter:
            field = 'color'
            value = '#003399'
    Style:
        element = 'Label'
        style_class = 'task-dialog-content'
        Setter:
            field = 'font'
            value = '9pt "Segoe UI"'