Debian Codegraph @

integrationtests/styled_date_editor_test.py

raw
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 from datetime import date
12
13 from traits.api import Date, Dict, HasTraits, List, observe
14 from traitsui.api import View, Item, StyledDateEditor
15 from traitsui.editors.styled_date_editor import CellFormat
16
17
18 class Foo(HasTraits):
19 dates = Dict()
20 styles = Dict()
21
22 fast_dates = List()
23 slow_dates = List()
24
25 current_date = Date()
26
27 traits_view = View(
28 Item(
29 "current_date",
30 style="custom",
31 show_label=False,
32 editor=StyledDateEditor(
33 dates_trait="dates", styles_trait="styles"
34 ),
35 )
36 )
37
38 def __init__(self, *args, **kw):
39 HasTraits.__init__(self, *args, **kw)
40 self.styles = {
41 "fast": CellFormat(bold=True, fgcolor="darkGreen"),
42 "slow": CellFormat(italics=True, fgcolor="lightGray"),
43 }
44
45 self.fast_dates = [
46 date(2010, 7, 4),
47 date(2010, 7, 3),
48 date(2010, 7, 2),
49 ]
50 self.slow_dates = [
51 date(2010, 6, 28),
52 date(2010, 6, 27),
53 date(2010, 6, 24),
54 ]
55
56 @observe("fast_dates,slow_dates")
57 def _update_dates_dict(self, event):
58 self.dates["fast"] = self.fast_dates
59 self.dates["slow"] = self.slow_dates
60
61 def _current_date_changed(self, old, new):
62 print("Old:", old, "New:", new)
63
64
65 def main():
66 foo = Foo()
67 foo.configure_traits()
68
69
70 if __name__ == "__main__":
71 main()