Skip to content

Commit 945b45f

Browse files
committed
Add "Rename" context menu entry in item list
1 parent 9f8d9ce commit 945b45f

File tree

6 files changed

+63
-13
lines changed

6 files changed

+63
-13
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
# Changelog #
22

3-
## Version 2.7.5 ##
3+
## Version 2.8.0 ##
44

55
💥 New features / Enhancements:
66

77
* [Issue #45](https://github.com/PlotPyStack/PlotPy/issues/45) - Add support for new curve Y-range cursor tool `YRangeCursorTool`:
88
* This tool is similar to the existing `CurveStatsTool`, but it simply shows the Y-range values (min, max and interval).
99
* It can be added to the plot widget using `plot_widget.manager.add_tool(YRangeCursorTool)`
1010
* Update color configurations defaults for improved visibility
11+
* Item list:
12+
* Added a new "Rename" context menu entry to rename the selected item
13+
* This entry is only available for editable items
1114

1215
🛠️ Bug fixes:
1316

plotpy/locale/fr/LC_MESSAGES/plotpy.po

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ msgid ""
66
msgstr ""
77
"Project-Id-Version: plotpy 2.7.4\n"
88
"Report-Msgid-Bugs-To: p.raybaut@codra.fr\n"
9-
"POT-Creation-Date: 2025-07-06 14:53+0200\n"
9+
"POT-Creation-Date: 2025-07-27 15:03+0200\n"
1010
"PO-Revision-Date: 2025-06-02 11:14+0200\n"
1111
"Last-Translator: Christophe Debonnel <c.debonnel@codra.fr>\n"
1212
"Language: fr\n"
@@ -282,6 +282,9 @@ msgstr ""
282282
"\n"
283283
"Note : la LUT est codée sur 1024 niveaux (0...1023)"
284284

285+
msgid "Rename"
286+
msgstr "Renommer"
287+
285288
msgid "Move to back"
286289
msgstr "Déplacer vers l'arrière-plan"
287290

@@ -294,6 +297,9 @@ msgstr "Supprimer"
294297
msgid "Axes associated to selected item"
295298
msgstr "Axes associés à l'objet sélectionné"
296299

300+
msgid "New title:"
301+
msgstr "Nouveau titre :"
302+
297303
msgid "Do you really want to remove this item?"
298304
msgstr "Souhaitez-vous vraiment supprimer cet objet ?"
299305

@@ -1678,4 +1684,3 @@ msgstr "Rotation et rognage"
16781684

16791685
msgid "Show cropping rectangle"
16801686
msgstr "Afficher le rectangle de rognage"
1681-

plotpy/locale/plotpy.pot

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ msgid ""
77
msgstr ""
88
"Project-Id-Version: plotpy VERSION\n"
99
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
10-
"POT-Creation-Date: 2025-07-06 14:53+0200\n"
10+
"POT-Creation-Date: 2025-07-27 15:03+0200\n"
1111
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1212
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1313
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -273,6 +273,9 @@ msgid ""
273273
"Note: LUT is coded over 1024 levels (0...1023)"
274274
msgstr ""
275275

276+
msgid "Rename"
277+
msgstr ""
278+
276279
msgid "Move to back"
277280
msgstr ""
278281

@@ -285,6 +288,9 @@ msgstr ""
285288
msgid "Axes associated to selected item"
286289
msgstr ""
287290

291+
msgid "New title:"
292+
msgstr ""
293+
288294
msgid "Do you really want to remove this item?"
289295
msgstr ""
290296

plotpy/panels/itemlist.py

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ def contextMenuEvent(self, event: QContextMenuEvent) -> None:
8282

8383
def setup_actions(self) -> None:
8484
"""Setup actions"""
85+
self.rename_ac = create_action(
86+
self,
87+
_("Rename"),
88+
icon=get_icon("rename.png"),
89+
triggered=self.rename_item,
90+
shortcut="F2",
91+
)
8592
self.movedown_ac = create_action(
8693
self,
8794
_("Move to back"),
@@ -94,7 +101,7 @@ def setup_actions(self) -> None:
94101
icon=get_icon("arrow_up.png"),
95102
triggered=lambda: self.move_item("up"),
96103
)
97-
settings_ac = create_action(
104+
self.settings_ac = create_action(
98105
self,
99106
_("Parameters..."),
100107
icon=get_icon("settings.png"),
@@ -103,7 +110,14 @@ def setup_actions(self) -> None:
103110
self.remove_ac = create_action(
104111
self, _("Remove"), icon=get_icon("trash.png"), triggered=self.remove_item
105112
)
106-
return [self.moveup_ac, self.movedown_ac, None, settings_ac, self.remove_ac]
113+
return [
114+
self.rename_ac,
115+
self.moveup_ac,
116+
self.movedown_ac,
117+
None,
118+
self.settings_ac,
119+
self.remove_ac,
120+
]
107121

108122
def edit_plot_parameters(self) -> None:
109123
"""Edit plot parameters"""
@@ -162,12 +176,14 @@ def refresh_actions(self) -> None:
162176
if action is not None:
163177
action.setEnabled(is_selection)
164178
if is_selection:
165-
remove_state = True
179+
editable_state = True
166180
for item in self.get_selected_items():
167-
remove_state = remove_state and not item.is_readonly()
168-
self.remove_ac.setEnabled(remove_state)
181+
editable_state = editable_state and not item.is_readonly()
182+
self.remove_ac.setEnabled(editable_state)
169183
for action in [self.moveup_ac, self.movedown_ac]:
170184
action.setEnabled(self.__is_selection_contiguous())
185+
self.rename_ac.setEnabled(editable_state and len(self.selectedItems()) == 1)
186+
self.settings_ac.setEnabled(editable_state)
171187

172188
def __get_item_icon(self, item: itf.IBasePlotItem) -> QIcon:
173189
"""Get item icon"""
@@ -272,6 +288,18 @@ def item_changed(self, listwidgetitem: QListWidgetItem) -> None:
272288
if visible != item.isVisible():
273289
self.plot.set_item_visible(item, visible)
274290

291+
def rename_item(self) -> None:
292+
"""Rename item"""
293+
item = self.get_selected_items()[0]
294+
title = item.title().text()
295+
new_title, ok = QW.QInputDialog.getText(
296+
self, _("Rename"), _("New title:"), text=title
297+
)
298+
if ok and new_title != title:
299+
item.setTitle(new_title)
300+
self.plot.replot()
301+
self.items_changed(self.plot)
302+
275303
def move_item(self, direction: str) -> None:
276304
"""Move item to the background/foreground
277305
Works only for contiguous selection

plotpy/tests/items/test_curves.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ def test_plot():
2424
with qt_app_context(exec_loop=True):
2525
items = [
2626
make.curve(x, y, color="b"),
27-
make.curve(x2, y2, color="g", curvestyle="Sticks", title="toto"),
28-
make.curve(x, np.sin(2 * y), color="r"),
27+
curve1 := make.curve(x2, y2, color="g", title="Readonly"),
28+
curve2 := make.curve(x, np.sin(2 * y), color="r", title="Private"),
2929
make.merror(x, y / 2, dy),
3030
make.label(
3131
"Relative position <b>outside</b>", (x[0], y[0]), (-10, -10), "BR"
@@ -40,8 +40,14 @@ def test_plot():
4040
movable=False,
4141
),
4242
]
43+
curve1.set_readonly(True)
44+
curve2.set_private(True)
4345
_win = ptv.show_items(
44-
items, wintitle=test_plot.__doc__, title="Curves", plot_type="curve"
46+
items,
47+
wintitle=test_plot.__doc__,
48+
title="Curves",
49+
plot_type="curve",
50+
disable_readonly_for_items=False,
4551
)
4652

4753

plotpy/tests/vistools.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def show_items(
2929
show_itemlist: bool = True,
3030
show_contrast: bool = False,
3131
winsize: tuple[int, int] | None = None,
32+
disable_readonly_for_items: bool = True,
3233
) -> PlotDialog:
3334
"""Show plot items in a dialog box"""
3435
winsize = (640, 480) if winsize is None else winsize
@@ -50,6 +51,7 @@ def show_items(
5051
plot = win.manager.get_plot()
5152
for item in items:
5253
plot.add_item(item)
53-
plot.set_items_readonly(False)
54+
if disable_readonly_for_items:
55+
plot.set_items_readonly(False)
5456
win.show()
5557
return win

0 commit comments

Comments
 (0)