| 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 |
Implementation of a DateEditor demo plugin for Traits UI demo program. |
| 20 |
|
| 21 |
This demo shows a few different styles of the DateEditor and how it can be |
| 22 |
customized. |
| 23 |
""" |
| 24 |
# Issue related to the demo warning: enthought/traitsui#962 |
| 25 |
|
| 26 |
from traits.api import HasTraits, Date, List, Str |
| 27 |
from traitsui.api import View, Item, DateEditor, Group |
| 28 |
|
| 29 |
|
| 30 |
class DateEditorDemo(HasTraits): |
| 31 |
"""Demo class to show Date editors.""" |
| 32 |
|
| 33 |
single_date = Date() |
| 34 |
multi_date = List(Date) |
| 35 |
info_string = Str( |
| 36 |
'The editors for Traits Date objects. Showing both ' |
| 37 |
'the defaults, and one with alternate options.' |
| 38 |
) |
| 39 |
|
| 40 |
multi_select_editor = DateEditor( |
| 41 |
allow_future=False, |
| 42 |
multi_select=True, |
| 43 |
shift_to_select=False, |
| 44 |
on_mixed_select='max_change', |
| 45 |
# Qt ignores these setting and always shows only 1 month: |
| 46 |
months=2, |
| 47 |
padding=30, |
| 48 |
) |
| 49 |
|
| 50 |
traits_view = View( |
| 51 |
Item('info_string', show_label=False, style='readonly'), |
| 52 |
Group( |
| 53 |
Item('single_date', label='Simple date editor'), |
| 54 |
Item('single_date', style='custom', label='Default custom editor'), |
| 55 |
Item( |
| 56 |
'single_date', |
| 57 |
style='readonly', |
| 58 |
editor=DateEditor( |
| 59 |
strftime='You picked %B %d %Y', |
| 60 |
message='Click a date above.', |
| 61 |
), |
| 62 |
label='ReadOnly editor', |
| 63 |
), |
| 64 |
label='Default settings for editors', |
| 65 |
), |
| 66 |
Group( |
| 67 |
Item( |
| 68 |
'multi_date', |
| 69 |
editor=multi_select_editor, |
| 70 |
style='custom', |
| 71 |
label='Multi-select custom editor', |
| 72 |
), |
| 73 |
label='More customized editor: multi-select; disallow ' |
| 74 |
'future; selection style; etc.', |
| 75 |
), |
| 76 |
resizable=True, |
| 77 |
) |
| 78 |
|
| 79 |
def _multi_date_changed(self): |
| 80 |
"""Print each time the date value is changed in the editor.""" |
| 81 |
print(self.multi_date) |
| 82 |
|
| 83 |
def _simple_date_changed(self): |
| 84 |
"""Print each time the date value is changed in the editor.""" |
| 85 |
print(self.simple_date, self.single_date) |
| 86 |
|
| 87 |
def _single_date_changed(self): |
| 88 |
"""Print each time the date value is changed in the editor.""" |
| 89 |
print(self.single_date) |
| 90 |
|
| 91 |
|
| 92 |
# -- Set Up The Demo ------------------------------------------------------ |
| 93 |
|
| 94 |
demo = DateEditorDemo() |
| 95 |
|
| 96 |
if __name__ == "__main__": |
| 97 |
demo.configure_traits() |