Skip to content

Commit 9f8d9ce

Browse files
committed
Edit tools (edit data, parameters, ...): excluding read-only items
1 parent 0ff3c05 commit 9f8d9ce

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
* This signal is emitted when the parameters of an item are changed using the parameters dialog, or a specific tool (e.g. the colormap selection tool, or the lock/unlock tool for image items)
2323
* The signal is emitted with the item as argument
2424
* The `ItemListWidget` now listens to this signal and refreshes the item list accordingly
25+
* Edit tools (Edit data, parameters, etc.):
26+
* Exclude read-only items from the list of editable items
27+
* It is no longer possible to edit parameters or data of read-only items
2528

2629
Other changes:
2730

plotpy/plot/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1812,7 +1812,8 @@ def get_plot_parameters_status(self, key: str) -> bool:
18121812
bool: True if the plot parameters are available
18131813
"""
18141814
if key == "item":
1815-
return self.get_active_item() is not None
1815+
item = self.get_active_item()
1816+
return item is not None and not item.is_readonly()
18161817
else:
18171818
return True
18181819

plotpy/tools/item.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,20 @@ def __init__(self, manager, toolbar_id: str | type[DefaultToolbarID] | None = No
131131
manager, toolbar_id, curve_func=edit_curve_data, image_func=edit_image_data
132132
)
133133

134+
def get_supported_items(self, plot: BasePlot) -> list:
135+
"""
136+
Get supported items from the plot.
137+
138+
Args:
139+
plot: Plot instance
140+
141+
Returns:
142+
List of supported plot items
143+
"""
144+
items = super().get_supported_items(plot)
145+
# Read-only items are not editable, obviously
146+
return [item for item in items if not item.is_readonly()]
147+
134148

135149
class ExportItemDataTool(ItemManipulationBaseTool):
136150
"""Tool for exporting item data."""
@@ -189,10 +203,11 @@ def get_supported_items(self, plot: BasePlot) -> list:
189203
AnnotatedCircle,
190204
AnnotatedPolygon,
191205
)
206+
# Read-only items are not editable, obviously
192207
return [
193208
item
194209
for item in plot.get_selected_items(z_sorted=True)
195-
if isinstance(item, item_types)
210+
if isinstance(item, item_types) and not item.is_readonly()
196211
]
197212

198213
def update_status(self, plot: BasePlot) -> None:
@@ -233,15 +248,15 @@ def __init__(self, manager, toolbar_id: str | type[DefaultToolbarID] | None = No
233248
"""
234249
super().__init__(manager, _("Remove"), "trash.png", toolbar_id=toolbar_id)
235250

236-
def get_removable_items(self, plot: BasePlot) -> list:
251+
def get_supported_items(self, plot: BasePlot) -> list:
237252
"""
238-
Get removable items from the plot.
253+
Get supported items from the plot.
239254
240255
Args:
241256
plot: Plot instance
242257
243258
Returns:
244-
List of removable plot items
259+
List of supported plot items
245260
"""
246261
return [item for item in plot.get_selected_items() if not item.is_readonly()]
247262

@@ -252,7 +267,7 @@ def update_status(self, plot: BasePlot) -> None:
252267
Args:
253268
plot: Plot instance
254269
"""
255-
self.action.setEnabled(len(self.get_removable_items(plot)) > 0)
270+
self.action.setEnabled(len(self.get_supported_items(plot)) > 0)
256271

257272
def activate_command(self, plot: BasePlot, checked: bool) -> None:
258273
"""
@@ -262,7 +277,7 @@ def activate_command(self, plot: BasePlot, checked: bool) -> None:
262277
plot: Plot instance
263278
checked: Whether the tool is checked
264279
"""
265-
items = self.get_removable_items(plot)
280+
items = self.get_supported_items(plot)
266281
if len(items) == 1:
267282
message = _("Do you really want to remove this item?")
268283
else:

0 commit comments

Comments
 (0)