Fix HistogramLUTWidget with background parameter (#953)

* Fix HistogramLUTWidget with background parameter

HistogramLUTWidget cannot be initialized with the `background` parameter, because all parameters are also passed to the constructor of HistogramLUTItem which does not have a `background` parameter. This pull request fixes that issue by defining `background` explicitly as parameter in the function header.

Closes #175

* Added test for HistogramLUTWidget initialization with background

* Fixed Python2 compatibility

* Do not pg.exit() after test

* Moved test_histogramlutwidget to widget tests
This commit is contained in:
2xB 2019-09-27 22:02:54 +02:00 committed by Ogi Moore
parent aa3a5d3995
commit 96a4270a30
2 changed files with 45 additions and 1 deletions

View File

@ -13,7 +13,7 @@ __all__ = ['HistogramLUTWidget']
class HistogramLUTWidget(GraphicsView):
def __init__(self, parent=None, *args, **kargs):
background = kargs.get('background', 'default')
background = kargs.pop('background', 'default')
GraphicsView.__init__(self, parent, useOpenGL=False, background=background)
self.item = HistogramLUTItem(*args, **kargs)
self.setCentralItem(self.item)

View File

@ -0,0 +1,44 @@
"""
HistogramLUTWidget test:
Tests the creation of a HistogramLUTWidget.
"""
import pyqtgraph as pg
from pyqtgraph.Qt import QtGui
import numpy as np
def testHistogramLUTWidget():
pg.mkQApp()
win = QtGui.QMainWindow()
win.show()
cw = QtGui.QWidget()
win.setCentralWidget(cw)
l = QtGui.QGridLayout()
cw.setLayout(l)
l.setSpacing(0)
v = pg.GraphicsView()
vb = pg.ViewBox()
vb.setAspectLocked()
v.setCentralItem(vb)
l.addWidget(v, 0, 0, 3, 1)
w = pg.HistogramLUTWidget(background='w')
l.addWidget(w, 0, 1)
data = pg.gaussianFilter(np.random.normal(size=(256, 256, 3)), (20, 20, 0))
for i in range(32):
for j in range(32):
data[i*8, j*8] += .1
img = pg.ImageItem(data)
vb.addItem(img)
vb.autoRange()
w.setImageItem(img)
QtGui.QApplication.processEvents()