File: Date_editor_demo.py

package info (click to toggle)
python-traitsui 4.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 13,292 kB
  • sloc: python: 39,867; makefile: 120; sh: 5
file content (73 lines) | stat: -rw-r--r-- 2,679 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#  Copyright (c) 2007-2009, Enthought, Inc.
#  License: BSD Style.

"""
A Traits UI editor that wraps a WX calendar panel.
"""

from traits.api import HasTraits, Date, List, Str
from traitsui.api import View, Item, DateEditor, Group


class DateEditorDemo(HasTraits):
    """ Demo class to show Date editors. """
    single_date = Date
    multi_date = List(Date)
    info_string = Str('The editors for Traits Date objects.  Showing both '\
                      'the defaults, and one with alternate options.')

    multi_select_editor = DateEditor(multi_select=True,
                                     months=2,
                                     allow_future=False,
                                     padding=30,
                                     on_mixed_select='max_change',
                                     shift_to_select=False)

    view = View(Item('info_string',
                     show_label=False,
                     style='readonly'),

                Group(Item('single_date',
                           label='Simple date editor'),
                      Item('single_date',
                           style='custom',
                           label='Default custom editor'),
                      Item('single_date',
                           style='readonly',
                           editor=DateEditor(strftime='You picked %B %d %Y',
                                             message='Click a date above.'),
                           label='ReadOnly editor'),
                      label='Default settings for editors'),

                Group(Item('multi_date',
                           editor=multi_select_editor,
                           style='custom',
                           label='Multi-select custom editor'),
                      label='More customized editor: multi-select; disallow '\
                            'future; two months; padding; selection '\
                            'style; etc.'),

                resizable=True)


    def _multi_date_changed(self):
        """ Print each time the date value is changed in the editor. """
        print self.multi_date

    def _simple_date_changed(self):
        """ Print each time the date value is changed in the editor. """
        print self.simple_date, self.single_date

    def _single_date_changed(self):
        """ Print each time the date value is changed in the editor. """
        print self.single_date


#-- Set Up The Demo ------------------------------------------------------------

demo = DateEditorDemo()

if __name__ == "__main__":
    demo.configure_traits()

#-- eof -----------------------------------------------------------------------