Skip to content

Commit 1001b70

Browse files
committed
Fix contrast panel: clean up histogram when the image is removed from plot
1 parent f303630 commit 1001b70

File tree

3 files changed

+66
-22
lines changed

3 files changed

+66
-22
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# Changelog #
22

3+
## Version 2.4.1 ##
4+
5+
In this release, test coverage is 79%.
6+
7+
🛠️ Bug fixes:
8+
9+
* Contrast adjustment panel:
10+
* A regression was introduced in V2.0.0: levels histogram was no longer removed from
11+
contrast adjustment panel when the associated image was removed from the plot
12+
* This is now fixed: when an image is removed, the histogram is removed as well and
13+
the contrast panel is refreshed (which was not the case even before the regression)
14+
315
## Version 2.4.0 ##
416

517
In this release, test coverage is 79%.

plotpy/panels/contrastadjustment.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,14 +210,18 @@ def item_removed(self, item: BaseImageItem) -> None:
210210
Args:
211211
item: item which was removed
212212
"""
213-
for _plot, items in list(self._tracked_items.items()):
214-
if item in items:
213+
replot = False
214+
for _plot, items_dict in list(self._tracked_items.items()):
215+
if item in items_dict:
215216
try:
216-
self.del_item(item)
217+
self.del_item(items_dict[item])
218+
replot = True
217219
except ValueError:
218220
pass # Histogram has not yet been created
219-
items.pop(item)
221+
items_dict.pop(item)
220222
break
223+
if replot:
224+
self.replot()
221225

222226
def active_item_changed(self, plot: BasePlot) -> None:
223227
"""Active item changed callback

plotpy/tests/features/test_contrast.py

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,39 @@
1515

1616
from plotpy.builder import make
1717
from plotpy.tests import get_path
18+
from plotpy.tests.data import gen_image1
1819

1920

20-
def test_contrast():
21-
"""Test"""
22-
# -- Create QApplication
21+
def __create_dialog_with_contrast(item):
22+
"""Create plot dialog with contrast panel
23+
24+
Args:
25+
Item: item to be added to the plot
26+
"""
27+
win = make.dialog(
28+
edit=False,
29+
toolbar=True,
30+
wintitle="Contrast test",
31+
show_contrast=True,
32+
type="image",
33+
)
34+
plot = win.get_plot()
35+
plot.add_item(item)
36+
plot.set_active_item(item)
37+
item.unselect()
38+
win.resize(600, 600)
39+
win.show()
40+
return win
41+
42+
43+
def test_contrast1():
44+
"""Contrast test 1"""
2345
with qt_app_context(exec_loop=True):
24-
filename = get_path("brain.png")
25-
image = make.image(filename=filename, title="Original", colormap="gray")
26-
win = make.dialog(
27-
edit=False,
28-
toolbar=True,
29-
wintitle="Contrast test",
30-
show_contrast=True,
31-
type="image",
32-
)
33-
plot = win.manager.get_plot()
34-
plot.add_item(image)
35-
win.resize(600, 600)
36-
win.show()
46+
item = make.image(filename=get_path("brain.png"), colormap="gray")
47+
win = __create_dialog_with_contrast(item)
3748
fname = "contrast.png"
3849
try:
39-
plot.save_widget(fname)
50+
win.get_plot().save_widget(fname)
4051
except IOError:
4152
# Skipping this part of the test
4253
# because user has no write permission on current directory
@@ -45,5 +56,22 @@ def test_contrast():
4556
os.unlink(fname)
4657

4758

59+
def test_contrast2():
60+
"""Contrast test 2
61+
62+
Test if level histogram is really removed when the associated image is removed from
63+
the plot (the validation is not automatic)
64+
"""
65+
with qt_app_context(exec_loop=True):
66+
item1 = make.image(filename=get_path("brain.png"), colormap="gray")
67+
win = __create_dialog_with_contrast(item1)
68+
plot = win.get_plot()
69+
plot.del_item(item1)
70+
item2 = make.image(gen_image1())
71+
plot.add_item(item2)
72+
plot.set_active_item(item2)
73+
74+
4875
if __name__ == "__main__":
49-
test_contrast()
76+
# test_contrast1()
77+
test_contrast2()

0 commit comments

Comments
 (0)