Skip to content

Commit

Permalink
Toggle all polygons menu with shortcuts
Browse files Browse the repository at this point in the history
(cherry picked from commit 46311d5)
  • Loading branch information
Michael Litvin authored and wkentaro committed Dec 30, 2023
1 parent 7328a7c commit 11c4fcd
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
18 changes: 16 additions & 2 deletions labelme/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,17 +460,27 @@ def __init__(
hideAll = action(
self.tr("&Hide\nPolygons"),
functools.partial(self.togglePolygons, False),
shortcuts["hide_all_polygons"],
icon="eye",
tip=self.tr("Hide all polygons"),
enabled=False,
)
showAll = action(
self.tr("&Show\nPolygons"),
functools.partial(self.togglePolygons, True),
shortcuts["show_all_polygons"],
icon="eye",
tip=self.tr("Show all polygons"),
enabled=False,
)
toggleAll = action(
self.tr("&Toggle\nPolygons"),
functools.partial(self.togglePolygons, None),
shortcuts["toggle_all_polygons"],
icon="eye",
tip=self.tr("Toggle all polygons"),
enabled=False,
)

help = action(
self.tr("&Tutorial"),
Expand Down Expand Up @@ -692,7 +702,7 @@ def __init__(
editMode,
brightnessContrast,
),
onShapesPresent=(saveAs, hideAll, showAll),
onShapesPresent=(saveAs, hideAll, showAll, toggleAll),
)

self.canvas.vertexSelected.connect(self.actions.removePoint.setEnabled)
Expand Down Expand Up @@ -738,6 +748,7 @@ def __init__(
None,
hideAll,
showAll,
toggleAll,
None,
zoomIn,
zoomOut,
Expand Down Expand Up @@ -1496,8 +1507,11 @@ def brightnessContrast(self, value):
self.brightnessContrast_values[self.filename] = (brightness, contrast)

def togglePolygons(self, value):
flag = value
for item in self.labelList:
item.setCheckState(Qt.Checked if value else Qt.Unchecked)
if value is None:
flag = (item.checkState() == Qt.Unchecked)
item.setCheckState(Qt.Checked if flag else Qt.Unchecked)

def loadFile(self, filename=None):
"""Load the specified file, or the last opened file if None."""
Expand Down
4 changes: 4 additions & 0 deletions labelme/config/default_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,7 @@ shortcuts:
edit_label: Ctrl+E
toggle_keep_prev_mode: Ctrl+P
remove_selected_point: [Meta+H, Backspace]

show_all_polygons: G
hide_all_polygons: H
toggle_all_polygons: T
11 changes: 11 additions & 0 deletions labelme/translate/empty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,17 @@ Polygons</source>
<source>Show all polygons</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../app.py" line="329"/>
<source>&amp;Toggle
Polygons</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../app.py" line="329"/>
<source>Toggle all polygons</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../app.py" line="331"/>
<source>&amp;Tutorial</source>
Expand Down
11 changes: 11 additions & 0 deletions labelme/translate/zh_CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,17 @@ Polygons</source>
<source>Show all polygons</source>
<translation>显示所有多边形</translation>
</message>
<message>
<location filename="../app.py" line="329"/>
<source>&amp;Toggle
Polygons</source>
<translation>开关多边形(&amp;S)</translation>
</message>
<message>
<location filename="../app.py" line="329"/>
<source>Toggle all polygons</source>
<translation>开关所有多边形</translation>
</message>
<message>
<location filename="../app.py" line="331"/>
<source>&amp;Tutorial</source>
Expand Down

0 comments on commit 11c4fcd

Please sign in to comment.