File: History_demo.py

package info (click to toggle)
python-traitsui 8.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 18,232 kB
  • sloc: python: 58,982; makefile: 113
file content (70 lines) | stat: -rw-r--r-- 2,463 bytes parent folder | download | duplicates (2)
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
# (C) Copyright 2004-2023 Enthought, Inc., Austin, TX
# All rights reserved.
#
# This software is provided without warranty under the terms of the BSD
# license included in LICENSE.txt and may be redistributed only under
# the conditions described in the aforementioned license. The license
# is also available online at http://www.enthought.com/licenses/BSD.txt
#
# Thanks for using Enthought open source!

"""
This program demonstrates the use of editors that support *history*. A
history is a persistent record of the last 'n' values the user has entered or
selected for a particular trait.

In order for the history to be recorded correctly, you must specify an *id*
for both the Item containing the history editor and the View containing the
Item.

The maximum number of history entries recorded is specified by the value of
the history editor's *entries* trait. If *entries* is less than or
equal to 0, then a normal, non-history, version of the editor will be used.

A history editor also attempts to restore the last value set as the current
value for the trait if the current value of the trait is the empty string. You
can see this for yourself by setting some values in the fields, selecting a
different demo, then reselecting this demo. Each field should have the same
value it had when the demo was run the previous time.
"""

# -- Imports --------------------------------------------------------------

from traits.api import HasTraits, Str, File, Directory

from traitsui.api import View, Item, FileEditor, DirectoryEditor, HistoryEditor

# -- HistoryDemo Class ----------------------------------------------------


class HistoryDemo(HasTraits):

    name = Str()
    file = File()
    directory = Directory()

    view = View(
        Item('name', id='name', editor=HistoryEditor(entries=5)),
        Item('file', id='file1', editor=FileEditor(entries=10)),
        Item(
            'file',
            id='file2',
            editor=FileEditor(
                entries=10,
                filter=['All files (*.*)|*.*', 'Python files (*.py)|*.py'],
            ),
        ),
        Item('directory', id='directory', editor=DirectoryEditor(entries=10)),
        title='History Editor Demo',
        id='enthought.test.history_demo.HistoryDemo',
        width=0.33,
        resizable=True,
    )


# Create the demo:
demo = HistoryDemo()

# Run the demo (if invoked from the command line):
if __name__ == '__main__':
    demo.configure_traits()