Skip to content

Add opacity to null-toolkit-defined rgba_color_trait#374

Merged
corranwebster merged 1 commit into
masterfrom
fix/rgba_color_trait_opacity
Feb 15, 2020
Merged

Add opacity to null-toolkit-defined rgba_color_trait#374
corranwebster merged 1 commit into
masterfrom
fix/rgba_color_trait_opacity

Conversation

@ZachPope531

Copy link
Copy Markdown
Contributor

If ETSConfig.toolkit is not wx or qt4, the alpha channel of rgba_color is not available. This patch defaults the opacity to 1.0 in that case.
You can reproduce the bug by running

from enable.trait_defs.rgba_color_trait import rgba_color
from traits.etsconfig.api import ETSConfig

ETSConfig.toolkit = ''
print(rgba_color(255)[3])  # Throws IndexError, should be alpha channel

If ETSConfig.toolkit is not `wx` or `qt4`, the alpha channel of `rgba_color` is not available. This patch defaults the opacity to 1.0 in that case.
You can reproduce the bug by running 
```
from enable.trait_defs.rgba_color_trait import rgba_color
from traits.etsconfig.api import ETSConfig

ETSConfig.toolkit = ''
print(rgba_color(255)[3])  # Throws IndexError, should be alpha channel
```
@corranwebster

Copy link
Copy Markdown
Contributor

I'm curious about the use case: most of the time Enable/Chaco uses enable.colors.ColorTraitor one of its specializations such as black_color_trait. The RGBAColor and related classes and values are only used in situations where you expect to have a UI.

@codecov-io

codecov-io commented Nov 26, 2019

Copy link
Copy Markdown

Codecov Report

Merging #374 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #374   +/-   ##
=======================================
  Coverage   33.33%   33.33%           
=======================================
  Files         206      206           
  Lines       18273    18273           
  Branches     2470     2470           
=======================================
  Hits         6091     6091           
  Misses      11789    11789           
  Partials      393      393
Impacted Files Coverage Δ
enable/trait_defs/rgba_color_trait.py 0% <ø> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a88911f...6386ad7. Read the comment docs.

@rkern

rkern commented Dec 14, 2019

Copy link
Copy Markdown
Member
  1. The code in master is simply buggy and does not implement what it promises.
  2. RGBAColor is used elsewhere to represent RGBA colors in models, even when enable isn't used (because it's the one color trait that actually implements the alpha channel).
  3. Even enable needs to run with the null TraitsUI/PyFace toolkit in order to make static PNGs, etc.

This particular bug was evoked because the code managed to import this module before importing TraitsUI/PyFace/etc. that actually picked a backend. It was worked around by setting ETS_TOOLKIT to enforce the desired toolkit on app start, which is good, but the code in master is still buggy.

@corranwebster corranwebster merged commit 92f797b into master Feb 15, 2020
@corranwebster corranwebster deleted the fix/rgba_color_trait_opacity branch February 15, 2020 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants