Skip to content

issue 18 : Inverted background colors #64

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

Merged
merged 2 commits into from
Sep 11, 2017
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
28 changes: 9 additions & 19 deletions larray_editor/arraymodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np

from larray_editor.utils import (get_font, from_qvariant, to_qvariant, to_text_string,
is_float, is_number, SUPPORTED_FORMATS)
is_float, is_number, LinearGradient, SUPPORTED_FORMATS)

from qtpy.QtCore import Qt, QModelIndex, QAbstractTableModel
from qtpy.QtGui import QColor
Expand Down Expand Up @@ -217,19 +217,10 @@ def __init__(self, parent=None, data=None, readonly=False, format="%.3f", font=N
AbstractArrayModel.__init__(self, parent, data, readonly, font)
self._format = format

# Backgroundcolor settings
# TODO: use LinearGradient
# self.bgfunc = bgfunc
huerange = [.66, .99] # Hue
self.sat = .7 # Saturation
self.val = 1. # Value
self.alp = .6 # Alpha-channel
self.hue0 = huerange[0]
self.dhue = huerange[1] - huerange[0]
# Backgroundcolor settings (HSV --> Hue, Saturation, Value, Alpha-channel)
self.hsv_min = [0.99, 0.7, 1.0, 0.6]
self.hsv_max = [0.66, 0.7, 1.0, 0.6]
self.bgcolor_enabled = True
# hue = self.hue0
# color = QColor.fromHsvF(hue, self.sat, self.val, self.alp)
# self.color = to_qvariant(color)

self.minvalue = minvalue
self.maxvalue = maxvalue
Expand Down Expand Up @@ -293,11 +284,14 @@ def reset_minmax(self):
if self.vmax == self.vmin:
self.vmin -= 1
self.bgcolor_enabled = True
self.bg_gradient = LinearGradient([(self.vmin, self.hsv_min), (self.vmax, self.hsv_max)])

# ValueError for empty arrays
except (TypeError, ValueError):
self.vmin = None
self.vmax = None
self.bgcolor_enabled = False
self.bg_gradient = None

def set_format(self, format):
"""Change display format"""
Expand Down Expand Up @@ -352,12 +346,8 @@ def data(self, index, role=Qt.DisplayRole):
return to_qvariant(self._format % value)
elif role == Qt.BackgroundColorRole:
if self.bgcolor_enabled and value is not np.ma.masked:
if self.bg_gradient is None:
maxdiff = self.vmax - self.vmin
color_val = float(self.color_func(value))
hue = self.hue0 + self.dhue * (self.vmax - color_val) / maxdiff
color = QColor.fromHsvF(hue, self.sat, self.val, self.alp)
return to_qvariant(color)
if self.bg_value is None:
return self.bg_gradient[float(self.color_func(value))]
else:
bg_value = self.bg_value
x, y = index.row(), index.column()
Expand Down
16 changes: 8 additions & 8 deletions larray_editor/comparator.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ def setup_and_check(self, arrays, names, title=''):
else:
# all 0.5 (white)
bg_value = full_like(diff, 0.5)
gradient = LinearGradient([(0, [.66, .85, 1., .6]),
(0.5 - 1e-16, [.66, .15, 1., .6]),
gradient = LinearGradient([(0, [.99, .85, 1., .6]),
(0.5 - 1e-16, [.99, .15, 1., .6]),
(0.5, [1., 0., 1., 1.]),
(0.5 + 1e-16, [.99, .15, 1., .6]),
(1, [.99, .85, 1., .6])])
(0.5 + 1e-16, [.66, .15, 1., .6]),
(1, [.66, .85, 1., .6])])

self.arraywidget = ArrayEditorWidget(self, self.array, readonly=True,
bg_value=bg_value,
Expand Down Expand Up @@ -105,11 +105,11 @@ def __init__(self, parent=None):
self.names = None
self.arraywidget = None
self.maxdiff_label = None
self.gradient = LinearGradient([(0, [.66, .85, 1., .6]),
(0.5 - 1e-16, [.66, .15, 1., .6]),
self.gradient = LinearGradient([(0, [.99, .85, 1., .6]),
(0.5 - 1e-16, [.99, .15, 1., .6]),
(0.5, [1., 0., 1., 1.]),
(0.5 + 1e-16, [.99, .15, 1., .6]),
(1, [.99, .85, 1., .6])])
(0.5 + 1e-16, [.66, .15, 1., .6]),
(1, [.66, .85, 1., .6])])

def setup_and_check(self, sessions, names, title=''):
"""
Expand Down
6 changes: 6 additions & 0 deletions larray_editor/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ class LinearGradient(object):
I cannot believe I had to roll my own class for this when PyQt already
contains QLinearGradient... but you cannot get intermediate values out of
QLinearGradient!

Parameters
----------
stop_points: list/tuple, optional
List containing pairs (stop_position, colors_HsvF).
`colors` is a 4 elements list containing `hue`, `saturation`, `value` and `alpha-channel`
"""
def __init__(self, stop_points=None):
if stop_points is None:
Expand Down