From 96a4270a30b0fb273b1ae916a7ab9373ced77690 Mon Sep 17 00:00:00 2001 From: 2xB <31772910+2xB@users.noreply.github.com> Date: Fri, 27 Sep 2019 22:02:54 +0200 Subject: [PATCH] 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 --- pyqtgraph/widgets/HistogramLUTWidget.py | 2 +- .../widgets/tests/test_histogramlutwidget.py | 44 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 pyqtgraph/widgets/tests/test_histogramlutwidget.py diff --git a/pyqtgraph/widgets/HistogramLUTWidget.py b/pyqtgraph/widgets/HistogramLUTWidget.py index 9aec837c..5259900c 100644 --- a/pyqtgraph/widgets/HistogramLUTWidget.py +++ b/pyqtgraph/widgets/HistogramLUTWidget.py @@ -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) diff --git a/pyqtgraph/widgets/tests/test_histogramlutwidget.py b/pyqtgraph/widgets/tests/test_histogramlutwidget.py new file mode 100644 index 00000000..f8a381a7 --- /dev/null +++ b/pyqtgraph/widgets/tests/test_histogramlutwidget.py @@ -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() +