| 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 |
A timer editor |
| 13 |
|
| 14 |
Display or edit a time. |
| 15 |
|
| 16 |
You can edit the time directly, or by using only the arrow keys (left & right |
| 17 |
to navigate, up & down to change). |
| 18 |
|
| 19 |
""" |
| 20 |
|
| 21 |
import datetime |
| 22 |
|
| 23 |
from traits.api import HasTraits, Time |
| 24 |
from traitsui.api import View, Item, TimeEditor |
| 25 |
|
| 26 |
|
| 27 |
class TimeEditorDemo(HasTraits): |
| 28 |
"""Demo class.""" |
| 29 |
|
| 30 |
time = Time(datetime.time(12, 0, 0)) |
| 31 |
|
| 32 |
traits_view = View( |
| 33 |
Item('time', label='Simple Editor'), |
| 34 |
Item( |
| 35 |
'time', |
| 36 |
label='Readonly Editor', |
| 37 |
style='readonly', |
| 38 |
# Show 24-hour mode instead of default 12 hour. |
| 39 |
editor=TimeEditor(strftime='%H:%M:%S'), |
| 40 |
), |
| 41 |
resizable=True, |
| 42 |
) |
| 43 |
|
| 44 |
def _time_changed(self): |
| 45 |
"""Print each time the time value is changed in the editor.""" |
| 46 |
print(self.time) |
| 47 |
|
| 48 |
|
| 49 |
# -- Set Up The Demo ------------------------------------------------------ |
| 50 |
|
| 51 |
demo = TimeEditorDemo() |
| 52 |
|
| 53 |
if __name__ == "__main__": |
| 54 |
demo.configure_traits() |