File: focus_traversal.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 (77 lines) | stat: -rw-r--r-- 2,527 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
#------------------------------------------------------------------------------
# Copyright (c) 2014-2024,, Nucleic Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file LICENSE, distributed with this software.
#------------------------------------------------------------------------------
""" An example of using the FocusTraversal advanced widget feature.

The FocusTraversal is an advanced widget feature for controlling the
order in which widgets receive focus during Tab and Shift+Tab keyboard
events. It enables two methods which can be implemented as declarative
Enaml functions which will compute the next/previous focus widgets on
demand.

In this example, the traversal handlers simply return the next or
previous field from a double-linked list of fields. However, there
is no restriction on how the handlers actually compute the focus
widgets.

<< autodoc-me >>
"""
from enaml.widgets.api import Window, GroupBox, Field, FocusTracker, Container, Feature


enamldef LinkField(Field):
    attr next_field
    attr prev_field


enamldef Main(Window):
    title = 'Focus Traversal'
    Container:
        features = Feature.FocusTraversal

        next_focus_child => (current):      # triggered on Tab
            return getattr(current, 'next_field', None)

        previous_focus_child => (current):  # triggered on Shift+Tab
            return getattr(current, 'prev_field', None)

        FocusTracker:
            focused_widget::
                print(change["value"])

        GroupBox:
            title = 'First Group'
            LinkField: f1:
                placeholder = '1'
                next_field = f4
                prev_field = f5
            LinkField: f2:
                placeholder = '5'
                next_field = f7
                prev_field = f6
            LinkField: f3:
                placeholder = '3'
                next_field = f6
                prev_field = f4
            LinkField: f4:
                placeholder = '2'
                next_field = f3
                prev_field = f1
        GroupBox:
            title = 'Second Group'
            LinkField: f5:
                placeholder = '7'
                next_field = f1
                prev_field = f7
            LinkField: f6:
                placeholder = '4'
                next_field = f2
                prev_field = f3
            LinkField: f7:
                placeholder = '6'
                next_field = f5
                prev_field = f2