From da1a4022a0c6daf6d221a653762407278e539086 Mon Sep 17 00:00:00 2001 From: Corran Webster Date: Fri, 3 Apr 2020 09:30:47 +0100 Subject: [PATCH 1/3] Promote LEDEditor to a first-class editor It now has both Qt and Wx backends, so no reason not to. --- .../api/traitsui.editors.led_editor.rst | 7 ++++ examples/demo/Extras/LED_display.py | 18 +++------ traitsui/api.py | 1 + traitsui/editors/api.py | 1 + traitsui/qt4/{extra => }/led_editor.py | 20 +++++----- traitsui/wx/{extra => }/led_editor.py | 40 +++++++------------ 6 files changed, 38 insertions(+), 49 deletions(-) create mode 100644 docs/source/api/traitsui.editors.led_editor.rst rename traitsui/qt4/{extra => }/led_editor.py (66%) rename traitsui/wx/{extra => }/led_editor.py (56%) diff --git a/docs/source/api/traitsui.editors.led_editor.rst b/docs/source/api/traitsui.editors.led_editor.rst new file mode 100644 index 000000000..1449e7f0b --- /dev/null +++ b/docs/source/api/traitsui.editors.led_editor.rst @@ -0,0 +1,7 @@ +traitsui\.editors\.led\_editor module +===================================== + +.. automodule:: traitsui.editors.led_editor + :members: + :undoc-members: + :show-inheritance: diff --git a/examples/demo/Extras/LED_display.py b/examples/demo/Extras/LED_display.py index 440db61c9..ffd849353 100644 --- a/examples/demo/Extras/LED_display.py +++ b/examples/demo/Extras/LED_display.py @@ -11,24 +11,16 @@ using a simulated LED display control. """ -from threading import Thread - +from threading import Thread from time import sleep from traits.api import HasTraits, Instance, Int, Bool, Float -from traitsui.api import View, Item, HGroup, Handler, UIInfo, spring - -from traits.etsconfig.api import ETSConfig -if ETSConfig.toolkit == 'wx': - from traitsui.wx.extra.led_editor import LEDEditor -else: - from traitsui.qt4.extra.led_editor import LEDEditor - -# Handler class for the LEDDemo class view: +from traitsui.api import View, Item, HGroup, Handler, LEDEditor, UIInfo, spring class LEDDemoHandler(Handler): + """ Handler class for the LEDDemo class view. """ # The UIInfo object associated with the UI: info = Instance(UIInfo) @@ -55,10 +47,9 @@ def _update_counter(self): sleep(.01) self.alive = False -# The main demo class: - class LEDDemo(HasTraits): + """ The main class for the LED Demo. """ # A counter to display: counter1 = Int() @@ -119,6 +110,7 @@ class LEDDemo(HasTraits): handler=LEDDemoHandler ) + # Create the demo: demo = LEDDemo() diff --git a/traitsui/api.py b/traitsui/api.py index 9b1e2ad74..b6bf2f274 100644 --- a/traitsui/api.py +++ b/traitsui/api.py @@ -60,6 +60,7 @@ ImageEnumEditor, InstanceEditor, KeyBindingEditor, + LEDEditor, ListEditor, ListStrEditor, NullEditor, diff --git a/traitsui/editors/api.py b/traitsui/editors/api.py index 81cb1327b..475f0ac6f 100644 --- a/traitsui/editors/api.py +++ b/traitsui/editors/api.py @@ -41,6 +41,7 @@ from .image_editor import ImageEditor from .image_enum_editor import ImageEnumEditor from .instance_editor import InstanceEditor +from .led_editor import LEDEditor from .list_editor import ListEditor from .list_str_editor import ListStrEditor from .null_editor import NullEditor diff --git a/traitsui/qt4/extra/led_editor.py b/traitsui/qt4/led_editor.py similarity index 66% rename from traitsui/qt4/extra/led_editor.py rename to traitsui/qt4/led_editor.py index c358527f2..c0865cd09 100644 --- a/traitsui/qt4/extra/led_editor.py +++ b/traitsui/qt4/led_editor.py @@ -7,12 +7,14 @@ # Thanks for using Enthought open source! from pyface.qt import QtGui -from traitsui.qt4.editor import Editor -from traitsui.basic_editor_factory import BasicEditorFactory -from traits.api import Any, Undefined +from .editor import Editor + + +class LEDEditor(Editor): + """ Traits UI 'display only' LED numeric editor. + """ -class _LEDEditor(Editor): def init(self, parent): self.control = QtGui.QLCDNumber() self.control.setSegmentStyle(QtGui.QLCDNumber.Flat) @@ -22,9 +24,7 @@ def update_editor(self): self.control.display(self.str_value) -class LEDEditor(BasicEditorFactory): - - #: The editor class to be created - klass = _LEDEditor - #: Alignment is not supported for QT backend - alignment = Any(Undefined) +# editor names for factory to find +ReadonlyEditor = LEDEditor +SimpleEditor = LEDEditor +CustomEditor = LEDEditor diff --git a/traitsui/wx/extra/led_editor.py b/traitsui/wx/led_editor.py similarity index 56% rename from traitsui/wx/extra/led_editor.py rename to traitsui/wx/led_editor.py index 47d6a61de..3aba153b2 100644 --- a/traitsui/wx/extra/led_editor.py +++ b/traitsui/wx/led_editor.py @@ -1,6 +1,4 @@ -# ------------------------------------------------------------------------- -# -# Copyright (c) 2007, Enthought, Inc. +# Copyright (c) 2007-2020, Enthought, Inc. # All rights reserved. # # This software is provided without warranty under the terms of the BSD @@ -9,11 +7,6 @@ # is also available online at http://www.enthought.com/licenses/BSD.txt # # Thanks for using Enthought open source! -# -# Author: David C. Morrill -# Date: 03/02/2007 -# -# ------------------------------------------------------------------------- """ Traits UI 'display only' LED numeric editor. """ @@ -28,9 +21,7 @@ from traits.api import Enum -from traitsui.wx.editor import Editor - -from traitsui.basic_editor_factory import BasicEditorFactory +from .editor import Editor # LED alignment styles: @@ -41,16 +32,19 @@ } -class _LEDEditor(Editor): +class LEDEditor(Editor): """ Traits UI 'display only' LED numeric editor. """ + #: The alignment of the numeric text within the control. + alignment = Enum("right", "center", "left") + def init(self, parent): """ Finishes initializing the editor by creating the underlying toolkit widget. """ self.control = LEDNumberCtrl(parent, -1) - self.control.SetAlignment(LEDStyles[self.factory.alignment]) + self.control.SetAlignment(LEDStyles[self.alignment]) self.set_tooltip() def update_editor(self): @@ -59,18 +53,12 @@ def update_editor(self): """ self.control.SetValue(self.str_value) + def _alignment_changed(self): + if self.control is not None: + self.control.SetAlignment(LEDStyles[self.alignment]) -# ------------------------------------------------------------------------- -# Create the editor factory object: -# ------------------------------------------------------------------------- - -# wxPython editor factory for LED editors: - - -class LEDEditor(BasicEditorFactory): - - #: The editor class to be created: - klass = _LEDEditor - #: The alignment of the numeric text within the control: - alignment = Enum("right", "left", "center") +# editor names for factory to find +ReadonlyEditor = LEDEditor +SimpleEditor = LEDEditor +CustomEditor = LEDEditor From ccda4b0ed66a126d7aa05ff2fccc007ae5dfe713 Mon Sep 17 00:00:00 2001 From: Corran Webster Date: Fri, 3 Apr 2020 10:20:52 +0100 Subject: [PATCH 2/3] Add LEDEditor to ToC. --- docs/source/api/traitsui.editors.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/source/api/traitsui.editors.rst b/docs/source/api/traitsui.editors.rst index b21cefcb7..56765a2d8 100644 --- a/docs/source/api/traitsui.editors.rst +++ b/docs/source/api/traitsui.editors.rst @@ -30,6 +30,7 @@ Submodules traitsui.editors.image_enum_editor traitsui.editors.instance_editor traitsui.editors.key_binding_editor + traitsui.editors.led_editor traitsui.editors.list_editor traitsui.editors.list_str_editor traitsui.editors.null_editor From 8416bbdb36b18f167af9a77e060f95e8740fe501 Mon Sep 17 00:00:00 2001 From: Corran Webster Date: Fri, 3 Apr 2020 10:39:37 +0100 Subject: [PATCH 3/3] Add missing module. --- traitsui/editors/led_editor.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 traitsui/editors/led_editor.py diff --git a/traitsui/editors/led_editor.py b/traitsui/editors/led_editor.py new file mode 100644 index 000000000..7a781f905 --- /dev/null +++ b/traitsui/editors/led_editor.py @@ -0,0 +1,20 @@ +# (C) Copyright 2020 Enthought, Inc., Austin, TX +# All rights reserved. +# This software is provided without warranty under the terms of the BSD +# license included in LICENSE.txt and may be redistributed only +# under the conditions described in the aforementioned license. The license +# is also available online at http://www.enthought.com/licenses/BSD.txt +# Thanks for using Enthought open source! + +""" A Traits UI editor that wraps a LED-style integer display. +""" + +from traitsui.editor_factory import EditorFactory +from traits.api import Enum + + +class LEDEditor(EditorFactory): + """ Editor factory for an LED editor. """ + + #: The alignment of the numeric text within the control. (Wx only) + alignment = Enum("right", "center", "left")