use QColor methods and functions
This commit is contained in:
parent
4bf1866c2a
commit
efa662415e
|
@ -34,12 +34,6 @@ Qt uses the classes QColor, QPen, and QBrush to determine how to draw lines and
|
||||||
|
|
||||||
.. autofunction:: pyqtgraph.colorCIELab
|
.. autofunction:: pyqtgraph.colorCIELab
|
||||||
|
|
||||||
.. autofunction:: pyqtgraph.colorTuple
|
|
||||||
|
|
||||||
.. autofunction:: pyqtgraph.colorStr
|
|
||||||
|
|
||||||
.. autofunction:: pyqtgraph.glColor
|
|
||||||
|
|
||||||
.. autofunction:: pyqtgraph.colorDistance
|
.. autofunction:: pyqtgraph.colorDistance
|
||||||
|
|
||||||
|
|
||||||
|
@ -108,3 +102,16 @@ Miscellaneous Functions
|
||||||
.. autofunction:: pyqtgraph.systemInfo
|
.. autofunction:: pyqtgraph.systemInfo
|
||||||
|
|
||||||
.. autofunction:: pyqtgraph.exit
|
.. autofunction:: pyqtgraph.exit
|
||||||
|
|
||||||
|
|
||||||
|
Legacy Color Helper Functions
|
||||||
|
-------------------------------
|
||||||
|
|
||||||
|
The following helper functions should no longer be used. The functionality that they implement is trivial and it is suggested that the user use the equivalent QColor methods directly.
|
||||||
|
|
||||||
|
|
||||||
|
.. autofunction:: pyqtgraph.colorTuple
|
||||||
|
|
||||||
|
.. autofunction:: pyqtgraph.colorStr
|
||||||
|
|
||||||
|
.. autofunction:: pyqtgraph.glColor
|
||||||
|
|
|
@ -6,7 +6,6 @@ Demonstrate use of GLLinePlotItem to draw cross-sections of a surface.
|
||||||
## Add path to library (just for examples; you do not need this)
|
## Add path to library (just for examples; you do not need this)
|
||||||
import initExample
|
import initExample
|
||||||
|
|
||||||
from pyqtgraph.Qt import QtCore, QtGui
|
|
||||||
import pyqtgraph.opengl as gl
|
import pyqtgraph.opengl as gl
|
||||||
import pyqtgraph as pg
|
import pyqtgraph as pg
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
@ -37,7 +36,7 @@ for i in range(n):
|
||||||
d = np.hypot(x, yi)
|
d = np.hypot(x, yi)
|
||||||
z = 10 * np.cos(d) / (d+1)
|
z = 10 * np.cos(d) / (d+1)
|
||||||
pts = np.column_stack([x, np.full_like(x, yi), z])
|
pts = np.column_stack([x, np.full_like(x, yi), z])
|
||||||
plt = gl.GLLinePlotItem(pos=pts, color=pg.glColor((i,n*1.3)), width=(i+1)/10., antialias=True)
|
plt = gl.GLLinePlotItem(pos=pts, color=pg.mkColor((i,n*1.3)), width=(i+1)/10., antialias=True)
|
||||||
w.addItem(plt)
|
w.addItem(plt)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
@ -249,8 +249,7 @@ def makeHslCycle( hue=0.0, saturation=1.0, lightness=0.5, steps=36 ):
|
||||||
lgt_vals = np.linspace(lgtA, lgtB, num=steps+1)
|
lgt_vals = np.linspace(lgtA, lgtB, num=steps+1)
|
||||||
color_list = []
|
color_list = []
|
||||||
for hue, sat, lgt in zip( hue_vals, sat_vals, lgt_vals):
|
for hue, sat, lgt in zip( hue_vals, sat_vals, lgt_vals):
|
||||||
qcol = QtGui.QColor()
|
qcol = QtGui.QColor.fromHslF( hue%1.0, sat, lgt )
|
||||||
qcol.setHslF( hue%1.0, sat, lgt )
|
|
||||||
color_list.append( qcol )
|
color_list.append( qcol )
|
||||||
name = f'Hue {hueA:0.2f}-{hueB:0.2f}'
|
name = f'Hue {hueA:0.2f}-{hueB:0.2f}'
|
||||||
return ColorMap( None, color_list, name=name )
|
return ColorMap( None, color_list, name=name )
|
||||||
|
@ -311,8 +310,7 @@ def makeMonochrome(color='neutral'):
|
||||||
l_vals = np.linspace(l_min, l_max, num=16)
|
l_vals = np.linspace(l_min, l_max, num=16)
|
||||||
color_list = []
|
color_list = []
|
||||||
for l_val in l_vals:
|
for l_val in l_vals:
|
||||||
qcol = QtGui.QColor()
|
qcol = QtGui.QColor.fromHslF( h_val, s_val, l_val )
|
||||||
qcol.setHslF( h_val, s_val, l_val )
|
|
||||||
color_list.append( qcol )
|
color_list.append( qcol )
|
||||||
return ColorMap( None, color_list, name=name, linearize=True )
|
return ColorMap( None, color_list, name=name, linearize=True )
|
||||||
|
|
||||||
|
@ -581,7 +579,7 @@ class ColorMap(object):
|
||||||
mode = self.enumMap[mode.lower()]
|
mode = self.enumMap[mode.lower()]
|
||||||
|
|
||||||
if mode == self.QCOLOR:
|
if mode == self.QCOLOR:
|
||||||
pos, color = self.getStops(self.BYTE)
|
pos, color = self.getStops(self.FLOAT)
|
||||||
else:
|
else:
|
||||||
pos, color = self.getStops(mode)
|
pos, color = self.getStops(mode)
|
||||||
|
|
||||||
|
@ -606,9 +604,9 @@ class ColorMap(object):
|
||||||
# Convert to QColor if requested
|
# Convert to QColor if requested
|
||||||
if mode == self.QCOLOR:
|
if mode == self.QCOLOR:
|
||||||
if np.isscalar(data):
|
if np.isscalar(data):
|
||||||
return QtGui.QColor(*interp)
|
return QtGui.QColor.fromRgbF(*interp)
|
||||||
else:
|
else:
|
||||||
return [QtGui.QColor(*x.tolist()) for x in interp]
|
return [QtGui.QColor.fromRgbF(*x.tolist()) for x in interp]
|
||||||
else:
|
else:
|
||||||
return interp
|
return interp
|
||||||
|
|
||||||
|
@ -762,8 +760,10 @@ class ColorMap(object):
|
||||||
color = color.astype(float) / 255.
|
color = color.astype(float) / 255.
|
||||||
elif mode == self.QCOLOR:
|
elif mode == self.QCOLOR:
|
||||||
if color.dtype.kind == 'f':
|
if color.dtype.kind == 'f':
|
||||||
color = (color*255).astype(np.ubyte)
|
factory = QtGui.QColor.fromRgbF
|
||||||
color = [QtGui.QColor(*x.tolist()) for x in color]
|
else:
|
||||||
|
factory = QtGui.QColor.fromRgb
|
||||||
|
color = [factory(*x.tolist()) for x in color]
|
||||||
self.stopsCache[mode] = (self.pos, color)
|
self.stopsCache[mode] = (self.pos, color)
|
||||||
return self.stopsCache[mode]
|
return self.stopsCache[mode]
|
||||||
|
|
||||||
|
|
|
@ -95,19 +95,19 @@ class MatplotlibExporter(Exporter):
|
||||||
linestyle = ''
|
linestyle = ''
|
||||||
else:
|
else:
|
||||||
linestyle = '-'
|
linestyle = '-'
|
||||||
color = tuple([c/255. for c in fn.colorTuple(pen.color())])
|
color = pen.color().getRgbF()
|
||||||
symbol = opts['symbol']
|
symbol = opts['symbol']
|
||||||
if symbol == 't':
|
if symbol == 't':
|
||||||
symbol = '^'
|
symbol = '^'
|
||||||
symbolPen = fn.mkPen(opts['symbolPen'])
|
symbolPen = fn.mkPen(opts['symbolPen'])
|
||||||
symbolBrush = fn.mkBrush(opts['symbolBrush'])
|
symbolBrush = fn.mkBrush(opts['symbolBrush'])
|
||||||
markeredgecolor = tuple([c/255. for c in fn.colorTuple(symbolPen.color())])
|
markeredgecolor = symbolPen.color().getRgbF()
|
||||||
markerfacecolor = tuple([c/255. for c in fn.colorTuple(symbolBrush.color())])
|
markerfacecolor = symbolBrush.color().getRgbF()
|
||||||
markersize = opts['symbolSize']
|
markersize = opts['symbolSize']
|
||||||
|
|
||||||
if opts['fillLevel'] is not None and opts['fillBrush'] is not None:
|
if opts['fillLevel'] is not None and opts['fillBrush'] is not None:
|
||||||
fillBrush = fn.mkBrush(opts['fillBrush'])
|
fillBrush = fn.mkBrush(opts['fillBrush'])
|
||||||
fillcolor = tuple([c/255. for c in fn.colorTuple(fillBrush.color())])
|
fillcolor = fillBrush.color().getRgbF()
|
||||||
ax.fill_between(x=x, y1=y, y2=opts['fillLevel'], facecolor=fillcolor)
|
ax.fill_between(x=x, y1=y, y2=opts['fillLevel'], facecolor=fillcolor)
|
||||||
|
|
||||||
pl = ax.plot(x, y, marker=symbol, color=color, linewidth=pen.width(),
|
pl = ax.plot(x, y, marker=symbol, color=color, linewidth=pen.width(),
|
||||||
|
|
|
@ -224,7 +224,7 @@ class Color(QtGui.QColor):
|
||||||
|
|
||||||
def glColor(self):
|
def glColor(self):
|
||||||
"""Return (r,g,b,a) normalized for use in opengl"""
|
"""Return (r,g,b,a) normalized for use in opengl"""
|
||||||
return (self.red()/255., self.green()/255., self.blue()/255., self.alpha()/255.)
|
return self.getRgbF()
|
||||||
|
|
||||||
def __getitem__(self, ind):
|
def __getitem__(self, ind):
|
||||||
return (self.red, self.green, self.blue, self.alpha)[ind]()
|
return (self.red, self.green, self.blue, self.alpha)[ind]()
|
||||||
|
@ -390,9 +390,7 @@ def mkPen(*args, **kargs):
|
||||||
|
|
||||||
def hsvColor(hue, sat=1.0, val=1.0, alpha=1.0):
|
def hsvColor(hue, sat=1.0, val=1.0, alpha=1.0):
|
||||||
"""Generate a QColor from HSVa values. (all arguments are float 0.0-1.0)"""
|
"""Generate a QColor from HSVa values. (all arguments are float 0.0-1.0)"""
|
||||||
c = QtGui.QColor()
|
return QtGui.QColor.fromHsvF(hue, sat, val, alpha)
|
||||||
c.setHsvF(hue, sat, val, alpha)
|
|
||||||
return c
|
|
||||||
|
|
||||||
# Matrices and math taken from "CIELab Color Space" by Gernot Hoffmann
|
# Matrices and math taken from "CIELab Color Space" by Gernot Hoffmann
|
||||||
# http://docs-hoffmann.de/cielab03022003.pdf
|
# http://docs-hoffmann.de/cielab03022003.pdf
|
||||||
|
@ -475,10 +473,7 @@ def CIELabColor(L, a, b, alpha=1.0):
|
||||||
else:
|
else:
|
||||||
arr_sRGB[idx] = 12.92 * val # (s)
|
arr_sRGB[idx] = 12.92 * val # (s)
|
||||||
arr_sRGB = clip_array( arr_sRGB, 0.0, 1.0 ) # avoid QColor errors
|
arr_sRGB = clip_array( arr_sRGB, 0.0, 1.0 ) # avoid QColor errors
|
||||||
qcol = QtGui.QColor()
|
return QtGui.QColor.fromRgbF( *arr_sRGB, alpha )
|
||||||
qcol.setRgbF( *arr_sRGB )
|
|
||||||
if alpha < 1.0: qcol.setAlpha(alpha)
|
|
||||||
return qcol
|
|
||||||
|
|
||||||
def colorCIELab(qcol):
|
def colorCIELab(qcol):
|
||||||
"""
|
"""
|
||||||
|
@ -555,7 +550,7 @@ def colorDistance(colors, metric='CIE76'):
|
||||||
|
|
||||||
def colorTuple(c):
|
def colorTuple(c):
|
||||||
"""Return a tuple (R,G,B,A) from a QColor"""
|
"""Return a tuple (R,G,B,A) from a QColor"""
|
||||||
return (c.red(), c.green(), c.blue(), c.alpha())
|
return c.getRgb()
|
||||||
|
|
||||||
def colorStr(c):
|
def colorStr(c):
|
||||||
"""Generate a hex string code from a QColor"""
|
"""Generate a hex string code from a QColor"""
|
||||||
|
@ -581,10 +576,7 @@ def intColor(index, hues=9, values=1, maxValue=255, minValue=150, maxHue=360, mi
|
||||||
v = maxValue
|
v = maxValue
|
||||||
h = minHue + (indh * (maxHue-minHue)) // hues
|
h = minHue + (indh * (maxHue-minHue)) // hues
|
||||||
|
|
||||||
c = QtGui.QColor()
|
return QtGui.QColor.fromHsv(h, sat, v, alpha)
|
||||||
c.setHsv(h, sat, v)
|
|
||||||
c.setAlpha(alpha)
|
|
||||||
return c
|
|
||||||
|
|
||||||
|
|
||||||
def glColor(*args, **kargs):
|
def glColor(*args, **kargs):
|
||||||
|
@ -593,7 +585,7 @@ def glColor(*args, **kargs):
|
||||||
Accepts same arguments as :func:`mkColor <pyqtgraph.mkColor>`.
|
Accepts same arguments as :func:`mkColor <pyqtgraph.mkColor>`.
|
||||||
"""
|
"""
|
||||||
c = mkColor(*args, **kargs)
|
c = mkColor(*args, **kargs)
|
||||||
return (c.red()/255., c.green()/255., c.blue()/255., c.alpha()/255.)
|
return c.getRgbF()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -433,7 +433,7 @@ class AxisItem(GraphicsWidget):
|
||||||
self._pen = fn.mkPen(*args, **kwargs)
|
self._pen = fn.mkPen(*args, **kwargs)
|
||||||
else:
|
else:
|
||||||
self._pen = fn.mkPen(getConfigOption('foreground'))
|
self._pen = fn.mkPen(getConfigOption('foreground'))
|
||||||
self.labelStyle['color'] = '#' + fn.colorStr(self._pen.color())[:6]
|
self.labelStyle['color'] = self._pen.color().name() # #RRGGBB
|
||||||
self._updateLabel()
|
self._updateLabel()
|
||||||
|
|
||||||
def textPen(self):
|
def textPen(self):
|
||||||
|
@ -451,7 +451,7 @@ class AxisItem(GraphicsWidget):
|
||||||
self._textPen = fn.mkPen(*args, **kwargs)
|
self._textPen = fn.mkPen(*args, **kwargs)
|
||||||
else:
|
else:
|
||||||
self._textPen = fn.mkPen(getConfigOption('foreground'))
|
self._textPen = fn.mkPen(getConfigOption('foreground'))
|
||||||
self.labelStyle['color'] = '#' + fn.colorStr(self._textPen.color())[:6]
|
self.labelStyle['color'] = self._textPen.color().name() # #RRGGBB
|
||||||
self._updateLabel()
|
self._updateLabel()
|
||||||
|
|
||||||
def setScale(self, scale=None):
|
def setScale(self, scale=None):
|
||||||
|
|
|
@ -581,7 +581,7 @@ class GradientEditorItem(TickSliderItem):
|
||||||
for t,x in self.listTicks():
|
for t,x in self.listTicks():
|
||||||
pos.append(x)
|
pos.append(x)
|
||||||
c = t.color
|
c = t.color
|
||||||
color.append([c.red(), c.green(), c.blue(), c.alpha()])
|
color.append(c.getRgb())
|
||||||
return ColorMap(np.array(pos), np.array(color, dtype=np.ubyte))
|
return ColorMap(np.array(pos), np.array(color, dtype=np.ubyte))
|
||||||
|
|
||||||
def updateGradient(self):
|
def updateGradient(self):
|
||||||
|
@ -671,13 +671,13 @@ class GradientEditorItem(TickSliderItem):
|
||||||
if toQColor:
|
if toQColor:
|
||||||
return QtGui.QColor(c) # always copy colors before handing them out
|
return QtGui.QColor(c) # always copy colors before handing them out
|
||||||
else:
|
else:
|
||||||
return (c.red(), c.green(), c.blue(), c.alpha())
|
return c.getRgb()
|
||||||
if x >= ticks[-1][1]:
|
if x >= ticks[-1][1]:
|
||||||
c = ticks[-1][0].color
|
c = ticks[-1][0].color
|
||||||
if toQColor:
|
if toQColor:
|
||||||
return QtGui.QColor(c) # always copy colors before handing them out
|
return QtGui.QColor(c) # always copy colors before handing them out
|
||||||
else:
|
else:
|
||||||
return (c.red(), c.green(), c.blue(), c.alpha())
|
return c.getRgb()
|
||||||
|
|
||||||
x2 = ticks[0][1]
|
x2 = ticks[0][1]
|
||||||
for i in range(1,len(ticks)):
|
for i in range(1,len(ticks)):
|
||||||
|
@ -708,12 +708,11 @@ class GradientEditorItem(TickSliderItem):
|
||||||
h = h1 * (1.-f) + h2 * f
|
h = h1 * (1.-f) + h2 * f
|
||||||
s = s1 * (1.-f) + s2 * f
|
s = s1 * (1.-f) + s2 * f
|
||||||
v = v1 * (1.-f) + v2 * f
|
v = v1 * (1.-f) + v2 * f
|
||||||
c = QtGui.QColor()
|
c = QtGui.QColor.fromHsv(int(h), int(s), int(v))
|
||||||
c.setHsv(*map(int, [h,s,v]))
|
|
||||||
if toQColor:
|
if toQColor:
|
||||||
return c
|
return c
|
||||||
else:
|
else:
|
||||||
return (c.red(), c.green(), c.blue(), c.alpha())
|
return c.getRgb()
|
||||||
|
|
||||||
def getLookupTable(self, nPts, alpha=None):
|
def getLookupTable(self, nPts, alpha=None):
|
||||||
"""
|
"""
|
||||||
|
@ -757,8 +756,8 @@ class GradientEditorItem(TickSliderItem):
|
||||||
return False
|
return False
|
||||||
if ticks[0][1] != 0.0 or ticks[1][1] != 1.0:
|
if ticks[0][1] != 0.0 or ticks[1][1] != 1.0:
|
||||||
return False
|
return False
|
||||||
c1 = fn.colorTuple(ticks[0][0].color)
|
c1 = ticks[0][0].color.getRgb()
|
||||||
c2 = fn.colorTuple(ticks[1][0].color)
|
c2 = ticks[1][0].color.getRgb()
|
||||||
if c1 != (0,0,0,255) or c2 != (255,255,255,255):
|
if c1 != (0,0,0,255) or c2 != (255,255,255,255):
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
@ -794,7 +793,7 @@ class GradientEditorItem(TickSliderItem):
|
||||||
ticks = []
|
ticks = []
|
||||||
for t in self.ticks:
|
for t in self.ticks:
|
||||||
c = t.color
|
c = t.color
|
||||||
ticks.append((self.ticks[t], (c.red(), c.green(), c.blue(), c.alpha())))
|
ticks.append((self.ticks[t], c.getRgb()))
|
||||||
state = {'mode': self.colorMode,
|
state = {'mode': self.colorMode,
|
||||||
'ticks': ticks,
|
'ticks': ticks,
|
||||||
'ticksVisible': next(iter(self.ticks)).isVisible()}
|
'ticksVisible': next(iter(self.ticks)).isVisible()}
|
||||||
|
|
|
@ -56,7 +56,7 @@ class LabelItem(GraphicsWidget, GraphicsWidgetAnchor):
|
||||||
if color is None:
|
if color is None:
|
||||||
color = getConfigOption('foreground')
|
color = getConfigOption('foreground')
|
||||||
color = fn.mkColor(color)
|
color = fn.mkColor(color)
|
||||||
optlist.append('color: #' + fn.colorStr(color)[:6])
|
optlist.append('color: ' + color.name())
|
||||||
if 'size' in opts:
|
if 'size' in opts:
|
||||||
optlist.append('font-size: ' + opts['size'])
|
optlist.append('font-size: ' + opts['size'])
|
||||||
if 'bold' in opts and opts['bold'] in [True, False]:
|
if 'bold' in opts and opts['bold'] in [True, False]:
|
||||||
|
|
|
@ -620,8 +620,7 @@ class PlotCurveItem(GraphicsObject):
|
||||||
try:
|
try:
|
||||||
gl.glVertexPointerf(pos)
|
gl.glVertexPointerf(pos)
|
||||||
pen = fn.mkPen(self.opts['pen'])
|
pen = fn.mkPen(self.opts['pen'])
|
||||||
color = pen.color()
|
gl.glColor4f(*pen.color().getRgbF())
|
||||||
gl.glColor4f(color.red()/255., color.green()/255., color.blue()/255., color.alpha()/255.)
|
|
||||||
width = pen.width()
|
width = pen.width()
|
||||||
if pen.isCosmetic() and width < 1:
|
if pen.isCosmetic() and width < 1:
|
||||||
width = 1
|
width = 1
|
||||||
|
|
|
@ -763,9 +763,8 @@ class PlotItem(GraphicsWidget):
|
||||||
|
|
||||||
for item in self.curves:
|
for item in self.curves:
|
||||||
if isinstance(item, PlotCurveItem):
|
if isinstance(item, PlotCurveItem):
|
||||||
color = fn.colorStr(item.pen.color())
|
color = item.pen.color()
|
||||||
opacity = item.pen.color().alpha() / 255.
|
hrrggbb, opacity = color.name(), color.alphaF()
|
||||||
color = color[:6]
|
|
||||||
x, y = item.getData()
|
x, y = item.getData()
|
||||||
mask = (x > xRange[0]) * (x < xRange[1])
|
mask = (x > xRange[0]) * (x < xRange[1])
|
||||||
mask[:-1] += mask[1:]
|
mask[:-1] += mask[1:]
|
||||||
|
@ -780,9 +779,9 @@ class PlotItem(GraphicsWidget):
|
||||||
# fh.write('<g fill="none" stroke="#%s" '
|
# fh.write('<g fill="none" stroke="#%s" '
|
||||||
# 'stroke-opacity="1" stroke-width="1">\n' % (
|
# 'stroke-opacity="1" stroke-width="1">\n' % (
|
||||||
# color, ))
|
# color, ))
|
||||||
fh.write('<path fill="none" stroke="#%s" '
|
fh.write('<path fill="none" stroke="%s" '
|
||||||
'stroke-opacity="%f" stroke-width="1" '
|
'stroke-opacity="%f" stroke-width="1" '
|
||||||
'd="M%f,%f ' % (color, opacity, x[0], y[0]))
|
'd="M%f,%f ' % (hrrggbb, opacity, x[0], y[0]))
|
||||||
for i in range(1, len(x)):
|
for i in range(1, len(x)):
|
||||||
fh.write('L%f,%f ' % (x[i], y[i]))
|
fh.write('L%f,%f ' % (x[i], y[i]))
|
||||||
|
|
||||||
|
@ -798,15 +797,14 @@ class PlotItem(GraphicsWidget):
|
||||||
pos = point.pos()
|
pos = point.pos()
|
||||||
if not rect.contains(pos):
|
if not rect.contains(pos):
|
||||||
continue
|
continue
|
||||||
color = fn.colorStr(point.brush.color())
|
color = point.brush.color()
|
||||||
opacity = point.brush.color().alpha() / 255.
|
hrrggbb, opacity = color.name(), color.alphaF()
|
||||||
color = color[:6]
|
|
||||||
x = pos.x() * sx
|
x = pos.x() * sx
|
||||||
y = pos.y() * sy
|
y = pos.y() * sy
|
||||||
|
|
||||||
fh.write('<circle cx="%f" cy="%f" r="1" fill="#%s" '
|
fh.write('<circle cx="%f" cy="%f" r="1" fill="%s" '
|
||||||
'stroke="none" fill-opacity="%f"/>\n' % (
|
'stroke="none" fill-opacity="%f"/>\n' % (
|
||||||
x, y, color, opacity))
|
x, y, hrrggbb, opacity))
|
||||||
|
|
||||||
fh.write("</svg>\n")
|
fh.write("</svg>\n")
|
||||||
|
|
||||||
|
|
|
@ -138,9 +138,9 @@ class GLViewWidget(QtWidgets.QOpenGLWidget):
|
||||||
def setBackgroundColor(self, *args, **kwds):
|
def setBackgroundColor(self, *args, **kwds):
|
||||||
"""
|
"""
|
||||||
Set the background color of the widget. Accepts the same arguments as
|
Set the background color of the widget. Accepts the same arguments as
|
||||||
pg.mkColor() and pg.glColor().
|
:func:`~pyqtgraph.mkColor`.
|
||||||
"""
|
"""
|
||||||
self.opts['bgcolor'] = fn.glColor(*args, **kwds)
|
self.opts['bgcolor'] = fn.mkColor(*args, **kwds).getRgbF()
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
def getViewport(self):
|
def getViewport(self):
|
||||||
|
|
|
@ -38,7 +38,7 @@ class GLBoxItem(GLGraphicsItem):
|
||||||
|
|
||||||
def setColor(self, *args):
|
def setColor(self, *args):
|
||||||
"""Set the color of the box. Arguments are the same as those accepted by functions.mkColor()"""
|
"""Set the color of the box. Arguments are the same as those accepted by functions.mkColor()"""
|
||||||
self.__color = fn.Color(*args)
|
self.__color = fn.mkColor(*args)
|
||||||
|
|
||||||
def color(self):
|
def color(self):
|
||||||
return self.__color
|
return self.__color
|
||||||
|
@ -54,7 +54,7 @@ class GLBoxItem(GLGraphicsItem):
|
||||||
|
|
||||||
glBegin( GL_LINES )
|
glBegin( GL_LINES )
|
||||||
|
|
||||||
glColor4f(*self.color().glColor())
|
glColor4f(*self.color().getRgbF())
|
||||||
x,y,z = self.size()
|
x,y,z = self.size()
|
||||||
glVertex3f(0, 0, 0)
|
glVertex3f(0, 0, 0)
|
||||||
glVertex3f(0, 0, z)
|
glVertex3f(0, 0, z)
|
||||||
|
|
|
@ -56,7 +56,7 @@ class GLGridItem(GLGraphicsItem):
|
||||||
|
|
||||||
def setColor(self, color):
|
def setColor(self, color):
|
||||||
"""Set the color of the grid. Arguments are the same as those accepted by functions.mkColor()"""
|
"""Set the color of the grid. Arguments are the same as those accepted by functions.mkColor()"""
|
||||||
self.__color = fn.Color(color)
|
self.__color = fn.mkColor(color)
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
def color(self):
|
def color(self):
|
||||||
|
@ -77,7 +77,7 @@ class GLGridItem(GLGraphicsItem):
|
||||||
xs,ys,zs = self.spacing()
|
xs,ys,zs = self.spacing()
|
||||||
xvals = np.arange(-x/2., x/2. + xs*0.001, xs)
|
xvals = np.arange(-x/2., x/2. + xs*0.001, xs)
|
||||||
yvals = np.arange(-y/2., y/2. + ys*0.001, ys)
|
yvals = np.arange(-y/2., y/2. + ys*0.001, ys)
|
||||||
glColor4f(*self.color().glColor())
|
glColor4f(*self.color().getRgbF())
|
||||||
for x in xvals:
|
for x in xvals:
|
||||||
glVertex3f(x, yvals[0], 0)
|
glVertex3f(x, yvals[0], 0)
|
||||||
glVertex3f(x, yvals[-1], 0)
|
glVertex3f(x, yvals[-1], 0)
|
||||||
|
|
|
@ -66,10 +66,12 @@ class GLLinePlotItem(GLGraphicsItem):
|
||||||
glEnableClientState(GL_COLOR_ARRAY)
|
glEnableClientState(GL_COLOR_ARRAY)
|
||||||
glColorPointerf(self.color)
|
glColorPointerf(self.color)
|
||||||
else:
|
else:
|
||||||
if isinstance(self.color, (str, QtGui.QColor)):
|
color = self.color
|
||||||
glColor4f(*fn.glColor(self.color))
|
if isinstance(color, str):
|
||||||
else:
|
color = fn.mkColor(color)
|
||||||
glColor4f(*self.color)
|
if isinstance(color, QtGui.QColor):
|
||||||
|
color = color.getRgbF()
|
||||||
|
glColor4f(*color)
|
||||||
glLineWidth(self.width)
|
glLineWidth(self.width)
|
||||||
|
|
||||||
if self.antialias:
|
if self.antialias:
|
||||||
|
|
|
@ -3,7 +3,6 @@ from .. GLGraphicsItem import GLGraphicsItem
|
||||||
from .. MeshData import MeshData
|
from .. MeshData import MeshData
|
||||||
from ...Qt import QtGui
|
from ...Qt import QtGui
|
||||||
from .. import shaders
|
from .. import shaders
|
||||||
from ... import functions as fn
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
|
|
||||||
|
@ -181,7 +180,7 @@ class GLMeshItem(GLGraphicsItem):
|
||||||
if self.colors is None:
|
if self.colors is None:
|
||||||
color = self.opts['color']
|
color = self.opts['color']
|
||||||
if isinstance(color, QtGui.QColor):
|
if isinstance(color, QtGui.QColor):
|
||||||
glColor4f(*fn.glColor(color))
|
glColor4f(*color.getRgbF())
|
||||||
else:
|
else:
|
||||||
glColor4f(*color)
|
glColor4f(*color)
|
||||||
else:
|
else:
|
||||||
|
@ -213,7 +212,7 @@ class GLMeshItem(GLGraphicsItem):
|
||||||
if self.edgeColors is None:
|
if self.edgeColors is None:
|
||||||
color = self.opts['edgeColor']
|
color = self.opts['edgeColor']
|
||||||
if isinstance(color, QtGui.QColor):
|
if isinstance(color, QtGui.QColor):
|
||||||
glColor4f(*fn.glColor(color))
|
glColor4f(*color.getRgbF())
|
||||||
else:
|
else:
|
||||||
glColor4f(*color)
|
glColor4f(*color)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -126,10 +126,10 @@ class GLScatterPlotItem(GLGraphicsItem):
|
||||||
glEnableClientState(GL_COLOR_ARRAY)
|
glEnableClientState(GL_COLOR_ARRAY)
|
||||||
glColorPointerf(self.color)
|
glColorPointerf(self.color)
|
||||||
else:
|
else:
|
||||||
if isinstance(self.color, QtGui.QColor):
|
color = self.color
|
||||||
glColor4f(*fn.glColor(self.color))
|
if isinstance(color, QtGui.QColor):
|
||||||
else:
|
color = color.getRgbF()
|
||||||
glColor4f(*self.color)
|
glColor4f(*color)
|
||||||
|
|
||||||
if not self.pxMode or isinstance(self.size, np.ndarray):
|
if not self.pxMode or isinstance(self.size, np.ndarray):
|
||||||
glEnableClientState(GL_NORMAL_ARRAY)
|
glEnableClientState(GL_NORMAL_ARRAY)
|
||||||
|
|
|
@ -27,5 +27,5 @@ class ColorParameter(SimpleParameter):
|
||||||
|
|
||||||
def saveState(self, filter=None):
|
def saveState(self, filter=None):
|
||||||
state = super().saveState(filter)
|
state = super().saveState(filter)
|
||||||
state['value'] = fn.colorTuple(self.value())
|
state['value'] = self.value().getRgb()
|
||||||
return state
|
return state
|
||||||
|
|
|
@ -72,7 +72,7 @@ class ColorButton(QtGui.QPushButton):
|
||||||
self.setColor(self._color, finished=True)
|
self.setColor(self._color, finished=True)
|
||||||
|
|
||||||
def saveState(self):
|
def saveState(self):
|
||||||
return functions.colorTuple(self._color)
|
return self._color.getRgb()
|
||||||
|
|
||||||
def restoreState(self, state):
|
def restoreState(self, state):
|
||||||
self.setColor(state)
|
self.setColor(state)
|
||||||
|
@ -82,9 +82,9 @@ class ColorButton(QtGui.QPushButton):
|
||||||
if mode == 'qcolor':
|
if mode == 'qcolor':
|
||||||
return color
|
return color
|
||||||
elif mode == 'byte':
|
elif mode == 'byte':
|
||||||
return (color.red(), color.green(), color.blue(), color.alpha())
|
return color.getRgb()
|
||||||
elif mode == 'float':
|
elif mode == 'float':
|
||||||
return (color.red()/255., color.green()/255., color.blue()/255., color.alpha()/255.)
|
return color.getRgbF()
|
||||||
|
|
||||||
def widgetGroupInterface(self):
|
def widgetGroupInterface(self):
|
||||||
return (self.sigColorChanged, ColorButton.saveState, ColorButton.restoreState)
|
return (self.sigColorChanged, ColorButton.saveState, ColorButton.restoreState)
|
||||||
|
|
|
@ -217,7 +217,7 @@ class RangeColorMapItem(ptree.types.SimpleParameter):
|
||||||
|
|
||||||
mask = np.invert(np.isfinite(data))
|
mask = np.invert(np.isfinite(data))
|
||||||
nanColor = self['NaN']
|
nanColor = self['NaN']
|
||||||
nanColor = (nanColor.red()/255., nanColor.green()/255., nanColor.blue()/255., nanColor.alpha()/255.)
|
nanColor = nanColor.getRgbF()
|
||||||
colors[mask] = nanColor
|
colors[mask] = nanColor
|
||||||
|
|
||||||
return colors
|
return colors
|
||||||
|
@ -254,12 +254,12 @@ class EnumColorMapItem(ptree.types.GroupParameter):
|
||||||
def map(self, data):
|
def map(self, data):
|
||||||
data = data[self.fieldName]
|
data = data[self.fieldName]
|
||||||
colors = np.empty((len(data), 4))
|
colors = np.empty((len(data), 4))
|
||||||
default = np.array(fn.colorTuple(self['Default'])) / 255.
|
default = np.array(self['Default'].getRgbF())
|
||||||
colors[:] = default
|
colors[:] = default
|
||||||
|
|
||||||
for v in self.param('Values'):
|
for v in self.param('Values'):
|
||||||
mask = data == v.maskValue
|
mask = data == v.maskValue
|
||||||
c = np.array(fn.colorTuple(v.value())) / 255.
|
c = np.array(v.value().getRgbF())
|
||||||
colors[mask] = c
|
colors[mask] = c
|
||||||
#scaled = np.clip((data-self['Min']) / (self['Max']-self['Min']), 0, 1)
|
#scaled = np.clip((data-self['Min']) / (self['Max']-self['Min']), 0, 1)
|
||||||
#cmap = self.value()
|
#cmap = self.value()
|
||||||
|
@ -267,7 +267,7 @@ class EnumColorMapItem(ptree.types.GroupParameter):
|
||||||
|
|
||||||
#mask = np.isnan(data) | np.isinf(data)
|
#mask = np.isnan(data) | np.isinf(data)
|
||||||
#nanColor = self['NaN']
|
#nanColor = self['NaN']
|
||||||
#nanColor = (nanColor.red()/255., nanColor.green()/255., nanColor.blue()/255., nanColor.alpha()/255.)
|
#nanColor = nanColor.getRgbF()
|
||||||
#colors[mask] = nanColor
|
#colors[mask] = nanColor
|
||||||
|
|
||||||
return colors
|
return colors
|
||||||
|
|
Loading…
Reference in New Issue