| 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 |
**WARNING** |
| 13 |
|
| 14 |
This demo might not work as expected and some documented features might be |
| 15 |
missing. |
| 16 |
|
| 17 |
------------------------------------------------------------------------------- |
| 18 |
|
| 19 |
A Traits UI editor that edits a datetime panel. |
| 20 |
|
| 21 |
Please refer to the `DatetimeEditor API docs`_ for further information. |
| 22 |
|
| 23 |
.. _DatetimeEditor API docs: https://docs.enthought.com/traitsui/api/traitsui.editors.datetime_editor.html#traitsui.editors.datetime_editor.DatetimeEditor |
| 24 |
""" |
| 25 |
# Issue related to the demo warning: enthought/traitsui#943 |
| 26 |
|
| 27 |
|
| 28 |
import datetime |
| 29 |
|
| 30 |
from traits.api import HasTraits, Datetime, Str |
| 31 |
from traitsui.api import View, Item, Group |
| 32 |
|
| 33 |
|
| 34 |
class DateEditorDemo(HasTraits): |
| 35 |
"""Demo class to show Datetime editors.""" |
| 36 |
|
| 37 |
datetime = Datetime(allow_none=True) |
| 38 |
info_string = Str('The editors for Traits Datetime objects.') |
| 39 |
|
| 40 |
traits_view = View( |
| 41 |
Item( |
| 42 |
'info_string', |
| 43 |
show_label=False, |
| 44 |
style='readonly', |
| 45 |
), |
| 46 |
Group( |
| 47 |
Item( |
| 48 |
'datetime', |
| 49 |
label='Simple date editor', |
| 50 |
), |
| 51 |
Item( |
| 52 |
'datetime', |
| 53 |
style='readonly', |
| 54 |
label='ReadOnly editor', |
| 55 |
), |
| 56 |
label='Default settings for editors', |
| 57 |
), |
| 58 |
resizable=True, |
| 59 |
) |
| 60 |
|
| 61 |
def _datetime_changed(self): |
| 62 |
"""Print each time the date value is changed in the editor.""" |
| 63 |
print(self.datetime) |
| 64 |
|
| 65 |
|
| 66 |
# -- Set Up The Demo ------------------------------------------------------ |
| 67 |
|
| 68 |
demo = DateEditorDemo(datetime=datetime.datetime.now()) |
| 69 |
|
| 70 |
if __name__ == "__main__": |
| 71 |
demo.configure_traits() |