-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Promote LEDEditor to a first-class editor #779
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
traitsui\.editors\.led\_editor module | ||
===================================== | ||
|
||
.. automodule:: traitsui.editors.led_editor | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shall we keep |
||
|
||
# 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() | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo: "a" -> "an" |
||
""" | ||
|
||
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") |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -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]) | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, I think we can defer making
traitsui/traitsui/qt4/list_str_editor.py Line 114 in 7841ca7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Please ignore this half of the comment. The |
||||
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]) | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we make such a change in a separate PR such that this PR is more focused about exposing the existing editor as first-class / built-in / whatever editor? Furthermore I expect there being very limited use case to mutate the alignment after the editor is created - we can wait for this feature request to arise. The fewer mutables there are, the simpler and more maintainable the code is. |
||||
|
||||
# ------------------------------------------------------------------------- | ||||
# 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 | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we actually need to populate all the three styles? If the custom/readonly editors are not implemented, then in the future we will be certain that they are never used because attempts to set e.g. The TableEditor does not have a custom editor. ButtonEditor does not have a readonly editor. They don't seem to be missed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The API documentation is now being generated automatically. So this file and
traitsui.editors.rst
are not needed any more.