class HasDatetimeTraits(HasStrictTraits): #: Simple case - no default, no parameters, no metadata simple_datetime = Datetime() #: Datetime with default epoch = Datetime(UNIX_EPOCH) #: Datetime with default provided via keyword. alternative_epoch = Datetime(default_value=NT_EPOCH) #: None prohibited none_prohibited = Datetime(allow_none=False) #: None allowed none_allowed = Datetime(allow_none=True)
class DateEditorDemo(HasTraits): """ Demo class to show Datetime editors. """ datetime = Datetime() info_string = Str('The editors for Traits Datetime objects.') traits_view = View( Item( 'info_string', show_label=False, style='readonly', ), Group( Item( 'datetime', label='Simple date editor', ), Item( 'datetime', style='readonly', label='ReadOnly editor', ), label='Default settings for editors', ), resizable=True, ) def _datetime_changed(self): """ Print each time the date value is changed in the editor. """ print(self.datetime)
class DatetimeEditor(EditorFactory): """ Editor factory for the datetime editor. """ # ------------------------------------------------------------------------- # Trait definitions: # ------------------------------------------------------------------------- #: The earliest datetime allowed by the editor minimum_datetime = Datetime(datetime.datetime(100, 1, 1)) #: The latest datetime allowed by the editor maximum_datetime = Datetime(datetime.datetime.max) # -- ReadonlyEditor traits ------------------------------------------------ #: Message to show when datetime is None. message = Str("Undefined") #: The string representation of the datetime to show. Uses time.strftime #: format. strftime = Str("%Y-%m-%dT%H:%M:%S")
class InstanceWithDatetime(HasTraits): """ Demo class to show Datetime editors. """ date_time = Datetime()
class TestClass(HasTraits): t = Datetime() x = Int()