Skip to content

Commit 5709374

Browse files
committed
Add SIG_ITEM_PARAMETERS_CHANGED signal to BasePlot class
1 parent 7bd1454 commit 5709374

6 files changed

Lines changed: 31 additions & 7 deletions

File tree

CHANGELOG.md

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

3+
## Version 2.2.0 ##
4+
5+
New features:
6+
7+
* Added `SIG_ITEM_PARAMETERS_CHANGED` signal to `BasePlot` class:
8+
* This signal is emitted when the parameters of an item are changed using the
9+
parameters dialog, or a specific tool (e.g. the colormap selection tool,
10+
or the lock/unlock tool for image items)
11+
* This signal is emitted with the item as argument
12+
* It is often emitted before the `SIG_ITEMS_CHANGED` signal, which is global to all
13+
items, but not necessarily. For example, when the colormap of an image is changed,
14+
the `SIG_ITEM_PARAMETERS_CHANGED` signal is emitted for the image item, but the
15+
`SIG_ITEMS_CHANGED` signal is not emitted.
16+
317
## Version 2.1.2 ##
418

519
New features:

doc/features/signals.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Signals emitted by :py:class:`.BasePlot` objects:
2424
- :py:attr:`.BasePlot.SIG_ANNOTATION_CHANGED`
2525
- :py:attr:`.BasePlot.SIG_RANGE_CHANGED`
2626
- :py:attr:`.BasePlot.SIG_ITEMS_CHANGED`
27+
- :py:attr:`.BasePlot.SIG_ITEM_PARAMETERS_CHANGED`
2728
- :py:attr:`.BasePlot.SIG_ACTIVE_ITEM_CHANGED`
2829
- :py:attr:`.BasePlot.SIG_ITEM_REMOVED`
2930
- :py:attr:`.BasePlot.SIG_ITEM_SELECTION_CHANGED`

plotpy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
.. _GitHub: https://github.com/PierreRaybaut/plotpy
2121
"""
2222

23-
__version__ = "2.1.2"
23+
__version__ = "2.2.0"
2424
__VERSION__ = tuple([int(number) for number in __version__.split(".")])
2525

2626
# --- Important note: DATAPATH and LOCALEPATH are used by guidata.configtools

plotpy/plot/base.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,13 @@ class BasePlot(qwt.QwtPlot):
229229
#: plot: the plot
230230
SIG_ITEMS_CHANGED = QC.Signal(object)
231231

232+
#: Signal emitted by plot when item parameters have changed (through the item's
233+
#: parameters dialog, or when setting colormap using the dedicated tool)
234+
#:
235+
#: Args:
236+
#: item: the item
237+
SIG_ITEM_PARAMETERS_CHANGED = QC.Signal(object)
238+
232239
#: Signal emitted by plot when selected item has changed
233240
#:
234241
#: Args:

plotpy/styles/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ def update(self, plot: BasePlot) -> None:
274274
"""
275275
for item in self.items:
276276
item.set_item_parameters(self)
277+
plot.SIG_ITEM_PARAMETERS_CHANGED.emit(item)
277278
plot.replot()
278279
plot.SIG_ITEMS_CHANGED.emit(plot)
279280

plotpy/tools/image.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ class ReverseYAxisTool(ToggleTool):
285285
def __init__(self, manager: PlotManager) -> None:
286286
super().__init__(manager, _("Reverse Y axis"))
287287

288-
def activate_command(self, plot: PlotManager, checked: bool) -> None:
288+
def activate_command(self, plot: BasePlot, checked: bool) -> None:
289289
"""Triggers tool action.
290290
291291
Args:
@@ -295,7 +295,7 @@ def activate_command(self, plot: PlotManager, checked: bool) -> None:
295295
plot.set_axis_direction("left", checked)
296296
plot.replot()
297297

298-
def update_status(self, plot: PlotManager) -> None:
298+
def update_status(self, plot: BasePlot) -> None:
299299
"""Update tool status if the plot type is not PlotType.CURVE.
300300
301301
Args:
@@ -346,7 +346,7 @@ def set_aspect_ratio_1_1(self) -> None:
346346
plot.set_aspect_ratio(ratio=1)
347347
plot.replot()
348348

349-
def activate_command(self, plot: PlotManager, checked: bool) -> None:
349+
def activate_command(self, plot: BasePlot, checked: bool) -> None:
350350
"""Triggers tool action.
351351
352352
Args:
@@ -499,16 +499,16 @@ def activate_cmap(self, cmap: str | EditableColormap) -> None:
499499
self._active_colormap = get_cmap(cmap)
500500
else:
501501
self._active_colormap = cmap
502-
plot = self.get_active_plot()
502+
plot: BasePlot = self.get_active_plot()
503503
if self._active_colormap is not None and plot is not None:
504504
items = self.get_selected_images(plot)
505505
for item in items:
506506
item.param.colormap = self._active_colormap.name
507507
item.param.update_item(item)
508+
plot.SIG_ITEM_PARAMETERS_CHANGED.emit(item)
508509
self.action.setText(_("Colormap: %s") % self._active_colormap.name)
509510
plot.invalidate()
510511
self.update_status(plot)
511-
plot.SIG_ITEMS_CHANGED.emit(plot)
512512

513513
def update_status(self, plot: BasePlot) -> None:
514514
"""Update tool status if the plot type is not PlotType.CURVE.
@@ -825,7 +825,7 @@ def __init__(self, manager: PlotManager, toolbar_id=None) -> None:
825825
manager, title=_("Lock"), icon=get_icon("lock.png"), toolbar_id=None
826826
)
827827

828-
def activate_command(self, plot: PlotManager, checked: bool) -> None:
828+
def activate_command(self, plot: BasePlot, checked: bool) -> None:
829829
"""Trigger tool action.
830830
831831
Args:
@@ -840,6 +840,7 @@ def activate_command(self, plot: PlotManager, checked: bool) -> None:
840840
item.setIcon(get_icon("trimage_lock.png"))
841841
else:
842842
item.setIcon(get_icon("image.png"))
843+
plot.SIG_ITEM_PARAMETERS_CHANGED.emit(item)
843844
plot.SIG_ITEMS_CHANGED.emit(plot)
844845

845846
def get_supported_items(self, plot: BasePlot) -> list[IBasePlotItem | TrImageItem]:

0 commit comments

Comments
 (0)