| 1 |
# (C) Copyright 2004-2023 Enthought, Inc., Austin, TX |
| 2 |
# All rights reserved. |
| 3 |
# |
| 4 |
# This software is provided without warranty under the terms of the BSD |
| 5 |
# license included in LICENSE.txt and may be redistributed only under |
| 6 |
# the conditions described in the aforementioned license. The license |
| 7 |
# is also available online at http://www.enthought.com/licenses/BSD.txt |
| 8 |
# |
| 9 |
# Thanks for using Enthought open source! |
| 10 |
|
| 11 |
""" |
| 12 |
This program demonstrates the use of editors that support *history*. A |
| 13 |
history is a persistent record of the last 'n' values the user has entered or |
| 14 |
selected for a particular trait. |
| 15 |
|
| 16 |
In order for the history to be recorded correctly, you must specify an *id* |
| 17 |
for both the Item containing the history editor and the View containing the |
| 18 |
Item. |
| 19 |
|
| 20 |
The maximum number of history entries recorded is specified by the value of |
| 21 |
the history editor's *entries* trait. If *entries* is less than or |
| 22 |
equal to 0, then a normal, non-history, version of the editor will be used. |
| 23 |
|
| 24 |
A history editor also attempts to restore the last value set as the current |
| 25 |
value for the trait if the current value of the trait is the empty string. You |
| 26 |
can see this for yourself by setting some values in the fields, selecting a |
| 27 |
different demo, then reselecting this demo. Each field should have the same |
| 28 |
value it had when the demo was run the previous time. |
| 29 |
""" |
| 30 |
|
| 31 |
# -- Imports -------------------------------------------------------------- |
| 32 |
|
| 33 |
from traits.api import HasTraits, Str, File, Directory |
| 34 |
|
| 35 |
from traitsui.api import View, Item, FileEditor, DirectoryEditor, HistoryEditor |
| 36 |
|
| 37 |
# -- HistoryDemo Class ---------------------------------------------------- |
| 38 |
|
| 39 |
|
| 40 |
class HistoryDemo(HasTraits): |
| 41 |
|
| 42 |
name = Str() |
| 43 |
file = File() |
| 44 |
directory = Directory() |
| 45 |
|
| 46 |
view = View( |
| 47 |
Item('name', id='name', editor=HistoryEditor(entries=5)), |
| 48 |
Item('file', id='file1', editor=FileEditor(entries=10)), |
| 49 |
Item( |
| 50 |
'file', |
| 51 |
id='file2', |
| 52 |
editor=FileEditor( |
| 53 |
entries=10, |
| 54 |
filter=['All files (*.*)|*.*', 'Python files (*.py)|*.py'], |
| 55 |
), |
| 56 |
), |
| 57 |
Item('directory', id='directory', editor=DirectoryEditor(entries=10)), |
| 58 |
title='History Editor Demo', |
| 59 |
id='enthought.test.history_demo.HistoryDemo', |
| 60 |
width=0.33, |
| 61 |
resizable=True, |
| 62 |
) |
| 63 |
|
| 64 |
|
| 65 |
# Create the demo: |
| 66 |
demo = HistoryDemo() |
| 67 |
|
| 68 |
# Run the demo (if invoked from the command line): |
| 69 |
if __name__ == '__main__': |
| 70 |
demo.configure_traits() |