Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion examples/demo/Standard_Editors/BooleanEditor_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

A Boolean (True/False) trait is displayed and edited as a checkbox, by default.

It can also be displayed as text 'True' / 'False', either editable or read-only.
It can also be displayed as text 'True'/'False', either editable or read-only.

This example also shows how to listen for a change in a trait, and take
action when its value changes.
Expand Down Expand Up @@ -60,6 +60,7 @@ def _my_boolean_trait_changed(self):
resizable=True
)


# Create the demo view (but do not yet display it):
demo = BooleanEditorDemo()

Expand Down
8 changes: 5 additions & 3 deletions examples/demo/Standard_Editors/ButtonEditor_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@
"""

from traits.api import HasTraits, Button, Int
from traitsui.api import View

from traitsui.api import Item, View


class ButtonEditorDemo(HasTraits):
""" Defines the main ButtonEditor demo class. """

# Define a Button trait:
my_button_trait = Button('Click Me')
click_counter = Int()
click_counter = Int(0)

# When the button is clicked, do something.
# The listener method is named '_TraitName_fired', where
Expand All @@ -27,12 +28,13 @@ def _my_button_trait_fired(self):
# Demo view:
traits_view = View(
'my_button_trait',
'click_counter',
Item('click_counter', style='readonly'),
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was changed to avoid #928

title='ButtonEditor',
buttons=['OK'],
resizable=True
)


# Create the demo:
demo = ButtonEditorDemo()

Expand Down
179 changes: 107 additions & 72 deletions examples/demo/Standard_Editors/CSVListEditor_demo.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
"""
Demonstrate the CSVListEditor class.<br>
<br>
**WARNING**

This demo might not work as expected and some documented features might be
missing.

-------------------------------------------------------------------------------

Demonstrate the CSVListEditor class.

This editor allows the user to enter a *single* line of input text, containing
comma-separated values (or another separator may be specified). Your program
specifies an element Trait type of Int, Float, Str, Enum, or Range.
"""
# Issue related to the demo warning: enthought/traitsui#913


from traits.api import HasTraits, List, Int, Float, Enum, Range, Str, Button, \
Property
from traitsui.api import View, Item, Label, Heading, VGroup, HGroup, UItem, \
spring, TextEditor, CSVListEditor
from traits.api import (
HasTraits, List, Int, Float, Enum, Range, Str, Button, Property
)
from traitsui.api import (
View, Item, Label, Heading, VGroup, HGroup, UItem, spring, TextEditor,
CSVListEditor
)


class Demo(HasTraits):
class CSVListEditorDemo(HasTraits):

list1 = List(Int)

Expand All @@ -39,73 +51,96 @@ class Demo(HasTraits):
# This will be str(self.list1).
list1str = Property(Str, depends_on='list1')

traits_view = \
View(
HGroup(
# This VGroup forms the column of CSVListEditor examples.
VGroup(
Item('list1', label="List(Int)",
editor=CSVListEditor(ignore_trailing_sep=False),
tooltip='options: ignore_trailing_sep=False'),
Item('list1', label="List(Int)", style='readonly',
editor=CSVListEditor()),
Item('list2', label="List(Float)",
editor=CSVListEditor(enter_set=True, auto_set=False),
tooltip='options: enter_set=True, auto_set=False'),
Item('list3', label="List(Str, maxlen=3)",
editor=CSVListEditor()),
Item('list4',
label="List(Enum('red', 'green', 'blue', 2, 3))",
editor=CSVListEditor(sep=None),
tooltip='options: sep=None'),
Item('list5', label="List(Range(low=0.0, high=10.0))",
editor=CSVListEditor()),
Item('list6', label="List(Range(low=-1.0, high='high'))",
editor=CSVListEditor()),
Item('list7', label="List(Range(low='low', high='high'))",
editor=CSVListEditor()),
springy=True,
traits_view = View(
HGroup(
# This VGroup forms the column of CSVListEditor examples.
VGroup(
Item(
'list1',
label="List(Int)",
editor=CSVListEditor(ignore_trailing_sep=False),
tooltip='options: ignore_trailing_sep=False'
),
Item(
'list1',
label="List(Int)",
style='readonly',
editor=CSVListEditor()
),
# This VGroup forms the right column; it will display the
# Python str representation of the lists.
VGroup(
UItem('list1str', editor=TextEditor(),
enabled_when='False', width=240),
UItem('list1str', editor=TextEditor(),
enabled_when='False', width=240),
UItem('list2', editor=TextEditor(),
enabled_when='False', width=240),
UItem('list3', editor=TextEditor(),
enabled_when='False', width=240),
UItem('list4', editor=TextEditor(),
enabled_when='False', width=240),
UItem('list5', editor=TextEditor(),
enabled_when='False', width=240),
UItem('list6', editor=TextEditor(),
enabled_when='False', width=240),
UItem('list7', editor=TextEditor(),
enabled_when='False', width=240),
Item(
'list2',
label="List(Float)",
editor=CSVListEditor(enter_set=True, auto_set=False),
tooltip='options: enter_set=True, auto_set=False'
),
Item(
'list3',
label="List(Str, maxlen=3)",
editor=CSVListEditor()
),
Item(
'list4',
label="List(Enum('red', 'green', 'blue', 2, 3))",
editor=CSVListEditor(sep=None),
tooltip='options: sep=None'
),
Item(
'list5',
label="List(Range(low=0.0, high=10.0))",
editor=CSVListEditor()
),
Item(
'list6',
label="List(Range(low=-1.0, high='high'))",
editor=CSVListEditor()
),
Item(
'list7',
label="List(Range(low='low', high='high'))",
editor=CSVListEditor()
),
springy=True,
),
# This VGroup forms the right column; it will display the
# Python str representation of the lists.
VGroup(
UItem('list1str', editor=TextEditor(),
enabled_when='False', width=240),
UItem('list1str', editor=TextEditor(),
enabled_when='False', width=240),
UItem('list2', editor=TextEditor(),
enabled_when='False', width=240),
UItem('list3', editor=TextEditor(),
enabled_when='False', width=240),
UItem('list4', editor=TextEditor(),
enabled_when='False', width=240),
UItem('list5', editor=TextEditor(),
enabled_when='False', width=240),
UItem('list6', editor=TextEditor(),
enabled_when='False', width=240),
UItem('list7', editor=TextEditor(),
enabled_when='False', width=240),
),
'_',
HGroup('low', 'high', spring, UItem('pop1'), UItem('sort1')),
Heading("Notes"),
Label("Hover over a list to see which editor options are set, "
"if any."),
Label("The editor of the first list, List(Int), uses "
"ignore_trailing_sep=False, so a trailing comma is "
"an error."),
Label("The second list is a read-only view of the first list."),
Label("The editor of the List(Float) example has enter_set=True "
"and auto_set=False; press Enter to validate."),
Label("The List(Str) example will accept at most 3 elements."),
Label("The editor of the List(Enum(...)) example uses sep=None, "
"i.e. whitespace acts as a separator."),
Label("The last two List(Range(...)) examples take one or both "
"of their limits from the Low and High fields below."),
width=720,
title="CSVListEditor Demonstration",
)
),
'_',
HGroup('low', 'high', spring, UItem('pop1'), UItem('sort1')),
Heading("Notes"),
Label("Hover over a list to see which editor options are set, "
"if any."),
Label("The editor of the first list, List(Int), uses "
"ignore_trailing_sep=False, so a trailing comma is "
"an error."),
Label("The second list is a read-only view of the first list."),
Label("The editor of the List(Float) example has enter_set=True "
"and auto_set=False; press Enter to validate."),
Label("The List(Str) example will accept at most 3 elements."),
Label("The editor of the List(Enum(...)) example uses sep=None, "
"i.e. whitespace acts as a separator."),
Label("The last three List(Range(...)) examples take neither, one or "
"both of their limits from the Low and High fields below."),
width=720,
title="CSVListEditor Demonstration",
)

def _list1_default(self):
return [1, 4, 0, 10]
Expand All @@ -123,5 +158,5 @@ def _sort1_fired(self):


if __name__ == "__main__":
demo = Demo()
demo = CSVListEditorDemo()
demo.configure_traits()
44 changes: 25 additions & 19 deletions examples/demo/Standard_Editors/CheckListEditor_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,36 @@
each of the four styles of the CheckListEditor.
"""

# Imports:
from traits.api \
import HasTraits, List
from traits.api import HasTraits, List

from traitsui.api \
import Item, Group, View, CheckListEditor

# Define the demo class:
from traitsui.api import Item, Group, View, CheckListEditor


# Define the demo class:
class CheckListEditorDemo(HasTraits):
""" Define the main CheckListEditor demo class. """

# Define a trait for each of three formations:
checklist_4col = List(editor=CheckListEditor(
values=['one', 'two', 'three', 'four'],
cols=4))
checklist_4col = List(
editor=CheckListEditor(
values=['one', 'two', 'three', 'four'],
cols=4
)
)

checklist_2col = List(editor=CheckListEditor(
values=['one', 'two', 'three', 'four'],
cols=2))
checklist_2col = List(
editor=CheckListEditor(
values=['one', 'two', 'three', 'four'],
cols=2
)
)

checklist_1col = List(editor=CheckListEditor(
values=['one', 'two', 'three', 'four'],
cols=1))
checklist_1col = List(
editor=CheckListEditor(
values=['one', 'two', 'three', 'four'],
cols=1
)
)

# CheckListEditor display with four columns:
cl_4_group = Group(
Expand Down Expand Up @@ -70,9 +75,9 @@ class CheckListEditorDemo(HasTraits):
label='1-column'
)

# The view includes one group per column formation. These will be displayed
# on separate tabbed panels.
view1 = View(
# The view includes one group per column formation. These will be
# displayed on separate tabbed panels.
traits_view = View(
cl_4_group,
cl_2_group,
cl_1_group,
Expand All @@ -81,6 +86,7 @@ class CheckListEditorDemo(HasTraits):
resizable=True
)


# Create the demo:
demo = CheckListEditorDemo()

Expand Down
19 changes: 11 additions & 8 deletions examples/demo/Standard_Editors/CheckListEditor_simple_demo.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""
Checklist editor for a List of strings

The checklist editor provides a simple way for the user to select multiple items
from a list of known strings.
The checklist editor provides a simple way for the user to select multiple
items from a list of known strings.

This example demonstrates the checklist editor's two most useful styles:

Expand All @@ -26,17 +26,19 @@ class CheckListEditorDemo(HasTraits):
""" Define the main CheckListEditor simple demo class. """

# Specify the strings to be displayed in the checklist:
checklist = List(editor=CheckListEditor(
values=['one', 'two', 'three', 'four',
'five', 'six'],
cols=2))
checklist = List(
editor=CheckListEditor(
values=['one', 'two', 'three', 'four', 'five', 'six'],
cols=2
)
)

# CheckListEditor display with two columns:
checklist_group = Group(
'10', # insert vertical space
'10', # insert vertical space (10 empty pixels)
Label('The custom style lets you select items from a checklist:'),
UItem('checklist', style='custom'),
'10', '_', '10', # a horizontal line with 10 empty pixels above and below
'10', '_', '10', # horizontal line with vertical space above and below
Label('The readonly style shows you which items are selected, '
'as a Python list:'),
UItem('checklist', style='readonly'),
Expand All @@ -49,6 +51,7 @@ class CheckListEditorDemo(HasTraits):
resizable=True
)


# Create the demo:
demo = CheckListEditorDemo()

Expand Down
Loading