Skip to content

DataView/Plot bgcolor can't be tuple #907

@corranwebster

Description

@corranwebster

Problem Description

The when given a bgcolor trait which is a tuple (or other valid non-color name values) DataView code errors with an error like:

Traceback (most recent call last):
  File "/Users/cwebster/src/experiment/chaco/temp/reported_errors.py", line 29, in <module>
    LinePlot().configure_traits()
  File "/Users/cwebster/.venvs/chaco-3.11/lib/python3.11/site-packages/traits/has_traits.py", line 2164, in configure_traits
    rc = toolkit().view_application(
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cwebster/src/experiment/traitsui/traitsui/qt/toolkit.py", line 237, in view_application
    return view_application.view_application(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cwebster/src/experiment/traitsui/traitsui/qt/view_application.py", line 92, in view_application
    return ViewApplication(
           ^^^^^^^^^^^^^^^^
  File "/Users/cwebster/src/experiment/traitsui/traitsui/qt/view_application.py", line 127, in __init__
    self.ui = self.view.ui(
              ^^^^^^^^^^^^^
  File "/Users/cwebster/src/experiment/traitsui/traitsui/view.py", line 457, in ui
    ui.ui(parent, kind)
  File "/Users/cwebster/src/experiment/traitsui/traitsui/ui.py", line 234, in ui
    self.rebuild(self, parent)
  File "/Users/cwebster/src/experiment/traitsui/traitsui/qt/toolkit.py", line 168, in ui_live
    ui_live.ui_live(ui, parent)
  File "/Users/cwebster/src/experiment/traitsui/traitsui/qt/ui_live.py", line 52, in ui_live
    _ui_dialog(ui, parent, BaseDialog.NONMODAL)
  File "/Users/cwebster/src/experiment/traitsui/traitsui/qt/ui_live.py", line 72, in _ui_dialog
    BaseDialog.display_ui(ui, parent, style)
  File "/Users/cwebster/src/experiment/traitsui/traitsui/qt/ui_base.py", line 294, in display_ui
    ui.owner.init(ui, parent, style)
  File "/Users/cwebster/src/experiment/traitsui/traitsui/qt/ui_live.py", line 231, in init
    self.add_contents(panel(ui), bbox)
                      ^^^^^^^^^
  File "/Users/cwebster/src/experiment/traitsui/traitsui/qt/ui_panel.py", line 270, in panel
    panel = _GroupPanel(content[0], ui).control
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cwebster/src/experiment/traitsui/traitsui/qt/ui_panel.py", line 621, in __init__
    layout = self._add_items(content, inner)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cwebster/src/experiment/traitsui/traitsui/qt/ui_panel.py", line 855, in _add_items
    editor = factory_method(
             ^^^^^^^^^^^^^^^
  File "/Users/cwebster/src/experiment/traitsui/traitsui/editor_factory.py", line 117, in simple_editor
    return self.simple_editor_class(
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cwebster/src/experiment/traitsui/traitsui/editor.py", line 540, in __init__
    self.old_value = getattr(self.object, self.name)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cwebster/src/experiment/chaco/temp/reported_errors.py", line 23, in _plot_default
    plot = Plot(plotdata)
           ^^^^^^^^^^^^^^
  File "/Users/cwebster/src/experiment/chaco/chaco/plot.py", line 198, in __init__
    super().__init__(**kwtraits)
  File "/Users/cwebster/src/experiment/chaco/chaco/data_view.py", line 298, in __init__
    self._init_components()
  File "/Users/cwebster/src/experiment/chaco/chaco/data_view.py", line 361, in _init_components
    if color_table[self.bgcolor] == color_table[grid_color]:
       ~~~~~~~~~~~^^^^^^^^^^^^^^
KeyError: (1.0, 1.0, 0.9)

Proximate cause seems to be code which is trying to ensure that grids can be seen against the background.

Reproduction Steps:

Create a Plot instance with a bgcolor which is a RGB(A) tuple

Plot(bgcolor=(1.0, 1.0, 0.9))

Expected behavior:

Should set the color to the specified tuple.

OS, Python version: All

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions