Debian Codegraph @

traitsui/examples/demo/Standard_Editors/CodeEditor_demo.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 """
12 Implementation of a CodeEditor demo plugin for Traits UI demo program.
13
14 This demo shows each of the four styles of the CodeEditor.
15
16 Please refer to the `CodeEditor API docs`_ for further information.
17
18 .. _CodeEditor API docs: https://docs.enthought.com/traitsui/api/traitsui.editors.code_editor.html#traitsui.editors.code_editor.CodeEditor
19 """
20
21 from traits.api import HasTraits, Code
22
23 from traitsui.api import Item, Group, View
24
25
26 # The main demo class:
27 class CodeEditorDemo(HasTraits):
28 """Defines the CodeEditor demo class."""
29
30 # Define a trait to view:
31 code_sample = Code('import sys\n\nsys.print("hello world!")')
32
33 # Display specification:
34 code_group = Group(
35 Item('code_sample', style='simple', label='Simple'),
36 Item('_'),
37 Item('code_sample', style='custom', label='Custom'),
38 Item('_'),
39 Item('code_sample', style='text', label='Text'),
40 Item('_'),
41 Item('code_sample', style='readonly', label='ReadOnly'),
42 )
43
44 # Demo view:
45 traits_view = View(
46 code_group, title='CodeEditor', width=600, height=600, buttons=['OK']
47 )
48
49
50 # Create the demo:
51 demo = CodeEditorDemo()
52
53 # Run the demo (if invoked from the command line):
54 if __name__ == "__main__":
55 demo.configure_traits()